tick.h 6.2 KB

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