我试图使用perf分析一个具有用户空间和内核空间代码的应用程序。我尝试了所有其他的支持各种内核配置的可能性,但是我无法获得仅在userspace/核空间中的指令/周期计数。我尝试使用":u“和":k扩展的指令和循环计数,但我得到的答复是
$ perf stat -e cycles:u,instructions:u ls
Performance counter stats for 'ls':
<not supported> cycles:u
<not supported> instructions:u
0.006047045 seconds time elapsed
0.000000000 seconds user
0.008098000 seconds sys但是,只运行循环/指令就会得到如下所示的适当结果。
$ perf stat -e cycles,instructions ls
Performance counter stats for 'ls':
5362086 cycles
528783 instructions # 0.10 insn per cycle
0.005487940 seconds time elapsed
0.007800000 seconds user
0.000000000 seconds sys注意: ls只是作为一个例子来突出这个问题。
我正在运行Linux5.4和perf版本5.4.77.g1206eede9156。我在手臂板上运行上面的命令。下面是我在Linux内核中启用的配置
CONFIG_PERF_EVENTS=y
CONFIG_PROFILING=y
CONFIG_TRACEPOINTS=y
CONFIG_KPROBES=y
CONFIG_OPTPROBES=y
CONFIG_KPROBES_ON_FTRACE=y
CONFIG_UPROBES=y
CONFIG_HAVE_KPROBES=y
CONFIG_HAVE_KRETPROBES=y
CONFIG_HAVE_OPTPROBES=y
CONFIG_HAVE_KPROBES_ON_FTRACE=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_INFO_DWARF4=y
CONFIG_FRAME_POINTER=y
CONFIG_FTRACE=y
CONFIG_KPROBE_EVENTS=y
CONFIG_UPROBE_EVENTS=y
CONFIG_PROBE_EVENTS=y此外,命令行上的perf列表还列出了硬件/软件事件等。
$ perf list
branch-instructions OR branches [Hardware event]
branch-misses [Hardware event]
cache-misses [Hardware event]
cache-references [Hardware event]
cpu-cycles OR cycles [Hardware event]
instructions [Hardware event]
alignment-faults [Software event]
bpf-output [Software event]
context-switches OR cs [Software event]
cpu-clock [Software event]
cpu-migrations OR migrations [Software event]
dummy [Software event]
emulation-faults [Software event]
major-faults [Software event]
minor-faults [Software event]
page-faults OR faults [Software event]
task-clock [Software event]
duration_time [Tool 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]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-store-misses [Hardware cache event]
iTLB-load-misses [Hardware cache event]请建议如何解决这个问题。我做错什么了吗?
发布于 2021-10-15 09:24:26
为我工作,444,022 cycles:u为perf stat -e cycles:u ls工作。perf版本5.13.g62fb9874f5da,Linux5.12.15-arch1-1,裸金属(x86-64-Skylake),带有perf_event_paranoid=0。
(使用现代perf,您还可以使用perf stat --all-user来暗示所有事件的:u。)
我猜您的ARM CPU的硬件perf计数器不支持使用特权级别的掩码进行编程,因此perf报告说没有硬件计数器可以只计算用户空间指令。
AFAIK,并不是每个中断入口点都有钩子来启用/禁用HW计数器;仅计算内核,只有用户,或者两者都是硬件特性。
HW支持显然是精确计数的关键,因为在软件实现中,计数器仍然在计数,直到内核代码运行到保存了当前计数的内核代码为止。(以及在还原状态之后、返回到用户空间之前的内核代码。)而且,它将使每一个中断和系统调用都变得更加昂贵,而不仅仅是通过保存/还原每个任务/线程之间的上下文切换来虚拟化perf计数器。因此,即使在没有HW支持特权掩码的CPU上,内核也有很好的理由不支持在软件中执行此操作的松散尝试。
https://stackoverflow.com/questions/69573380
复制相似问题