]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
8b094cd0 TG |
2 | #ifndef _LINUX_TIMEKEEPING_H |
3 | #define _LINUX_TIMEKEEPING_H | |
4 | ||
b536fd58 | 5 | #include <linux/errno.h> |
86d34732 | 6 | |
8b094cd0 TG |
7 | /* Included from linux/ktime.h */ |
8 | ||
9 | void timekeeping_init(void); | |
10 | extern int timekeeping_suspended; | |
11 | ||
93b5a9a7 IM |
12 | /* Architecture timer tick functions: */ |
13 | extern void update_process_times(int user); | |
14 | extern void xtime_update(unsigned long ticks); | |
15 | ||
8b094cd0 TG |
16 | /* |
17 | * Get and set timeofday | |
18 | */ | |
21f7eca5 | 19 | extern int do_settimeofday64(const struct timespec64 *ts); |
86d34732 BW |
20 | extern int do_sys_settimeofday64(const struct timespec64 *tv, |
21 | const struct timezone *tz); | |
8b094cd0 TG |
22 | /* |
23 | * Kernel time accessors | |
24 | */ | |
8758a240 | 25 | struct timespec64 current_kernel_time64(void); |
8758a240 | 26 | |
8b094cd0 | 27 | /* |
6546911e | 28 | * timespec64 based interfaces |
8b094cd0 | 29 | */ |
334334b5 | 30 | struct timespec64 get_monotonic_coarse64(void); |
cdba2ec5 | 31 | extern void getrawmonotonic64(struct timespec64 *ts); |
d6d29896 | 32 | extern void ktime_get_ts64(struct timespec64 *ts); |
9e3680b1 | 33 | extern time64_t ktime_get_seconds(void); |
dbe7aa62 | 34 | extern time64_t ktime_get_real_seconds(void); |
d6d29896 TG |
35 | |
36 | extern int __getnstimeofday64(struct timespec64 *tv); | |
37 | extern void getnstimeofday64(struct timespec64 *tv); | |
d08c0cdd | 38 | extern void getboottime64(struct timespec64 *ts); |
d6d29896 | 39 | |
d6d29896 | 40 | #define ktime_get_real_ts64(ts) getnstimeofday64(ts) |
8b094cd0 TG |
41 | |
42 | /* | |
43 | * ktime_t based interfaces | |
44 | */ | |
0077dc60 TG |
45 | |
46 | enum tk_offsets { | |
47 | TK_OFFS_REAL, | |
48 | TK_OFFS_BOOT, | |
49 | TK_OFFS_TAI, | |
50 | TK_OFFS_MAX, | |
51 | }; | |
52 | ||
8b094cd0 | 53 | extern ktime_t ktime_get(void); |
0077dc60 | 54 | extern ktime_t ktime_get_with_offset(enum tk_offsets offs); |
9a6b5197 | 55 | extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs); |
f519b1a2 | 56 | extern ktime_t ktime_get_raw(void); |
6374f912 | 57 | extern u32 ktime_get_resolution_ns(void); |
8b094cd0 | 58 | |
f5264d5d TG |
59 | /** |
60 | * ktime_get_real - get the real (wall-) time in ktime_t format | |
61 | */ | |
62 | static inline ktime_t ktime_get_real(void) | |
63 | { | |
64 | return ktime_get_with_offset(TK_OFFS_REAL); | |
65 | } | |
66 | ||
b82c817e TG |
67 | /** |
68 | * ktime_get_boottime - Returns monotonic time since boot in ktime_t format | |
69 | * | |
70 | * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the | |
71 | * time spent in suspend. | |
72 | */ | |
73 | static inline ktime_t ktime_get_boottime(void) | |
74 | { | |
75 | return ktime_get_with_offset(TK_OFFS_BOOT); | |
76 | } | |
77 | ||
afab07c0 TG |
78 | /** |
79 | * ktime_get_clocktai - Returns the TAI time of day in ktime_t format | |
80 | */ | |
81 | static inline ktime_t ktime_get_clocktai(void) | |
82 | { | |
83 | return ktime_get_with_offset(TK_OFFS_TAI); | |
84 | } | |
85 | ||
9a6b5197 TG |
86 | /** |
87 | * ktime_mono_to_real - Convert monotonic time to clock realtime | |
88 | */ | |
89 | static inline ktime_t ktime_mono_to_real(ktime_t mono) | |
90 | { | |
91 | return ktime_mono_to_any(mono, TK_OFFS_REAL); | |
92 | } | |
93 | ||
897994e3 TG |
94 | static inline u64 ktime_get_ns(void) |
95 | { | |
96 | return ktime_to_ns(ktime_get()); | |
97 | } | |
98 | ||
99 | static inline u64 ktime_get_real_ns(void) | |
100 | { | |
101 | return ktime_to_ns(ktime_get_real()); | |
102 | } | |
103 | ||
104 | static inline u64 ktime_get_boot_ns(void) | |
105 | { | |
106 | return ktime_to_ns(ktime_get_boottime()); | |
107 | } | |
108 | ||
fe5fba05 PZ |
109 | static inline u64 ktime_get_tai_ns(void) |
110 | { | |
111 | return ktime_to_ns(ktime_get_clocktai()); | |
112 | } | |
113 | ||
f519b1a2 TG |
114 | static inline u64 ktime_get_raw_ns(void) |
115 | { | |
116 | return ktime_to_ns(ktime_get_raw()); | |
117 | } | |
118 | ||
4396e058 | 119 | extern u64 ktime_get_mono_fast_ns(void); |
f09cb9a1 | 120 | extern u64 ktime_get_raw_fast_ns(void); |
948a5312 | 121 | extern u64 ktime_get_boot_fast_ns(void); |
4c3711d7 | 122 | extern u64 ktime_get_real_fast_ns(void); |
4396e058 | 123 | |
48f18fd6 | 124 | /* |
6546911e | 125 | * timespec64 interfaces utilizing the ktime based ones |
48f18fd6 | 126 | */ |
2e0c78ee JS |
127 | static inline void get_monotonic_boottime64(struct timespec64 *ts) |
128 | { | |
129 | *ts = ktime_to_timespec64(ktime_get_boottime()); | |
130 | } | |
131 | ||
3c9c12f4 DD |
132 | static inline void timekeeping_clocktai64(struct timespec64 *ts) |
133 | { | |
134 | *ts = ktime_to_timespec64(ktime_get_clocktai()); | |
135 | } | |
136 | ||
8b094cd0 TG |
137 | /* |
138 | * RTC specific | |
139 | */ | |
0fa88cb4 XP |
140 | extern bool timekeeping_rtc_skipsuspend(void); |
141 | extern bool timekeeping_rtc_skipresume(void); | |
142 | ||
04d90890 | 143 | extern void timekeeping_inject_sleeptime64(struct timespec64 *delta); |
144 | ||
9da0f49c CH |
145 | /* |
146 | * struct system_time_snapshot - simultaneous raw/real time capture with | |
147 | * counter value | |
148 | * @cycles: Clocksource counter value to produce the system times | |
149 | * @real: Realtime system time | |
150 | * @raw: Monotonic raw system time | |
2c756feb CH |
151 | * @clock_was_set_seq: The sequence number of clock was set events |
152 | * @cs_was_changed_seq: The sequence number of clocksource change events | |
9da0f49c CH |
153 | */ |
154 | struct system_time_snapshot { | |
a5a1d1c2 | 155 | u64 cycles; |
9da0f49c CH |
156 | ktime_t real; |
157 | ktime_t raw; | |
2c756feb CH |
158 | unsigned int clock_was_set_seq; |
159 | u8 cs_was_changed_seq; | |
9da0f49c CH |
160 | }; |
161 | ||
8006c245 CH |
162 | /* |
163 | * struct system_device_crosststamp - system/device cross-timestamp | |
164 | * (syncronized capture) | |
165 | * @device: Device time | |
166 | * @sys_realtime: Realtime simultaneous with device time | |
167 | * @sys_monoraw: Monotonic raw simultaneous with device time | |
168 | */ | |
169 | struct system_device_crosststamp { | |
170 | ktime_t device; | |
171 | ktime_t sys_realtime; | |
172 | ktime_t sys_monoraw; | |
173 | }; | |
174 | ||
175 | /* | |
176 | * struct system_counterval_t - system counter value with the pointer to the | |
177 | * corresponding clocksource | |
178 | * @cycles: System counter value | |
179 | * @cs: Clocksource corresponding to system counter value. Used by | |
180 | * timekeeping code to verify comparibility of two cycle values | |
181 | */ | |
182 | struct system_counterval_t { | |
a5a1d1c2 | 183 | u64 cycles; |
8006c245 CH |
184 | struct clocksource *cs; |
185 | }; | |
186 | ||
187 | /* | |
188 | * Get cross timestamp between system clock and device clock | |
189 | */ | |
190 | extern int get_device_system_crosststamp( | |
191 | int (*get_time_fn)(ktime_t *device_time, | |
192 | struct system_counterval_t *system_counterval, | |
193 | void *ctx), | |
194 | void *ctx, | |
2c756feb | 195 | struct system_time_snapshot *history, |
8006c245 CH |
196 | struct system_device_crosststamp *xtstamp); |
197 | ||
9da0f49c CH |
198 | /* |
199 | * Simultaneously snapshot realtime and monotonic raw clocks | |
200 | */ | |
201 | extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot); | |
202 | ||
8b094cd0 TG |
203 | /* |
204 | * Persistent clock related interfaces | |
205 | */ | |
8b094cd0 TG |
206 | extern int persistent_clock_is_local; |
207 | ||
2ee96632 | 208 | extern void read_persistent_clock64(struct timespec64 *ts); |
9a806ddb | 209 | extern void read_boot_clock64(struct timespec64 *ts); |
3c00a1fe | 210 | extern int update_persistent_clock64(struct timespec64 now); |
8b094cd0 TG |
211 | |
212 | ||
213 | #endif |