timex.h 837 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  4. */
  5. #ifndef _ASM_TIMEX_H
  6. #define _ASM_TIMEX_H
  7. #ifdef __KERNEL__
  8. #include <linux/compiler.h>
  9. #include <asm/cpu.h>
  10. #include <asm/cpu-features.h>
  11. typedef unsigned long cycles_t;
  12. #define get_cycles get_cycles
  13. static inline cycles_t get_cycles(void)
  14. {
  15. #ifdef CONFIG_32BIT
  16. return rdtime_l();
  17. #else
  18. return rdtime_d();
  19. #endif
  20. }
  21. #ifdef CONFIG_32BIT
  22. #define get_cycles_hi get_cycles_hi
  23. static inline cycles_t get_cycles_hi(void)
  24. {
  25. return rdtime_h();
  26. }
  27. #endif
  28. static inline u64 get_cycles64(void)
  29. {
  30. #ifdef CONFIG_32BIT
  31. u32 hi, lo;
  32. do {
  33. hi = rdtime_h();
  34. lo = rdtime_l();
  35. } while (hi != rdtime_h());
  36. return ((u64)hi << 32) | lo;
  37. #else
  38. return rdtime_d();
  39. #endif
  40. }
  41. #endif /* __KERNEL__ */
  42. #endif /* _ASM_TIMEX_H */