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