From: Peter Zijlstra <peterz@infradead.org>
To: Stephane Eranian <eranian@google.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
mingo@elte.hu, "Frédéric Weisbecker" <fweisbec@gmail.com>,
"Paul Mackerras" <paulus@samba.org>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: perf_events: question about __perf_event_read()
Date: Wed, 26 Jan 2011 15:40:34 +0100 [thread overview]
Message-ID: <1296052834.28776.1165.camel@laptop> (raw)
In-Reply-To: <AANLkTima4Bfe-wRewbEkbrF9MGJmW1D0Cd3B4KynntSk@mail.gmail.com>
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@chello.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@google.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.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)
next prev parent reply other threads:[~2011-01-26 14:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-21 18:06 Stephane Eranian
2011-01-21 18:18 ` Peter Zijlstra
2011-01-21 18:25 ` Stephane Eranian
2011-01-26 14:40 ` Peter Zijlstra [this message]
2011-01-26 14:50 ` Stephane Eranian
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=1296052834.28776.1165.camel@laptop \
--to=peterz@infradead.org \
--cc=davem@davemloft.net \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.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
all inboxes | Powered by JetHome®