【发布时间】: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 事件(cycles、instructions、branches、branch-misses、cache-misses)。
如果这些不是被引用的 CPU 事件,它们是什么?
标签: linux-kernel x86 profiling perf intel-pmu