tick.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* linux/include/linux/tick.h
  2. *
  3. * This file contains the structure definitions for tick related functions
  4. *
  5. */
  6. #ifndef _LINUX_TICK_H
  7. #define _LINUX_TICK_H
  8. #include <linux/clockchips.h>
  9. #include <linux/irqflags.h>
  10. #include <linux/percpu.h>
  11. #include <linux/hrtimer.h>
  12. #include <linux/context_tracking_state.h>
  13. #include <linux/cpumask.h>
  14. #include <linux/sched.h>
  15. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  16. enum tick_device_mode {
  17. TICKDEV_MODE_PERIODIC,
  18. TICKDEV_MODE_ONESHOT,
  19. };
  20. struct tick_device {
  21. struct clock_event_device *evtdev;
  22. enum tick_device_mode mode;
  23. };
  24. enum tick_nohz_mode {
  25. NOHZ_MODE_INACTIVE,
  26. NOHZ_MODE_LOWRES,
  27. NOHZ_MODE_HIGHRES,
  28. };
  29. /**
  30. * struct tick_sched - sched tick emulation and no idle tick control/stats
  31. * @sched_timer: hrtimer to schedule the periodic tick in high
  32. * resolution mode
  33. * @last_tick: Store the last tick expiry time when the tick
  34. * timer is modified for nohz sleeps. This is necessary
  35. * to resume the tick timer operation in the timeline
  36. * when the CPU returns from nohz sleep.
  37. * @tick_stopped: Indicator that the idle tick has been stopped
  38. * @idle_jiffies: jiffies at the entry to idle for idle time accounting
  39. * @idle_calls: Total number of idle calls
  40. * @idle_sleeps: Number of idle calls, where the sched tick was stopped
  41. * @idle_entrytime: Time when the idle call was entered
  42. * @idle_waketime: Time when the idle was interrupted
  43. * @idle_exittime: Time when the idle state was left
  44. * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped
  45. * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding
  46. * @sleep_length: Duration of the current idle sleep
  47. * @do_timer_lst: CPU was the last one doing do_timer before going idle
  48. */
  49. struct tick_sched {
  50. struct hrtimer sched_timer;
  51. unsigned long check_clocks;
  52. enum tick_nohz_mode nohz_mode;
  53. ktime_t last_tick;
  54. int inidle;
  55. int tick_stopped;
  56. unsigned long idle_jiffies;
  57. unsigned long idle_calls;
  58. unsigned long idle_sleeps;
  59. int idle_active;
  60. ktime_t idle_entrytime;
  61. ktime_t idle_entrytime_wo_cpuoffline;
  62. ktime_t idle_waketime;
  63. ktime_t idle_exittime;
  64. ktime_t idle_sleeptime;
  65. ktime_t iowait_sleeptime;
  66. ktime_t idle_sleeptime_wo_cpuoffline;
  67. ktime_t iowait_sleeptime_wo_cpuoffline;
  68. ktime_t sleep_length;
  69. unsigned long last_jiffies;
  70. unsigned long next_jiffies;
  71. ktime_t idle_expires;
  72. int do_timer_last;
  73. int cpu_plug_off_flag;
  74. };
  75. extern void __init tick_init(void);
  76. extern int tick_is_oneshot_available(void);
  77. extern struct tick_device *tick_get_device(int cpu);
  78. # ifdef CONFIG_HIGH_RES_TIMERS
  79. extern int tick_init_highres(void);
  80. extern int tick_program_event(ktime_t expires, int force);
  81. extern void tick_setup_sched_timer(void);
  82. # endif
  83. # if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
  84. extern void tick_cancel_sched_timer(int cpu);
  85. # else
  86. static inline void tick_cancel_sched_timer(int cpu) { }
  87. # endif
  88. # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  89. extern struct tick_device *tick_get_broadcast_device(void);
  90. extern struct cpumask *tick_get_broadcast_mask(void);
  91. # ifdef CONFIG_TICK_ONESHOT
  92. extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
  93. # endif
  94. # endif /* BROADCAST */
  95. # ifdef CONFIG_TICK_ONESHOT
  96. extern void tick_clock_notify(void);
  97. extern int tick_check_oneshot_change(int allow_nohz);
  98. extern struct tick_sched *tick_get_tick_sched(int cpu);
  99. extern void tick_irq_enter(void);
  100. extern int tick_oneshot_mode_active(void);
  101. # ifndef arch_needs_cpu
  102. # define arch_needs_cpu() (0)
  103. # endif
  104. # else
  105. static inline void tick_clock_notify(void) { }
  106. static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
  107. static inline void tick_irq_enter(void) { }
  108. static inline int tick_oneshot_mode_active(void) { return 0; }
  109. # endif
  110. #else /* CONFIG_GENERIC_CLOCKEVENTS */
  111. static inline void tick_init(void) { }
  112. static inline void tick_cancel_sched_timer(int cpu) { }
  113. static inline void tick_clock_notify(void) { }
  114. static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
  115. static inline void tick_irq_enter(void) { }
  116. static inline int tick_oneshot_mode_active(void) { return 0; }
  117. #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
  118. # ifdef CONFIG_NO_HZ_COMMON
  119. DECLARE_PER_CPU(struct tick_sched, tick_cpu_sched);
  120. static inline int tick_nohz_tick_stopped(void)
  121. {
  122. return __this_cpu_read(tick_cpu_sched.tick_stopped);
  123. }
  124. extern void tick_nohz_idle_enter(void);
  125. extern void tick_nohz_idle_exit(void);
  126. extern void tick_nohz_irq_exit(void);
  127. extern ktime_t tick_nohz_get_sleep_length(void);
  128. extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
  129. extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
  130. extern void tick_set_cpu_plugoff_flag(int flag);
  131. extern u64 get_cpu_idle_time_us_wo_cpuoffline(int cpu, u64 *last_update_time);
  132. extern u64 get_cpu_iowait_time_us_wo_cpuoffline(int cpu, u64 *last_update_time);
  133. # else /* !CONFIG_NO_HZ_COMMON */
  134. static inline int tick_nohz_tick_stopped(void)
  135. {
  136. return 0;
  137. }
  138. static inline void tick_nohz_idle_enter(void) { }
  139. static inline void tick_nohz_idle_exit(void) { }
  140. static inline ktime_t tick_nohz_get_sleep_length(void)
  141. {
  142. ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
  143. return len;
  144. }
  145. static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
  146. static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
  147. # endif /* !CONFIG_NO_HZ_COMMON */
  148. #ifdef CONFIG_NO_HZ_FULL
  149. extern bool tick_nohz_full_running;
  150. extern cpumask_var_t tick_nohz_full_mask;
  151. extern cpumask_var_t housekeeping_mask;
  152. static inline bool tick_nohz_full_enabled(void)
  153. {
  154. if (!context_tracking_is_enabled())
  155. return false;
  156. return tick_nohz_full_running;
  157. }
  158. static inline bool tick_nohz_full_cpu(int cpu)
  159. {
  160. if (!tick_nohz_full_enabled())
  161. return false;
  162. return cpumask_test_cpu(cpu, tick_nohz_full_mask);
  163. }
  164. extern void __tick_nohz_full_check(void);
  165. extern void tick_nohz_full_kick(void);
  166. extern void tick_nohz_full_kick_cpu(int cpu);
  167. extern void tick_nohz_full_kick_all(void);
  168. extern void __tick_nohz_task_switch(struct task_struct *tsk);
  169. #else
  170. static inline bool tick_nohz_full_enabled(void) { return false; }
  171. static inline bool tick_nohz_full_cpu(int cpu) { return false; }
  172. static inline void __tick_nohz_full_check(void) { }
  173. static inline void tick_nohz_full_kick_cpu(int cpu) { }
  174. static inline void tick_nohz_full_kick(void) { }
  175. static inline void tick_nohz_full_kick_all(void) { }
  176. static inline void __tick_nohz_task_switch(struct task_struct *tsk) { }
  177. #endif
  178. static inline bool is_housekeeping_cpu(int cpu)
  179. {
  180. #ifdef CONFIG_NO_HZ_FULL
  181. if (tick_nohz_full_enabled())
  182. return cpumask_test_cpu(cpu, housekeeping_mask);
  183. #endif
  184. return true;
  185. }
  186. static inline void housekeeping_affine(struct task_struct *t)
  187. {
  188. #ifdef CONFIG_NO_HZ_FULL
  189. if (tick_nohz_full_enabled())
  190. set_cpus_allowed_ptr(t, housekeeping_mask);
  191. #endif
  192. }
  193. static inline void tick_nohz_full_check(void)
  194. {
  195. if (tick_nohz_full_enabled())
  196. __tick_nohz_full_check();
  197. }
  198. static inline void tick_nohz_task_switch(struct task_struct *tsk)
  199. {
  200. if (tick_nohz_full_enabled())
  201. __tick_nohz_task_switch(tsk);
  202. }
  203. #endif