Adrian Hunter | 0b43786 | 2014-07-14 13:03:03 +0300 | [diff] [blame] | 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; |
Adrian Hunter | a23f96e | 2016-03-07 16:44:42 -0300 | [diff] [blame] | 22 | rem = cyc & (((u64)1 << tc->time_shift) - 1); |
Adrian Hunter | 0b43786 | 2014-07-14 13:03:03 +0300 | [diff] [blame] | 23 | return tc->time_zero + quot * tc->time_mult + |
| 24 | ((rem * tc->time_mult) >> tc->time_shift); |
| 25 | } |
Adrian Hunter | a6a69db | 2014-07-22 16:17:32 +0300 | [diff] [blame] | 26 | |
| 27 | u64 __weak rdtsc(void) |
| 28 | { |
| 29 | return 0; |
| 30 | } |