我试图弄清楚为什么修改后的 C 程序比未修改的对应部分运行得更快(我添加了很少的代码行来执行一些额外的工作)。在这种情况下,我怀疑“缓存效果”是主要的解释(指令缓存)。因此,我访问了perf
(https://perf.wiki.kernel.org/index.php/Main_Page)分析工具,但不幸的是我无法理解其关于缓存未命中的输出的含义。
提供了几个关于缓存的事件:
cache-references [Hardware event]
cache-misses [Hardware event]
L1-dcache-loads [Hardware cache event]
L1-dcache-load-misses [Hardware cache event]
L1-dcache-stores [Hardware cache event]
L1-dcache-store-misses [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-dcache-prefetch-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-prefetches [Hardware cache event]
L1-icache-prefetch-misses [Hardware cache event]
LLC-loads [Hardware cache event]
LLC-load-misses [Hardware cache event]
LLC-stores [Hardware cache event]
LLC-store-misses [Hardware cache event]
LLC-prefetches [Hardware cache event]
LLC-prefetch-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-stores [Hardware cache event]
dTLB-store-misses [Hardware cache event]
dTLB-prefetches [Hardware cache event]
dTLB-prefetch-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
node-loads [Hardware cache event]
node-load-misses [Hardware cache event]
node-stores [Hardware cache event]
node-store-misses [Hardware cache event]
node-prefetches [Hardware cache event]
node-prefetch-misses [Hardware cache event]
我在哪里可以找到有关这些字段的说明?cache-misses 事件总是小于其他事件。本次活动衡量什么?
如何解释 ls 的 26,760 个 L1-icache-load-misses 与以下示例中的 5,708 个缓存未命中?
perf stat -e L1-icache-load-misses ls
caches caches~ out
Performance counter stats for 'ls':
26,760 L1-icache-load-misses
0.002816690 seconds time elapsed
perf stat -e cache-misses ls
caches caches~ out
Performance counter stats for 'ls':
5,708 cache-misses
0.002822122 seconds time elapsed