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