diff options
author | Stephane Eranian <eranian@google.com> | 2010-10-26 10:08:01 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-11-10 16:58:39 -0500 |
commit | eed01528a45dc4138e9a08064b4b6cc1a9426899 (patch) | |
tree | c7b4256b4158abc74338f14ac2071ec33c52d7e6 /include/linux/perf_event.h | |
parent | 7e55055e5bb00085051ca59c570c83a820e1e0ee (diff) |
perf_events: Fix time tracking in samples
This patch corrects time tracking in samples. Without this patch
both time_enabled and time_running are bogus when user asks for
PERF_SAMPLE_READ.
One uses PERF_SAMPLE_READ to sample the values of other counters
in each sample. Because of multiplexing, it is necessary to know
both time_enabled, time_running to be able to scale counts correctly.
In this second version of the patch, we maintain a shadow
copy of ctx->time which allows us to compute ctx->time without
calling update_context_time() from NMI context. We avoid the
issue that update_context_time() must always be called with
ctx->lock held.
We do not keep shadow copies of the other event timings
because if the lead event is overflowing then it is active
and thus it's been scheduled in via event_sched_in() in
which case neither tstamp_stopped, tstamp_running can be modified.
This timing logic only applies to samples when PERF_SAMPLE_READ
is used.
Note that this patch does not address timing issues related
to sampling inheritance between tasks. This will be addressed
in a future patch.
With this patch, the libpfm4 example task_smpl now reports
correct counts (shown on 2.4GHz Core 2):
$ task_smpl -p 2400000000 -e unhalted_core_cycles:u,instructions_retired:u,baclears noploop 5
noploop for 5 seconds
IIP:0x000000004006d6 PID:5596 TID:5596 TIME:466,210,211,430 STREAM_ID:33 PERIOD:2,400,000,000 ENA=1,010,157,814 RUN=1,010,157,814 NR=3
2,400,000,254 unhalted_core_cycles:u (33)
2,399,273,744 instructions_retired:u (34)
53,340 baclears (35)
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <4cc6e14b.1e07e30a.256e.5190@mx.google.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include/linux/perf_event.h')
-rw-r--r-- | include/linux/perf_event.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 057bf22a8323..40150f345982 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -747,6 +747,16 @@ struct perf_event { | |||
747 | u64 tstamp_running; | 747 | u64 tstamp_running; |
748 | u64 tstamp_stopped; | 748 | u64 tstamp_stopped; |
749 | 749 | ||
750 | /* | ||
751 | * timestamp shadows the actual context timing but it can | ||
752 | * be safely used in NMI interrupt context. It reflects the | ||
753 | * context time as it was when the event was last scheduled in. | ||
754 | * | ||
755 | * ctx_time already accounts for ctx->timestamp. Therefore to | ||
756 | * compute ctx_time for a sample, simply add perf_clock(). | ||
757 | */ | ||
758 | u64 shadow_ctx_time; | ||
759 | |||
750 | struct perf_event_attr attr; | 760 | struct perf_event_attr attr; |
751 | struct hw_perf_event hw; | 761 | struct hw_perf_event hw; |
752 | 762 | ||