PERF_EVENT_PARANOID==1实际上对x86 PERF施加了什么限制? [英] What restriction is perf_event_paranoid == 1 actually putting on x86 perf?

查看:22
本文介绍了PERF_EVENT_PARANOID==1实际上对x86 PERF施加了什么限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

kernel documenation我们可以看到各种值的以下行为:

PERF_EVENT_PARANOID:

控制非特权用户对Performance Events系统的使用 (不带CAP_SYSTEM_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事件,它们是什么?

推荐答案

在本例中,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

这篇关于PERF_EVENT_PARANOID==1实际上对x86 PERF施加了什么限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆