Merge branches 'acpica-fixes', 'acpi-pci-fixes' and 'acpi-debug-fixes'
[deliverable/linux.git] / include / linux / timekeeping.h
CommitLineData
8b094cd0
TG
1#ifndef _LINUX_TIMEKEEPING_H
2#define _LINUX_TIMEKEEPING_H
3
86d34732
BW
4#include <asm-generic/errno-base.h>
5
8b094cd0
TG
6/* Included from linux/ktime.h */
7
8void timekeeping_init(void);
9extern int timekeeping_suspended;
10
11/*
12 * Get and set timeofday
13 */
14extern void do_gettimeofday(struct timeval *tv);
21f7eca5 15extern int do_settimeofday64(const struct timespec64 *ts);
86d34732
BW
16extern int do_sys_settimeofday64(const struct timespec64 *tv,
17 const struct timezone *tz);
18static inline int do_sys_settimeofday(const struct timespec *tv,
19 const struct timezone *tz)
20{
21 struct timespec64 ts64;
22
23 if (!tv)
dfc2507b
JS
24 return do_sys_settimeofday64(NULL, tz);
25
26 if (!timespec_valid(tv))
86d34732
BW
27 return -EINVAL;
28
29 ts64 = timespec_to_timespec64(*tv);
30 return do_sys_settimeofday64(&ts64, tz);
31}
8b094cd0
TG
32
33/*
34 * Kernel time accessors
35 */
36unsigned long get_seconds(void);
8758a240 37struct timespec64 current_kernel_time64(void);
8b094cd0
TG
38/* does not take xtime_lock */
39struct timespec __current_kernel_time(void);
40
8758a240
BW
41static inline struct timespec current_kernel_time(void)
42{
43 struct timespec64 now = current_kernel_time64();
44
45 return timespec64_to_timespec(now);
46}
47
8b094cd0
TG
48/*
49 * timespec based interfaces
50 */
334334b5 51struct timespec64 get_monotonic_coarse64(void);
cdba2ec5 52extern void getrawmonotonic64(struct timespec64 *ts);
d6d29896 53extern void ktime_get_ts64(struct timespec64 *ts);
9e3680b1 54extern time64_t ktime_get_seconds(void);
dbe7aa62 55extern time64_t ktime_get_real_seconds(void);
d6d29896
TG
56
57extern int __getnstimeofday64(struct timespec64 *tv);
58extern void getnstimeofday64(struct timespec64 *tv);
d08c0cdd 59extern void getboottime64(struct timespec64 *ts);
d6d29896
TG
60
61#if BITS_PER_LONG == 64
21f7eca5 62/**
63 * Deprecated. Use do_settimeofday64().
64 */
65static inline int do_settimeofday(const struct timespec *ts)
66{
67 return do_settimeofday64(ts);
68}
69
d6d29896
TG
70static inline int __getnstimeofday(struct timespec *ts)
71{
72 return __getnstimeofday64(ts);
73}
74
75static inline void getnstimeofday(struct timespec *ts)
76{
77 getnstimeofday64(ts);
78}
79
80static inline void ktime_get_ts(struct timespec *ts)
81{
82 ktime_get_ts64(ts);
83}
84
85static inline void ktime_get_real_ts(struct timespec *ts)
86{
87 getnstimeofday64(ts);
88}
89
cdba2ec5
JS
90static inline void getrawmonotonic(struct timespec *ts)
91{
92 getrawmonotonic64(ts);
93}
94
334334b5
JS
95static inline struct timespec get_monotonic_coarse(void)
96{
97 return get_monotonic_coarse64();
98}
d08c0cdd
JS
99
100static inline void getboottime(struct timespec *ts)
101{
102 return getboottime64(ts);
103}
d6d29896 104#else
21f7eca5 105/**
106 * Deprecated. Use do_settimeofday64().
107 */
108static inline int do_settimeofday(const struct timespec *ts)
109{
110 struct timespec64 ts64;
111
112 ts64 = timespec_to_timespec64(*ts);
113 return do_settimeofday64(&ts64);
114}
115
d6d29896
TG
116static inline int __getnstimeofday(struct timespec *ts)
117{
118 struct timespec64 ts64;
119 int ret = __getnstimeofday64(&ts64);
120
121 *ts = timespec64_to_timespec(ts64);
122 return ret;
123}
124
125static inline void getnstimeofday(struct timespec *ts)
126{
127 struct timespec64 ts64;
128
129 getnstimeofday64(&ts64);
130 *ts = timespec64_to_timespec(ts64);
131}
132
133static inline void ktime_get_ts(struct timespec *ts)
134{
135 struct timespec64 ts64;
136
137 ktime_get_ts64(&ts64);
138 *ts = timespec64_to_timespec(ts64);
139}
140
141static inline void ktime_get_real_ts(struct timespec *ts)
142{
143 struct timespec64 ts64;
144
145 getnstimeofday64(&ts64);
146 *ts = timespec64_to_timespec(ts64);
147}
cdba2ec5
JS
148
149static inline void getrawmonotonic(struct timespec *ts)
150{
151 struct timespec64 ts64;
152
153 getrawmonotonic64(&ts64);
154 *ts = timespec64_to_timespec(ts64);
155}
334334b5
JS
156
157static inline struct timespec get_monotonic_coarse(void)
158{
159 return timespec64_to_timespec(get_monotonic_coarse64());
160}
8b094cd0 161
d08c0cdd
JS
162static inline void getboottime(struct timespec *ts)
163{
164 struct timespec64 ts64;
165
166 getboottime64(&ts64);
167 *ts = timespec64_to_timespec(ts64);
168}
169#endif
8b094cd0 170
d6d29896 171#define ktime_get_real_ts64(ts) getnstimeofday64(ts)
8b094cd0
TG
172
173/*
174 * ktime_t based interfaces
175 */
0077dc60
TG
176
177enum tk_offsets {
178 TK_OFFS_REAL,
179 TK_OFFS_BOOT,
180 TK_OFFS_TAI,
181 TK_OFFS_MAX,
182};
183
8b094cd0 184extern ktime_t ktime_get(void);
0077dc60 185extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
9a6b5197 186extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
f519b1a2 187extern ktime_t ktime_get_raw(void);
6374f912 188extern u32 ktime_get_resolution_ns(void);
8b094cd0 189
f5264d5d
TG
190/**
191 * ktime_get_real - get the real (wall-) time in ktime_t format
192 */
193static inline ktime_t ktime_get_real(void)
194{
195 return ktime_get_with_offset(TK_OFFS_REAL);
196}
197
b82c817e
TG
198/**
199 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
200 *
201 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
202 * time spent in suspend.
203 */
204static inline ktime_t ktime_get_boottime(void)
205{
206 return ktime_get_with_offset(TK_OFFS_BOOT);
207}
208
afab07c0
TG
209/**
210 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
211 */
212static inline ktime_t ktime_get_clocktai(void)
213{
214 return ktime_get_with_offset(TK_OFFS_TAI);
215}
216
9a6b5197
TG
217/**
218 * ktime_mono_to_real - Convert monotonic time to clock realtime
219 */
220static inline ktime_t ktime_mono_to_real(ktime_t mono)
221{
222 return ktime_mono_to_any(mono, TK_OFFS_REAL);
223}
224
897994e3
TG
225static inline u64 ktime_get_ns(void)
226{
227 return ktime_to_ns(ktime_get());
228}
229
230static inline u64 ktime_get_real_ns(void)
231{
232 return ktime_to_ns(ktime_get_real());
233}
234
235static inline u64 ktime_get_boot_ns(void)
236{
237 return ktime_to_ns(ktime_get_boottime());
238}
239
fe5fba05
PZ
240static inline u64 ktime_get_tai_ns(void)
241{
242 return ktime_to_ns(ktime_get_clocktai());
243}
244
f519b1a2
TG
245static inline u64 ktime_get_raw_ns(void)
246{
247 return ktime_to_ns(ktime_get_raw());
248}
249
4396e058 250extern u64 ktime_get_mono_fast_ns(void);
f09cb9a1 251extern u64 ktime_get_raw_fast_ns(void);
4396e058 252
48f18fd6
TG
253/*
254 * Timespec interfaces utilizing the ktime based ones
255 */
256static inline void get_monotonic_boottime(struct timespec *ts)
257{
258 *ts = ktime_to_timespec(ktime_get_boottime());
259}
260
2e0c78ee
JS
261static inline void get_monotonic_boottime64(struct timespec64 *ts)
262{
263 *ts = ktime_to_timespec64(ktime_get_boottime());
264}
265
61edec81
TG
266static inline void timekeeping_clocktai(struct timespec *ts)
267{
268 *ts = ktime_to_timespec(ktime_get_clocktai());
269}
270
8b094cd0
TG
271/*
272 * RTC specific
273 */
0fa88cb4
XP
274extern bool timekeeping_rtc_skipsuspend(void);
275extern bool timekeeping_rtc_skipresume(void);
276
04d90890 277extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
278
8b094cd0
TG
279/*
280 * PPS accessor
281 */
071eee45
AB
282extern void ktime_get_raw_and_real_ts64(struct timespec64 *ts_raw,
283 struct timespec64 *ts_real);
8b094cd0 284
9da0f49c
CH
285/*
286 * struct system_time_snapshot - simultaneous raw/real time capture with
287 * counter value
288 * @cycles: Clocksource counter value to produce the system times
289 * @real: Realtime system time
290 * @raw: Monotonic raw system time
2c756feb
CH
291 * @clock_was_set_seq: The sequence number of clock was set events
292 * @cs_was_changed_seq: The sequence number of clocksource change events
9da0f49c
CH
293 */
294struct system_time_snapshot {
295 cycle_t cycles;
296 ktime_t real;
297 ktime_t raw;
2c756feb
CH
298 unsigned int clock_was_set_seq;
299 u8 cs_was_changed_seq;
9da0f49c
CH
300};
301
8006c245
CH
302/*
303 * struct system_device_crosststamp - system/device cross-timestamp
304 * (syncronized capture)
305 * @device: Device time
306 * @sys_realtime: Realtime simultaneous with device time
307 * @sys_monoraw: Monotonic raw simultaneous with device time
308 */
309struct system_device_crosststamp {
310 ktime_t device;
311 ktime_t sys_realtime;
312 ktime_t sys_monoraw;
313};
314
315/*
316 * struct system_counterval_t - system counter value with the pointer to the
317 * corresponding clocksource
318 * @cycles: System counter value
319 * @cs: Clocksource corresponding to system counter value. Used by
320 * timekeeping code to verify comparibility of two cycle values
321 */
322struct system_counterval_t {
323 cycle_t cycles;
324 struct clocksource *cs;
325};
326
327/*
328 * Get cross timestamp between system clock and device clock
329 */
330extern int get_device_system_crosststamp(
331 int (*get_time_fn)(ktime_t *device_time,
332 struct system_counterval_t *system_counterval,
333 void *ctx),
334 void *ctx,
2c756feb 335 struct system_time_snapshot *history,
8006c245
CH
336 struct system_device_crosststamp *xtstamp);
337
9da0f49c
CH
338/*
339 * Simultaneously snapshot realtime and monotonic raw clocks
340 */
341extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot);
342
8b094cd0
TG
343/*
344 * Persistent clock related interfaces
345 */
8b094cd0
TG
346extern int persistent_clock_is_local;
347
8b094cd0 348extern void read_persistent_clock(struct timespec *ts);
2ee96632 349extern void read_persistent_clock64(struct timespec64 *ts);
9a806ddb 350extern void read_boot_clock64(struct timespec64 *ts);
8b094cd0 351extern int update_persistent_clock(struct timespec now);
3c00a1fe 352extern int update_persistent_clock64(struct timespec64 now);
8b094cd0
TG
353
354
355#endif
This page took 0.170993 seconds and 5 git commands to generate.