为什么我不能将 perf 事件修饰符与 power/energy-cores/ 一起使用

Why i can't use perf event modifiers with power/energy-cores/

我正在尝试使用事件 power/energy-cores/ 和 perf 工具在内核 space 中读取系统的功能,命令如下:

perf stat -a -e power/energy-cores/:k -I 1000 sleep 10

:k 是一个修饰符,仅在内核 space 中收集事件,如本文档 https://perf.wiki.kernel.org/index.php/Tutorial 中所述,但是当我使用此 :k 时,出现以下错误:

user@dkphome:/sys/bus/event_source/devices/cpu$ sudo perf stat -a -e
power/energy-cores/:k -I 1000 sleep 30
event syntax error: '..nergy-cores/:k'
                                   \___ parser error
Run 'perf list' for a list of valid events

  Usage: perf stat [<options>] [<command>]

     -e, --event <event>   event selector. use 'perf list' to list available events

首先我虽然这个事件不支持 :k 修饰符,但我做了其他测试,现在我认为这可能是一个错误或者我正在尝试使用错误的语法。为了测试它,我尝试了如下其他事件:

缓存未命中事件可以通过两种方式调用缓存未命中或 cpu/cache-misses/ 所以我都尝试了修饰符

user@dkphome:/sys/bus/event_source/devices/cpu$ sudo perf stat -a -e cache-misses:k -I 1000 sleep 5
#           time             counts unit events
     1.000429017            287.589      cache-misses:k                                              
     2.000828552            195.999      cache-misses:k                                              
     3.001086195            216.885      cache-misses:k                                              
     4.001438671            240.842      cache-misses:k                                              
     5.000702347            314.469      cache-misses:k                                              
user@dkphome:/sys/bus/event_source/devices/cpu$ sudo perf stat -a -e cpu/cache-misses/:k -I 1000 sleep 5
event syntax error: '..ache-misses/:k'
                                   \___ parser error
Run 'perf list' for a list of valid events

  Usage: perf stat [<options>] [<command>]

     -e, --event <event>   event selector. use 'perf list' to list available events
user@dkphome:/sys/bus/event_source/devices/cpu$ sudo perf stat -a -e cpu/cache-misses/ -I 1000 sleep 5
#           time             counts unit events
     1.000379149          1.949.866      cpu/cache-misses/                                           
     2.000628057          1.023.040      cpu/cache-misses/                                           
     3.000906500          1.284.476      cpu/cache-misses/                                           
     4.001197960            853.127      cpu/cache-misses/                                           
     5.000762257            722.242      cpu/cache-misses/ 

有人知道我如何在 power/energy-cores/ 事件中使用 :k 修饰符吗?

结果: 它在没有 : 的情况下工作,正如正确答案所指出的那样,但不幸的是,对我来说,修饰符似乎不支持它。

user@dkphome:~$ sudo perf stat -a -e power/energy-cores/k -I 1000 sleep 5
#           time             counts unit events
     1.000099515    <not supported> Joules power/energy-cores/k                                        
     2.000246523    <not supported> Joules power/energy-cores/k                                        
     3.000440743    <not supported> Joules power/energy-cores/k                                        
     4.000673143    <not supported> Joules power/energy-cores/k                                        
     5.000722624    <not supported> Joules power/energy-cores/k                                        
user@dkphome:~$ sudo perf stat -a -e power/energy-cores/ -I 1000 sleep 5
 #           time             counts   unit events
     1.000128209               0,19 Joules power/energy-cores/                                         
     2.000257170               0,25 Joules power/energy-cores/                                         
     3.000406715               0,26 Joules power/energy-cores/                                         
     4.000571140               0,20 Joules power/energy-cores/                                         
     5.000711815               1,01 Joules power/energy-cores/                                         
     5.000882867               0,00 Joules power/energy-cores/                                         

通常,当您使用 perf 命令开始测量任何事件时,第一步通常是 运行 perf list 并检查您的系统是否支持事件 power/energy cores .我将在我的系统上举一个例子 运行ning perf list。

~/linux-4.11.3/tools/perf$ ./perf list

List of pre-defined events (to be used in -e):

branch-instructions OR branches [Hardware event]

branch-misses [Hardware event]

power/energy-cores/ [Kernel PMU event]

这样,您将确定您的系统是否真正支持对事件 power/energy-cores 的测量。

确认后,您应该使用以下语法来衡量此事件:

./perf stat -a -e power/energy-cores/ -I 1000 sleep 30(不是 :k 或不是 :u)

编辑#1:

如果您可以像下面这样指定事件 power/energy-cores,您可以使用 :k 或 :u :-

./perf stat -a -e energy-cores:k -I 1000 sleep 30(但是 perf 无法识别 energy-cores 事件,除非您像这样指定完全限定的事件名称:power/energy-cores)。

但是正如我在第二次编辑中所建议的那样,这些计数器无论如何都不支持用户-space 和内核-space 分离。

编辑#2:

不幸的是,这些 RAPL 计数器不会根据内核 space 或用户 space 分隔值。此外,与这些事件相关的性能监控单元也无法进行采样。

这是代码中的证明:

arch/x86/events/intel/rapl.c

此外,您可以阅读下面的补丁文档来理解:-

RAPL patch