aboutsummaryrefslogtreecommitdiff
path: root/include/linux/perf_counter.h
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2009-04-02 11:12:04 +0200
committerIngo Molnar <mingo@elte.hu>2009-04-06 09:30:47 +0200
commit92f22a3865abe87eea2609a6f8e5be5123f7ce4f (patch)
tree4ded8d6858a4e50f0e3401e5e3f2a6c37fee8f58 /include/linux/perf_counter.h
parent5872bdb88a35fae7d224bd6b21e5f377e854ccfc (diff)
perf_counter: update mmap() counter read
Paul noted that we don't need SMP barriers for the mmap() counter read because its always on the same cpu (otherwise you can't access the hw counter anyway). So remove the SMP barriers and replace them with regular compiler barriers. Further, update the comment to include a race free method of reading said hardware counter. The primary change is putting the pmc_read inside the seq-loop, otherwise we can still race and read rubbish. Noticed-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Orig-LKML-Reference: <20090402091319.577951445@chello.nl> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include/linux/perf_counter.h')
-rw-r--r--include/linux/perf_counter.h22
1 files changed, 10 insertions, 12 deletions
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 90cce0c74a0..f2b914de3f0 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -167,30 +167,28 @@ struct perf_counter_mmap_page {
/*
* Bits needed to read the hw counters in user-space.
*
- * The index and offset should be read atomically using the seqlock:
- *
- * __u32 seq, index;
- * __s64 offset;
+ * u32 seq;
+ * s64 count;
*
* again:
- * rmb();
* seq = pc->lock;
- *
* if (unlikely(seq & 1)) {
* cpu_relax();
* goto again;
* }
*
- * index = pc->index;
- * offset = pc->offset;
+ * if (pc->index) {
+ * count = pmc_read(pc->index - 1);
+ * count += pc->offset;
+ * } else
+ * goto regular_read;
*
- * rmb();
+ * barrier();
* if (pc->lock != seq)
* goto again;
*
- * After this, index contains architecture specific counter index + 1,
- * so that 0 means unavailable, offset contains the value to be added
- * to the result of the raw timer read to obtain this counter's value.
+ * NOTE: for obvious reason this only works on self-monitoring
+ * processes.
*/
__u32 lock; /* seqlock for synchronization */
__u32 index; /* hardware counter identifier */