[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <AANLkTik=zGEUqh0AOWDus_bUM4xYxka0Grqn6cRDgz_j@mail.gmail.com>
Date: Wed, 26 Jan 2011 15:50:32 +0100
From: Stephane Eranian <eranian@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: LKML <linux-kernel@...r.kernel.org>, mingo@...e.hu,
Frédéric Weisbecker <fweisbec@...il.com>,
Paul Mackerras <paulus@...ba.org>,
"David S. Miller" <davem@...emloft.net>
Subject: Re: perf_events: question about __perf_event_read()
Yeah, something like that.
I didn't quite understand why the event->pmu->read() was outside of the
lock.
Thanks.
On Wed, Jan 26, 2011 at 3:40 PM, Peter Zijlstra <peterz@...radead.org> wrote:
> On Fri, 2011-01-21 at 19:25 +0100, Stephane Eranian wrote:
>
>> I remember checking this about a month ago and tip-x86 had
>> some checks in this routine, but now the're gone.
>
> I did a quick look through history and I couldn't find anything like
> that, a well...
>
>> I think you need something like:
>>
>> + if (ctx->is_active)
>> + update_context_time(ctx);
>>
>> + if (event->state == PERF_EVENT_STATE_ACTIVE)
>> + event->pmu->read(event);
>
> Something like so?
>
> ---
> Subject: perf: Fix race in perf_event_read()
> From: Peter Zijlstra <a.p.zijlstra@...llo.nl>
> Date: Wed Jan 26 15:38:35 CET 2011
>
> It is quite possible for the event to have been disabled between
> perf_event_read() sending the IPI and the CPU servicing the IPI and
> calling __perf_event_read(), hence revalidate the state.
>
> Reported-by: Stephane Eranian <eranian@...gle.com>
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@...llo.nl>
> LKML-Reference: <new-submission>
> ---
> kernel/perf_event.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> Index: linux-2.6/kernel/perf_event.c
> ===================================================================
> --- linux-2.6.orig/kernel/perf_event.c
> +++ linux-2.6/kernel/perf_event.c
> @@ -1901,11 +1901,12 @@ static void __perf_event_read(void *info
> return;
>
> raw_spin_lock(&ctx->lock);
> - update_context_time(ctx);
> + if (ctx->is_active)
> + update_context_time(ctx);
> update_event_times(event);
> + if (event->state == PERF_EVENT_STATE_ACTIVE)
> + event->pmu->read(event);
> raw_spin_unlock(&ctx->lock);
> -
> - event->pmu->read(event);
> }
>
> static inline u64 perf_event_count(struct perf_event *event)
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists