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 get_monotonic_boottime(struct timespec *ts);
31 extern void ktime_get_ts64(struct timespec64 *ts);
33 extern int __getnstimeofday64(struct timespec64 *tv);
34 extern void getnstimeofday64(struct timespec64 *tv);
36 #if BITS_PER_LONG == 64
37 static inline int __getnstimeofday(struct timespec *ts)
39 return __getnstimeofday64(ts);
42 static inline void getnstimeofday(struct timespec *ts)
47 static inline void ktime_get_ts(struct timespec *ts)
52 static inline void ktime_get_real_ts(struct timespec *ts)
58 static inline int __getnstimeofday(struct timespec *ts)
60 struct timespec64 ts64;
61 int ret = __getnstimeofday64(&ts64);
63 *ts = timespec64_to_timespec(ts64);
67 static inline void getnstimeofday(struct timespec *ts)
69 struct timespec64 ts64;
71 getnstimeofday64(&ts64);
72 *ts = timespec64_to_timespec(ts64);
75 static inline void ktime_get_ts(struct timespec *ts)
77 struct timespec64 ts64;
79 ktime_get_ts64(&ts64);
80 *ts = timespec64_to_timespec(ts64);
83 static inline void ktime_get_real_ts(struct timespec *ts)
85 struct timespec64 ts64;
87 getnstimeofday64(&ts64);
88 *ts = timespec64_to_timespec(ts64);
92 extern void getboottime(struct timespec *ts);
94 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
95 #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
98 * ktime_t based interfaces
108 extern ktime_t ktime_get(void);
109 extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
110 extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
113 * ktime_get_real - get the real (wall-) time in ktime_t format
115 static inline ktime_t ktime_get_real(void)
117 return ktime_get_with_offset(TK_OFFS_REAL);
121 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
123 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
124 * time spent in suspend.
126 static inline ktime_t ktime_get_boottime(void)
128 return ktime_get_with_offset(TK_OFFS_BOOT);
132 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
134 static inline ktime_t ktime_get_clocktai(void)
136 return ktime_get_with_offset(TK_OFFS_TAI);
140 * ktime_mono_to_real - Convert monotonic time to clock realtime
142 static inline ktime_t ktime_mono_to_real(ktime_t mono)
144 return ktime_mono_to_any(mono, TK_OFFS_REAL);
147 static inline u64 ktime_get_ns(void)
149 return ktime_to_ns(ktime_get());
152 static inline u64 ktime_get_real_ns(void)
154 return ktime_to_ns(ktime_get_real());
157 static inline u64 ktime_get_boot_ns(void)
159 return ktime_to_ns(ktime_get_boottime());
165 extern void timekeeping_inject_sleeptime(struct timespec *delta);
170 extern void getnstime_raw_and_real(struct timespec *ts_raw,
171 struct timespec *ts_real);
174 * Persistent clock related interfaces
176 extern bool persistent_clock_exist;
177 extern int persistent_clock_is_local;
179 static inline bool has_persistent_clock(void)
181 return persistent_clock_exist;
184 extern void read_persistent_clock(struct timespec *ts);
185 extern void read_boot_clock(struct timespec *ts);
186 extern int update_persistent_clock(struct timespec now);