Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 1 | #ifndef _LINUX_TIMEKEEPING_H |
| 2 | #define _LINUX_TIMEKEEPING_H |
| 3 | |
| 4 | /* Included from linux/ktime.h */ |
| 5 | |
| 6 | void timekeeping_init(void); |
| 7 | extern int timekeeping_suspended; |
| 8 | |
| 9 | /* |
| 10 | * Get and set timeofday |
| 11 | */ |
| 12 | extern void do_gettimeofday(struct timeval *tv); |
| 13 | extern int do_settimeofday(const struct timespec *tv); |
| 14 | extern int do_sys_settimeofday(const struct timespec *tv, |
| 15 | const struct timezone *tz); |
| 16 | |
| 17 | /* |
| 18 | * Kernel time accessors |
| 19 | */ |
| 20 | unsigned long get_seconds(void); |
| 21 | struct timespec current_kernel_time(void); |
| 22 | /* does not take xtime_lock */ |
| 23 | struct timespec __current_kernel_time(void); |
| 24 | |
| 25 | /* |
| 26 | * timespec based interfaces |
| 27 | */ |
| 28 | struct timespec get_monotonic_coarse(void); |
| 29 | extern void getrawmonotonic(struct timespec *ts); |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 30 | extern void ktime_get_ts64(struct timespec64 *ts); |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 31 | |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 32 | extern int __getnstimeofday64(struct timespec64 *tv); |
| 33 | extern void getnstimeofday64(struct timespec64 *tv); |
| 34 | |
| 35 | #if BITS_PER_LONG == 64 |
| 36 | static inline int __getnstimeofday(struct timespec *ts) |
| 37 | { |
| 38 | return __getnstimeofday64(ts); |
| 39 | } |
| 40 | |
| 41 | static inline void getnstimeofday(struct timespec *ts) |
| 42 | { |
| 43 | getnstimeofday64(ts); |
| 44 | } |
| 45 | |
| 46 | static inline void ktime_get_ts(struct timespec *ts) |
| 47 | { |
| 48 | ktime_get_ts64(ts); |
| 49 | } |
| 50 | |
| 51 | static inline void ktime_get_real_ts(struct timespec *ts) |
| 52 | { |
| 53 | getnstimeofday64(ts); |
| 54 | } |
| 55 | |
| 56 | #else |
| 57 | static inline int __getnstimeofday(struct timespec *ts) |
| 58 | { |
| 59 | struct timespec64 ts64; |
| 60 | int ret = __getnstimeofday64(&ts64); |
| 61 | |
| 62 | *ts = timespec64_to_timespec(ts64); |
| 63 | return ret; |
| 64 | } |
| 65 | |
| 66 | static inline void getnstimeofday(struct timespec *ts) |
| 67 | { |
| 68 | struct timespec64 ts64; |
| 69 | |
| 70 | getnstimeofday64(&ts64); |
| 71 | *ts = timespec64_to_timespec(ts64); |
| 72 | } |
| 73 | |
| 74 | static inline void ktime_get_ts(struct timespec *ts) |
| 75 | { |
| 76 | struct timespec64 ts64; |
| 77 | |
| 78 | ktime_get_ts64(&ts64); |
| 79 | *ts = timespec64_to_timespec(ts64); |
| 80 | } |
| 81 | |
| 82 | static inline void ktime_get_real_ts(struct timespec *ts) |
| 83 | { |
| 84 | struct timespec64 ts64; |
| 85 | |
| 86 | getnstimeofday64(&ts64); |
| 87 | *ts = timespec64_to_timespec(ts64); |
| 88 | } |
| 89 | #endif |
| 90 | |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 91 | extern void getboottime(struct timespec *ts); |
| 92 | |
| 93 | #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 94 | #define ktime_get_real_ts64(ts) getnstimeofday64(ts) |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * ktime_t based interfaces |
| 98 | */ |
Thomas Gleixner | 0077dc6 | 2014-07-16 21:04:13 +0000 | [diff] [blame] | 99 | |
| 100 | enum tk_offsets { |
| 101 | TK_OFFS_REAL, |
| 102 | TK_OFFS_BOOT, |
| 103 | TK_OFFS_TAI, |
| 104 | TK_OFFS_MAX, |
| 105 | }; |
| 106 | |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 107 | extern ktime_t ktime_get(void); |
Thomas Gleixner | 0077dc6 | 2014-07-16 21:04:13 +0000 | [diff] [blame] | 108 | extern ktime_t ktime_get_with_offset(enum tk_offsets offs); |
Thomas Gleixner | 9a6b519 | 2014-07-16 21:04:22 +0000 | [diff] [blame] | 109 | extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs); |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 110 | |
Thomas Gleixner | f5264d5 | 2014-07-16 21:04:14 +0000 | [diff] [blame] | 111 | /** |
| 112 | * ktime_get_real - get the real (wall-) time in ktime_t format |
| 113 | */ |
| 114 | static inline ktime_t ktime_get_real(void) |
| 115 | { |
| 116 | return ktime_get_with_offset(TK_OFFS_REAL); |
| 117 | } |
| 118 | |
Thomas Gleixner | b82c817 | 2014-07-16 21:04:16 +0000 | [diff] [blame] | 119 | /** |
| 120 | * ktime_get_boottime - Returns monotonic time since boot in ktime_t format |
| 121 | * |
| 122 | * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the |
| 123 | * time spent in suspend. |
| 124 | */ |
| 125 | static inline ktime_t ktime_get_boottime(void) |
| 126 | { |
| 127 | return ktime_get_with_offset(TK_OFFS_BOOT); |
| 128 | } |
| 129 | |
Thomas Gleixner | afab07c | 2014-07-16 21:04:17 +0000 | [diff] [blame] | 130 | /** |
| 131 | * ktime_get_clocktai - Returns the TAI time of day in ktime_t format |
| 132 | */ |
| 133 | static inline ktime_t ktime_get_clocktai(void) |
| 134 | { |
| 135 | return ktime_get_with_offset(TK_OFFS_TAI); |
| 136 | } |
| 137 | |
Thomas Gleixner | 9a6b519 | 2014-07-16 21:04:22 +0000 | [diff] [blame] | 138 | /** |
| 139 | * ktime_mono_to_real - Convert monotonic time to clock realtime |
| 140 | */ |
| 141 | static inline ktime_t ktime_mono_to_real(ktime_t mono) |
| 142 | { |
| 143 | return ktime_mono_to_any(mono, TK_OFFS_REAL); |
| 144 | } |
| 145 | |
Thomas Gleixner | 897994e | 2014-07-16 21:04:29 +0000 | [diff] [blame] | 146 | static inline u64 ktime_get_ns(void) |
| 147 | { |
| 148 | return ktime_to_ns(ktime_get()); |
| 149 | } |
| 150 | |
| 151 | static inline u64 ktime_get_real_ns(void) |
| 152 | { |
| 153 | return ktime_to_ns(ktime_get_real()); |
| 154 | } |
| 155 | |
| 156 | static inline u64 ktime_get_boot_ns(void) |
| 157 | { |
| 158 | return ktime_to_ns(ktime_get_boottime()); |
| 159 | } |
| 160 | |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 161 | /* |
Thomas Gleixner | 48f18fd | 2014-07-16 21:04:57 +0000 | [diff] [blame] | 162 | * Timespec interfaces utilizing the ktime based ones |
| 163 | */ |
| 164 | static inline void get_monotonic_boottime(struct timespec *ts) |
| 165 | { |
| 166 | *ts = ktime_to_timespec(ktime_get_boottime()); |
| 167 | } |
| 168 | |
Thomas Gleixner | 61edec8 | 2014-07-16 21:05:01 +0000 | [diff] [blame] | 169 | static inline void timekeeping_clocktai(struct timespec *ts) |
| 170 | { |
| 171 | *ts = ktime_to_timespec(ktime_get_clocktai()); |
| 172 | } |
| 173 | |
Thomas Gleixner | 48f18fd | 2014-07-16 21:04:57 +0000 | [diff] [blame] | 174 | /* |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 175 | * RTC specific |
| 176 | */ |
| 177 | extern void timekeeping_inject_sleeptime(struct timespec *delta); |
| 178 | |
| 179 | /* |
| 180 | * PPS accessor |
| 181 | */ |
| 182 | extern void getnstime_raw_and_real(struct timespec *ts_raw, |
| 183 | struct timespec *ts_real); |
| 184 | |
| 185 | /* |
| 186 | * Persistent clock related interfaces |
| 187 | */ |
| 188 | extern bool persistent_clock_exist; |
| 189 | extern int persistent_clock_is_local; |
| 190 | |
| 191 | static inline bool has_persistent_clock(void) |
| 192 | { |
| 193 | return persistent_clock_exist; |
| 194 | } |
| 195 | |
| 196 | extern void read_persistent_clock(struct timespec *ts); |
| 197 | extern void read_boot_clock(struct timespec *ts); |
| 198 | extern int update_persistent_clock(struct timespec now); |
| 199 | |
| 200 | |
| 201 | #endif |