tsc.c 620 B

12345678910111213141516171819202122232425262728293031
  1. #include <linux/compiler.h>
  2. #include <linux/types.h>
  3. #include "tsc.h"
  4. u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc)
  5. {
  6. u64 t, quot, rem;
  7. t = ns - tc->time_zero;
  8. quot = t / tc->time_mult;
  9. rem = t % tc->time_mult;
  10. return (quot << tc->time_shift) +
  11. (rem << tc->time_shift) / tc->time_mult;
  12. }
  13. u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc)
  14. {
  15. u64 quot, rem;
  16. quot = cyc >> tc->time_shift;
  17. rem = cyc & (((u64)1 << tc->time_shift) - 1);
  18. return tc->time_zero + quot * tc->time_mult +
  19. ((rem * tc->time_mult) >> tc->time_shift);
  20. }
  21. u64 __weak rdtsc(void)
  22. {
  23. return 0;
  24. }