blob: 2fc606203c8cbc41d86e417c8d2809a64ff2e63f [file] [log] [blame]
Thomas Gleixner8b094cd2014-07-16 21:04:02 +00001#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);
13extern int do_settimeofday(const struct timespec *tv);
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);
21struct timespec current_kernel_time(void);
22/* does not take xtime_lock */
23struct timespec __current_kernel_time(void);
24
25/*
26 * timespec based interfaces
27 */
28struct timespec get_monotonic_coarse(void);
29extern void getrawmonotonic(struct timespec *ts);
30extern void monotonic_to_bootbased(struct timespec *ts);
31extern void get_monotonic_boottime(struct timespec *ts);
Thomas Gleixnerd6d29892014-07-16 21:04:04 +000032extern void ktime_get_ts64(struct timespec64 *ts);
Thomas Gleixner8b094cd2014-07-16 21:04:02 +000033
Thomas Gleixnerd6d29892014-07-16 21:04:04 +000034extern int __getnstimeofday64(struct timespec64 *tv);
35extern void getnstimeofday64(struct timespec64 *tv);
36
37#if BITS_PER_LONG == 64
38static inline int __getnstimeofday(struct timespec *ts)
39{
40 return __getnstimeofday64(ts);
41}
42
43static inline void getnstimeofday(struct timespec *ts)
44{
45 getnstimeofday64(ts);
46}
47
48static inline void ktime_get_ts(struct timespec *ts)
49{
50 ktime_get_ts64(ts);
51}
52
53static inline void ktime_get_real_ts(struct timespec *ts)
54{
55 getnstimeofday64(ts);
56}
57
58#else
59static inline int __getnstimeofday(struct timespec *ts)
60{
61 struct timespec64 ts64;
62 int ret = __getnstimeofday64(&ts64);
63
64 *ts = timespec64_to_timespec(ts64);
65 return ret;
66}
67
68static inline void getnstimeofday(struct timespec *ts)
69{
70 struct timespec64 ts64;
71
72 getnstimeofday64(&ts64);
73 *ts = timespec64_to_timespec(ts64);
74}
75
76static inline void ktime_get_ts(struct timespec *ts)
77{
78 struct timespec64 ts64;
79
80 ktime_get_ts64(&ts64);
81 *ts = timespec64_to_timespec(ts64);
82}
83
84static inline void ktime_get_real_ts(struct timespec *ts)
85{
86 struct timespec64 ts64;
87
88 getnstimeofday64(&ts64);
89 *ts = timespec64_to_timespec(ts64);
90}
91#endif
92
Thomas Gleixner8b094cd2014-07-16 21:04:02 +000093extern void getboottime(struct timespec *ts);
94
95#define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
Thomas Gleixnerd6d29892014-07-16 21:04:04 +000096#define ktime_get_real_ts64(ts) getnstimeofday64(ts)
Thomas Gleixner8b094cd2014-07-16 21:04:02 +000097
98/*
99 * ktime_t based interfaces
100 */
Thomas Gleixner0077dc62014-07-16 21:04:13 +0000101
102enum tk_offsets {
103 TK_OFFS_REAL,
104 TK_OFFS_BOOT,
105 TK_OFFS_TAI,
106 TK_OFFS_MAX,
107};
108
Thomas Gleixner8b094cd2014-07-16 21:04:02 +0000109extern ktime_t ktime_get(void);
Thomas Gleixner0077dc62014-07-16 21:04:13 +0000110extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
Thomas Gleixner8b094cd2014-07-16 21:04:02 +0000111extern ktime_t ktime_get_monotonic_offset(void);
112extern ktime_t ktime_get_clocktai(void);
113
Thomas Gleixnerf5264d52014-07-16 21:04:14 +0000114/**
115 * ktime_get_real - get the real (wall-) time in ktime_t format
116 */
117static inline ktime_t ktime_get_real(void)
118{
119 return ktime_get_with_offset(TK_OFFS_REAL);
120}
121
Thomas Gleixnerb82c8172014-07-16 21:04:16 +0000122/**
123 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
124 *
125 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
126 * time spent in suspend.
127 */
128static inline ktime_t ktime_get_boottime(void)
129{
130 return ktime_get_with_offset(TK_OFFS_BOOT);
131}
132
Thomas Gleixner8b094cd2014-07-16 21:04:02 +0000133/*
134 * RTC specific
135 */
136extern void timekeeping_inject_sleeptime(struct timespec *delta);
137
138/*
139 * PPS accessor
140 */
141extern void getnstime_raw_and_real(struct timespec *ts_raw,
142 struct timespec *ts_real);
143
144/*
145 * Persistent clock related interfaces
146 */
147extern bool persistent_clock_exist;
148extern int persistent_clock_is_local;
149
150static inline bool has_persistent_clock(void)
151{
152 return persistent_clock_exist;
153}
154
155extern void read_persistent_clock(struct timespec *ts);
156extern void read_boot_clock(struct timespec *ts);
157extern int update_persistent_clock(struct timespec now);
158
159
160#endif