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