tick.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Tick related global functions
  3. */
  4. #ifndef _LINUX_TICK_H
  5. #define _LINUX_TICK_H
  6. #include <linux/clockchips.h>
  7. #include <linux/irqflags.h>
  8. #include <linux/percpu.h>
  9. #include <linux/context_tracking_state.h>
  10. #include <linux/cpumask.h>
  11. #include <linux/sched.h>
  12. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  13. extern void __init tick_init(void);
  14. /* Should be core only, but ARM BL switcher requires it */
  15. extern void tick_suspend_local(void);
  16. /* Should be core only, but XEN resume magic and ARM BL switcher require it */
  17. extern void tick_resume_local(void);
  18. extern void tick_handover_do_timer(void);
  19. extern void tick_cleanup_dead_cpu(int cpu);
  20. #else /* CONFIG_GENERIC_CLOCKEVENTS */
  21. static inline void tick_init(void) { }
  22. static inline void tick_suspend_local(void) { }
  23. static inline void tick_resume_local(void) { }
  24. static inline void tick_handover_do_timer(void) { }
  25. static inline void tick_cleanup_dead_cpu(int cpu) { }
  26. #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
  27. #if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_SUSPEND)
  28. extern void tick_freeze(void);
  29. extern void tick_unfreeze(void);
  30. #else
  31. static inline void tick_freeze(void) { }
  32. static inline void tick_unfreeze(void) { }
  33. #endif
  34. #ifdef CONFIG_TICK_ONESHOT
  35. extern void tick_irq_enter(void);
  36. # ifndef arch_needs_cpu
  37. # define arch_needs_cpu() (0)
  38. # endif
  39. # else
  40. static inline void tick_irq_enter(void) { }
  41. #endif
  42. #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
  43. extern void hotplug_cpu__broadcast_tick_pull(int dead_cpu);
  44. #else
  45. static inline void hotplug_cpu__broadcast_tick_pull(int dead_cpu) { }
  46. #endif
  47. enum tick_broadcast_mode {
  48. TICK_BROADCAST_OFF,
  49. TICK_BROADCAST_ON,
  50. TICK_BROADCAST_FORCE,
  51. };
  52. enum tick_broadcast_state {
  53. TICK_BROADCAST_EXIT,
  54. TICK_BROADCAST_ENTER,
  55. };
  56. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  57. extern void tick_broadcast_control(enum tick_broadcast_mode mode);
  58. #else
  59. static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
  60. #endif /* BROADCAST */
  61. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  62. extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
  63. #else
  64. static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state)
  65. {
  66. return 0;
  67. }
  68. #endif
  69. static inline void tick_broadcast_enable(void)
  70. {
  71. tick_broadcast_control(TICK_BROADCAST_ON);
  72. }
  73. static inline void tick_broadcast_disable(void)
  74. {
  75. tick_broadcast_control(TICK_BROADCAST_OFF);
  76. }
  77. static inline void tick_broadcast_force(void)
  78. {
  79. tick_broadcast_control(TICK_BROADCAST_FORCE);
  80. }
  81. static inline int tick_broadcast_enter(void)
  82. {
  83. return tick_broadcast_oneshot_control(TICK_BROADCAST_ENTER);
  84. }
  85. static inline void tick_broadcast_exit(void)
  86. {
  87. tick_broadcast_oneshot_control(TICK_BROADCAST_EXIT);
  88. }
  89. #ifdef CONFIG_NO_HZ_COMMON
  90. extern int tick_nohz_tick_stopped(void);
  91. extern void tick_nohz_idle_enter(void);
  92. extern void tick_nohz_idle_exit(void);
  93. extern void tick_nohz_irq_exit(void);
  94. extern ktime_t tick_nohz_get_sleep_length(void);
  95. extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
  96. extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
  97. #else /* !CONFIG_NO_HZ_COMMON */
  98. static inline int tick_nohz_tick_stopped(void) { return 0; }
  99. static inline void tick_nohz_idle_enter(void) { }
  100. static inline void tick_nohz_idle_exit(void) { }
  101. static inline ktime_t tick_nohz_get_sleep_length(void)
  102. {
  103. ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
  104. return len;
  105. }
  106. static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
  107. static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
  108. #endif /* !CONFIG_NO_HZ_COMMON */
  109. #ifdef CONFIG_NO_HZ_FULL
  110. extern bool tick_nohz_full_running;
  111. extern cpumask_var_t tick_nohz_full_mask;
  112. extern cpumask_var_t housekeeping_mask;
  113. static inline bool tick_nohz_full_enabled(void)
  114. {
  115. if (!context_tracking_is_enabled())
  116. return false;
  117. return tick_nohz_full_running;
  118. }
  119. static inline bool tick_nohz_full_cpu(int cpu)
  120. {
  121. if (!tick_nohz_full_enabled())
  122. return false;
  123. return cpumask_test_cpu(cpu, tick_nohz_full_mask);
  124. }
  125. static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask)
  126. {
  127. if (tick_nohz_full_enabled())
  128. cpumask_or(mask, mask, tick_nohz_full_mask);
  129. }
  130. static inline int housekeeping_any_cpu(void)
  131. {
  132. return cpumask_any_and(housekeeping_mask, cpu_online_mask);
  133. }
  134. extern void tick_nohz_full_kick(void);
  135. extern void tick_nohz_full_kick_cpu(int cpu);
  136. extern void tick_nohz_full_kick_all(void);
  137. extern void __tick_nohz_task_switch(void);
  138. #else
  139. static inline int housekeeping_any_cpu(void)
  140. {
  141. return smp_processor_id();
  142. }
  143. static inline bool tick_nohz_full_enabled(void) { return false; }
  144. static inline bool tick_nohz_full_cpu(int cpu) { return false; }
  145. static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { }
  146. static inline void tick_nohz_full_kick_cpu(int cpu) { }
  147. static inline void tick_nohz_full_kick(void) { }
  148. static inline void tick_nohz_full_kick_all(void) { }
  149. static inline void __tick_nohz_task_switch(void) { }
  150. #endif
  151. static inline const struct cpumask *housekeeping_cpumask(void)
  152. {
  153. #ifdef CONFIG_NO_HZ_FULL
  154. if (tick_nohz_full_enabled())
  155. return housekeeping_mask;
  156. #endif
  157. return cpu_possible_mask;
  158. }
  159. static inline bool is_housekeeping_cpu(int cpu)
  160. {
  161. #ifdef CONFIG_NO_HZ_FULL
  162. if (tick_nohz_full_enabled())
  163. return cpumask_test_cpu(cpu, housekeeping_mask);
  164. #endif
  165. return true;
  166. }
  167. static inline void housekeeping_affine(struct task_struct *t)
  168. {
  169. #ifdef CONFIG_NO_HZ_FULL
  170. if (tick_nohz_full_enabled())
  171. set_cpus_allowed_ptr(t, housekeeping_mask);
  172. #endif
  173. }
  174. static inline void tick_nohz_task_switch(void)
  175. {
  176. if (tick_nohz_full_enabled())
  177. __tick_nohz_task_switch();
  178. }
  179. #endif