tick.h 5.0 KB

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