timekeeper_internal.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * You SHOULD NOT be including this unless you're vsyscall
  3. * handling code or timekeeping internal code!
  4. */
  5. #ifndef _LINUX_TIMEKEEPER_INTERNAL_H
  6. #define _LINUX_TIMEKEEPER_INTERNAL_H
  7. #include <linux/clocksource.h>
  8. #include <linux/jiffies.h>
  9. #include <linux/time.h>
  10. /*
  11. * Structure holding internal timekeeping values.
  12. *
  13. * Note: wall_to_monotonic is what we need to add to xtime (or xtime
  14. * corrected for sub jiffie times) to get to monotonic time.
  15. * Monotonic is pegged at zero at system boot time, so
  16. * wall_to_monotonic will be negative, however, we will ALWAYS keep
  17. * the tv_nsec part positive so we can use the usual normalization.
  18. *
  19. * wall_to_monotonic is moved after resume from suspend for the
  20. * monotonic time not to jump. To calculate the real boot time offset
  21. * we need to do offs_real - offs_boot.
  22. *
  23. * - wall_to_monotonic is no longer the boot time, getboottime must be
  24. * used instead.
  25. */
  26. struct timekeeper {
  27. /* Current clocksource used for timekeeping. */
  28. struct clocksource *clock;
  29. /* Read function of @clock */
  30. cycle_t (*read)(struct clocksource *cs);
  31. /* Bitmask for two's complement subtraction of non 64bit counters */
  32. cycle_t mask;
  33. /* Last cycle value */
  34. cycle_t cycle_last;
  35. /* NTP adjusted clock multiplier */
  36. u32 mult;
  37. /* The shift value of the current clocksource. */
  38. u32 shift;
  39. /* Clock shifted nano seconds */
  40. u64 xtime_nsec;
  41. /* Monotonic base time */
  42. ktime_t base_mono;
  43. /* Current CLOCK_REALTIME time in seconds */
  44. u64 xtime_sec;
  45. /* CLOCK_REALTIME to CLOCK_MONOTONIC offset */
  46. struct timespec64 wall_to_monotonic;
  47. /* Offset clock monotonic -> clock realtime */
  48. ktime_t offs_real;
  49. /* Offset clock monotonic -> clock boottime */
  50. ktime_t offs_boot;
  51. /* Offset clock monotonic -> clock tai */
  52. ktime_t offs_tai;
  53. /* The current UTC to TAI offset in seconds */
  54. s32 tai_offset;
  55. /* Monotonic raw base time */
  56. ktime_t base_raw;
  57. /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
  58. struct timespec64 raw_time;
  59. /* Number of clock cycles in one NTP interval. */
  60. cycle_t cycle_interval;
  61. /* Number of clock shifted nano seconds in one NTP interval. */
  62. u64 xtime_interval;
  63. /* shifted nano seconds left over when rounding cycle_interval */
  64. s64 xtime_remainder;
  65. /* Raw nano seconds accumulated per NTP interval. */
  66. u32 raw_interval;
  67. /*
  68. * Difference between accumulated time and NTP time in ntp
  69. * shifted nano seconds.
  70. */
  71. s64 ntp_error;
  72. /*
  73. * Shift conversion between clock shifted nano seconds and
  74. * ntp shifted nano seconds.
  75. */
  76. u32 ntp_error_shift;
  77. };
  78. #ifdef CONFIG_GENERIC_TIME_VSYSCALL
  79. extern void update_vsyscall(struct timekeeper *tk);
  80. extern void update_vsyscall_tz(void);
  81. #elif defined(CONFIG_GENERIC_TIME_VSYSCALL_OLD)
  82. extern void update_vsyscall_old(struct timespec *ts, struct timespec *wtm,
  83. struct clocksource *c, u32 mult,
  84. cycles_t cycle_last);
  85. extern void update_vsyscall_tz(void);
  86. #else
  87. static inline void update_vsyscall(struct timekeeper *tk)
  88. {
  89. }
  90. static inline void update_vsyscall_tz(void)
  91. {
  92. }
  93. #endif
  94. #endif /* _LINUX_TIMEKEEPER_INTERNAL_H */