tick-internal.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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, int cpu);
  56. extern int tick_is_broadcast_device(struct clock_event_device *dev);
  57. extern void tick_suspend_broadcast(void);
  58. extern void tick_resume_broadcast(void);
  59. extern bool tick_resume_check_broadcast(void);
  60. extern void tick_broadcast_init(void);
  61. extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
  62. extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
  63. extern struct tick_device *tick_get_broadcast_device(void);
  64. extern struct cpumask *tick_get_broadcast_mask(void);
  65. extern const struct clock_event_device *tick_get_wakeup_device(int cpu);
  66. # else /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST: */
  67. static inline void tick_install_broadcast_device(struct clock_event_device *dev, int cpu) { }
  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_suspend_broadcast(void) { }
  72. static inline void tick_resume_broadcast(void) { }
  73. static inline bool tick_resume_check_broadcast(void) { return false; }
  74. static inline void tick_broadcast_init(void) { }
  75. static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
  76. /* Set the periodic handler in non broadcast mode */
  77. static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
  78. {
  79. dev->event_handler = tick_handle_periodic;
  80. }
  81. # endif /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST */
  82. #else /* !GENERIC_CLOCKEVENTS: */
  83. static inline void tick_suspend(void) { }
  84. static inline void tick_resume(void) { }
  85. #endif /* !GENERIC_CLOCKEVENTS */
  86. /* Oneshot related functions */
  87. #ifdef CONFIG_TICK_ONESHOT
  88. extern void tick_setup_oneshot(struct clock_event_device *newdev,
  89. void (*handler)(struct clock_event_device *),
  90. ktime_t nextevt);
  91. extern int tick_program_event(ktime_t expires, int force);
  92. extern void tick_oneshot_notify(void);
  93. extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
  94. extern void tick_resume_oneshot(void);
  95. static inline bool tick_oneshot_possible(void) { return true; }
  96. extern int tick_oneshot_mode_active(void);
  97. extern void tick_clock_notify(void);
  98. extern int tick_check_oneshot_change(int allow_nohz);
  99. extern int tick_init_highres(void);
  100. #else /* !CONFIG_TICK_ONESHOT: */
  101. static inline
  102. void tick_setup_oneshot(struct clock_event_device *newdev,
  103. void (*handler)(struct clock_event_device *),
  104. ktime_t nextevt) { BUG(); }
  105. static inline void tick_resume_oneshot(void) { BUG(); }
  106. static inline int tick_program_event(ktime_t expires, int force) { return 0; }
  107. static inline void tick_oneshot_notify(void) { }
  108. static inline bool tick_oneshot_possible(void) { return false; }
  109. static inline int tick_oneshot_mode_active(void) { return 0; }
  110. static inline void tick_clock_notify(void) { }
  111. static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
  112. #endif /* !CONFIG_TICK_ONESHOT */
  113. /* Functions related to oneshot broadcasting */
  114. #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
  115. extern void tick_broadcast_switch_to_oneshot(void);
  116. extern int tick_broadcast_oneshot_active(void);
  117. extern void tick_check_oneshot_broadcast_this_cpu(void);
  118. bool tick_broadcast_oneshot_available(void);
  119. extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
  120. #else /* !(BROADCAST && ONESHOT): */
  121. static inline void tick_broadcast_switch_to_oneshot(void) { }
  122. static inline int tick_broadcast_oneshot_active(void) { return 0; }
  123. static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
  124. static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
  125. #endif /* !(BROADCAST && ONESHOT) */
  126. #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_HOTPLUG_CPU)
  127. extern void tick_broadcast_offline(unsigned int cpu);
  128. #else
  129. static inline void tick_broadcast_offline(unsigned int cpu) { }
  130. #endif
  131. /* NO_HZ_FULL internal */
  132. #ifdef CONFIG_NO_HZ_FULL
  133. extern void tick_nohz_init(void);
  134. # else
  135. static inline void tick_nohz_init(void) { }
  136. #endif
  137. #ifdef CONFIG_NO_HZ_COMMON
  138. extern unsigned long tick_nohz_active;
  139. extern void timers_update_nohz(void);
  140. # ifdef CONFIG_SMP
  141. extern struct static_key_false timers_migration_enabled;
  142. # endif
  143. #else /* CONFIG_NO_HZ_COMMON */
  144. static inline void timers_update_nohz(void) { }
  145. #define tick_nohz_active (0)
  146. #endif
  147. DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
  148. extern u64 get_next_timer_interrupt(unsigned long basej, u64 basem);
  149. void timer_clear_idle(void);
  150. void clock_was_set(void);
  151. void clock_was_set_delayed(void);