tick-internal.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. extern void clockevents_shutdown(struct clock_event_device *dev);
  33. extern void clockevents_exchange_device(struct clock_event_device *old,
  34. struct clock_event_device *new);
  35. extern void clockevents_set_state(struct clock_event_device *dev,
  36. enum clock_event_state state);
  37. extern int clockevents_program_event(struct clock_event_device *dev,
  38. ktime_t expires, bool force);
  39. extern void clockevents_handle_noop(struct clock_event_device *dev);
  40. extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
  41. extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
  42. /* Broadcasting support */
  43. # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  44. extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
  45. extern void tick_install_broadcast_device(struct clock_event_device *dev);
  46. extern int tick_is_broadcast_device(struct clock_event_device *dev);
  47. extern void tick_shutdown_broadcast(unsigned int cpu);
  48. extern void tick_suspend_broadcast(void);
  49. extern void tick_resume_broadcast(void);
  50. extern bool tick_resume_check_broadcast(void);
  51. extern void tick_broadcast_init(void);
  52. extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
  53. extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
  54. extern struct tick_device *tick_get_broadcast_device(void);
  55. extern struct cpumask *tick_get_broadcast_mask(void);
  56. # else /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST: */
  57. static inline void tick_install_broadcast_device(struct clock_event_device *dev) { }
  58. static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
  59. static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
  60. static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
  61. static inline void tick_shutdown_broadcast(unsigned int cpu) { }
  62. static inline void tick_suspend_broadcast(void) { }
  63. static inline void tick_resume_broadcast(void) { }
  64. static inline bool tick_resume_check_broadcast(void) { return false; }
  65. static inline void tick_broadcast_init(void) { }
  66. static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
  67. /* Set the periodic handler in non broadcast mode */
  68. static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
  69. {
  70. dev->event_handler = tick_handle_periodic;
  71. }
  72. # endif /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST */
  73. #else /* !GENERIC_CLOCKEVENTS: */
  74. static inline void tick_suspend(void) { }
  75. static inline void tick_resume(void) { }
  76. #endif /* !GENERIC_CLOCKEVENTS */
  77. /* Oneshot related functions */
  78. #ifdef CONFIG_TICK_ONESHOT
  79. extern void tick_setup_oneshot(struct clock_event_device *newdev,
  80. void (*handler)(struct clock_event_device *),
  81. ktime_t nextevt);
  82. extern int tick_program_event(ktime_t expires, int force);
  83. extern void tick_oneshot_notify(void);
  84. extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
  85. extern void tick_resume_oneshot(void);
  86. static inline bool tick_oneshot_possible(void) { return true; }
  87. extern int tick_oneshot_mode_active(void);
  88. extern void tick_clock_notify(void);
  89. extern int tick_check_oneshot_change(int allow_nohz);
  90. extern int tick_init_highres(void);
  91. #else /* !CONFIG_TICK_ONESHOT: */
  92. static inline
  93. void tick_setup_oneshot(struct clock_event_device *newdev,
  94. void (*handler)(struct clock_event_device *),
  95. ktime_t nextevt) { BUG(); }
  96. static inline void tick_resume_oneshot(void) { BUG(); }
  97. static inline int tick_program_event(ktime_t expires, int force) { return 0; }
  98. static inline void tick_oneshot_notify(void) { }
  99. static inline bool tick_oneshot_possible(void) { return false; }
  100. static inline int tick_oneshot_mode_active(void) { return 0; }
  101. static inline void tick_clock_notify(void) { }
  102. static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
  103. #endif /* !CONFIG_TICK_ONESHOT */
  104. /* Functions related to oneshot broadcasting */
  105. #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
  106. extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
  107. extern void tick_broadcast_switch_to_oneshot(void);
  108. extern void tick_shutdown_broadcast_oneshot(unsigned int cpu);
  109. extern int tick_broadcast_oneshot_active(void);
  110. extern void tick_check_oneshot_broadcast_this_cpu(void);
  111. bool tick_broadcast_oneshot_available(void);
  112. extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
  113. #else /* !(BROADCAST && ONESHOT): */
  114. static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
  115. static inline void tick_broadcast_switch_to_oneshot(void) { }
  116. static inline void tick_shutdown_broadcast_oneshot(unsigned int cpu) { }
  117. static inline int tick_broadcast_oneshot_active(void) { return 0; }
  118. static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
  119. static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
  120. #endif /* !(BROADCAST && ONESHOT) */
  121. /* NO_HZ_FULL internal */
  122. #ifdef CONFIG_NO_HZ_FULL
  123. extern void tick_nohz_init(void);
  124. # else
  125. static inline void tick_nohz_init(void) { }
  126. #endif