【发布时间】:2017-07-28 07:43:22
【问题描述】:
我正在使用 linux perf 工具来分析 one of CRONO benchmarks,我对 L1 DCache Misses 特别感兴趣,所以我这样运行程序:
perf record -e L1-dcache-read-misses -o perf/apsp.cycles apps/apsp/apsp 4 16384 16
它运行良好,但会产生这些警告:
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,
check /proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux
file is not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved
even with a suitable vmlinux or kallsyms file.
Cannot read kernel map
Couldn't record kernel reference relocation symbol
Symbol resolution may be skewed if relocation was used (e.g. kexec).
Check /proc/kallsyms permission or run as root.
Threads Returned!
Threads Joined!
Time: 2.932636 seconds
[ perf record: Woken up 5 times to write data ]
[ perf record: Captured and wrote 1.709 MB perf/apsp.cycles (44765 samples) ]
然后我像这样注释输出文件:
perf annotate --stdio -i perf/apsp.cycles --dsos=apsp
但在其中一个代码部分,我看到了一些奇怪的结果:
Percent | Source code & Disassembly of apsp for L1-dcache-read-misses
---------------------------------------------------------------------------
: {
: if((D[W_index[v][i]] > (D[v] + W[v][i])))
19.36 : 401140: movslq (%r10,%rcx,4),%rsi
14.50 : 401144: lea (%rax,%rsi,4),%rdi
1.22 : 401148: mov (%r9,%rcx,4),%esi
5.82 : 40114c: add (%rax,%r8,4),%esi
20.02 : 401150: cmp %esi,(%rdi)
0.00 : 401152: jle 401156 <do_work(void*)+0x226>
: D[W_index[v][i]] = D[v] + W[v][i];
9.72 : 401154: mov %esi,(%rdi)
19.93 : 401156: add $0x1,%rcx
:
现在在这些结果中,为什么一些算术指令有 L1 读取未命中?此外,为什么第二条语句的指令会导致如此多的缓存未命中,即使它们应该被前一个 if 语句带入缓存? 我在这里做错了吗?我在具有 root 访问权限的另一台机器上尝试了相同的操作,它给了我类似的结果,所以我认为我上面提到的警告并没有导致这种情况。但究竟发生了什么?
【问题讨论】:
-
你能提供绝对数字吗?我认为这会很有帮助。我预计每次迭代的缓存未命中率略高于一次(D[W_index...]。Perf 可能会显示一些模糊的结果,但这种相对时间在这种情况下没有帮助。
-
@overseas 我不知道如何从性能中获取绝对数字。我用谷歌搜索了一下,我似乎找不到任何东西。如果我使用 perf list 所有列出的事件将输出百分比,就像我的问题中显示的那样。
-
在此处查看此代码:pastebin.com/nr2mHmbS 您可能还想查看
man perf_open_event。 -
要从 perf 中获取绝对数(函数中有多少样本),我们可以使用
-n选项,但它仅适用于perf report命令,not forperf annotate这就像一个错误.以-c 100000等固定事件周期重新运行perf record以获得稳定的样本数,使用perf report获取函数的样本数,然后使用perf annotate获取函数中的事件分布(100% 是总样本数当前函数)。
标签: c++ caching linux-kernel profiling perf