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