timekeeper_internal.h 3.1 KB

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