【问题标题】:What restriction is perf_event_paranoid == 1 actually putting on x86 perf?perf_event_paranoid == 1 实际上对 x86 性能有什么限制?
【发布时间】:2019-01-25 10:33:05
【问题描述】:

较新的 Linux 内核有一个 sysfs 可调参数 /proc/sys/kernel/perf_event_paranoid,它允许用户为非 root 用户调整 perf_events 的可用功能,数字越大越安全(提供相应的功能越少):

kernel documenation 开始,我们对各种值有以下行为:

perf_event_paranoid:

控制非特权用户对表演事件系统的使用 (没有 CAP_SYS_ADMIN)。默认值为 2。

-1:允许所有用户使用(几乎)所有事件 在没有 CAP_IPC_LOCK 的 perf_event_mlock_kb 之后忽略 mlock 限制

>=0: 不允许没有 CAP_SYS_ADMIN 的用户使用 ftrace 函数跟踪点 禁止没有 CAP_SYS_ADMIN 的用户访问原始跟踪点

>=1: 不允许没有 CAP_SYS_ADMIN 的用户访问 CPU 事件

>=2: 不允许没有 CAP_SYS_ADMIN 的用户进行内核分析

我的 perf_event_paranoid 文件中有 1 应该“禁止 CPU 事件访问” - 但这到底是什么意思?

简单的阅读意味着无法访问 CPU 性能计数器事件(例如 Intel PMU 事件),但似乎我可以访问那些就好了。例如:

$ perf stat sleep 1

 Performance counter stats for 'sleep 1':

          0.408734      task-clock (msec)         #    0.000 CPUs utilized          
                 1      context-switches          #    0.002 M/sec                  
                 0      cpu-migrations            #    0.000 K/sec                  
                57      page-faults               #    0.139 M/sec                  
         1,050,362      cycles                    #    2.570 GHz                    
           769,135      instructions              #    0.73  insn per cycle         
           152,661      branches                  #  373.497 M/sec                  
             6,942      branch-misses             #    4.55% of all branches        

       1.000830821 seconds time elapsed

这里,许多事件都是 CPU PMU 事件(cyclesinstructionsbranchesbranch-missescache-misses)。

如果这些不是被引用的 CPU 事件,它们是什么?

标签: linux-kernel x86 profiling perf intel-pmu


【解决方案1】:

在这种情况下,CPU 事件 是指监控每个 CPU 而不是每个任务的事件。对于perf 工具,这会限制使用

-C, --cpu=
    Count only on the list of CPUs provided. Multiple CPUs can be provided as a comma-separated list with no space: 0,1.
    Ranges of CPUs are specified with -: 0-2. In per-thread mode, this option is ignored. The -a option is still necessary
    to activate system-wide monitoring. Default is to count on all CPUs.

-a, --all-cpus
    system-wide collection from all CPUs (default if no target is specified)

对于perf_event_open,考虑以下情况:

pid == -1 and cpu >= 0
       This measures all processes/threads on the specified CPU.  This requires CAP_SYS_ADMIN capability or a /proc/sys/ker‐
       nel/perf_event_paranoid value of less than 1.

这可能是特定于版本的,引用的文档来自 4.17。这是another related question

【讨论】:

  • 对于它的价值,the accepted answer 在另一个问题上似乎是错误的 wrt paranoid == 2。使用paranoid == 2,我绝对仍然可以使用perf stat 来获取事件,但我只是看不到内核PMU 计数(仅限用户)。
  • 我可以通过查看代码来确认这个答案是正确的。此外,还会执行检查sysctl_perf_event_paranoid > 0 以确定是否允许在 P4 处理器上使用线程共享(逻辑处理器之间共享)事件(正式称为 TI 事件)。
  • 通过本地测试确认。
猜你喜欢
  • 1970-01-01
  • 2018-09-13
  • 1970-01-01
  • 2012-09-11
  • 2014-07-14
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
相关资源
最近更新 更多