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