Skip to content

Commit

Permalink
perf tools: Move rdtsc() function
Browse files Browse the repository at this point in the history
Move the rdtsc() function so it can be reusued.

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/1406035081-14301-24-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Adrian Hunter authored and Arnaldo Carvalho de Melo committed Jul 23, 2014
1 parent b9d266b commit a6a69db
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
9 changes: 9 additions & 0 deletions tools/perf/arch/x86/util/tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,

return 0;
}

u64 rdtsc(void)
{
unsigned int low, high;

asm volatile("rdtsc" : "=a" (low), "=d" (high));

return low | ((u64)high) << 32;
}
9 changes: 0 additions & 9 deletions tools/perf/tests/perf-time-to-tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
} \
}

static u64 rdtsc(void)
{
unsigned int low, high;

asm volatile("rdtsc" : "=a" (low), "=d" (high));

return low | ((u64)high) << 32;
}

/**
* test__perf_time_to_tsc - test converting perf time to TSC.
*
Expand Down
5 changes: 5 additions & 0 deletions tools/perf/util/tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc)
return tc->time_zero + quot * tc->time_mult +
((rem * tc->time_mult) >> tc->time_shift);
}

u64 __weak rdtsc(void)
{
return 0;
}
1 change: 1 addition & 0 deletions tools/perf/util/tsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
u64 rdtsc(void);

#endif

0 comments on commit a6a69db

Please sign in to comment.