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