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