]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/timekeeping.h
Merge tag 'dm-3.19-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device...
[mirror_ubuntu-artful-kernel.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);
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 */
334334b5 28struct timespec64 get_monotonic_coarse64(void);
cdba2ec5 29extern void getrawmonotonic64(struct timespec64 *ts);
d6d29896 30extern void ktime_get_ts64(struct timespec64 *ts);
9e3680b1 31extern time64_t ktime_get_seconds(void);
dbe7aa62 32extern time64_t ktime_get_real_seconds(void);
d6d29896
TG
33
34extern int __getnstimeofday64(struct timespec64 *tv);
35extern void getnstimeofday64(struct timespec64 *tv);
36
37#if BITS_PER_LONG == 64
21f7eca5 38/**
39 * Deprecated. Use do_settimeofday64().
40 */
41static inline int do_settimeofday(const struct timespec *ts)
42{
43 return do_settimeofday64(ts);
44}
45
d6d29896
TG
46static inline int __getnstimeofday(struct timespec *ts)
47{
48 return __getnstimeofday64(ts);
49}
50
51static inline void getnstimeofday(struct timespec *ts)
52{
53 getnstimeofday64(ts);
54}
55
56static inline void ktime_get_ts(struct timespec *ts)
57{
58 ktime_get_ts64(ts);
59}
60
61static inline void ktime_get_real_ts(struct timespec *ts)
62{
63 getnstimeofday64(ts);
64}
65
cdba2ec5
JS
66static inline void getrawmonotonic(struct timespec *ts)
67{
68 getrawmonotonic64(ts);
69}
70
334334b5
JS
71static inline struct timespec get_monotonic_coarse(void)
72{
73 return get_monotonic_coarse64();
74}
d6d29896 75#else
21f7eca5 76/**
77 * Deprecated. Use do_settimeofday64().
78 */
79static inline int do_settimeofday(const struct timespec *ts)
80{
81 struct timespec64 ts64;
82
83 ts64 = timespec_to_timespec64(*ts);
84 return do_settimeofday64(&ts64);
85}
86
d6d29896
TG
87static inline int __getnstimeofday(struct timespec *ts)
88{
89 struct timespec64 ts64;
90 int ret = __getnstimeofday64(&ts64);
91
92 *ts = timespec64_to_timespec(ts64);
93 return ret;
94}
95
96static inline void getnstimeofday(struct timespec *ts)
97{
98 struct timespec64 ts64;
99
100 getnstimeofday64(&ts64);
101 *ts = timespec64_to_timespec(ts64);
102}
103
104static inline void ktime_get_ts(struct timespec *ts)
105{
106 struct timespec64 ts64;
107
108 ktime_get_ts64(&ts64);
109 *ts = timespec64_to_timespec(ts64);
110}
111
112static inline void ktime_get_real_ts(struct timespec *ts)
113{
114 struct timespec64 ts64;
115
116 getnstimeofday64(&ts64);
117 *ts = timespec64_to_timespec(ts64);
118}
cdba2ec5
JS
119
120static inline void getrawmonotonic(struct timespec *ts)
121{
122 struct timespec64 ts64;
123
124 getrawmonotonic64(&ts64);
125 *ts = timespec64_to_timespec(ts64);
126}
334334b5
JS
127
128static inline struct timespec get_monotonic_coarse(void)
129{
130 return timespec64_to_timespec(get_monotonic_coarse64());
131}
d6d29896 132#endif
8b094cd0 133
8b094cd0
TG
134extern void getboottime(struct timespec *ts);
135
136#define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
d6d29896 137#define ktime_get_real_ts64(ts) getnstimeofday64(ts)
8b094cd0
TG
138
139/*
140 * ktime_t based interfaces
141 */
0077dc60
TG
142
143enum tk_offsets {
144 TK_OFFS_REAL,
145 TK_OFFS_BOOT,
146 TK_OFFS_TAI,
147 TK_OFFS_MAX,
148};
149
8b094cd0 150extern ktime_t ktime_get(void);
0077dc60 151extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
9a6b5197 152extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
f519b1a2 153extern ktime_t ktime_get_raw(void);
8b094cd0 154
f5264d5d
TG
155/**
156 * ktime_get_real - get the real (wall-) time in ktime_t format
157 */
158static inline ktime_t ktime_get_real(void)
159{
160 return ktime_get_with_offset(TK_OFFS_REAL);
161}
162
b82c817e
TG
163/**
164 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
165 *
166 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
167 * time spent in suspend.
168 */
169static inline ktime_t ktime_get_boottime(void)
170{
171 return ktime_get_with_offset(TK_OFFS_BOOT);
172}
173
afab07c0
TG
174/**
175 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
176 */
177static inline ktime_t ktime_get_clocktai(void)
178{
179 return ktime_get_with_offset(TK_OFFS_TAI);
180}
181
9a6b5197
TG
182/**
183 * ktime_mono_to_real - Convert monotonic time to clock realtime
184 */
185static inline ktime_t ktime_mono_to_real(ktime_t mono)
186{
187 return ktime_mono_to_any(mono, TK_OFFS_REAL);
188}
189
897994e3
TG
190static inline u64 ktime_get_ns(void)
191{
192 return ktime_to_ns(ktime_get());
193}
194
195static inline u64 ktime_get_real_ns(void)
196{
197 return ktime_to_ns(ktime_get_real());
198}
199
200static inline u64 ktime_get_boot_ns(void)
201{
202 return ktime_to_ns(ktime_get_boottime());
203}
204
f519b1a2
TG
205static inline u64 ktime_get_raw_ns(void)
206{
207 return ktime_to_ns(ktime_get_raw());
208}
209
4396e058
TG
210extern u64 ktime_get_mono_fast_ns(void);
211
48f18fd6
TG
212/*
213 * Timespec interfaces utilizing the ktime based ones
214 */
215static inline void get_monotonic_boottime(struct timespec *ts)
216{
217 *ts = ktime_to_timespec(ktime_get_boottime());
218}
219
61edec81
TG
220static inline void timekeeping_clocktai(struct timespec *ts)
221{
222 *ts = ktime_to_timespec(ktime_get_clocktai());
223}
224
8b094cd0
TG
225/*
226 * RTC specific
227 */
04d90890 228extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
229
8b094cd0
TG
230/*
231 * PPS accessor
232 */
233extern void getnstime_raw_and_real(struct timespec *ts_raw,
234 struct timespec *ts_real);
235
236/*
237 * Persistent clock related interfaces
238 */
239extern bool persistent_clock_exist;
240extern int persistent_clock_is_local;
241
242static inline bool has_persistent_clock(void)
243{
244 return persistent_clock_exist;
245}
246
247extern void read_persistent_clock(struct timespec *ts);
248extern void read_boot_clock(struct timespec *ts);
249extern int update_persistent_clock(struct timespec now);
250
251
252#endif