blob: 75bb8add78f53b26ef88ec4f3154fe51a2232efe [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 Gleixner6d3aadf2014-07-16 21:05:15 +000032 /* Read function of @clock */
33 cycle_t (*read)(struct clocksource *cs);
34 /* Bitmask for two's complement subtraction of non 64bit counters */
35 cycle_t mask;
Thomas Gleixner4a0e6372014-07-16 21:05:13 +000036 /* Last cycle value */
37 cycle_t cycle_last;
John Stultzd7b42022012-09-04 15:12:07 -040038 /* NTP adjusted clock multiplier */
39 u32 mult;
40 /* The shift value of the current clocksource. */
41 u32 shift;
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000042 /* Clock shifted nano seconds */
43 u64 xtime_nsec;
44
Thomas Gleixner7c032df2014-07-16 21:04:10 +000045 /* Monotonic base time */
46 ktime_t base_mono;
47
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000048 /* Current CLOCK_REALTIME time in seconds */
49 u64 xtime_sec;
50 /* CLOCK_REALTIME to CLOCK_MONOTONIC offset */
51 struct timespec64 wall_to_monotonic;
52
53 /* Offset clock monotonic -> clock realtime */
54 ktime_t offs_real;
55 /* Offset clock monotonic -> clock boottime */
56 ktime_t offs_boot;
57 /* Offset clock monotonic -> clock tai */
58 ktime_t offs_tai;
59
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000060 /* The current UTC to TAI offset in seconds */
61 s32 tai_offset;
62
Thomas Gleixnerf519b1a2014-07-16 21:05:04 +000063 /* Monotonic raw base time */
64 ktime_t base_raw;
65
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000066 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
67 struct timespec64 raw_time;
68
John Stultzd7b42022012-09-04 15:12:07 -040069 /* Number of clock cycles in one NTP interval. */
70 cycle_t cycle_interval;
71 /* Number of clock shifted nano seconds in one NTP interval. */
72 u64 xtime_interval;
73 /* shifted nano seconds left over when rounding cycle_interval */
74 s64 xtime_remainder;
75 /* Raw nano seconds accumulated per NTP interval. */
76 u32 raw_interval;
77
John Stultzd7b42022012-09-04 15:12:07 -040078 /*
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000079 * Difference between accumulated time and NTP time in ntp
80 * shifted nano seconds.
John Stultzd7b42022012-09-04 15:12:07 -040081 */
Thomas Gleixner3fdb14f2014-07-16 21:04:07 +000082 s64 ntp_error;
83 /*
84 * Shift conversion between clock shifted nano seconds and
85 * ntp shifted nano seconds.
86 */
87 u32 ntp_error_shift;
John Stultzd7b42022012-09-04 15:12:07 -040088};
John Stultz189374a2012-09-04 15:27:48 -040089
John Stultz576094b2012-09-11 19:58:13 -040090#ifdef CONFIG_GENERIC_TIME_VSYSCALL
91
92extern void update_vsyscall(struct timekeeper *tk);
John Stultz189374a2012-09-04 15:27:48 -040093extern void update_vsyscall_tz(void);
John Stultz576094b2012-09-11 19:58:13 -040094
95#elif defined(CONFIG_GENERIC_TIME_VSYSCALL_OLD)
96
97extern void update_vsyscall_old(struct timespec *ts, struct timespec *wtm,
Thomas Gleixner4a0e6372014-07-16 21:05:13 +000098 struct clocksource *c, u32 mult,
99 cycles_t cycle_last);
John Stultz576094b2012-09-11 19:58:13 -0400100extern void update_vsyscall_tz(void);
101
John Stultz189374a2012-09-04 15:27:48 -0400102#else
John Stultz576094b2012-09-11 19:58:13 -0400103
104static inline void update_vsyscall(struct timekeeper *tk)
John Stultz189374a2012-09-04 15:27:48 -0400105{
106}
107static inline void update_vsyscall_tz(void)
108{
109}
110#endif
111
John Stultzd7b42022012-09-04 15:12:07 -0400112#endif /* _LINUX_TIMEKEEPER_INTERNAL_H */