4 #include <linux/perf_event.h>
6 #include "../../perf.h"
7 #include <linux/types.h>
8 #include "../../util/debug.h"
9 #include "../../util/tsc.h"
11 int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
12 struct perf_tsc_conversion *tc)
14 bool cap_user_time_zero;
21 tc->time_mult = pc->time_mult;
22 tc->time_shift = pc->time_shift;
23 tc->time_zero = pc->time_zero;
24 cap_user_time_zero = pc->cap_user_time_zero;
26 if (pc->lock == seq && !(seq & 1))
29 pr_debug("failed to get perf_event_mmap_page lock\n");
34 if (!cap_user_time_zero)
42 unsigned int low, high;
44 asm volatile("rdtsc" : "=a" (low), "=d" (high));
46 return low | ((u64)high) << 32;
49 int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
50 struct perf_tool *tool,
51 perf_event__handler_t process,
52 struct machine *machine)
54 union perf_event event = {
57 .type = PERF_RECORD_TIME_CONV,
58 .size = sizeof(struct time_conv_event),
62 struct perf_tsc_conversion tc;
65 err = perf_read_tsc_conversion(pc, &tc);
66 if (err == -EOPNOTSUPP)
71 pr_debug2("Synthesizing TSC conversion information\n");
73 event.time_conv.time_mult = tc.time_mult;
74 event.time_conv.time_shift = tc.time_shift;
75 event.time_conv.time_zero = tc.time_zero;
77 return process(tool, &event, NULL, machine);