timex.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2012 Regents of the University of California
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _ASM_RISCV_TIMEX_H
  14. #define _ASM_RISCV_TIMEX_H
  15. #include <asm/param.h>
  16. typedef unsigned long cycles_t;
  17. static inline cycles_t get_cycles_inline(void)
  18. {
  19. cycles_t n;
  20. __asm__ __volatile__ (
  21. "rdtime %0"
  22. : "=r" (n));
  23. return n;
  24. }
  25. #define get_cycles get_cycles_inline
  26. #ifdef CONFIG_64BIT
  27. static inline uint64_t get_cycles64(void)
  28. {
  29. return get_cycles();
  30. }
  31. #else
  32. static inline uint64_t get_cycles64(void)
  33. {
  34. u32 lo, hi, tmp;
  35. __asm__ __volatile__ (
  36. "1:\n"
  37. "rdtimeh %0\n"
  38. "rdtime %1\n"
  39. "rdtimeh %2\n"
  40. "bne %0, %2, 1b"
  41. : "=&r" (hi), "=&r" (lo), "=&r" (tmp));
  42. return ((u64)hi << 32) | lo;
  43. }
  44. #endif
  45. #define ARCH_HAS_READ_CURRENT_TIMER
  46. static inline int read_current_timer(unsigned long *timer_val)
  47. {
  48. *timer_val = get_cycles();
  49. return 0;
  50. }
  51. #endif /* _ASM_RISCV_TIMEX_H */