Skip to content

Commit a6a69db

Browse files
ahunter6acmel
authored andcommitted
perf tools: Move rdtsc() function
Move the rdtsc() function so it can be reusued. Signed-off-by: Adrian Hunter <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b9d266b commit a6a69db

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

tools/perf/arch/x86/util/tsc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
3737

3838
return 0;
3939
}
40+
41+
u64 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+
}

tools/perf/tests/perf-time-to-tsc.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@
2525
} \
2626
}
2727

28-
static 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-
3728
/**
3829
* test__perf_time_to_tsc - test converting perf time to TSC.
3930
*

tools/perf/util/tsc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc)
2323
return tc->time_zero + quot * tc->time_mult +
2424
((rem * tc->time_mult) >> tc->time_shift);
2525
}
26+
27+
u64 __weak rdtsc(void)
28+
{
29+
return 0;
30+
}

tools/perf/util/tsc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77

88
u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
99
u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
10+
u64 rdtsc(void);
1011

1112
#endif

0 commit comments

Comments
 (0)