tick-internal.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * tick internal variable and functions used by low/high res code
  3. */
  4. #include <linux/hrtimer.h>
  5. #include <linux/tick.h>
  6. #include "timekeeping.h"
  7. #include "tick-sched.h"
  8. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  9. # define TICK_DO_TIMER_NONE -1
  10. # define TICK_DO_TIMER_BOOT -2
  11. DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
  12. extern ktime_t tick_next_period;
  13. extern ktime_t tick_period;
  14. extern int tick_do_timer_cpu __read_mostly;
  15. extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
  16. extern void tick_handle_periodic(struct clock_event_device *dev);
  17. extern void tick_check_new_device(struct clock_event_device *dev);
  18. extern void tick_shutdown(unsigned int cpu);
  19. extern void tick_suspend(void);
  20. extern void tick_resume(void);
  21. extern bool tick_check_replacement(struct clock_event_device *curdev,
  22. struct clock_event_device *newdev);
  23. extern void tick_install_replacement(struct clock_event_device *dev);
  24. extern int tick_is_oneshot_available(void);
  25. extern struct tick_device *tick_get_device(int cpu);
  26. extern int clockevents_tick_resume(struct clock_event_device *dev);
  27. /* Check, if the device is functional or a dummy for broadcast */
  28. static inline int tick_device_is_functional(struct clock_event_device *dev)
  29. {
  30. return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
  31. }
  32. static inline enum clock_event_state clockevent_get_state(struct clock_event_device *dev)
  33. {
  34. return dev->state_use_accessors;
  35. }
  36. static inline void clockevent_set_state(struct clock_event_device *dev,
  37. enum clock_event_state state)
  38. {
  39. dev->state_use_accessors = state;
  40. }
  41. extern void clockevents_shutdown(struct clock_event_device *dev);
  42. extern void clockevents_exchange_device(struct clock_event_device *old,
  43. struct clock_event_device *new);
  44. extern void clockevents_switch_state(struct clock_event_device *dev,
  45. enum clock_event_state state);
  46. extern int clockevents_program_event(struct clock_event_device *dev,
  47. ktime_t expires, bool force);
  48. extern void clockevents_handle_noop(struct clock_event_device *dev);
  49. extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
  50. extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
  51. /* Broadcasting support */
  52. # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  53. extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
  54. extern void tick_install_broadcast_device(struct clock_event_device *dev);
  55. extern int tick_is_broadcast_device(struct clock_event_device *dev);
  56. extern void tick_shutdown_broadcast(unsigned int cpu);
  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. # else /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST: */
  66. static inline void tick_install_broadcast_device(struct clock_event_device *dev) { }
  67. static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
  68. static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
  69. static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
  70. static inline void tick_shutdown_broadcast(unsigned int cpu) { }
  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_setup_oneshot(struct clock_event_device *bc);
  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_setup_oneshot(struct clock_event_device *bc) { BUG(); }
  124. static inline void tick_broadcast_switch_to_oneshot(void) { }
  125. static inline void tick_shutdown_broadcast_oneshot(unsigned int cpu) { }
  126. static inline int tick_broadcast_oneshot_active(void) { return 0; }
  127. static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
  128. static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
  129. #endif /* !(BROADCAST && ONESHOT) */
  130. /* NO_HZ_FULL internal */
  131. #ifdef CONFIG_NO_HZ_FULL
  132. extern void tick_nohz_init(void);
  133. # else
  134. static inline void tick_nohz_init(void) { }
  135. #endif
  136. #ifdef CONFIG_NO_HZ_COMMON
  137. extern unsigned long tick_nohz_active;
  138. #else
  139. #define tick_nohz_active (0)
  140. #endif
  141. #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
  142. extern void timers_update_migration(bool update_nohz);
  143. #else
  144. static inline void timers_update_migration(bool update_nohz) { }
  145. #endif
  146. DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
  147. extern u64 get_next_timer_interrupt(unsigned long basej, u64 basem);
  148. void timer_clear_idle(void);