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
);
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
);
69 static inline struct timespec
get_monotonic_coarse(void)
71 return get_monotonic_coarse64();
75 * Deprecated. Use do_settimeofday64().
77 static inline int do_settimeofday(const struct timespec
*ts
)
79 struct timespec64 ts64
;
81 ts64
= timespec_to_timespec64(*ts
);
82 return do_settimeofday64(&ts64
);
85 static inline int __getnstimeofday(struct timespec
*ts
)
87 struct timespec64 ts64
;
88 int ret
= __getnstimeofday64(&ts64
);
90 *ts
= timespec64_to_timespec(ts64
);
94 static inline void getnstimeofday(struct timespec
*ts
)
96 struct timespec64 ts64
;
98 getnstimeofday64(&ts64
);
99 *ts
= timespec64_to_timespec(ts64
);
102 static inline void ktime_get_ts(struct timespec
*ts
)
104 struct timespec64 ts64
;
106 ktime_get_ts64(&ts64
);
107 *ts
= timespec64_to_timespec(ts64
);
110 static inline void ktime_get_real_ts(struct timespec
*ts
)
112 struct timespec64 ts64
;
114 getnstimeofday64(&ts64
);
115 *ts
= timespec64_to_timespec(ts64
);
118 static inline void getrawmonotonic(struct timespec
*ts
)
120 struct timespec64 ts64
;
122 getrawmonotonic64(&ts64
);
123 *ts
= timespec64_to_timespec(ts64
);
126 static inline struct timespec
get_monotonic_coarse(void)
128 return timespec64_to_timespec(get_monotonic_coarse64());
132 extern void getboottime(struct timespec
*ts
);
134 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
135 #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
138 * ktime_t based interfaces
148 extern ktime_t
ktime_get(void);
149 extern ktime_t
ktime_get_with_offset(enum tk_offsets offs
);
150 extern ktime_t
ktime_mono_to_any(ktime_t tmono
, enum tk_offsets offs
);
151 extern ktime_t
ktime_get_raw(void);
154 * ktime_get_real - get the real (wall-) time in ktime_t format
156 static inline ktime_t
ktime_get_real(void)
158 return ktime_get_with_offset(TK_OFFS_REAL
);
162 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
164 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
165 * time spent in suspend.
167 static inline ktime_t
ktime_get_boottime(void)
169 return ktime_get_with_offset(TK_OFFS_BOOT
);
173 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
175 static inline ktime_t
ktime_get_clocktai(void)
177 return ktime_get_with_offset(TK_OFFS_TAI
);
181 * ktime_mono_to_real - Convert monotonic time to clock realtime
183 static inline ktime_t
ktime_mono_to_real(ktime_t mono
)
185 return ktime_mono_to_any(mono
, TK_OFFS_REAL
);
188 static inline u64
ktime_get_ns(void)
190 return ktime_to_ns(ktime_get());
193 static inline u64
ktime_get_real_ns(void)
195 return ktime_to_ns(ktime_get_real());
198 static inline u64
ktime_get_boot_ns(void)
200 return ktime_to_ns(ktime_get_boottime());
203 static inline u64
ktime_get_raw_ns(void)
205 return ktime_to_ns(ktime_get_raw());
208 extern u64
ktime_get_mono_fast_ns(void);
211 * Timespec interfaces utilizing the ktime based ones
213 static inline void get_monotonic_boottime(struct timespec
*ts
)
215 *ts
= ktime_to_timespec(ktime_get_boottime());
218 static inline void timekeeping_clocktai(struct timespec
*ts
)
220 *ts
= ktime_to_timespec(ktime_get_clocktai());
226 extern void timekeeping_inject_sleeptime64(struct timespec64
*delta
);
229 * Deprecated. Use timekeeping_inject_sleeptime64().
231 static inline void timekeeping_inject_sleeptime(struct timespec
*delta
)
233 struct timespec64 delta64
;
235 delta64
= timespec_to_timespec64(*delta
);
236 timekeeping_inject_sleeptime64(&delta64
);
242 extern void getnstime_raw_and_real(struct timespec
*ts_raw
,
243 struct timespec
*ts_real
);
246 * Persistent clock related interfaces
248 extern bool persistent_clock_exist
;
249 extern int persistent_clock_is_local
;
251 static inline bool has_persistent_clock(void)
253 return persistent_clock_exist
;
256 extern void read_persistent_clock(struct timespec
*ts
);
257 extern void read_boot_clock(struct timespec
*ts
);
258 extern int update_persistent_clock(struct timespec now
);