e40a8d60fb21adee2ace5fc7684475a6991b15d4
[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 timespec get_monotonic_coarse(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 #else
70 /**
71 * Deprecated. Use do_settimeofday64().
72 */
73 static 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
81 static 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
90 static inline void getnstimeofday(struct timespec *ts)
91 {
92 struct timespec64 ts64;
93
94 getnstimeofday64(&ts64);
95 *ts = timespec64_to_timespec(ts64);
96 }
97
98 static 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
106 static 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 }
113
114 static inline void getrawmonotonic(struct timespec *ts)
115 {
116 struct timespec64 ts64;
117
118 getrawmonotonic64(&ts64);
119 *ts = timespec64_to_timespec(ts64);
120 }
121 #endif
122
123 extern void getboottime(struct timespec *ts);
124
125 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
126 #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
127
128 /*
129 * ktime_t based interfaces
130 */
131
132 enum tk_offsets {
133 TK_OFFS_REAL,
134 TK_OFFS_BOOT,
135 TK_OFFS_TAI,
136 TK_OFFS_MAX,
137 };
138
139 extern ktime_t ktime_get(void);
140 extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
141 extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
142 extern ktime_t ktime_get_raw(void);
143
144 /**
145 * ktime_get_real - get the real (wall-) time in ktime_t format
146 */
147 static inline ktime_t ktime_get_real(void)
148 {
149 return ktime_get_with_offset(TK_OFFS_REAL);
150 }
151
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 */
158 static inline ktime_t ktime_get_boottime(void)
159 {
160 return ktime_get_with_offset(TK_OFFS_BOOT);
161 }
162
163 /**
164 * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
165 */
166 static inline ktime_t ktime_get_clocktai(void)
167 {
168 return ktime_get_with_offset(TK_OFFS_TAI);
169 }
170
171 /**
172 * ktime_mono_to_real - Convert monotonic time to clock realtime
173 */
174 static inline ktime_t ktime_mono_to_real(ktime_t mono)
175 {
176 return ktime_mono_to_any(mono, TK_OFFS_REAL);
177 }
178
179 static inline u64 ktime_get_ns(void)
180 {
181 return ktime_to_ns(ktime_get());
182 }
183
184 static inline u64 ktime_get_real_ns(void)
185 {
186 return ktime_to_ns(ktime_get_real());
187 }
188
189 static inline u64 ktime_get_boot_ns(void)
190 {
191 return ktime_to_ns(ktime_get_boottime());
192 }
193
194 static inline u64 ktime_get_raw_ns(void)
195 {
196 return ktime_to_ns(ktime_get_raw());
197 }
198
199 extern u64 ktime_get_mono_fast_ns(void);
200
201 /*
202 * Timespec interfaces utilizing the ktime based ones
203 */
204 static inline void get_monotonic_boottime(struct timespec *ts)
205 {
206 *ts = ktime_to_timespec(ktime_get_boottime());
207 }
208
209 static inline void timekeeping_clocktai(struct timespec *ts)
210 {
211 *ts = ktime_to_timespec(ktime_get_clocktai());
212 }
213
214 /*
215 * RTC specific
216 */
217 extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
218
219 /**
220 * Deprecated. Use timekeeping_inject_sleeptime64().
221 */
222 static 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 }
229
230 /*
231 * PPS accessor
232 */
233 extern void getnstime_raw_and_real(struct timespec *ts_raw,
234 struct timespec *ts_real);
235
236 /*
237 * Persistent clock related interfaces
238 */
239 extern bool persistent_clock_exist;
240 extern int persistent_clock_is_local;
241
242 static inline bool has_persistent_clock(void)
243 {
244 return persistent_clock_exist;
245 }
246
247 extern void read_persistent_clock(struct timespec *ts);
248 extern void read_boot_clock(struct timespec *ts);
249 extern int update_persistent_clock(struct timespec now);
250
251
252 #endif
This page took 0.041122 seconds and 4 git commands to generate.