这个缓存未命中练习的答案是什么

问题描述

练习 5.
英特尔至强 X5650 处理器具有以下特点,

taken from /proc/cpuinfo:
vendor_id : GenuineIntel
cpu family : 6
model : 44
model name : Intel(R) Xeon(R) cpu X5650 @ 2.67GHz
stepping : 2
microcode : 0x1f
cpu MHz : 1600.021
L3 cache size : 12288 KB
physical id : 0
siblings : 12
core id : 0
cpu cores: 6
{...}
clflush size : 64
cache line size : 64

考虑以下两个函数,它们都将数组中的值增加 100。

void incrementVector1(INT4* v,int n) {
    for (int k = 0; k < 100; ++k) {
        for (int i = 0; i < n; ++i) {
            v[i] = v[i] + 1;
        }
    }
}

void incrementVector2(INT4* v,int n) {
    for (int i = 0; i < n; ++i) {
        for (int k = 0; k < 100; ++k) {
            v[i] = v[i] + 1;
        }
    }
}

使用 perf 实用程序收集的以下数据捕获用于执行的运行时信息 英特尔至强 X5650 处理器上的每一个功能都适用于各种数据大小。在此数据中:

• 程序vector1.bin 执行函数incrementVector1;

• 程序vector2.bin 执行函数incrementVector2;

• 程序采用一个命令行参数来设置 n 的值;

• 两个程序都首先分配一个大小为 n 的数组并将所有元素初始化为 0。

• LLC-loads 表示“最后一级缓存加载”,即访问 L3 的次数

• LLC-load-misses 表示“最后一级缓存未命中”,即 L3 缓存未命中数。


Runtime performance of vector1.bin.

Performance counter stats for ’./vector1.bin 1000000’:

230,070 LLC-loads
3,280 LLC-load-misses # 1.43% of all LL-cache references
0.383542737 seconds time elapsed

Performance counter stats for ’./vector1.bin 3000000’:

669,884 LLC-loads
242,876 LLC-load-misses # 36.26% of all LL-cache references
1.156663301 seconds time elapsed

Performance counter stats for ’./vector1.bin 5000000’:

1,234,031 LLC-loads
898,577 LLC-load-misses # 72.82% of all LL-cache references
1.941832434 seconds time elapsed

Performance counter stats for ’./vector1.bin 7000000’:

1,620,026 LLC-loads
1,142,275 LLC-load-misses # 70.51% of all LL-cache references
2.621428714 seconds time elapsed

Performance counter stats for ’./vector1.bin 9000000’:

2,068,028 LLC-loads
1,422,269 LLC-load-misses # 68.77% of all LL-cache references
3.308037628 seconds time elapsed



Runtime performance of vector2.bin.

Performance counter stats for ’./vector2.bin 1000000’:

16,464 LLC-loads
1,168 LLC-load-misses # 7.049% of all LL-cache references
0.319311959 seconds time elapsed

Performance counter stats for ’./vector2.bin 3000000’:

42,052 LLC-loads
17,027 LLC-load-misses # 40.49% of all LL-cache references
0.954854798 seconds time elapsed

Performance counter stats for ’./vector2.bin 5000000’:

63,991 LLC-loads
38,459 LLC-load-misses # 60.10% of all LL-cache references
1.593526338 seconds time elapsed

Performance counter stats for ’./vector2.bin 7000000’:

99,773 LLC-loads
56,481 LLC-load-misses # 56.61% of all LL-cache references
2.198810471 seconds time elapsed

Performance counter stats for ’./vector2.bin 9000000’:

120,456 LLC-loads
76,951 LLC-load-misses # 63.88% of all LL-cache references
2.772653964 seconds time elapsed

问题 1:考虑 vector1.bin 的缓存未命中率。矢量大小之间 1000000 和 5000000,缓存未命中率急剧增加。这是什么原因 缓存未命中率增加

问题 2:考虑两个程序的缓存未命中率。请注意,未命中率 对于任何特定的数组大小,这两个程序之间大致相等。为什么会这样?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)