tick-internal.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * tick internal variable and functions used by low/high res code
  4. */
  5. #include <linux/hrtimer.h>
  6. #include <linux/tick.h>
  7. #include "timekeeping.h"
  8. #include "tick-sched.h"
  9. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  10. # define TICK_DO_TIMER_NONE -1
  11. # define TICK_DO_TIMER_BOOT -2
  12. DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
  13. extern ktime_t tick_next_period;
  14. extern ktime_t tick_period;
  15. extern int tick_do_timer_cpu __read_mostly;
  16. extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
  17. extern void tick_handle_periodic(struct clock_event_device *dev);
  18. extern void tick_check_new_device(struct clock_event_device *dev);
  19. extern void tick_shutdown(unsigned int cpu);
  20. extern void tick_suspend(void);
  21. extern void tick_resume(void);
  22. extern bool tick_check_replacement(struct clock_event_device *curdev,
  23. struct clock_event_device *newdev);
  24. extern void tick_install_replacement(struct clock_event_device *dev);
  25. extern int tick_is_oneshot_available(void);
  26. extern struct tick_device *tick_get_device(int cpu);
  27. extern int clockevents_tick_resume(struct clock_event_device *dev);
  28. /* Check, if the device is functional or a dummy for broadcast */
  29. static inline int tick_device_is_functional(struct clock_event_device *dev)
  30. {
  31. return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
  32. }
  33. static inline enum clock_event_state clockevent_get_state(struct clock_event_device *dev)
  34. {
  35. return dev->state_use_accessors;
  36. }
  37. static inline void clockevent_set_state(struct clock_event_device *dev,
  38. enum clock_event_state state)
  39. {
  40. dev->state_use_accessors = state;
  41. }
  42. extern void clockevents_shutdown(struct clock_event_device *dev);
  43. extern void clockevents_exchange_device(struct clock_event_device *old,
  44. struct clock_event_device *new);
  45. extern void clockevents_switch_state(struct clock_event_device *dev,
  46. enum clock_event_state state);
  47. extern int clockevents_program_event(struct clock_event_device *dev,
  48. ktime_t expires, bool force);
  49. extern void clockevents_handle_noop(struct clock_event_device *dev);
  50. extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
  51. extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
  52. /* Broadcasting support */
  53. # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  54. extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
  55. extern void tick_install_broadcast_device(struct clock_event_device *dev);
  56. extern int tick_is_broadcast_device(struct clock_event_device *dev);
  57. extern void tick_shutdown_broadcast(unsigned int cpu);
  58. extern void tick_suspend_broadcast(void);
  59. extern void tick_resume_broadcast(void);
  60. extern bool tick_resume_check_broadcast(void);
  61. extern void tick_broadcast_init(void);
  62. extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
  63. extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
  64. extern struct tick_device *tick_get_broadcast_device(void);
  65. extern struct cpumask *tick_get_broadcast_mask(void);
  66. # else /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST: */
  67. static inline void tick_install_broadcast_device(struct clock_event_device *dev) { }
  68. static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
  69. static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
  70. static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
  71. static inline void tick_shutdown_broadcast(unsigned int cpu) { }
  72. static inline void tick_suspend_broadcast(void) { }
  73. static inline void tick_resume_broadcast(void) { }
  74. static inline bool tick_resume_check_broadcast(void) { return false; }
  75. static inline void tick_broadcast_init(void) { }
  76. static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
  77. /* Set the periodic handler in non broadcast mode */
  78. static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
  79. {
  80. dev->event_handler = tick_handle_periodic;
  81. }
  82. # endif /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST */
  83. #else /* !GENERIC_CLOCKEVENTS: */
  84. static inline void tick_suspend(void) { }
  85. static inline void tick_resume(void) { }
  86. #endif /* !GENERIC_CLOCKEVENTS */
  87. /* Oneshot related functions */
  88. #ifdef CONFIG_TICK_ONESHOT
  89. extern void tick_setup_oneshot(struct clock_event_device *newdev,
  90. void (*handler)(struct clock_event_device *),
  91. ktime_t nextevt);
  92. extern int tick_program_event(ktime_t expires, int force);
  93. extern void tick_oneshot_notify(void);
  94. extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
  95. extern void tick_resume_oneshot(void);
  96. static inline bool tick_oneshot_possible(void) { return true; }
  97. extern int tick_oneshot_mode_active(void);
  98. extern void tick_clock_notify(void);
  99. extern int tick_check_oneshot_change(int allow_nohz);
  100. extern int tick_init_highres(void);
  101. #else /* !CONFIG_TICK_ONESHOT: */
  102. static inline
  103. void tick_setup_oneshot(struct clock_event_device *newdev,
  104. void (*handler)(struct clock_event_device *),
  105. ktime_t nextevt) { BUG(); }
  106. static inline void tick_resume_oneshot(void) { BUG(); }
  107. static inline int tick_program_event(ktime_t expires, int force) { return 0; }
  108. static inline void tick_oneshot_notify(void) { }
  109. static inline bool tick_oneshot_possible(void) { return false; }
  110. static inline int tick_oneshot_mode_active(void) { return 0; }
  111. static inline void tick_clock_notify(void) { }
  112. static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
  113. #endif /* !CONFIG_TICK_ONESHOT */
  114. /* Functions related to oneshot broadcasting */
  115. #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
  116. extern void tick_broadcast_switch_to_oneshot(void);
  117. extern void tick_shutdown_broadcast_oneshot(unsigned int cpu);
  118. extern int tick_broadcast_oneshot_active(void);
  119. extern void tick_check_oneshot_broadcast_this_cpu(void);
  120. bool tick_broadcast_oneshot_available(void);
  121. extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
  122. #else /* !(BROADCAST && ONESHOT): */
  123. static inline void tick_broadcast_switch_to_oneshot(void) { }
  124. static inline void tick_shutdown_broadcast_oneshot(unsigned int cpu) { }
  125. static inline int tick_broadcast_oneshot_active(void) { return 0; }
  126. static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
  127. static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
  128. #endif /* !(BROADCAST && ONESHOT) */
  129. /* NO_HZ_FULL internal */
  130. #ifdef CONFIG_NO_HZ_FULL
  131. extern void tick_nohz_init(void);
  132. # else
  133. static inline void tick_nohz_init(void) { }
  134. #endif
  135. #ifdef CONFIG_NO_HZ_COMMON
  136. extern unsigned long tick_nohz_active;
  137. #else
  138. #define tick_nohz_active (0)
  139. #endif
  140. #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
  141. extern void timers_update_migration(bool update_nohz);
  142. #else
  143. static inline void timers_update_migration(bool update_nohz) { }
  144. #endif
  145. DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
  146. extern u64 get_next_timer_interrupt(unsigned long basej, u64 basem);
  147. void timer_clear_idle(void);