tick-sched.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _TICK_SCHED_H
  3. #define _TICK_SCHED_H
  4. #include <linux/hrtimer.h>
  5. enum tick_device_mode {
  6. TICKDEV_MODE_PERIODIC,
  7. TICKDEV_MODE_ONESHOT,
  8. };
  9. struct tick_device {
  10. struct clock_event_device *evtdev;
  11. enum tick_device_mode mode;
  12. };
  13. enum tick_nohz_mode {
  14. NOHZ_MODE_INACTIVE,
  15. NOHZ_MODE_LOWRES,
  16. NOHZ_MODE_HIGHRES,
  17. };
  18. /**
  19. * struct tick_sched - sched tick emulation and no idle tick control/stats
  20. * @sched_timer: hrtimer to schedule the periodic tick in high
  21. * resolution mode
  22. * @check_clocks: Notification mechanism about clocksource changes
  23. * @nohz_mode: Mode - one state of tick_nohz_mode
  24. * @inidle: Indicator that the CPU is in the tick idle mode
  25. * @tick_stopped: Indicator that the idle tick has been stopped
  26. * @idle_active: Indicator that the CPU is actively in the tick idle mode;
  27. * it is resetted during irq handling phases.
  28. * @do_timer_lst: CPU was the last one doing do_timer before going idle
  29. * @got_idle_tick: Tick timer function has run with @inidle set
  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. * @next_tick: Next tick to be fired when in dynticks mode.
  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. * @timer_expires: Anticipated timer expiration time (in case sched tick is stopped)
  44. * @timer_expires_base: Base time clock monotonic for @timer_expires
  45. * @next_timer: Expiry time of next expiring timer for debugging purpose only
  46. * @tick_dep_mask: Tick dependency mask - is set, if someone needs the tick
  47. */
  48. struct tick_sched {
  49. struct hrtimer sched_timer;
  50. unsigned long check_clocks;
  51. enum tick_nohz_mode nohz_mode;
  52. unsigned int inidle : 1;
  53. unsigned int tick_stopped : 1;
  54. unsigned int idle_active : 1;
  55. unsigned int do_timer_last : 1;
  56. unsigned int got_idle_tick : 1;
  57. ktime_t last_tick;
  58. ktime_t next_tick;
  59. unsigned long idle_jiffies;
  60. unsigned long idle_calls;
  61. unsigned long idle_sleeps;
  62. ktime_t idle_entrytime;
  63. ktime_t idle_waketime;
  64. ktime_t idle_exittime;
  65. ktime_t idle_sleeptime;
  66. ktime_t iowait_sleeptime;
  67. unsigned long last_jiffies;
  68. u64 timer_expires;
  69. u64 timer_expires_base;
  70. u64 next_timer;
  71. ktime_t idle_expires;
  72. atomic_t tick_dep_mask;
  73. };
  74. extern struct tick_sched *tick_get_tick_sched(int cpu);
  75. extern void tick_setup_sched_timer(void);
  76. #if defined CONFIG_NO_HZ_COMMON || 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 int __tick_broadcast_oneshot_control(enum tick_broadcast_state state);
  83. #else
  84. static inline int
  85. __tick_broadcast_oneshot_control(enum tick_broadcast_state state)
  86. {
  87. return -EBUSY;
  88. }
  89. #endif
  90. #endif