timekeeper_internal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /* Structure holding internal timekeeping values. */
  11. struct timekeeper {
  12. /* Current clocksource used for timekeeping. */
  13. struct clocksource *clock;
  14. /* NTP adjusted clock multiplier */
  15. u32 mult;
  16. /* The shift value of the current clocksource. */
  17. u32 shift;
  18. /* Number of clock cycles in one NTP interval. */
  19. cycle_t cycle_interval;
  20. /* Last cycle value (also stored in clock->cycle_last) */
  21. cycle_t cycle_last;
  22. /* Number of clock shifted nano seconds in one NTP interval. */
  23. u64 xtime_interval;
  24. /* shifted nano seconds left over when rounding cycle_interval */
  25. s64 xtime_remainder;
  26. /* Raw nano seconds accumulated per NTP interval. */
  27. u32 raw_interval;
  28. /* Current CLOCK_REALTIME time in seconds */
  29. u64 xtime_sec;
  30. /* Clock shifted nano seconds */
  31. u64 xtime_nsec;
  32. /* Difference between accumulated time and NTP time in ntp
  33. * shifted nano seconds. */
  34. s64 ntp_error;
  35. /* Shift conversion between clock shifted nano seconds and
  36. * ntp shifted nano seconds. */
  37. u32 ntp_error_shift;
  38. /*
  39. * wall_to_monotonic is what we need to add to xtime (or xtime corrected
  40. * for sub jiffie times) to get to monotonic time. Monotonic is pegged
  41. * at zero at system boot time, so wall_to_monotonic will be negative,
  42. * however, we will ALWAYS keep the tv_nsec part positive so we can use
  43. * the usual normalization.
  44. *
  45. * wall_to_monotonic is moved after resume from suspend for the
  46. * monotonic time not to jump. We need to add total_sleep_time to
  47. * wall_to_monotonic to get the real boot based time offset.
  48. *
  49. * - wall_to_monotonic is no longer the boot time, getboottime must be
  50. * used instead.
  51. */
  52. struct timespec wall_to_monotonic;
  53. /* Offset clock monotonic -> clock realtime */
  54. ktime_t offs_real;
  55. /* time spent in suspend */
  56. struct timespec total_sleep_time;
  57. /* Offset clock monotonic -> clock boottime */
  58. ktime_t offs_boot;
  59. /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
  60. struct timespec raw_time;
  61. /* The current UTC to TAI offset in seconds */
  62. s32 tai_offset;
  63. /* Offset clock monotonic -> clock tai */
  64. ktime_t offs_tai;
  65. };
  66. static inline struct timespec tk_xtime(struct timekeeper *tk)
  67. {
  68. struct timespec ts;
  69. ts.tv_sec = tk->xtime_sec;
  70. ts.tv_nsec = (long)(tk->xtime_nsec >> tk->shift);
  71. return ts;
  72. }
  73. #ifdef CONFIG_GENERIC_TIME_VSYSCALL
  74. extern void update_vsyscall(struct timekeeper *tk);
  75. extern void update_vsyscall_tz(void);
  76. #elif defined(CONFIG_GENERIC_TIME_VSYSCALL_OLD)
  77. extern void update_vsyscall_old(struct timespec *ts, struct timespec *wtm,
  78. struct clocksource *c, u32 mult);
  79. extern void update_vsyscall_tz(void);
  80. static inline void update_vsyscall(struct timekeeper *tk)
  81. {
  82. struct timespec xt;
  83. xt = tk_xtime(tk);
  84. update_vsyscall_old(&xt, &tk->wall_to_monotonic, tk->clock, tk->mult);
  85. }
  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 */