Skip to content

Commit aa616f5

Browse files
Leo Yanacmel
authored andcommitted
perf jit: Let convert_timestamp() to be backwards-compatible
Commit d110162 ("perf tsc: Support cap_user_time_short for event TIME_CONV") supports the extended parameters for event TIME_CONV, but it broke the backwards compatibility, so any perf data file with old event format fails to convert timestamp. This patch introduces a helper event_contains() to check if an event contains a specific member or not. For the backwards-compatibility, if the event size confirms the extended parameters are supported in the event TIME_CONV, then copies these parameters. Committer notes: To make this compiler backwards compatible add this patch: - struct perf_tsc_conversion tc = { 0 }; + struct perf_tsc_conversion tc = { .time_shift = 0, }; Fixes: d110162 ("perf tsc: Support cap_user_time_short for event TIME_CONV") Signed-off-by: Leo Yan <[email protected]> Acked-by: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Gustavo A. R. Silva <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steve MacLean <[email protected]> Cc: Yonatan Goldschmidt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e1d380e commit aa616f5

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

tools/lib/perf/include/perf/event.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <linux/bpf.h>
99
#include <sys/types.h> /* pid_t */
1010

11+
#define event_contains(obj, mem) ((obj).header.size > offsetof(typeof(obj), mem))
12+
1113
struct perf_record_mmap {
1214
struct perf_event_header header;
1315
__u32 pid, tid;

tools/perf/util/jitdump.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,21 +396,31 @@ static pid_t jr_entry_tid(struct jit_buf_desc *jd, union jr_entry *jr)
396396

397397
static uint64_t convert_timestamp(struct jit_buf_desc *jd, uint64_t timestamp)
398398
{
399-
struct perf_tsc_conversion tc;
399+
struct perf_tsc_conversion tc = { .time_shift = 0, };
400+
struct perf_record_time_conv *time_conv = &jd->session->time_conv;
400401

401402
if (!jd->use_arch_timestamp)
402403
return timestamp;
403404

404-
tc.time_shift = jd->session->time_conv.time_shift;
405-
tc.time_mult = jd->session->time_conv.time_mult;
406-
tc.time_zero = jd->session->time_conv.time_zero;
407-
tc.time_cycles = jd->session->time_conv.time_cycles;
408-
tc.time_mask = jd->session->time_conv.time_mask;
409-
tc.cap_user_time_zero = jd->session->time_conv.cap_user_time_zero;
410-
tc.cap_user_time_short = jd->session->time_conv.cap_user_time_short;
405+
tc.time_shift = time_conv->time_shift;
406+
tc.time_mult = time_conv->time_mult;
407+
tc.time_zero = time_conv->time_zero;
411408

412-
if (!tc.cap_user_time_zero)
413-
return 0;
409+
/*
410+
* The event TIME_CONV was extended for the fields from "time_cycles"
411+
* when supported cap_user_time_short, for backward compatibility,
412+
* checks the event size and assigns these extended fields if these
413+
* fields are contained in the event.
414+
*/
415+
if (event_contains(*time_conv, time_cycles)) {
416+
tc.time_cycles = time_conv->time_cycles;
417+
tc.time_mask = time_conv->time_mask;
418+
tc.cap_user_time_zero = time_conv->cap_user_time_zero;
419+
tc.cap_user_time_short = time_conv->cap_user_time_short;
420+
421+
if (!tc.cap_user_time_zero)
422+
return 0;
423+
}
414424

415425
return tsc_to_perf_time(timestamp, &tc);
416426
}

0 commit comments

Comments
 (0)