From 4b012cdc3d8cf7b29ad5bd7b9029fb07a4ecacfd Mon Sep 17 00:00:00 2001 From: Mathieu Poirier Date: Tue, 30 Apr 2019 20:44:46 +0000 Subject: perf tools: Properly set the value of 'old' in snapshot mode In snapshot mode the value of the 'old' pointer needs to be adjusted when 'head' has wrapped around in order to get the latest information in the buffer and be compatible with the generic AUX ring buffer mechanic. Signed-off-by: Mathieu Poirier --- tools/perf/arch/arm/util/cs-etm.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 911426721170..4e73fe1a6978 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -541,11 +541,19 @@ static int cs_etm_find_snapshot(struct auxtrace_record *itr __maybe_unused, unsigned char *data __maybe_unused, u64 *head, u64 *old) { + bool wrapped; + pr_debug3("%s: mmap index %d old head %zu new head %zu size %zu\n", __func__, idx, (size_t)*old, (size_t)*head, mm->len); - *old = *head; - *head += mm->len; + /* + * If the last byte in the ring buffer isn't zero, the head has + * wrapped around. + */ + wrapped = !!(data[mm->len - 1]); + + if (wrapped) + *old = *head - mm->len; return 0; } -- cgit v1.2.3