Skip to contentSkip to conversation

perf: Fix reading in perf_event_read()

tip:perf/urgent tip-bot for Peter Zijlstra 1 participant 1 message Feb 3, 2011

lore
Share & tools
lore
#0 lore raw
Commit-ID:  542e72fc90f5ed9eecb574f80f70868c7f296093
Gitweb:     http://git.kernel.org/tip/542e72fc90f5ed9eecb574f80f70868c7f296093
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 26 Jan 2011 15:38:35 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 3 Feb 2011 12:15:46 +0100

perf: Fix reading in perf_event_read()

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.

LKML-Reference: <new-submission>

---
 kernel/perf_event.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
kernel/perf_event.c +4 -3
index 852ae8c..999835b 100644
@@ -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)