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 timespec
get_monotonic_coarse(void);
29 extern void getrawmonotonic64(struct timespec64
*ts
);
30 extern void ktime_get_ts64(struct timespec64
*ts
);
32 extern int __getnstimeofday64(struct timespec64
*tv
);
33 extern void getnstimeofday64(struct timespec64
*tv
);
35 #if BITS_PER_LONG == 64
37 * Deprecated. Use do_settimeofday64().
39 static inline int do_settimeofday(const struct timespec
*ts
)
41 return do_settimeofday64(ts
);
44 static inline int __getnstimeofday(struct timespec
*ts
)
46 return __getnstimeofday64(ts
);
49 static inline void getnstimeofday(struct timespec
*ts
)
54 static inline void ktime_get_ts(struct timespec
*ts
)
59 static inline void ktime_get_real_ts(struct timespec
*ts
)
64 static inline void getrawmonotonic(struct timespec
*ts
)
66 getrawmonotonic64(ts
);
71 * Deprecated. Use do_settimeofday64().
73 static inline int do_settimeofday(const struct timespec
*ts
)
75 struct timespec64 ts64
;
77 ts64
= timespec_to_timespec64(*ts
);
78 return do_settimeofday64(&ts64
);
81 static inline int __getnstimeofday(struct timespec
*ts
)
83 struct timespec64 ts64
;
84 int ret
= __getnstimeofday64(&ts64
);
86 *ts
= timespec64_to_timespec(ts64
);
90 static inline void getnstimeofday(struct timespec
*ts
)
92 struct timespec64 ts64
;
94 getnstimeofday64(&ts64
);
95 *ts
= timespec64_to_timespec(ts64
);
98 static inline void ktime_get_ts(struct timespec
*ts
)
100 struct timespec64 ts64
;
102 ktime_get_ts64(&ts64
);
103 *ts
= timespec64_to_timespec(ts64
);
106 static inline void ktime_get_real_ts(struct timespec
*ts
)
108 struct timespec64 ts64
;
110 getnstimeofday64(&ts64
);
111 *ts
= timespec64_to_timespec(ts64
);
114 static inline void getrawmonotonic(struct timespec
*ts
)
116 struct timespec64 ts64
;
118 getrawmonotonic64(&ts64
);
119 *ts
= timespec64_to_timespec(ts64
);
123 extern void getboottime(struct timespec
*ts
);
125 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
126 #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
129 * ktime_t based interfaces
139 extern ktime_t
ktime_get(void);
140 extern ktime_t
ktime_get_with_offset(enum tk_offsets offs
);
141 extern ktime_t
ktime_mono_to_any(ktime_t tmono
, enum tk_offsets offs
);
142 extern ktime_t
ktime_get_raw(void);
145 * ktime_get_real - get the real (wall-) time in ktime_t format
147 static inline ktime_t
ktime_get_real(void)
149 return ktime_get_with_offset(TK_OFFS_REAL
);
153 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
155 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
156 * time spent in suspend.
158 static inline ktime_t
ktime_get_boottime(void)
160 return ktime_get_with_offset(TK_OFFS_BOOT
);
164 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
166 static inline ktime_t
ktime_get_clocktai(void)
168 return ktime_get_with_offset(TK_OFFS_TAI
);
172 * ktime_mono_to_real - Convert monotonic time to clock realtime
174 static inline ktime_t
ktime_mono_to_real(ktime_t mono
)
176 return ktime_mono_to_any(mono
, TK_OFFS_REAL
);
179 static inline u64
ktime_get_ns(void)
181 return ktime_to_ns(ktime_get());
184 static inline u64
ktime_get_real_ns(void)
186 return ktime_to_ns(ktime_get_real());
189 static inline u64
ktime_get_boot_ns(void)
191 return ktime_to_ns(ktime_get_boottime());
194 static inline u64
ktime_get_raw_ns(void)
196 return ktime_to_ns(ktime_get_raw());
199 extern u64
ktime_get_mono_fast_ns(void);
202 * Timespec interfaces utilizing the ktime based ones
204 static inline void get_monotonic_boottime(struct timespec
*ts
)
206 *ts
= ktime_to_timespec(ktime_get_boottime());
209 static inline void timekeeping_clocktai(struct timespec
*ts
)
211 *ts
= ktime_to_timespec(ktime_get_clocktai());
217 extern void timekeeping_inject_sleeptime64(struct timespec64
*delta
);
220 * Deprecated. Use timekeeping_inject_sleeptime64().
222 static inline void timekeeping_inject_sleeptime(struct timespec
*delta
)
224 struct timespec64 delta64
;
226 delta64
= timespec_to_timespec64(*delta
);
227 timekeeping_inject_sleeptime64(&delta64
);
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
);