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); |
pang.xunlei | 21f7eca | 2014-11-18 19:15:16 +0800 | [diff] [blame] | 13 | extern int do_settimeofday64(const struct timespec64 *ts); |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 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 | */ |
John Stultz | 334334b | 2014-11-07 11:20:40 -0800 | [diff] [blame] | 28 | struct timespec64 get_monotonic_coarse64(void); |
John Stultz | cdba2ec | 2014-11-07 11:03:20 -0800 | [diff] [blame] | 29 | extern void getrawmonotonic64(struct timespec64 *ts); |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 30 | extern void ktime_get_ts64(struct timespec64 *ts); |
Heena Sirwani | 9e3680b | 2014-10-29 16:01:16 +0530 | [diff] [blame] | 31 | extern time64_t ktime_get_seconds(void); |
Heena Sirwani | dbe7aa6 | 2014-10-29 16:01:50 +0530 | [diff] [blame] | 32 | extern time64_t ktime_get_real_seconds(void); |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 33 | |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 34 | extern int __getnstimeofday64(struct timespec64 *tv); |
| 35 | extern void getnstimeofday64(struct timespec64 *tv); |
John Stultz | d08c0cd | 2014-12-08 12:00:09 -0800 | [diff] [blame] | 36 | extern void getboottime64(struct timespec64 *ts); |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 37 | |
| 38 | #if BITS_PER_LONG == 64 |
pang.xunlei | 21f7eca | 2014-11-18 19:15:16 +0800 | [diff] [blame] | 39 | /** |
| 40 | * Deprecated. Use do_settimeofday64(). |
| 41 | */ |
| 42 | static inline int do_settimeofday(const struct timespec *ts) |
| 43 | { |
| 44 | return do_settimeofday64(ts); |
| 45 | } |
| 46 | |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 47 | static inline int __getnstimeofday(struct timespec *ts) |
| 48 | { |
| 49 | return __getnstimeofday64(ts); |
| 50 | } |
| 51 | |
| 52 | static inline void getnstimeofday(struct timespec *ts) |
| 53 | { |
| 54 | getnstimeofday64(ts); |
| 55 | } |
| 56 | |
| 57 | static inline void ktime_get_ts(struct timespec *ts) |
| 58 | { |
| 59 | ktime_get_ts64(ts); |
| 60 | } |
| 61 | |
| 62 | static inline void ktime_get_real_ts(struct timespec *ts) |
| 63 | { |
| 64 | getnstimeofday64(ts); |
| 65 | } |
| 66 | |
John Stultz | cdba2ec | 2014-11-07 11:03:20 -0800 | [diff] [blame] | 67 | static inline void getrawmonotonic(struct timespec *ts) |
| 68 | { |
| 69 | getrawmonotonic64(ts); |
| 70 | } |
| 71 | |
John Stultz | 334334b | 2014-11-07 11:20:40 -0800 | [diff] [blame] | 72 | static inline struct timespec get_monotonic_coarse(void) |
| 73 | { |
| 74 | return get_monotonic_coarse64(); |
| 75 | } |
John Stultz | d08c0cd | 2014-12-08 12:00:09 -0800 | [diff] [blame] | 76 | |
| 77 | static inline void getboottime(struct timespec *ts) |
| 78 | { |
| 79 | return getboottime64(ts); |
| 80 | } |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 81 | #else |
pang.xunlei | 21f7eca | 2014-11-18 19:15:16 +0800 | [diff] [blame] | 82 | /** |
| 83 | * Deprecated. Use do_settimeofday64(). |
| 84 | */ |
| 85 | static inline int do_settimeofday(const struct timespec *ts) |
| 86 | { |
| 87 | struct timespec64 ts64; |
| 88 | |
| 89 | ts64 = timespec_to_timespec64(*ts); |
| 90 | return do_settimeofday64(&ts64); |
| 91 | } |
| 92 | |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 93 | static inline int __getnstimeofday(struct timespec *ts) |
| 94 | { |
| 95 | struct timespec64 ts64; |
| 96 | int ret = __getnstimeofday64(&ts64); |
| 97 | |
| 98 | *ts = timespec64_to_timespec(ts64); |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | static inline void getnstimeofday(struct timespec *ts) |
| 103 | { |
| 104 | struct timespec64 ts64; |
| 105 | |
| 106 | getnstimeofday64(&ts64); |
| 107 | *ts = timespec64_to_timespec(ts64); |
| 108 | } |
| 109 | |
| 110 | static inline void ktime_get_ts(struct timespec *ts) |
| 111 | { |
| 112 | struct timespec64 ts64; |
| 113 | |
| 114 | ktime_get_ts64(&ts64); |
| 115 | *ts = timespec64_to_timespec(ts64); |
| 116 | } |
| 117 | |
| 118 | static inline void ktime_get_real_ts(struct timespec *ts) |
| 119 | { |
| 120 | struct timespec64 ts64; |
| 121 | |
| 122 | getnstimeofday64(&ts64); |
| 123 | *ts = timespec64_to_timespec(ts64); |
| 124 | } |
John Stultz | cdba2ec | 2014-11-07 11:03:20 -0800 | [diff] [blame] | 125 | |
| 126 | static inline void getrawmonotonic(struct timespec *ts) |
| 127 | { |
| 128 | struct timespec64 ts64; |
| 129 | |
| 130 | getrawmonotonic64(&ts64); |
| 131 | *ts = timespec64_to_timespec(ts64); |
| 132 | } |
John Stultz | 334334b | 2014-11-07 11:20:40 -0800 | [diff] [blame] | 133 | |
| 134 | static inline struct timespec get_monotonic_coarse(void) |
| 135 | { |
| 136 | return timespec64_to_timespec(get_monotonic_coarse64()); |
| 137 | } |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 138 | |
John Stultz | d08c0cd | 2014-12-08 12:00:09 -0800 | [diff] [blame] | 139 | static inline void getboottime(struct timespec *ts) |
| 140 | { |
| 141 | struct timespec64 ts64; |
| 142 | |
| 143 | getboottime64(&ts64); |
| 144 | *ts = timespec64_to_timespec(ts64); |
| 145 | } |
| 146 | #endif |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 147 | |
| 148 | #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) |
Thomas Gleixner | d6d2989 | 2014-07-16 21:04:04 +0000 | [diff] [blame] | 149 | #define ktime_get_real_ts64(ts) getnstimeofday64(ts) |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * ktime_t based interfaces |
| 153 | */ |
Thomas Gleixner | 0077dc6 | 2014-07-16 21:04:13 +0000 | [diff] [blame] | 154 | |
| 155 | enum tk_offsets { |
| 156 | TK_OFFS_REAL, |
| 157 | TK_OFFS_BOOT, |
| 158 | TK_OFFS_TAI, |
| 159 | TK_OFFS_MAX, |
| 160 | }; |
| 161 | |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 162 | extern ktime_t ktime_get(void); |
Thomas Gleixner | 0077dc6 | 2014-07-16 21:04:13 +0000 | [diff] [blame] | 163 | extern ktime_t ktime_get_with_offset(enum tk_offsets offs); |
Thomas Gleixner | 9a6b519 | 2014-07-16 21:04:22 +0000 | [diff] [blame] | 164 | extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs); |
Thomas Gleixner | f519b1a | 2014-07-16 21:05:04 +0000 | [diff] [blame] | 165 | extern ktime_t ktime_get_raw(void); |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 166 | |
Thomas Gleixner | f5264d5 | 2014-07-16 21:04:14 +0000 | [diff] [blame] | 167 | /** |
| 168 | * ktime_get_real - get the real (wall-) time in ktime_t format |
| 169 | */ |
| 170 | static inline ktime_t ktime_get_real(void) |
| 171 | { |
| 172 | return ktime_get_with_offset(TK_OFFS_REAL); |
| 173 | } |
| 174 | |
Thomas Gleixner | b82c817 | 2014-07-16 21:04:16 +0000 | [diff] [blame] | 175 | /** |
| 176 | * ktime_get_boottime - Returns monotonic time since boot in ktime_t format |
| 177 | * |
| 178 | * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the |
| 179 | * time spent in suspend. |
| 180 | */ |
| 181 | static inline ktime_t ktime_get_boottime(void) |
| 182 | { |
| 183 | return ktime_get_with_offset(TK_OFFS_BOOT); |
| 184 | } |
| 185 | |
Thomas Gleixner | afab07c | 2014-07-16 21:04:17 +0000 | [diff] [blame] | 186 | /** |
| 187 | * ktime_get_clocktai - Returns the TAI time of day in ktime_t format |
| 188 | */ |
| 189 | static inline ktime_t ktime_get_clocktai(void) |
| 190 | { |
| 191 | return ktime_get_with_offset(TK_OFFS_TAI); |
| 192 | } |
| 193 | |
Thomas Gleixner | 9a6b519 | 2014-07-16 21:04:22 +0000 | [diff] [blame] | 194 | /** |
| 195 | * ktime_mono_to_real - Convert monotonic time to clock realtime |
| 196 | */ |
| 197 | static inline ktime_t ktime_mono_to_real(ktime_t mono) |
| 198 | { |
| 199 | return ktime_mono_to_any(mono, TK_OFFS_REAL); |
| 200 | } |
| 201 | |
Thomas Gleixner | 897994e | 2014-07-16 21:04:29 +0000 | [diff] [blame] | 202 | static inline u64 ktime_get_ns(void) |
| 203 | { |
| 204 | return ktime_to_ns(ktime_get()); |
| 205 | } |
| 206 | |
| 207 | static inline u64 ktime_get_real_ns(void) |
| 208 | { |
| 209 | return ktime_to_ns(ktime_get_real()); |
| 210 | } |
| 211 | |
| 212 | static inline u64 ktime_get_boot_ns(void) |
| 213 | { |
| 214 | return ktime_to_ns(ktime_get_boottime()); |
| 215 | } |
| 216 | |
Peter Zijlstra | fe5fba0 | 2015-03-17 12:39:10 +0100 | [diff] [blame] | 217 | static inline u64 ktime_get_tai_ns(void) |
| 218 | { |
| 219 | return ktime_to_ns(ktime_get_clocktai()); |
| 220 | } |
| 221 | |
Thomas Gleixner | f519b1a | 2014-07-16 21:05:04 +0000 | [diff] [blame] | 222 | static inline u64 ktime_get_raw_ns(void) |
| 223 | { |
| 224 | return ktime_to_ns(ktime_get_raw()); |
| 225 | } |
| 226 | |
Thomas Gleixner | 4396e05 | 2014-07-16 21:05:23 +0000 | [diff] [blame] | 227 | extern u64 ktime_get_mono_fast_ns(void); |
Peter Zijlstra | f09cb9a | 2015-03-19 09:39:08 +0100 | [diff] [blame] | 228 | extern u64 ktime_get_raw_fast_ns(void); |
Thomas Gleixner | 4396e05 | 2014-07-16 21:05:23 +0000 | [diff] [blame] | 229 | |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 230 | /* |
Thomas Gleixner | 48f18fd | 2014-07-16 21:04:57 +0000 | [diff] [blame] | 231 | * Timespec interfaces utilizing the ktime based ones |
| 232 | */ |
| 233 | static inline void get_monotonic_boottime(struct timespec *ts) |
| 234 | { |
| 235 | *ts = ktime_to_timespec(ktime_get_boottime()); |
| 236 | } |
| 237 | |
John Stultz | 2e0c78e | 2014-12-18 18:04:34 -0800 | [diff] [blame] | 238 | static inline void get_monotonic_boottime64(struct timespec64 *ts) |
| 239 | { |
| 240 | *ts = ktime_to_timespec64(ktime_get_boottime()); |
| 241 | } |
| 242 | |
Thomas Gleixner | 61edec8 | 2014-07-16 21:05:01 +0000 | [diff] [blame] | 243 | static inline void timekeeping_clocktai(struct timespec *ts) |
| 244 | { |
| 245 | *ts = ktime_to_timespec(ktime_get_clocktai()); |
| 246 | } |
| 247 | |
Thomas Gleixner | 48f18fd | 2014-07-16 21:04:57 +0000 | [diff] [blame] | 248 | /* |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 249 | * RTC specific |
| 250 | */ |
Xunlei Pang | 0fa88cb | 2015-04-01 20:34:38 -0700 | [diff] [blame] | 251 | extern bool timekeeping_rtc_skipsuspend(void); |
| 252 | extern bool timekeeping_rtc_skipresume(void); |
| 253 | |
pang.xunlei | 04d9089 | 2014-11-18 19:15:17 +0800 | [diff] [blame] | 254 | extern void timekeeping_inject_sleeptime64(struct timespec64 *delta); |
| 255 | |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 256 | /* |
| 257 | * PPS accessor |
| 258 | */ |
| 259 | extern void getnstime_raw_and_real(struct timespec *ts_raw, |
| 260 | struct timespec *ts_real); |
| 261 | |
| 262 | /* |
| 263 | * Persistent clock related interfaces |
| 264 | */ |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 265 | extern int persistent_clock_is_local; |
| 266 | |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 267 | extern void read_persistent_clock(struct timespec *ts); |
Xunlei Pang | 2ee9663 | 2015-04-01 20:34:22 -0700 | [diff] [blame] | 268 | extern void read_persistent_clock64(struct timespec64 *ts); |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 269 | extern void read_boot_clock(struct timespec *ts); |
Xunlei Pang | 9a806dd | 2015-04-01 20:34:21 -0700 | [diff] [blame] | 270 | extern void read_boot_clock64(struct timespec64 *ts); |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 271 | extern int update_persistent_clock(struct timespec now); |
Xunlei Pang | 3c00a1f | 2015-04-01 20:34:23 -0700 | [diff] [blame] | 272 | extern int update_persistent_clock64(struct timespec64 now); |
Thomas Gleixner | 8b094cd | 2014-07-16 21:04:02 +0000 | [diff] [blame] | 273 | |
| 274 | |
| 275 | #endif |