aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/arch/x86/util/tsc.c9
-rw-r--r--tools/perf/tests/perf-time-to-tsc.c9
-rw-r--r--tools/perf/util/tsc.c5
-rw-r--r--tools/perf/util/tsc.h1
4 files changed, 15 insertions, 9 deletions
diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index 3655f24c3170..fd2868490d00 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -37,3 +37,12 @@ int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
37 37
38 return 0; 38 return 0;
39} 39}
40
41u64 rdtsc(void)
42{
43 unsigned int low, high;
44
45 asm volatile("rdtsc" : "=a" (low), "=d" (high));
46
47 return low | ((u64)high) << 32;
48}
diff --git a/tools/perf/tests/perf-time-to-tsc.c b/tools/perf/tests/perf-time-to-tsc.c
index 0372f6edca20..f238442b238a 100644
--- a/tools/perf/tests/perf-time-to-tsc.c
+++ b/tools/perf/tests/perf-time-to-tsc.c
@@ -25,15 +25,6 @@
25 } \ 25 } \
26} 26}
27 27
28static u64 rdtsc(void)
29{
30 unsigned int low, high;
31
32 asm volatile("rdtsc" : "=a" (low), "=d" (high));
33
34 return low | ((u64)high) << 32;
35}
36
37/** 28/**
38 * test__perf_time_to_tsc - test converting perf time to TSC. 29 * test__perf_time_to_tsc - test converting perf time to TSC.
39 * 30 *
diff --git a/tools/perf/util/tsc.c b/tools/perf/util/tsc.c
index ef4749836ce9..4d4210d4e13d 100644
--- a/tools/perf/util/tsc.c
+++ b/tools/perf/util/tsc.c
@@ -23,3 +23,8 @@ u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc)
23 return tc->time_zero + quot * tc->time_mult + 23 return tc->time_zero + quot * tc->time_mult +
24 ((rem * tc->time_mult) >> tc->time_shift); 24 ((rem * tc->time_mult) >> tc->time_shift);
25} 25}
26
27u64 __weak rdtsc(void)
28{
29 return 0;
30}
diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
index 4eca84887c8a..a8b78f1b3243 100644
--- a/tools/perf/util/tsc.h
+++ b/tools/perf/util/tsc.h
@@ -7,5 +7,6 @@
7 7
8u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc); 8u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
9u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc); 9u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
10u64 rdtsc(void);
10 11
11#endif 12#endif