blob: cb88096222c0a79c777674c2cb5604ded5feb49e [file] [log] [blame]
John Stultzd7b42022012-09-04 15:12:07 -04001/*
2 * You SHOULD NOT be including this unless you're vsyscall
3 * handling code or timekeeping internal code!
4 */
5
6#ifndef _LINUX_TIMEKEEPER_INTERNAL_H
7#define _LINUX_TIMEKEEPER_INTERNAL_H
8
9#include <linux/clocksource.h>
10#include <linux/jiffies.h>
11#include <linux/time.h>
12
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000013/*
14 * Structure holding internal timekeeping values.
15 *
16 * Note: wall_to_monotonic is what we need to add to xtime (or xtime
17 * corrected for sub jiffie times) to get to monotonic time.
18 * Monotonic is pegged at zero at system boot time, so
19 * wall_to_monotonic will be negative, however, we will ALWAYS keep
20 * the tv_nsec part positive so we can use the usual normalization.
21 *
22 * wall_to_monotonic is moved after resume from suspend for the
Thomas Gleixner47da70d2014-07-16 21:05:00 +000023 * monotonic time not to jump. To calculate the real boot time offset
24 * we need to do offs_real - offs_boot.
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000025 *
26 * - wall_to_monotonic is no longer the boot time, getboottime must be
27 * used instead.
28 */
John Stultzd7b42022012-09-04 15:12:07 -040029struct timekeeper {
30 /* Current clocksource used for timekeeping. */
31 struct clocksource *clock;
Thomas Gleixner4a0e6372014-07-16 21:05:13 +000032 /* Last cycle value */
33 cycle_t cycle_last;
John Stultzd7b42022012-09-04 15:12:07 -040034 /* NTP adjusted clock multiplier */
35 u32 mult;
36 /* The shift value of the current clocksource. */
37 u32 shift;
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000038 /* Clock shifted nano seconds */
39 u64 xtime_nsec;
40
Thomas Gleixner7c032df2014-07-16 21:04:10 +000041 /* Monotonic base time */
42 ktime_t base_mono;
43
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000044 /* Current CLOCK_REALTIME time in seconds */
45 u64 xtime_sec;
46 /* CLOCK_REALTIME to CLOCK_MONOTONIC offset */
47 struct timespec64 wall_to_monotonic;
48
49 /* Offset clock monotonic -> clock realtime */
50 ktime_t offs_real;
51 /* Offset clock monotonic -> clock boottime */
52 ktime_t offs_boot;
53 /* Offset clock monotonic -> clock tai */
54 ktime_t offs_tai;
55
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000056 /* The current UTC to TAI offset in seconds */
57 s32 tai_offset;
58
Thomas Gleixnerf519b1a2014-07-16 21:05:04 +000059 /* Monotonic raw base time */
60 ktime_t base_raw;
61
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000062 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
63 struct timespec64 raw_time;
64
John Stultzd7b42022012-09-04 15:12:07 -040065 /* Number of clock cycles in one NTP interval. */
66 cycle_t cycle_interval;
67 /* Number of clock shifted nano seconds in one NTP interval. */
68 u64 xtime_interval;
69 /* shifted nano seconds left over when rounding cycle_interval */
70 s64 xtime_remainder;
71 /* Raw nano seconds accumulated per NTP interval. */
72 u32 raw_interval;
73
John Stultzd7b42022012-09-04 15:12:07 -040074 /*
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000075 * Difference between accumulated time and NTP time in ntp
76 * shifted nano seconds.
John Stultzd7b42022012-09-04 15:12:07 -040077 */
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000078 s64 ntp_error;
79 /*
80 * Shift conversion between clock shifted nano seconds and
81 * ntp shifted nano seconds.
82 */
83 u32 ntp_error_shift;
John Stultzd7b42022012-09-04 15:12:07 -040084};
John Stultz189374a2012-09-04 15:27:48 -040085
John Stultz576094b2012-09-11 19:58:13 -040086#ifdef CONFIG_GENERIC_TIME_VSYSCALL
87
88extern void update_vsyscall(struct timekeeper *tk);
John Stultz189374a2012-09-04 15:27:48 -040089extern void update_vsyscall_tz(void);
John Stultz576094b2012-09-11 19:58:13 -040090
91#elif defined(CONFIG_GENERIC_TIME_VSYSCALL_OLD)
92
93extern void update_vsyscall_old(struct timespec *ts, struct timespec *wtm,
Thomas Gleixner4a0e6372014-07-16 21:05:13 +000094 struct clocksource *c, u32 mult,
95 cycles_t cycle_last);
John Stultz576094b2012-09-11 19:58:13 -040096extern void update_vsyscall_tz(void);
97
John Stultz189374a2012-09-04 15:27:48 -040098#else
John Stultz576094b2012-09-11 19:58:13 -040099
100static inline void update_vsyscall(struct timekeeper *tk)
John Stultz189374a2012-09-04 15:27:48 -0400101{
102}
103static inline void update_vsyscall_tz(void)
104{
105}
106#endif
107
John Stultzd7b42022012-09-04 15:12:07 -0400108#endif /* _LINUX_TIMEKEEPER_INTERNAL_H */