public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] perf/core: fix implicitly enable dynamic interrupt throttle
@ 2016-05-03  7:26 kan.liang
  2016-05-12  9:31 ` Peter Zijlstra
  2016-06-03 10:50 ` [tip:perf/core] perf/core: Fix " tip-bot for Kan Liang
  0 siblings, 2 replies; 4+ messages in thread
From: kan.liang @ 2016-05-03  7:26 UTC (permalink / raw)
  To: peterz; +Cc: mingo, acme, alexander.shishkin, ak, linux-kernel, Kan Liang

From: Kan Liang <kan.liang@intel.com>

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.

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 kernel/events/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4e2ebf6..4042a3d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -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)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] perf/core: fix implicitly enable dynamic interrupt throttle
  2016-05-03  7:26 [PATCH 1/1] perf/core: fix implicitly enable dynamic interrupt throttle kan.liang
@ 2016-05-12  9:31 ` Peter Zijlstra
  2016-05-12 13:26   ` Liang, Kan
  2016-06-03 10:50 ` [tip:perf/core] perf/core: Fix " tip-bot for Kan Liang
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2016-05-12  9:31 UTC (permalink / raw)
  To: kan.liang; +Cc: mingo, acme, alexander.shishkin, ak, linux-kernel

On Tue, May 03, 2016 at 12:26:06AM -0700, kan.liang@intel.com wrote:
> From: Kan Liang <kan.liang@intel.com>
> 
> 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.
> 
> Signed-off-by: Kan Liang <kan.liang@intel.com>
> ---
>  kernel/events/core.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4e2ebf6..4042a3d 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -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;
> +


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(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 050a290c72c7..0a51a568d4eb 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -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();

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH 1/1] perf/core: fix implicitly enable dynamic interrupt throttle
  2016-05-12  9:31 ` Peter Zijlstra
@ 2016-05-12 13:26   ` Liang, Kan
  0 siblings, 0 replies; 4+ messages in thread
From: Liang, Kan @ 2016-05-12 13:26 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo@redhat.com, acme@kernel.org,
	alexander.shishkin@linux.intel.com, ak@linux.intel.com,
	linux-kernel@vger.kernel.org


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

Yes, I agree.

Thanks,
Kan

> ---
>  kernel/events/core.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c index
> 050a290c72c7..0a51a568d4eb 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -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();

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:perf/core] perf/core: Fix implicitly enable dynamic interrupt throttle
  2016-05-03  7:26 [PATCH 1/1] perf/core: fix implicitly enable dynamic interrupt throttle kan.liang
  2016-05-12  9:31 ` Peter Zijlstra
@ 2016-06-03 10:50 ` tip-bot for Kan Liang
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Kan Liang @ 2016-06-03 10:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: vincent.weaver, tglx, kan.liang, alexander.shishkin, torvalds,
	peterz, hpa, mingo, jolsa, linux-kernel, acme, eranian

Commit-ID:  ab7fdefba68f66c8523571c3b3a940635d781824
Gitweb:     http://git.kernel.org/tip/ab7fdefba68f66c8523571c3b3a940635d781824
Author:     Kan Liang <kan.liang@intel.com>
AuthorDate: Tue, 3 May 2016 00:26:06 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Kan Liang <kan.liang@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: acme@kernel.org
Link: http://lkml.kernel.org/r/1462260366-3160-1-git-send-email-kan.liang@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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();

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-03 10:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-03  7:26 [PATCH 1/1] perf/core: fix implicitly enable dynamic interrupt throttle kan.liang
2016-05-12  9:31 ` Peter Zijlstra
2016-05-12 13:26   ` Liang, Kan
2016-06-03 10:50 ` [tip:perf/core] perf/core: Fix " tip-bot for Kan Liang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox