根据perf教程,
perf stat
应使用硬件计数器报告缓存未命中情况。然而,在我的系统上(最新的Arch Linux),它没有这样做:[joel@panda goog]$ perf stat ./hash
Performance counter stats for './hash':
869.447863 task-clock # 0.997 CPUs utilized
92 context-switches # 0.106 K/sec
4 cpu-migrations # 0.005 K/sec
1,041 page-faults # 0.001 M/sec
2,628,646,296 cycles # 3.023 GHz
819,269,992 stalled-cycles-frontend # 31.17% frontend cycles idle
132,355,435 stalled-cycles-backend # 5.04% backend cycles idle
4,515,152,198 instructions # 1.72 insns per cycle
# 0.18 stalled cycles per insn
1,060,739,808 branches # 1220.015 M/sec
2,653,157 branch-misses # 0.25% of all branches
0.871766141 seconds time elapsed
我错过了什么?我已经搜索了手册和网络,但没有找到明显的答案。
编辑:我的 CPU 是英特尔 i5 2300K,如果这有关系。
perf
,但我使用过PAPI
(http://icl.cs.utk.edu/PAPI/),可以检查可用的硬件计数器,以了解您的CPU可以获得什么。 - SamGamgeeperf stat -d
命令,它会报告一些缓存事件。同时查看新的perf mem
工具,可以记录/报告内存事件,文档在http://www.linuxtag.org/2013/fileadmin/www.linuxtag.org/slides/Arnaldo_Melo_-_Linux__perf__tools__Overview_and_Current_Developments.e323.pdf(第10页)和http://man7.org/linux/man-pages/man1/perf-mem.1.html。 - osgxperf stat -d
会打开事件多路复用,有时可能会报告不正确的速率。最好每次手动选择不超过5-7个硬件事件,并仅使用perf stat -d获取此类事件的名称。Intel的另一种方法是尝试来自https://github.com/andikleen/pmu-tools的toplev.py。 - osgx