Linux 5.1.15
[linux/fpc-iii.git] / tools / perf / util / tsc.c
blobbfa782421cbdf93087aba761fccf0120bccb036f
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include <linux/types.h>
5 #include "tsc.h"
7 u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc)
9 u64 t, quot, rem;
11 t = ns - tc->time_zero;
12 quot = t / tc->time_mult;
13 rem = t % tc->time_mult;
14 return (quot << tc->time_shift) +
15 (rem << tc->time_shift) / tc->time_mult;
18 u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc)
20 u64 quot, rem;
22 quot = cyc >> tc->time_shift;
23 rem = cyc & (((u64)1 << tc->time_shift) - 1);
24 return tc->time_zero + quot * tc->time_mult +
25 ((rem * tc->time_mult) >> tc->time_shift);
28 u64 __weak rdtsc(void)
30 return 0;