8cab4b754be76be957968970ef11ad642a8f4247
[deliverable/linux.git] / include / linux / timekeeping.h
1 #ifndef _LINUX_TIMEKEEPING_H
2 #define _LINUX_TIMEKEEPING_H
3
4 /* Included from linux/ktime.h */
5
6 void timekeeping_init(void);
7 extern int timekeeping_suspended;
8
9 /*
10 * Get and set timeofday
11 */
12 extern void do_gettimeofday(struct timeval *tv);
13 extern int do_settimeofday64(const struct timespec64 *ts);
14 extern int do_sys_settimeofday(const struct timespec *tv,
15 const struct timezone *tz);
16
17 /*
18 * Kernel time accessors
19 */
20 unsigned long get_seconds(void);
21 struct timespec current_kernel_time(void);
22 /* does not take xtime_lock */
23 struct timespec __current_kernel_time(void);
24
25 /*
26 * timespec based interfaces
27 */
28 struct timespec64 get_monotonic_coarse64(void);
29 extern void getrawmonotonic64(struct timespec64 *ts);
30 extern void ktime_get_ts64(struct timespec64 *ts);
31
32 extern int __getnstimeofday64(struct timespec64 *tv);
33 extern void getnstimeofday64(struct timespec64 *tv);
34
35 #if BITS_PER_LONG == 64
36 /**
37 * Deprecated. Use do_settimeofday64().
38 */
39 static inline int do_settimeofday(const struct timespec *ts)
40 {
41 return do_settimeofday64(ts);
42 }
43
44 static inline int __getnstimeofday(struct timespec *ts)
45 {
46 return __getnstimeofday64(ts);
47 }
48
49 static inline void getnstimeofday(struct timespec *ts)
50 {
51 getnstimeofday64(ts);
52 }
53
54 static inline void ktime_get_ts(struct timespec *ts)
55 {
56 ktime_get_ts64(ts);
57 }
58
59 static inline void ktime_get_real_ts(struct timespec *ts)
60 {
61 getnstimeofday64(ts);
62 }
63
64 static inline void getrawmonotonic(struct timespec *ts)
65 {
66 getrawmonotonic64(ts);
67 }
68
69 static inline struct timespec get_monotonic_coarse(void)
70 {
71 return get_monotonic_coarse64();
72 }
73 #else
74 /**
75 * Deprecated. Use do_settimeofday64().
76 */
77 static inline int do_settimeofday(const struct timespec *ts)
78 {
79 struct timespec64 ts64;
80
81 ts64 = timespec_to_timespec64(*ts);
82 return do_settimeofday64(&ts64);
83 }
84
85 static inline int __getnstimeofday(struct timespec *ts)
86 {
87 struct timespec64 ts64;
88 int ret = __getnstimeofday64(&ts64);
89
90 *ts = timespec64_to_timespec(ts64);
91 return ret;
92 }
93
94 static inline void getnstimeofday(struct timespec *ts)
95 {
96 struct timespec64 ts64;
97
98 getnstimeofday64(&ts64);
99 *ts = timespec64_to_timespec(ts64);
100 }
101
102 static inline void ktime_get_ts(struct timespec *ts)
103 {
104 struct timespec64 ts64;
105
106 ktime_get_ts64(&ts64);
107 *ts = timespec64_to_timespec(ts64);
108 }
109
110 static inline void ktime_get_real_ts(struct timespec *ts)
111 {
112 struct timespec64 ts64;
113
114 getnstimeofday64(&ts64);
115 *ts = timespec64_to_timespec(ts64);
116 }
117
118 static inline void getrawmonotonic(struct timespec *ts)
119 {
120 struct timespec64 ts64;
121
122 getrawmonotonic64(&ts64);
123 *ts = timespec64_to_timespec(ts64);
124 }
125
126 static inline struct timespec get_monotonic_coarse(void)
127 {
128 return timespec64_to_timespec(get_monotonic_coarse64());
129 }
130 #endif
131
132 extern void getboottime(struct timespec *ts);
133
134 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
135 #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
136
137 /*
138 * ktime_t based interfaces
139 */
140
141 enum tk_offsets {
142 TK_OFFS_REAL,
143 TK_OFFS_BOOT,
144 TK_OFFS_TAI,
145 TK_OFFS_MAX,
146 };
147
148 extern ktime_t ktime_get(void);
149 extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
150 extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
151 extern ktime_t ktime_get_raw(void);
152
153 /**
154 * ktime_get_real - get the real (wall-) time in ktime_t format
155 */
156 static inline ktime_t ktime_get_real(void)
157 {
158 return ktime_get_with_offset(TK_OFFS_REAL);
159 }
160
161 /**
162 * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
163 *
164 * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
165 * time spent in suspend.
166 */
167 static inline ktime_t ktime_get_boottime(void)
168 {
169 return ktime_get_with_offset(TK_OFFS_BOOT);
170 }
171
172 /**
173 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
174 */
175 static inline ktime_t ktime_get_clocktai(void)
176 {
177 return ktime_get_with_offset(TK_OFFS_TAI);
178 }
179
180 /**
181 * ktime_mono_to_real - Convert monotonic time to clock realtime
182 */
183 static inline ktime_t ktime_mono_to_real(ktime_t mono)
184 {
185 return ktime_mono_to_any(mono, TK_OFFS_REAL);
186 }
187
188 static inline u64 ktime_get_ns(void)
189 {
190 return ktime_to_ns(ktime_get());
191 }
192
193 static inline u64 ktime_get_real_ns(void)
194 {
195 return ktime_to_ns(ktime_get_real());
196 }
197
198 static inline u64 ktime_get_boot_ns(void)
199 {
200 return ktime_to_ns(ktime_get_boottime());
201 }
202
203 static inline u64 ktime_get_raw_ns(void)
204 {
205 return ktime_to_ns(ktime_get_raw());
206 }
207
208 extern u64 ktime_get_mono_fast_ns(void);
209
210 /*
211 * Timespec interfaces utilizing the ktime based ones
212 */
213 static inline void get_monotonic_boottime(struct timespec *ts)
214 {
215 *ts = ktime_to_timespec(ktime_get_boottime());
216 }
217
218 static inline void timekeeping_clocktai(struct timespec *ts)
219 {
220 *ts = ktime_to_timespec(ktime_get_clocktai());
221 }
222
223 /*
224 * RTC specific
225 */
226 extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
227
228 /**
229 * Deprecated. Use timekeeping_inject_sleeptime64().
230 */
231 static inline void timekeeping_inject_sleeptime(struct timespec *delta)
232 {
233 struct timespec64 delta64;
234
235 delta64 = timespec_to_timespec64(*delta);
236 timekeeping_inject_sleeptime64(&delta64);
237 }
238
239 /*
240 * PPS accessor
241 */
242 extern void getnstime_raw_and_real(struct timespec *ts_raw,
243 struct timespec *ts_real);
244
245 /*
246 * Persistent clock related interfaces
247 */
248 extern bool persistent_clock_exist;
249 extern int persistent_clock_is_local;
250
251 static inline bool has_persistent_clock(void)
252 {
253 return persistent_clock_exist;
254 }
255
256 extern void read_persistent_clock(struct timespec *ts);
257 extern void read_boot_clock(struct timespec *ts);
258 extern int update_persistent_clock(struct timespec now);
259
260
261 #endif
This page took 0.036247 seconds and 4 git commands to generate.