1 #ifndef _LINUX_TIMEKEEPING_H
2 #define _LINUX_TIMEKEEPING_H
4 /* Included from linux/ktime.h */
6 void timekeeping_init(void);
7 extern int timekeeping_suspended;
10 * Get and set timeofday
12 extern void do_gettimeofday(struct timeval *tv);
13 extern int do_settimeofday64(const struct timespec64 *ts);
14 extern int do_sys_settimeofday(const struct timespec *tv,
15 const struct timezone *tz);
18 * Kernel time accessors
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);
26 * timespec based interfaces
28 struct timespec64 get_monotonic_coarse64(void);
29 extern void getrawmonotonic64(struct timespec64 *ts);
30 extern void ktime_get_ts64(struct timespec64 *ts);
31 extern time64_t ktime_get_seconds(void);
32 extern time64_t ktime_get_real_seconds(void);
34 extern int __getnstimeofday64(struct timespec64 *tv);
35 extern void getnstimeofday64(struct timespec64 *tv);
37 #if BITS_PER_LONG == 64
39 * Deprecated. Use do_settimeofday64().
41 static inline int do_settimeofday(const struct timespec *ts)
43 return do_settimeofday64(ts);
46 static inline int __getnstimeofday(struct timespec *ts)
48 return __getnstimeofday64(ts);
51 static inline void getnstimeofday(struct timespec *ts)
56 static inline void ktime_get_ts(struct timespec *ts)
61 static inline void ktime_get_real_ts(struct timespec *ts)
66 static inline void getrawmonotonic(struct timespec *ts)
68 getrawmonotonic64(ts);
71 static inline struct timespec get_monotonic_coarse(void)
73 return get_monotonic_coarse64();
77 * Deprecated. Use do_settimeofday64().
79 static inline int do_settimeofday(const struct timespec *ts)
81 struct timespec64 ts64;
83 ts64 = timespec_to_timespec64(*ts);
84 return do_settimeofday64(&ts64);
87 static inline int __getnstimeofday(struct timespec *ts)
89 struct timespec64 ts64;
90 int ret = __getnstimeofday64(&ts64);
92 *ts = timespec64_to_timespec(ts64);
96 static inline void getnstimeofday(struct timespec *ts)
98 struct timespec64 ts64;
100 getnstimeofday64(&ts64);
101 *ts = timespec64_to_timespec(ts64);
104 static inline void ktime_get_ts(struct timespec *ts)
106 struct timespec64 ts64;
108 ktime_get_ts64(&ts64);
109 *ts = timespec64_to_timespec(ts64);
112 static inline void ktime_get_real_ts(struct timespec *ts)
114 struct timespec64 ts64;
116 getnstimeofday64(&ts64);
117 *ts = timespec64_to_timespec(ts64);
120 static inline void getrawmonotonic(struct timespec *ts)
122 struct timespec64 ts64;
124 getrawmonotonic64(&ts64);
125 *ts = timespec64_to_timespec(ts64);
128 static inline struct timespec get_monotonic_coarse(void)
130 return timespec64_to_timespec(get_monotonic_coarse64());
134 extern void getboottime(struct timespec *ts);
136 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
137 #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
140 * ktime_t based interfaces
150 extern ktime_t ktime_get(void);
151 extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
152 extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
153 extern ktime_t ktime_get_raw(void);
156 * ktime_get_real - get the real (wall-) time in ktime_t format
158 static inline ktime_t ktime_get_real(void)
160 return ktime_get_with_offset(TK_OFFS_REAL);
164 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
166 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
167 * time spent in suspend.
169 static inline ktime_t ktime_get_boottime(void)
171 return ktime_get_with_offset(TK_OFFS_BOOT);
175 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
177 static inline ktime_t ktime_get_clocktai(void)
179 return ktime_get_with_offset(TK_OFFS_TAI);
183 * ktime_mono_to_real - Convert monotonic time to clock realtime
185 static inline ktime_t ktime_mono_to_real(ktime_t mono)
187 return ktime_mono_to_any(mono, TK_OFFS_REAL);
190 static inline u64 ktime_get_ns(void)
192 return ktime_to_ns(ktime_get());
195 static inline u64 ktime_get_real_ns(void)
197 return ktime_to_ns(ktime_get_real());
200 static inline u64 ktime_get_boot_ns(void)
202 return ktime_to_ns(ktime_get_boottime());
205 static inline u64 ktime_get_raw_ns(void)
207 return ktime_to_ns(ktime_get_raw());
210 extern u64 ktime_get_mono_fast_ns(void);
213 * Timespec interfaces utilizing the ktime based ones
215 static inline void get_monotonic_boottime(struct timespec *ts)
217 *ts = ktime_to_timespec(ktime_get_boottime());
220 static inline void timekeeping_clocktai(struct timespec *ts)
222 *ts = ktime_to_timespec(ktime_get_clocktai());
228 extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
233 extern void getnstime_raw_and_real(struct timespec *ts_raw,
234 struct timespec *ts_real);
237 * Persistent clock related interfaces
239 extern bool persistent_clock_exist;
240 extern int persistent_clock_is_local;
242 static inline bool has_persistent_clock(void)
244 return persistent_clock_exist;
247 extern void read_persistent_clock(struct timespec *ts);
248 extern void read_boot_clock(struct timespec *ts);
249 extern int update_persistent_clock(struct timespec now);