0001
0002 #ifndef _LINUX_TIMEKEEPING_H
0003 #define _LINUX_TIMEKEEPING_H
0004
0005 #include <linux/errno.h>
0006 #include <linux/clocksource_ids.h>
0007
0008
0009
0010 void timekeeping_init(void);
0011 extern int timekeeping_suspended;
0012
0013
0014 extern void legacy_timer_tick(unsigned long ticks);
0015
0016
0017
0018
0019 extern int do_settimeofday64(const struct timespec64 *ts);
0020 extern int do_sys_settimeofday64(const struct timespec64 *tv,
0021 const struct timezone *tz);
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 extern void ktime_get_raw_ts64(struct timespec64 *ts);
0042 extern void ktime_get_ts64(struct timespec64 *ts);
0043 extern void ktime_get_real_ts64(struct timespec64 *tv);
0044 extern void ktime_get_coarse_ts64(struct timespec64 *ts);
0045 extern void ktime_get_coarse_real_ts64(struct timespec64 *ts);
0046
0047 void getboottime64(struct timespec64 *ts);
0048
0049
0050
0051
0052 extern time64_t ktime_get_seconds(void);
0053 extern time64_t __ktime_get_real_seconds(void);
0054 extern time64_t ktime_get_real_seconds(void);
0055
0056
0057
0058
0059
0060 enum tk_offsets {
0061 TK_OFFS_REAL,
0062 TK_OFFS_BOOT,
0063 TK_OFFS_TAI,
0064 TK_OFFS_MAX,
0065 };
0066
0067 extern ktime_t ktime_get(void);
0068 extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
0069 extern ktime_t ktime_get_coarse_with_offset(enum tk_offsets offs);
0070 extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
0071 extern ktime_t ktime_get_raw(void);
0072 extern u32 ktime_get_resolution_ns(void);
0073
0074
0075
0076
0077 static inline ktime_t ktime_get_real(void)
0078 {
0079 return ktime_get_with_offset(TK_OFFS_REAL);
0080 }
0081
0082 static inline ktime_t ktime_get_coarse_real(void)
0083 {
0084 return ktime_get_coarse_with_offset(TK_OFFS_REAL);
0085 }
0086
0087
0088
0089
0090
0091
0092
0093 static inline ktime_t ktime_get_boottime(void)
0094 {
0095 return ktime_get_with_offset(TK_OFFS_BOOT);
0096 }
0097
0098 static inline ktime_t ktime_get_coarse_boottime(void)
0099 {
0100 return ktime_get_coarse_with_offset(TK_OFFS_BOOT);
0101 }
0102
0103
0104
0105
0106 static inline ktime_t ktime_get_clocktai(void)
0107 {
0108 return ktime_get_with_offset(TK_OFFS_TAI);
0109 }
0110
0111 static inline ktime_t ktime_get_coarse_clocktai(void)
0112 {
0113 return ktime_get_coarse_with_offset(TK_OFFS_TAI);
0114 }
0115
0116 static inline ktime_t ktime_get_coarse(void)
0117 {
0118 struct timespec64 ts;
0119
0120 ktime_get_coarse_ts64(&ts);
0121 return timespec64_to_ktime(ts);
0122 }
0123
0124 static inline u64 ktime_get_coarse_ns(void)
0125 {
0126 return ktime_to_ns(ktime_get_coarse());
0127 }
0128
0129 static inline u64 ktime_get_coarse_real_ns(void)
0130 {
0131 return ktime_to_ns(ktime_get_coarse_real());
0132 }
0133
0134 static inline u64 ktime_get_coarse_boottime_ns(void)
0135 {
0136 return ktime_to_ns(ktime_get_coarse_boottime());
0137 }
0138
0139 static inline u64 ktime_get_coarse_clocktai_ns(void)
0140 {
0141 return ktime_to_ns(ktime_get_coarse_clocktai());
0142 }
0143
0144
0145
0146
0147 static inline ktime_t ktime_mono_to_real(ktime_t mono)
0148 {
0149 return ktime_mono_to_any(mono, TK_OFFS_REAL);
0150 }
0151
0152 static inline u64 ktime_get_ns(void)
0153 {
0154 return ktime_to_ns(ktime_get());
0155 }
0156
0157 static inline u64 ktime_get_real_ns(void)
0158 {
0159 return ktime_to_ns(ktime_get_real());
0160 }
0161
0162 static inline u64 ktime_get_boottime_ns(void)
0163 {
0164 return ktime_to_ns(ktime_get_boottime());
0165 }
0166
0167 static inline u64 ktime_get_clocktai_ns(void)
0168 {
0169 return ktime_to_ns(ktime_get_clocktai());
0170 }
0171
0172 static inline u64 ktime_get_raw_ns(void)
0173 {
0174 return ktime_to_ns(ktime_get_raw());
0175 }
0176
0177 extern u64 ktime_get_mono_fast_ns(void);
0178 extern u64 ktime_get_raw_fast_ns(void);
0179 extern u64 ktime_get_boot_fast_ns(void);
0180 extern u64 ktime_get_tai_fast_ns(void);
0181 extern u64 ktime_get_real_fast_ns(void);
0182
0183
0184
0185
0186
0187
0188 static inline void ktime_get_boottime_ts64(struct timespec64 *ts)
0189 {
0190 *ts = ktime_to_timespec64(ktime_get_boottime());
0191 }
0192
0193 static inline void ktime_get_coarse_boottime_ts64(struct timespec64 *ts)
0194 {
0195 *ts = ktime_to_timespec64(ktime_get_coarse_boottime());
0196 }
0197
0198 static inline time64_t ktime_get_boottime_seconds(void)
0199 {
0200 return ktime_divns(ktime_get_coarse_boottime(), NSEC_PER_SEC);
0201 }
0202
0203 static inline void ktime_get_clocktai_ts64(struct timespec64 *ts)
0204 {
0205 *ts = ktime_to_timespec64(ktime_get_clocktai());
0206 }
0207
0208 static inline void ktime_get_coarse_clocktai_ts64(struct timespec64 *ts)
0209 {
0210 *ts = ktime_to_timespec64(ktime_get_coarse_clocktai());
0211 }
0212
0213 static inline time64_t ktime_get_clocktai_seconds(void)
0214 {
0215 return ktime_divns(ktime_get_coarse_clocktai(), NSEC_PER_SEC);
0216 }
0217
0218
0219
0220
0221 extern bool timekeeping_rtc_skipsuspend(void);
0222 extern bool timekeeping_rtc_skipresume(void);
0223
0224 extern void timekeeping_inject_sleeptime64(const struct timespec64 *delta);
0225
0226
0227
0228
0229
0230
0231
0232 struct ktime_timestamps {
0233 u64 mono;
0234 u64 boot;
0235 u64 real;
0236 };
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247 struct system_time_snapshot {
0248 u64 cycles;
0249 ktime_t real;
0250 ktime_t raw;
0251 enum clocksource_ids cs_id;
0252 unsigned int clock_was_set_seq;
0253 u8 cs_was_changed_seq;
0254 };
0255
0256
0257
0258
0259
0260
0261
0262
0263 struct system_device_crosststamp {
0264 ktime_t device;
0265 ktime_t sys_realtime;
0266 ktime_t sys_monoraw;
0267 };
0268
0269
0270
0271
0272
0273
0274
0275
0276 struct system_counterval_t {
0277 u64 cycles;
0278 struct clocksource *cs;
0279 };
0280
0281
0282
0283
0284 extern int get_device_system_crosststamp(
0285 int (*get_time_fn)(ktime_t *device_time,
0286 struct system_counterval_t *system_counterval,
0287 void *ctx),
0288 void *ctx,
0289 struct system_time_snapshot *history,
0290 struct system_device_crosststamp *xtstamp);
0291
0292
0293
0294
0295 extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot);
0296
0297
0298 extern void ktime_get_fast_timestamps(struct ktime_timestamps *snap);
0299
0300
0301
0302
0303 extern int persistent_clock_is_local;
0304
0305 extern void read_persistent_clock64(struct timespec64 *ts);
0306 void read_persistent_wall_and_boot_offset(struct timespec64 *wall_clock,
0307 struct timespec64 *boot_offset);
0308 #ifdef CONFIG_GENERIC_CMOS_UPDATE
0309 extern int update_persistent_clock64(struct timespec64 now);
0310 #endif
0311
0312 #endif