diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2014-07-14 06:03:03 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-07-17 11:59:00 -0400 |
commit | 0b437860818dc717f6a9e8a5089223a8414f5fff (patch) | |
tree | 4953f7eca477e011aa9e16cdb236220ed9cec4be | |
parent | ff527bccd469067a64f4ae9747b9045914667d34 (diff) |
perf tools: Allow TSC conversion on any arch
It is possible to record a perf.data file on one architecture and
process it on another.
Consequently, TSC conversion functions need to be moved out of the arch
directory.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1405332185-4050-40-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/Makefile.perf | 2 | ||||
-rw-r--r-- | tools/perf/arch/x86/util/tsc.c | 22 | ||||
-rw-r--r-- | tools/perf/arch/x86/util/tsc.h | 3 | ||||
-rw-r--r-- | tools/perf/tests/perf-time-to-tsc.c | 3 | ||||
-rw-r--r-- | tools/perf/util/tsc.c | 25 | ||||
-rw-r--r-- | tools/perf/util/tsc.h | 11 |
6 files changed, 40 insertions, 26 deletions
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 90c498378a54..3308b22a1660 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
@@ -295,6 +295,7 @@ LIB_H += util/intlist.h | |||
295 | LIB_H += util/perf_regs.h | 295 | LIB_H += util/perf_regs.h |
296 | LIB_H += util/unwind.h | 296 | LIB_H += util/unwind.h |
297 | LIB_H += util/vdso.h | 297 | LIB_H += util/vdso.h |
298 | LIB_H += util/tsc.h | ||
298 | LIB_H += ui/helpline.h | 299 | LIB_H += ui/helpline.h |
299 | LIB_H += ui/progress.h | 300 | LIB_H += ui/progress.h |
300 | LIB_H += ui/util.h | 301 | LIB_H += ui/util.h |
@@ -374,6 +375,7 @@ LIB_OBJS += $(OUTPUT)util/stat.o | |||
374 | LIB_OBJS += $(OUTPUT)util/record.o | 375 | LIB_OBJS += $(OUTPUT)util/record.o |
375 | LIB_OBJS += $(OUTPUT)util/srcline.o | 376 | LIB_OBJS += $(OUTPUT)util/srcline.o |
376 | LIB_OBJS += $(OUTPUT)util/data.o | 377 | LIB_OBJS += $(OUTPUT)util/data.o |
378 | LIB_OBJS += $(OUTPUT)util/tsc.o | ||
377 | 379 | ||
378 | LIB_OBJS += $(OUTPUT)ui/setup.o | 380 | LIB_OBJS += $(OUTPUT)ui/setup.o |
379 | LIB_OBJS += $(OUTPUT)ui/helpline.o | 381 | LIB_OBJS += $(OUTPUT)ui/helpline.o |
diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c index 40021fa3129b..3655f24c3170 100644 --- a/tools/perf/arch/x86/util/tsc.c +++ b/tools/perf/arch/x86/util/tsc.c | |||
@@ -6,29 +6,9 @@ | |||
6 | #include "../../perf.h" | 6 | #include "../../perf.h" |
7 | #include <linux/types.h> | 7 | #include <linux/types.h> |
8 | #include "../../util/debug.h" | 8 | #include "../../util/debug.h" |
9 | #include "../../util/tsc.h" | ||
9 | #include "tsc.h" | 10 | #include "tsc.h" |
10 | 11 | ||
11 | u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc) | ||
12 | { | ||
13 | u64 t, quot, rem; | ||
14 | |||
15 | t = ns - tc->time_zero; | ||
16 | quot = t / tc->time_mult; | ||
17 | rem = t % tc->time_mult; | ||
18 | return (quot << tc->time_shift) + | ||
19 | (rem << tc->time_shift) / tc->time_mult; | ||
20 | } | ||
21 | |||
22 | u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc) | ||
23 | { | ||
24 | u64 quot, rem; | ||
25 | |||
26 | quot = cyc >> tc->time_shift; | ||
27 | rem = cyc & ((1 << tc->time_shift) - 1); | ||
28 | return tc->time_zero + quot * tc->time_mult + | ||
29 | ((rem * tc->time_mult) >> tc->time_shift); | ||
30 | } | ||
31 | |||
32 | int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc, | 12 | int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc, |
33 | struct perf_tsc_conversion *tc) | 13 | struct perf_tsc_conversion *tc) |
34 | { | 14 | { |
diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h index 2affe0366b59..2edc4d31065c 100644 --- a/tools/perf/arch/x86/util/tsc.h +++ b/tools/perf/arch/x86/util/tsc.h | |||
@@ -14,7 +14,4 @@ struct perf_event_mmap_page; | |||
14 | int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc, | 14 | int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc, |
15 | struct perf_tsc_conversion *tc); | 15 | struct perf_tsc_conversion *tc); |
16 | 16 | ||
17 | u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc); | ||
18 | u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc); | ||
19 | |||
20 | #endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */ | 17 | #endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */ |
diff --git a/tools/perf/tests/perf-time-to-tsc.c b/tools/perf/tests/perf-time-to-tsc.c index 3b7cd4d32dcb..0372f6edca20 100644 --- a/tools/perf/tests/perf-time-to-tsc.c +++ b/tools/perf/tests/perf-time-to-tsc.c | |||
@@ -8,10 +8,9 @@ | |||
8 | #include "evsel.h" | 8 | #include "evsel.h" |
9 | #include "thread_map.h" | 9 | #include "thread_map.h" |
10 | #include "cpumap.h" | 10 | #include "cpumap.h" |
11 | #include "tsc.h" | ||
11 | #include "tests.h" | 12 | #include "tests.h" |
12 | 13 | ||
13 | #include "../arch/x86/util/tsc.h" | ||
14 | |||
15 | #define CHECK__(x) { \ | 14 | #define CHECK__(x) { \ |
16 | while ((x) < 0) { \ | 15 | while ((x) < 0) { \ |
17 | pr_debug(#x " failed!\n"); \ | 16 | pr_debug(#x " failed!\n"); \ |
diff --git a/tools/perf/util/tsc.c b/tools/perf/util/tsc.c new file mode 100644 index 000000000000..ef4749836ce9 --- /dev/null +++ b/tools/perf/util/tsc.c | |||
@@ -0,0 +1,25 @@ | |||
1 | #include <linux/compiler.h> | ||
2 | #include <linux/types.h> | ||
3 | |||
4 | #include "tsc.h" | ||
5 | |||
6 | u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc) | ||
7 | { | ||
8 | u64 t, quot, rem; | ||
9 | |||
10 | t = ns - tc->time_zero; | ||
11 | quot = t / tc->time_mult; | ||
12 | rem = t % tc->time_mult; | ||
13 | return (quot << tc->time_shift) + | ||
14 | (rem << tc->time_shift) / tc->time_mult; | ||
15 | } | ||
16 | |||
17 | u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc) | ||
18 | { | ||
19 | u64 quot, rem; | ||
20 | |||
21 | quot = cyc >> tc->time_shift; | ||
22 | rem = cyc & ((1 << tc->time_shift) - 1); | ||
23 | return tc->time_zero + quot * tc->time_mult + | ||
24 | ((rem * tc->time_mult) >> tc->time_shift); | ||
25 | } | ||
diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h new file mode 100644 index 000000000000..4eca84887c8a --- /dev/null +++ b/tools/perf/util/tsc.h | |||
@@ -0,0 +1,11 @@ | |||
1 | #ifndef __PERF_TSC_H | ||
2 | #define __PERF_TSC_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | |||
6 | #include "../arch/x86/util/tsc.h" | ||
7 | |||
8 | u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc); | ||
9 | u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc); | ||
10 | |||
11 | #endif | ||