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_settimeofday(const struct timespec *tv);
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 timespec get_monotonic_coarse(void);
29 extern void getrawmonotonic(struct timespec *ts);
30 extern void monotonic_to_bootbased(struct timespec *ts);
31 extern void get_monotonic_boottime(struct timespec *ts);
32 extern void ktime_get_ts64(struct timespec64 *ts);
34 extern int __getnstimeofday64(struct timespec64 *tv);
35 extern void getnstimeofday64(struct timespec64 *tv);
37 #if BITS_PER_LONG == 64
38 static inline int __getnstimeofday(struct timespec *ts)
40 return __getnstimeofday64(ts);
43 static inline void getnstimeofday(struct timespec *ts)
48 static inline void ktime_get_ts(struct timespec *ts)
53 static inline void ktime_get_real_ts(struct timespec *ts)
59 static inline int __getnstimeofday(struct timespec *ts)
61 struct timespec64 ts64;
62 int ret = __getnstimeofday64(&ts64);
64 *ts = timespec64_to_timespec(ts64);
68 static inline void getnstimeofday(struct timespec *ts)
70 struct timespec64 ts64;
72 getnstimeofday64(&ts64);
73 *ts = timespec64_to_timespec(ts64);
76 static inline void ktime_get_ts(struct timespec *ts)
78 struct timespec64 ts64;
80 ktime_get_ts64(&ts64);
81 *ts = timespec64_to_timespec(ts64);
84 static inline void ktime_get_real_ts(struct timespec *ts)
86 struct timespec64 ts64;
88 getnstimeofday64(&ts64);
89 *ts = timespec64_to_timespec(ts64);
93 extern void getboottime(struct timespec *ts);
95 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
96 #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
99 * ktime_t based interfaces
109 extern ktime_t ktime_get(void);
110 extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
111 extern ktime_t ktime_get_monotonic_offset(void);
112 extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
115 * ktime_get_real - get the real (wall-) time in ktime_t format
117 static inline ktime_t ktime_get_real(void)
119 return ktime_get_with_offset(TK_OFFS_REAL);
123 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
125 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
126 * time spent in suspend.
128 static inline ktime_t ktime_get_boottime(void)
130 return ktime_get_with_offset(TK_OFFS_BOOT);
134 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
136 static inline ktime_t ktime_get_clocktai(void)
138 return ktime_get_with_offset(TK_OFFS_TAI);
142 * ktime_mono_to_real - Convert monotonic time to clock realtime
144 static inline ktime_t ktime_mono_to_real(ktime_t mono)
146 return ktime_mono_to_any(mono, TK_OFFS_REAL);
152 extern void timekeeping_inject_sleeptime(struct timespec *delta);
157 extern void getnstime_raw_and_real(struct timespec *ts_raw,
158 struct timespec *ts_real);
161 * Persistent clock related interfaces
163 extern bool persistent_clock_exist;
164 extern int persistent_clock_is_local;
166 static inline bool has_persistent_clock(void)
168 return persistent_clock_exist;
171 extern void read_persistent_clock(struct timespec *ts);
172 extern void read_boot_clock(struct timespec *ts);
173 extern int update_persistent_clock(struct timespec now);