Perf 使用注意事项
(perf 工具的基本用法可参考官方教程,本文不再涉及。)
当前 RISC-V 对 perf 的支持涉及以下软/硬件的框架/规范:
- Linux perf 框架
- perf 框架主体
- perf 工具的 pmu-events json 文件(允许 perf 工具以名字而非 raw 编码指定硬件平台所支持的特定事件)
- SBI PMU Extension
- RISC-V 硬件规范
- RISC-V ISA Privileged Specification 中定义的 HPM(Hardware Performance Monitor)内容
- Sscofpmf Extension
它们的关系如下:
但即使软/硬件上全都支持了以上内容,仍存在以下事项需 perf 的使用者关注:
perf list
所列出的硬件事件不一定全都可用
现象:
perf list
列出的硬件事件,并不表示当前硬件平台就全都支持这些事件。
例如,perf list
列出的硬件事件如下:
$ perf list | grep Hardware
branch-instructions OR branches [Hardware event]
branch-misses [Hardware event]
bus-cycles [Hardware event]
cache-misses [Hardware event]
cache-references [Hardware event]
cpu-cycles OR cycles [Hardware event]
instructions [Hardware event]
ref-cycles [Hardware event]
stalled-cycles-backend OR idle-cycles-backend [Hardware event]
stalled-cycles-frontend OR idle-cycles-frontend [Hardware event]
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetch-misses [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-dcache-store-misses [Hardware cache event]
L1-dcache-stores [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
L1-icache-prefetch-misses [Hardware cache event]
L1-icache-prefetches [Hardware cache event]
LLC-load-misses [Hardware cache event]
LLC-loads [Hardware cache event]
LLC-prefetch-misses [Hardware cache event]
LLC-prefetches [Hardware cache event]
LLC-store-misses [Hardware cache event]
LLC-stores [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
dTLB-prefetch-misses [Hardware cache event]
dTLB-prefetches [Hardware cache event]
dTLB-store-misses [Hardware cache event]
dTLB-stores [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
node-load-misses [Hardware cache event]
node-loads [Hardware cache event]
node-prefetch-misses [Hardware cache event]
node-prefetches [Hardware cache event]
node-store-misses [Hardware cache event]
node-stores [Hardware cache event]
但对某些事件的计数结果会显示 <not counted>
,有可能当前硬件平台不支持该事件(但也有可能是支持该事件但没统 计到计数):
$ perf stat -e cycles,branches,bus-cycles,ref-cycles ls
Performance counter stats for 'ls':
1719370 cycles
94325 branches
<not counted> bus-cycles (0.00%)
<not counted> ref-cycles (0.00%)
0.002556584 seconds time elapsed
0.002900000 seconds user
0.000000000 seconds sys