perf/core: Fix implicitly enable dynamic interrupt throttle This patch fixes an issue which was introduced by commit: 91a612eea9a3 ("perf/core: Fix dynamic interrupt throttle") ... which commit unconditionally sets the perf_sample_allowed_ns value to !0. But that could trigger a bug in the following corner case: The user can disable the dynamic interrupt throttle mechanism by setting perf_cpu_time_max_percent to 0. Then they change perf_event_max_sample_rate. For this case, the mechanism will be enabled implicitly, because perf_sample_allowed_ns becomes !0 - which is not what we want. This patch only updates perf_sample_allowed_ns when the dynamic interrupt throttle mechanism is enabled. Signed-off-by: Kan Liang <firstname.lastname@example.org> Signed-off-by: Peter Zijlstra (Intel) <email@example.com> Cc: Alexander Shishkin <firstname.lastname@example.org> Cc: Arnaldo Carvalho de Melo <email@example.com> Cc: Jiri Olsa <firstname.lastname@example.org> Cc: Linus Torvalds <email@example.com> Cc: Peter Zijlstra <firstname.lastname@example.org> Cc: Stephane Eranian <email@example.com> Cc: Thomas Gleixner <firstname.lastname@example.org> Cc: Vince Weaver <email@example.com> Cc: firstname.lastname@example.org Link: http://email@example.com Signed-off-by: Ingo Molnar <firstname.lastname@example.org>
This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit ab7fdef.
There are 7 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.
kernel/events/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index f54454e..f94f164 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -397,6 +397,13 @@ int perf_proc_update_handler(struct ctl_table *table, int write, if (ret || !write) return ret; + /* + * If throttling is disabled don't allow the write: + */ + if (sysctl_perf_cpu_time_max_percent == 100 || + sysctl_perf_cpu_time_max_percent == 0) + return -EINVAL; + max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ); perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate; update_perf_cpu_limits();