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