[PATCH 03/21] perf x86: Update event count properly for read syscall

From: Jiri Olsa
Date: Wed Sep 25 2013 - 08:51:21 EST


Within the read syscall we update the event count via
pmu->read callback if the event is in ACTIVE state.

This triggers event update (x86_perf_event_update) for
x86 pmu and leads to wrong event count in case the event
hasn't been started yet -> the event base is not adjusted
to new cpu and new count computation is based on previous
CPU prev_count.

Fixing this to update the counter only if it has been
started, so the event base is properly adjusted.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
arch/x86/kernel/cpu/perf_event.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 8355c84..e89c773 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1570,7 +1570,11 @@ early_initcall(init_hw_perf_events);

static inline void x86_pmu_read(struct perf_event *event)
{
- x86_perf_event_update(event);
+ struct hw_perf_event *hwc = &event->hw;
+
+ /* Update only if the event has already been started. */
+ if (!(hwc->state & PERF_HES_ARCH))
+ x86_perf_event_update(event);
}

/*
--
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/