Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / include / linux / timekeeping.h
blob816b7543f81bca3a31fb005b69c32daab72383c7
1 #ifndef _LINUX_TIMEKEEPING_H
2 #define _LINUX_TIMEKEEPING_H
4 #include <asm-generic/errno-base.h>
6 /* Included from linux/ktime.h */
8 void timekeeping_init(void);
9 extern int timekeeping_suspended;
12 * Get and set timeofday
14 extern void do_gettimeofday(struct timeval *tv);
15 extern int do_settimeofday64(const struct timespec64 *ts);
16 extern int do_sys_settimeofday64(const struct timespec64 *tv,
17 const struct timezone *tz);
18 static inline int do_sys_settimeofday(const struct timespec *tv,
19 const struct timezone *tz)
21 struct timespec64 ts64;
23 if (!tv)
24 return do_sys_settimeofday64(NULL, tz);
26 if (!timespec_valid(tv))
27 return -EINVAL;
29 ts64 = timespec_to_timespec64(*tv);
30 return do_sys_settimeofday64(&ts64, tz);
34 * Kernel time accessors
36 unsigned long get_seconds(void);
37 struct timespec64 current_kernel_time64(void);
38 /* does not take xtime_lock */
39 struct timespec __current_kernel_time(void);
41 static inline struct timespec current_kernel_time(void)
43 struct timespec64 now = current_kernel_time64();
45 return timespec64_to_timespec(now);
49 * timespec based interfaces
51 struct timespec64 get_monotonic_coarse64(void);
52 extern void getrawmonotonic64(struct timespec64 *ts);
53 extern void ktime_get_ts64(struct timespec64 *ts);
54 extern time64_t ktime_get_seconds(void);
55 extern time64_t ktime_get_real_seconds(void);
57 extern int __getnstimeofday64(struct timespec64 *tv);
58 extern void getnstimeofday64(struct timespec64 *tv);
59 extern void getboottime64(struct timespec64 *ts);
61 #if BITS_PER_LONG == 64
62 /**
63 * Deprecated. Use do_settimeofday64().
65 static inline int do_settimeofday(const struct timespec *ts)
67 return do_settimeofday64(ts);
70 static inline int __getnstimeofday(struct timespec *ts)
72 return __getnstimeofday64(ts);
75 static inline void getnstimeofday(struct timespec *ts)
77 getnstimeofday64(ts);
80 static inline void ktime_get_ts(struct timespec *ts)
82 ktime_get_ts64(ts);
85 static inline void ktime_get_real_ts(struct timespec *ts)
87 getnstimeofday64(ts);
90 static inline void getrawmonotonic(struct timespec *ts)
92 getrawmonotonic64(ts);
95 static inline struct timespec get_monotonic_coarse(void)
97 return get_monotonic_coarse64();
100 static inline void getboottime(struct timespec *ts)
102 return getboottime64(ts);
104 #else
106 * Deprecated. Use do_settimeofday64().
108 static inline int do_settimeofday(const struct timespec *ts)
110 struct timespec64 ts64;
112 ts64 = timespec_to_timespec64(*ts);
113 return do_settimeofday64(&ts64);
116 static inline int __getnstimeofday(struct timespec *ts)
118 struct timespec64 ts64;
119 int ret = __getnstimeofday64(&ts64);
121 *ts = timespec64_to_timespec(ts64);
122 return ret;
125 static inline void getnstimeofday(struct timespec *ts)
127 struct timespec64 ts64;
129 getnstimeofday64(&ts64);
130 *ts = timespec64_to_timespec(ts64);
133 static inline void ktime_get_ts(struct timespec *ts)
135 struct timespec64 ts64;
137 ktime_get_ts64(&ts64);
138 *ts = timespec64_to_timespec(ts64);
141 static inline void ktime_get_real_ts(struct timespec *ts)
143 struct timespec64 ts64;
145 getnstimeofday64(&ts64);
146 *ts = timespec64_to_timespec(ts64);
149 static inline void getrawmonotonic(struct timespec *ts)
151 struct timespec64 ts64;
153 getrawmonotonic64(&ts64);
154 *ts = timespec64_to_timespec(ts64);
157 static inline struct timespec get_monotonic_coarse(void)
159 return timespec64_to_timespec(get_monotonic_coarse64());
162 static inline void getboottime(struct timespec *ts)
164 struct timespec64 ts64;
166 getboottime64(&ts64);
167 *ts = timespec64_to_timespec(ts64);
169 #endif
171 #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
174 * ktime_t based interfaces
177 enum tk_offsets {
178 TK_OFFS_REAL,
179 TK_OFFS_BOOT,
180 TK_OFFS_TAI,
181 TK_OFFS_MAX,
184 extern ktime_t ktime_get(void);
185 extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
186 extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
187 extern ktime_t ktime_get_raw(void);
188 extern u32 ktime_get_resolution_ns(void);
191 * ktime_get_real - get the real (wall-) time in ktime_t format
193 static inline ktime_t ktime_get_real(void)
195 return ktime_get_with_offset(TK_OFFS_REAL);
199 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
201 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
202 * time spent in suspend.
204 static inline ktime_t ktime_get_boottime(void)
206 return ktime_get_with_offset(TK_OFFS_BOOT);
210 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
212 static inline ktime_t ktime_get_clocktai(void)
214 return ktime_get_with_offset(TK_OFFS_TAI);
218 * ktime_mono_to_real - Convert monotonic time to clock realtime
220 static inline ktime_t ktime_mono_to_real(ktime_t mono)
222 return ktime_mono_to_any(mono, TK_OFFS_REAL);
225 static inline u64 ktime_get_ns(void)
227 return ktime_to_ns(ktime_get());
230 static inline u64 ktime_get_real_ns(void)
232 return ktime_to_ns(ktime_get_real());
235 static inline u64 ktime_get_boot_ns(void)
237 return ktime_to_ns(ktime_get_boottime());
240 static inline u64 ktime_get_tai_ns(void)
242 return ktime_to_ns(ktime_get_clocktai());
245 static inline u64 ktime_get_raw_ns(void)
247 return ktime_to_ns(ktime_get_raw());
250 extern u64 ktime_get_mono_fast_ns(void);
251 extern u64 ktime_get_raw_fast_ns(void);
254 * Timespec interfaces utilizing the ktime based ones
256 static inline void get_monotonic_boottime(struct timespec *ts)
258 *ts = ktime_to_timespec(ktime_get_boottime());
261 static inline void get_monotonic_boottime64(struct timespec64 *ts)
263 *ts = ktime_to_timespec64(ktime_get_boottime());
266 static inline void timekeeping_clocktai(struct timespec *ts)
268 *ts = ktime_to_timespec(ktime_get_clocktai());
272 * RTC specific
274 extern bool timekeeping_rtc_skipsuspend(void);
275 extern bool timekeeping_rtc_skipresume(void);
277 extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
280 * PPS accessor
282 extern void ktime_get_raw_and_real_ts64(struct timespec64 *ts_raw,
283 struct timespec64 *ts_real);
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
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
294 struct system_time_snapshot {
295 cycle_t cycles;
296 ktime_t real;
297 ktime_t raw;
298 unsigned int clock_was_set_seq;
299 u8 cs_was_changed_seq;
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
309 struct system_device_crosststamp {
310 ktime_t device;
311 ktime_t sys_realtime;
312 ktime_t sys_monoraw;
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
322 struct system_counterval_t {
323 cycle_t cycles;
324 struct clocksource *cs;
328 * Get cross timestamp between system clock and device clock
330 extern 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,
335 struct system_time_snapshot *history,
336 struct system_device_crosststamp *xtstamp);
339 * Simultaneously snapshot realtime and monotonic raw clocks
341 extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot);
344 * Persistent clock related interfaces
346 extern int persistent_clock_is_local;
348 extern void read_persistent_clock(struct timespec *ts);
349 extern void read_persistent_clock64(struct timespec64 *ts);
350 extern void read_boot_clock64(struct timespec64 *ts);
351 extern int update_persistent_clock(struct timespec now);
352 extern int update_persistent_clock64(struct timespec64 now);
355 #endif