微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Linux内核中禁用perf子系统?

我正在运行一些基准测试.我的基准测试运行器监视实验之间的dmesg缓冲区,寻找可能影响性能的任何事情.今天它把它扔了:
[2015-08-17 10:20:14 WARNING] dmesg seems to have changed! Diff follows:
--- 2015-08-17 09:55:00
+++ 2015-08-17 10:20:14
@@ -825,3 +825,4 @@
 [    3.802206] [drm] Enabling RC6 states: RC6 on,RC6p off,RC6pp off
 [    7.900533] r8169 0000:06:00.0 eth0: link up
 [    7.900541] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
+[236832.221937] perf interrupt took too long (2504 > 2500),lowering kernel.perf_event_max_sample_rate to 50000

经过一番搜索,我现在知道这与Linux内核中名为“perf”的分析子系统有关.我认为我们不需要这个,所以我想完全禁用它.

再次搜索,我发现sysctl perf_cpu_time_max_percent可以提供帮助. Here有人建议通过将其设置为0来禁用.阅读此内容更多here

perf_cpu_time_max_percent:

Hints to the kernel how much cpu time it should be allowed to
use to handle perf sampling events. If the perf subsystem
is informed that its samples are exceeding this limit,it
will drop its sampling frequency to attempt to reduce its cpu usage.

Some perf sampling happens in NMIs. If these samples
unexpectedly take too long to execute,the NMIs can become
stacked up next to each other so much that nothing else is
allowed to execute.

0: disable the mechanism. Do not monitor or correct perf’s
sampling rate no matter how cpu time it takes.

1-100: attempt to throttle perf’s sample rate to this
percentage of cpu. Note: the kernel calculates an
“expected” length of each sample event. 100 here means
100% of that expected length. Even if this is set to
100,you may still see sample throttling if this
length is exceeded. Set to 0 if you truly do not care
how much cpu is consumed.

这听起来像0意味着不再检查分析采样率,但freq子系统仍在运行(?).

任何人都可以阐明如何使用freq完全禁用内核分析?

编辑:有人建议我尝试构建一个没有perf的内核,但我认为这甚至不可能.该选项似乎不可切换:

EDIT2:经过更多阅读后,我决定将kernel.perf_event_max_sample_rate设置为零.即每秒没有样品.但是,你也不能这样做(source):

commit 02f98e3e36da106338b7c732fed516420fb20e2a
Author: Knut Petersen 
Date:   Wed Sep 25 14:29:37 2013 +0200

perf: Enforce 1 as lower limit for perf_event_max_sample_rate

编辑3:FWIW,perf_cpu_time_max_percent设置为25,这意味着内核花费了超过25%的时间采样硬件寄存器.这对基准测试机来说是不可接受的.

我现在确定将perf_cpu_time_max_percent设置为零只会使情况恶化,因为内核将继续使用超过25%的时间读取硬件寄存器.该错误触发以调整采样率,从而尝试确保内核满足其使用< 25%的时间在perf中的配额.恕我直言,25%仍然过高. 如果我真的无法禁用perf,可能最好的折衷方案是将perf_event_max_sample_rate设置为1. 编辑4:一位朋友建议我可能误解了perf_cpu_time_max_percent的含义,因此上述陈述可能不正确.值25表示内核使用了超过其保留用于服务性能中断的任意长度的25%. EDIT5: 正如评论中所指出的,针对perf选项的 – * – 表明该功能被另一个启用的功能强制启用.如果我寻求帮助,它会说明这些功能

我认为我不能在这里获胜.通过说明选择的布尔公式

If you are targeting X86,or…

我刚刚检查过,目标X86_64确实启用了CONfig_X86.所以看来,只要你瞄准X86或X86_64,就会得到性能.

所以我想稍微改变一下我的问题:

Which perf settings can I use to minimise the time spent by the kernel in perf routines?

请记住,总体目标是控制随机变化的来源以进行基准测试.如果我无法禁用性能,我怎样才能最小化它对基准测试的影响?

解决方法

禁用[HAVE_PERF_EVENTS]内核选项并重新编译Linux内核.

原文地址:https://www.jb51.cc/linux/401181.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐