John Stultz | d7b4202 | 2012-09-04 15:12:07 -0400 | [diff] [blame] | 1 | /* |
| 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 Gleixner | 3fdb14f | 2014-07-16 21:04:07 +0000 | [diff] [blame] | 13 | /* |
| 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 |
| 23 | * monotonic time not to jump. We need to add total_sleep_time to |
| 24 | * wall_to_monotonic to get the real boot based time offset. |
| 25 | * |
| 26 | * - wall_to_monotonic is no longer the boot time, getboottime must be |
| 27 | * used instead. |
| 28 | */ |
John Stultz | d7b4202 | 2012-09-04 15:12:07 -0400 | [diff] [blame] | 29 | struct timekeeper { |
| 30 | /* Current clocksource used for timekeeping. */ |
| 31 | struct clocksource *clock; |
| 32 | /* NTP adjusted clock multiplier */ |
| 33 | u32 mult; |
| 34 | /* The shift value of the current clocksource. */ |
| 35 | u32 shift; |
Thomas Gleixner | 3fdb14f | 2014-07-16 21:04:07 +0000 | [diff] [blame] | 36 | /* Clock shifted nano seconds */ |
| 37 | u64 xtime_nsec; |
| 38 | |
| 39 | /* Current CLOCK_REALTIME time in seconds */ |
| 40 | u64 xtime_sec; |
| 41 | /* CLOCK_REALTIME to CLOCK_MONOTONIC offset */ |
| 42 | struct timespec64 wall_to_monotonic; |
| 43 | |
| 44 | /* Offset clock monotonic -> clock realtime */ |
| 45 | ktime_t offs_real; |
| 46 | /* Offset clock monotonic -> clock boottime */ |
| 47 | ktime_t offs_boot; |
| 48 | /* Offset clock monotonic -> clock tai */ |
| 49 | ktime_t offs_tai; |
| 50 | |
| 51 | /* time spent in suspend */ |
| 52 | struct timespec64 total_sleep_time; |
| 53 | /* The current UTC to TAI offset in seconds */ |
| 54 | s32 tai_offset; |
| 55 | |
| 56 | /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */ |
| 57 | struct timespec64 raw_time; |
| 58 | |
John Stultz | d7b4202 | 2012-09-04 15:12:07 -0400 | [diff] [blame] | 59 | /* Number of clock cycles in one NTP interval. */ |
| 60 | cycle_t cycle_interval; |
Thomas Gleixner | 14a3b6a | 2013-02-21 22:51:38 +0000 | [diff] [blame] | 61 | /* Last cycle value (also stored in clock->cycle_last) */ |
| 62 | cycle_t cycle_last; |
John Stultz | d7b4202 | 2012-09-04 15:12:07 -0400 | [diff] [blame] | 63 | /* Number of clock shifted nano seconds in one NTP interval. */ |
| 64 | u64 xtime_interval; |
| 65 | /* shifted nano seconds left over when rounding cycle_interval */ |
| 66 | s64 xtime_remainder; |
| 67 | /* Raw nano seconds accumulated per NTP interval. */ |
| 68 | u32 raw_interval; |
| 69 | |
John Stultz | d7b4202 | 2012-09-04 15:12:07 -0400 | [diff] [blame] | 70 | /* |
Thomas Gleixner | 3fdb14f | 2014-07-16 21:04:07 +0000 | [diff] [blame] | 71 | * Difference between accumulated time and NTP time in ntp |
| 72 | * shifted nano seconds. |
John Stultz | d7b4202 | 2012-09-04 15:12:07 -0400 | [diff] [blame] | 73 | */ |
Thomas Gleixner | 3fdb14f | 2014-07-16 21:04:07 +0000 | [diff] [blame] | 74 | s64 ntp_error; |
| 75 | /* |
| 76 | * Shift conversion between clock shifted nano seconds and |
| 77 | * ntp shifted nano seconds. |
| 78 | */ |
| 79 | u32 ntp_error_shift; |
John Stultz | d7b4202 | 2012-09-04 15:12:07 -0400 | [diff] [blame] | 80 | }; |
John Stultz | 189374a | 2012-09-04 15:27:48 -0400 | [diff] [blame] | 81 | |
John Stultz | 576094b | 2012-09-11 19:58:13 -0400 | [diff] [blame] | 82 | #ifdef CONFIG_GENERIC_TIME_VSYSCALL |
| 83 | |
| 84 | extern void update_vsyscall(struct timekeeper *tk); |
John Stultz | 189374a | 2012-09-04 15:27:48 -0400 | [diff] [blame] | 85 | extern void update_vsyscall_tz(void); |
John Stultz | 576094b | 2012-09-11 19:58:13 -0400 | [diff] [blame] | 86 | |
| 87 | #elif defined(CONFIG_GENERIC_TIME_VSYSCALL_OLD) |
| 88 | |
| 89 | extern void update_vsyscall_old(struct timespec *ts, struct timespec *wtm, |
| 90 | struct clocksource *c, u32 mult); |
| 91 | extern void update_vsyscall_tz(void); |
| 92 | |
John Stultz | 189374a | 2012-09-04 15:27:48 -0400 | [diff] [blame] | 93 | #else |
John Stultz | 576094b | 2012-09-11 19:58:13 -0400 | [diff] [blame] | 94 | |
| 95 | static inline void update_vsyscall(struct timekeeper *tk) |
John Stultz | 189374a | 2012-09-04 15:27:48 -0400 | [diff] [blame] | 96 | { |
| 97 | } |
| 98 | static inline void update_vsyscall_tz(void) |
| 99 | { |
| 100 | } |
| 101 | #endif |
| 102 | |
John Stultz | d7b4202 | 2012-09-04 15:12:07 -0400 | [diff] [blame] | 103 | #endif /* _LINUX_TIMEKEEPER_INTERNAL_H */ |