blob: 16de6d7c240a1599cf552c57dca6c2d08659847f [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
13/* Structure holding internal timekeeping values. */
14struct timekeeper {
15 /* Current clocksource used for timekeeping. */
16 struct clocksource *clock;
17 /* NTP adjusted clock multiplier */
18 u32 mult;
19 /* The shift value of the current clocksource. */
20 u32 shift;
21 /* Number of clock cycles in one NTP interval. */
22 cycle_t cycle_interval;
Thomas Gleixner14a3b6a2013-02-21 22:51:38 +000023 /* Last cycle value (also stored in clock->cycle_last) */
24 cycle_t cycle_last;
John Stultzd7b42022012-09-04 15:12:07 -040025 /* Number of clock shifted nano seconds in one NTP interval. */
26 u64 xtime_interval;
27 /* shifted nano seconds left over when rounding cycle_interval */
28 s64 xtime_remainder;
29 /* Raw nano seconds accumulated per NTP interval. */
30 u32 raw_interval;
31
32 /* Current CLOCK_REALTIME time in seconds */
33 u64 xtime_sec;
34 /* Clock shifted nano seconds */
35 u64 xtime_nsec;
36
37 /* Difference between accumulated time and NTP time in ntp
38 * shifted nano seconds. */
39 s64 ntp_error;
40 /* Shift conversion between clock shifted nano seconds and
41 * ntp shifted nano seconds. */
42 u32 ntp_error_shift;
43
44 /*
45 * wall_to_monotonic is what we need to add to xtime (or xtime corrected
46 * for sub jiffie times) to get to monotonic time. Monotonic is pegged
47 * at zero at system boot time, so wall_to_monotonic will be negative,
48 * however, we will ALWAYS keep the tv_nsec part positive so we can use
49 * the usual normalization.
50 *
51 * wall_to_monotonic is moved after resume from suspend for the
52 * monotonic time not to jump. We need to add total_sleep_time to
53 * wall_to_monotonic to get the real boot based time offset.
54 *
55 * - wall_to_monotonic is no longer the boot time, getboottime must be
56 * used instead.
57 */
John Stultz7d489d12014-07-16 21:04:01 +000058 struct timespec64 wall_to_monotonic;
John Stultzd7b42022012-09-04 15:12:07 -040059 /* Offset clock monotonic -> clock realtime */
60 ktime_t offs_real;
61 /* time spent in suspend */
John Stultz7d489d12014-07-16 21:04:01 +000062 struct timespec64 total_sleep_time;
John Stultzd7b42022012-09-04 15:12:07 -040063 /* Offset clock monotonic -> clock boottime */
64 ktime_t offs_boot;
65 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
John Stultz7d489d12014-07-16 21:04:01 +000066 struct timespec64 raw_time;
John Stultzcc244dd2012-05-03 12:30:07 -070067 /* The current UTC to TAI offset in seconds */
68 s32 tai_offset;
John Stultz90adda92013-01-21 17:00:11 -080069 /* Offset clock monotonic -> clock tai */
70 ktime_t offs_tai;
John Stultzcc244dd2012-05-03 12:30:07 -070071
John Stultzd7b42022012-09-04 15:12:07 -040072};
John Stultz189374a2012-09-04 15:27:48 -040073
John Stultz576094b2012-09-11 19:58:13 -040074#ifdef CONFIG_GENERIC_TIME_VSYSCALL
75
76extern void update_vsyscall(struct timekeeper *tk);
John Stultz189374a2012-09-04 15:27:48 -040077extern void update_vsyscall_tz(void);
John Stultz576094b2012-09-11 19:58:13 -040078
79#elif defined(CONFIG_GENERIC_TIME_VSYSCALL_OLD)
80
81extern void update_vsyscall_old(struct timespec *ts, struct timespec *wtm,
82 struct clocksource *c, u32 mult);
83extern void update_vsyscall_tz(void);
84
John Stultz189374a2012-09-04 15:27:48 -040085#else
John Stultz576094b2012-09-11 19:58:13 -040086
87static inline void update_vsyscall(struct timekeeper *tk)
John Stultz189374a2012-09-04 15:27:48 -040088{
89}
90static inline void update_vsyscall_tz(void)
91{
92}
93#endif
94
John Stultzd7b42022012-09-04 15:12:07 -040095#endif /* _LINUX_TIMEKEEPER_INTERNAL_H */