Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf tsc: Calculate timestamp with cap_user_time_short

The perf mmap'ed buffer contains the flag 'cap_user_time_short' and two
extra fields 'time_cycles' and 'time_mask', perf tool needs to know them
for handling the counter wrapping case.

This patch is to reads out the relevant parameters from the head of the
first mmap'ed page and stores into the structure 'perf_tsc_conversion',
if the flag 'cap_user_time_short' has been set, it will firstly
calibrate cycle value for timestamp calculation.

Committer testing:

Before/after:

# perf test tsc
70: Convert perf time to TSC : Ok
#
# perf test -v tsc
70: Convert perf time to TSC :
--- start ---
test child forked, pid 11059
mmap size 528384B
1st event perf time 996384576521 tsc 3850532906613
rdtsc time 996384578455 tsc 3850532913950
2nd event perf time 996384578845 tsc 3850532915428
test child finished with 0
---- end ----
Convert perf time to TSC: Ok
#

Signed-off-by: Leo Yan <leo.yan@linaro.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kemeng Shi <shikemeng@huawei.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Gasson <nick.gasson@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Remi Bernon <rbernon@codeweavers.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steve Maclean <steve.maclean@microsoft.com>
Cc: Will Deacon <will@kernel.org>
Cc: Zou Wei <zou_wei@huawei.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lore.kernel.org/lkml/20200914115311.2201-4-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
78a93d4c 4979e861

+14 -3
+9 -3
tools/perf/util/tsc.c
··· 28 28 { 29 29 u64 quot, rem; 30 30 31 + if (tc->cap_user_time_short) 32 + cyc = tc->time_cycles + 33 + ((cyc - tc->time_cycles) & tc->time_mask); 34 + 31 35 quot = cyc >> tc->time_shift; 32 36 rem = cyc & (((u64)1 << tc->time_shift) - 1); 33 37 return tc->time_zero + quot * tc->time_mult + ··· 41 37 int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc, 42 38 struct perf_tsc_conversion *tc) 43 39 { 44 - bool cap_user_time_zero; 45 40 u32 seq; 46 41 int i = 0; 47 42 ··· 50 47 tc->time_mult = pc->time_mult; 51 48 tc->time_shift = pc->time_shift; 52 49 tc->time_zero = pc->time_zero; 53 - cap_user_time_zero = pc->cap_user_time_zero; 50 + tc->time_cycles = pc->time_cycles; 51 + tc->time_mask = pc->time_mask; 52 + tc->cap_user_time_zero = pc->cap_user_time_zero; 53 + tc->cap_user_time_short = pc->cap_user_time_short; 54 54 rmb(); 55 55 if (pc->lock == seq && !(seq & 1)) 56 56 break; ··· 63 57 } 64 58 } 65 59 66 - if (!cap_user_time_zero) 60 + if (!tc->cap_user_time_zero) 67 61 return -EOPNOTSUPP; 68 62 69 63 return 0;
+5
tools/perf/util/tsc.h
··· 8 8 u16 time_shift; 9 9 u32 time_mult; 10 10 u64 time_zero; 11 + u64 time_cycles; 12 + u64 time_mask; 13 + 14 + bool cap_user_time_zero; 15 + bool cap_user_time_short; 11 16 }; 12 17 13 18 struct perf_event_mmap_page;