加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux-kernel – perf_event_paranoid == 1实际上对x86 perf有什

发布时间:2020-12-14 01:06:04 所属栏目:Linux 来源:网络整理
导读:较新的 Linux内核具有sysfs可调/ proc / sys / kernel / perf_event_paranoid,允许用户为非root用户调整perf_events的可用功能,更高的数字更安全(提供相应更少的功能): 从kernel documenation开始,我们对各种值有以下行为: perf_event_paranoid: Controls
较新的 Linux内核具有sysfs可调/ proc / sys / kernel / perf_event_paranoid,允许用户为非root用户调整perf_events的可用功能,更高的数字更安全(提供相应更少的功能):

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

perf_event_paranoid:

Controls use of the performance events system by unprivileged users
(without CAP_SYS_ADMIN). The default value is 2.

-1: Allow use of (almost) all events by all users
Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK

>=0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN
Disallow raw tracepoint access by users without CAP_SYS_ADMIN

>=1: Disallow CPU event access by users without CAP_SYS_ADMIN

>=2: Disallow kernel profiling by users without 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事件(周期,指令,分支,分支未命中,缓存未命中).

如果这些不是所引用的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                        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读