From: Frederic Weisbecker <fweisbec@gmail.com>
To: eranian@google.com
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
mingo@elte.hu, paulus@samba.org, perfmon2-devel@lists.sf.net,
robert.richter@amd.com, eranian@gmail.com
Subject: Re: [PATCH] perf_events: add sampling period randomization support
Date: Tue, 2 Mar 2010 14:10:05 +0100 [thread overview]
Message-ID: <20100302131002.GD5137@nowhere> (raw)
In-Reply-To: <1267510029-19750-1-git-send-email-eranian@google.com>
On Mon, Mar 01, 2010 at 10:07:09PM -0800, eranian@google.com wrote:
> This patch adds support for randomizing the sampling period.
> Randomization is very useful to mitigate the bias that exists
> with sampling. The random number generator does not need to
> be sophisticated. This patch uses the builtin random32()
> generator.
>
> The user activates randomization by setting the perf_event_attr.random
> field to 1 and by passing a bitmask to control the range of variation
> above the base period. Period will vary from period to period & mask.
> Note that randomization is not available when a target interrupt rate
> (freq) is enabled.
>
> The last used period can be collected using the PERF_SAMPLE_PERIOD flag
> in sample_type.
>
> The patch has been tested on X86. There is also code for PowerPC but
> I could not test it.
>
> Signed-off-by: Stephane Eranian <eranian@google.com>
>
> --
> arch/powerpc/kernel/perf_event.c | 3 +++
> arch/x86/kernel/cpu/perf_event.c | 2 ++
> arch/x86/kernel/cpu/perf_event_intel.c | 4 ++++
> include/linux/perf_event.h | 7 +++++--
> kernel/perf_event.c | 24 ++++++++++++++++++++++++
> 5 files changed, 38 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/kernel/perf_event.c b/arch/powerpc/kernel/perf_event.c
> index b6cf8f1..994df17 100644
> --- a/arch/powerpc/kernel/perf_event.c
> +++ b/arch/powerpc/kernel/perf_event.c
> @@ -1150,6 +1150,9 @@ static void record_and_restart(struct perf_event *event, unsigned long val,
> val = 0;
> left = atomic64_read(&event->hw.period_left) - delta;
> if (period) {
> + if (event->attr.random)
> + perf_randomize_event_period(event);
> +
> if (left <= 0) {
> left += period;
> if (left <= 0)
> diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
> index 641ccb9..159d951 100644
> --- a/arch/x86/kernel/cpu/perf_event.c
> +++ b/arch/x86/kernel/cpu/perf_event.c
> @@ -1110,6 +1110,8 @@ static int x86_pmu_handle_irq(struct pt_regs *regs)
> if (val & (1ULL << (x86_pmu.event_bits - 1)))
> continue;
>
> + if (event->attr.random)
> + perf_randomize_event_period(event);
> /*
> * event overflow
> */
> diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
> index cf6590c..5c8d6ed 100644
> --- a/arch/x86/kernel/cpu/perf_event_intel.c
> +++ b/arch/x86/kernel/cpu/perf_event_intel.c
> @@ -690,6 +690,10 @@ static int intel_pmu_save_and_restart(struct perf_event *event)
> int ret;
>
> x86_perf_event_update(event, hwc, idx);
> +
> + if (event->attr.random)
> + perf_randomize_event_period(event);
> +
> ret = x86_perf_event_set_period(event, hwc, idx);
>
> return ret;
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index 04f06b4..e91a759 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -203,8 +203,8 @@ struct perf_event_attr {
> enable_on_exec : 1, /* next exec enables */
> task : 1, /* trace fork/exit */
> watermark : 1, /* wakeup_watermark */
> -
> - __reserved_1 : 49;
> + random : 1, /* period randomization */
I'd rather name this field random_period. Even though the comment
tell us enough, it's better that the code speak for itself.
prev parent reply other threads:[~2010-03-02 13:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-02 6:07 [PATCH] perf_events: add sampling period randomization support eranian
2010-03-02 6:20 ` David Miller
2010-03-02 8:21 ` Peter Zijlstra
2010-03-02 10:53 ` Robert Richter
2010-03-02 11:41 ` Peter Zijlstra
2010-03-02 14:18 ` Robert Richter
2010-03-02 13:10 ` Frederic Weisbecker [this message]
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=20100302131002.GD5137@nowhere \
--to=fweisbec@gmail.com \
--cc=eranian@gmail.com \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=perfmon2-devel@lists.sf.net \
--cc=peterz@infradead.org \
--cc=robert.richter@amd.com \
/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