Skip to contentSkip to conversation

perf/core: fix implicitly enable dynamic interrupt throttle

PATCH In review [email protected] 3 participants 4 messages May 3, 2016 – Jun 3, 2016 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/core: fix implicitly enable dynamic interrupt throttle

From: Kan Liang <[email protected]>

This patch fixes an issue which was introduced from 'commit 91a612eea9a3 ("perf/core: Fix dynamic interrupt throttle")'
The old patch unconditionally sets the perf_sample_allowed_ns value to !0. But that could trigger an issue 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 changes perf_event_max_sample_rate.
For this case, the mechanism will be enabled implicitly, because perf_sample_allowed_ns becomes !0.

This patch only updates the perf_sample_allowed_ns when the dynamic interrupt throttle mechanism is enabled.

---
 kernel/events/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
kernel/events/core.c +8 -0
index 4e2ebf6..4042a3d 100644
@@ -375,6 +375,14 @@ static void update_perf_cpu_limits(void)
 {
 	u64 tmp = perf_sample_period_ns;
 
+	/*
+	 * Don't update the perf_sample_allowed_ns,
+	 * if the dynamic interrupt throttle mechanism is disabled.
+	 */
+	if (sysctl_perf_cpu_time_max_percent == 100 ||
+	    sysctl_perf_cpu_time_max_percent == 0)
+		return;
+
 	tmp *= sysctl_perf_cpu_time_max_percent;
 	tmp = div_u64(tmp, 100);
 	if (!tmp)
Signature · 1 line
2.5.0
maintainer
#1 lore raw
Quoted 26 lines · On Tue, May 03, 2016 at 12:26:06AM -0700, [email protected] wrote:

From: Kan Liang <[email protected]>

This patch fixes an issue which was introduced from 'commit 91a612eea9a3 ("perf/core: Fix dynamic interrupt throttle")'
The old patch unconditionally sets the perf_sample_allowed_ns value to !0. But that could trigger an issue 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 changes perf_event_max_sample_rate.
For this case, the mechanism will be enabled implicitly, because perf_sample_allowed_ns becomes !0.

This patch only updates the perf_sample_allowed_ns when the dynamic interrupt throttle mechanism is enabled.

---
 kernel/events/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
kernel/events/core.c +0 -0
index 4e2ebf6..4042a3d 100644
@@ -375,6 +375,14 @@ static void update_perf_cpu_limits(void)
 {

kernel/events/core.c static void update_perf_cpu_limits(void) · line 385

Quoted 10 lines
kernel/events/core.c +8 -0
 	u64 tmp = perf_sample_period_ns;
 
+	/*
+	 * Don't update the perf_sample_allowed_ns,
+	 * if the dynamic interrupt throttle mechanism is disabled.
+	 */
+	if (sysctl_perf_cpu_time_max_percent == 100 ||
+	    sysctl_perf_cpu_time_max_percent == 0)
+		return;
+

Hmm, would it not be nicer to simply reject the write instead of silently ignoring it?

---
 kernel/events/core.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/events/core.c +7 -0
index 050a290c72c7..0a51a568d4eb 100644
@@ -396,6 +396,13 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
 	if (ret || !write)
 		return ret;
 
+	/*
+	 * If the 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();
author
#2 lore raw
Quoted 6 lines

Hmm, would it not be nicer to simply reject the write instead of silently ignoring it?

Yes, I agree.

Thanks,
Kan

Quoted 25 lines
---
 kernel/events/core.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/events/core.c index renamed from kernel/events/core.c +0 -0

050a290c72c7..0a51a568d4eb 100644

kernel/events/core.c +7 -0
@@ -396,6 +396,13 @@ int perf_proc_update_handler(struct ctl_table
 *table, int write,
 	if (ret || !write)
 		return ret;
 
+	/*
+	 * If the 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();

#3 lore raw

[tip:perf/core] perf/core: Fix implicitly enable dynamic interrupt throttle

In reply to [email protected]
perf/core: Fix implicitly enable dynamic interrupt throttle
Commit-ID:  ab7fdefba68f66c8523571c3b3a940635d781824
Gitweb:     http://git.kernel.org/tip/ab7fdefba68f66c8523571c3b3a940635d781824
Author:     Kan Liang <[email protected]>
AuthorDate: Tue, 3 May 2016 00:26:06 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Jun 2016 09:40:16 +0200

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.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
---
 kernel/events/core.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/events/core.c +7 -0
index f54454e..f94f164 100644
@@ -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();