From: Peter Zijlstra <peterz@infradead.org>
To: Knut Petersen <Knut_Petersen@t-online.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf: Prevent divide by zero exception in kernel/events/core.c
Date: Wed, 25 Sep 2013 14:12:43 +0200 [thread overview]
Message-ID: <20130925121243.GK3081@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <5242D207.10306@t-online.de>
On Wed, Sep 25, 2013 at 02:07:35PM +0200, Knut Petersen wrote:
> From: Knut Petersen <Knut_Petersen@t-online.de>
> Date: Wed, 25 Sep 2013 13:34:57 +0200
> Subject: [PATCH] Enforce 1 as lower limit for perf_event_max_sample_rate
>
> /proc/sys/kernel/perf_event_max_sample_rate will accept
> negative values as well as 0.
>
> Negative values are unreasonable, and 0 causes a
> divide by zero exception in perf_proc_update_handler.
>
> This patch enforces a lower limit of 1.
>
> Signed-off-by: Knut Petersen <Knut_Petersen@t-online.de>
> ---
> kernel/events/core.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index dd236b6..350bb53 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -198,6 +198,9 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
> if (ret || !write)
> return ret;
>
> + if (sysctl_perf_event_sample_rate <= 0)
> + sysctl_perf_event_sample_rate = 1;
> +
> 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();
The 'normal' way of doing that is changing the sysctl table entry to use
proc_dointvec_minmax and set .extra = &one. See for example
&sysctl_sched_cfs_bandwidth_slice in kernel/sysctl.c
next prev parent reply other threads:[~2013-09-25 12:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-25 12:07 Knut Petersen
2013-09-25 12:12 ` Peter Zijlstra [this message]
2013-09-25 12:46 ` Knut Petersen
2013-10-04 17:32 ` [tip:perf/core] perf: Enforce 1 as lower limit for perf_event_max_sample_rate tip-bot for Knut Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130925121243.GK3081@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Knut_Petersen@t-online.de \
--cc=acme@ghostprotocols.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome