timekeeping.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef _LINUX_TIMEKEEPING_H
  2. #define _LINUX_TIMEKEEPING_H
  3. /* Included from linux/ktime.h */
  4. void timekeeping_init(void);
  5. extern int timekeeping_suspended;
  6. /*
  7. * Get and set timeofday
  8. */
  9. extern void do_gettimeofday(struct timeval *tv);
  10. extern int do_settimeofday(const struct timespec *tv);
  11. extern int do_sys_settimeofday(const struct timespec *tv,
  12. const struct timezone *tz);
  13. /*
  14. * Kernel time accessors
  15. */
  16. unsigned long get_seconds(void);
  17. struct timespec current_kernel_time(void);
  18. /* does not take xtime_lock */
  19. struct timespec __current_kernel_time(void);
  20. /*
  21. * timespec based interfaces
  22. */
  23. struct timespec get_monotonic_coarse(void);
  24. extern void getrawmonotonic(struct timespec *ts);
  25. extern void monotonic_to_bootbased(struct timespec *ts);
  26. extern void get_monotonic_boottime(struct timespec *ts);
  27. extern void ktime_get_ts64(struct timespec64 *ts);
  28. extern int __getnstimeofday64(struct timespec64 *tv);
  29. extern void getnstimeofday64(struct timespec64 *tv);
  30. #if BITS_PER_LONG == 64
  31. static inline int __getnstimeofday(struct timespec *ts)
  32. {
  33. return __getnstimeofday64(ts);
  34. }
  35. static inline void getnstimeofday(struct timespec *ts)
  36. {
  37. getnstimeofday64(ts);
  38. }
  39. static inline void ktime_get_ts(struct timespec *ts)
  40. {
  41. ktime_get_ts64(ts);
  42. }
  43. static inline void ktime_get_real_ts(struct timespec *ts)
  44. {
  45. getnstimeofday64(ts);
  46. }
  47. #else
  48. static inline int __getnstimeofday(struct timespec *ts)
  49. {
  50. struct timespec64 ts64;
  51. int ret = __getnstimeofday64(&ts64);
  52. *ts = timespec64_to_timespec(ts64);
  53. return ret;
  54. }
  55. static inline void getnstimeofday(struct timespec *ts)
  56. {
  57. struct timespec64 ts64;
  58. getnstimeofday64(&ts64);
  59. *ts = timespec64_to_timespec(ts64);
  60. }
  61. static inline void ktime_get_ts(struct timespec *ts)
  62. {
  63. struct timespec64 ts64;
  64. ktime_get_ts64(&ts64);
  65. *ts = timespec64_to_timespec(ts64);
  66. }
  67. static inline void ktime_get_real_ts(struct timespec *ts)
  68. {
  69. struct timespec64 ts64;
  70. getnstimeofday64(&ts64);
  71. *ts = timespec64_to_timespec(ts64);
  72. }
  73. #endif
  74. extern void getboottime(struct timespec *ts);
  75. #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
  76. #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
  77. /*
  78. * ktime_t based interfaces
  79. */
  80. extern ktime_t ktime_get(void);
  81. extern ktime_t ktime_get_real(void);
  82. extern ktime_t ktime_get_boottime(void);
  83. extern ktime_t ktime_get_monotonic_offset(void);
  84. extern ktime_t ktime_get_clocktai(void);
  85. /*
  86. * RTC specific
  87. */
  88. extern void timekeeping_inject_sleeptime(struct timespec *delta);
  89. /*
  90. * PPS accessor
  91. */
  92. extern void getnstime_raw_and_real(struct timespec *ts_raw,
  93. struct timespec *ts_real);
  94. /*
  95. * Persistent clock related interfaces
  96. */
  97. extern bool persistent_clock_exist;
  98. extern int persistent_clock_is_local;
  99. static inline bool has_persistent_clock(void)
  100. {
  101. return persistent_clock_exist;
  102. }
  103. extern void read_persistent_clock(struct timespec *ts);
  104. extern void read_boot_clock(struct timespec *ts);
  105. extern int update_persistent_clock(struct timespec now);
  106. #endif