tick-sched.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. /* The CPU is in the tick idle mode */
  14. #define TS_FLAG_INIDLE BIT(0)
  15. /* The idle tick has been stopped */
  16. #define TS_FLAG_STOPPED BIT(1)
  17. /*
  18. * Indicator that the CPU is actively in the tick idle mode;
  19. * it is reset during irq handling phases.
  20. */
  21. #define TS_FLAG_IDLE_ACTIVE BIT(2)
  22. /* CPU was the last one doing do_timer before going idle */
  23. #define TS_FLAG_DO_TIMER_LAST BIT(3)
  24. /* NO_HZ is enabled */
  25. #define TS_FLAG_NOHZ BIT(4)
  26. /* High resolution tick mode */
  27. #define TS_FLAG_HIGHRES BIT(5)
  28. /**
  29. * struct tick_sched - sched tick emulation and no idle tick control/stats
  30. *
  31. * @flags: State flags gathering the TS_FLAG_* features
  32. * @got_idle_tick: Tick timer function has run with @inidle set
  33. * @stalled_jiffies: Number of stalled jiffies detected across ticks
  34. * @last_tick_jiffies: Value of jiffies seen on last tick
  35. * @sched_timer: hrtimer to schedule the periodic tick in high
  36. * resolution mode
  37. * @last_tick: Store the last tick expiry time when the tick
  38. * timer is modified for nohz sleeps. This is necessary
  39. * to resume the tick timer operation in the timeline
  40. * when the CPU returns from nohz sleep.
  41. * @next_tick: Next tick to be fired when in dynticks mode.
  42. * @idle_jiffies: jiffies at the entry to idle for idle time accounting
  43. * @idle_waketime: Time when the idle was interrupted
  44. * @idle_sleeptime_seq: sequence counter for data consistency
  45. * @idle_entrytime: Time when the idle call was entered
  46. * @last_jiffies: Base jiffies snapshot when next event was last computed
  47. * @timer_expires_base: Base time clock monotonic for @timer_expires
  48. * @timer_expires: Anticipated timer expiration time (in case sched tick is stopped)
  49. * @next_timer: Expiry time of next expiring timer for debugging purpose only
  50. * @idle_expires: Next tick in idle, for debugging purpose only
  51. * @idle_calls: Total number of idle calls
  52. * @idle_sleeps: Number of idle calls, where the sched tick was stopped
  53. * @idle_exittime: Time when the idle state was left
  54. * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped
  55. * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding
  56. * @tick_dep_mask: Tick dependency mask - is set, if someone needs the tick
  57. * @check_clocks: Notification mechanism about clocksource changes
  58. */
  59. struct tick_sched {
  60. /* Common flags */
  61. unsigned long flags;
  62. /* Tick handling: jiffies stall check */
  63. unsigned int stalled_jiffies;
  64. unsigned long last_tick_jiffies;
  65. /* Tick handling */
  66. struct hrtimer sched_timer;
  67. ktime_t last_tick;
  68. ktime_t next_tick;
  69. unsigned long idle_jiffies;
  70. ktime_t idle_waketime;
  71. unsigned int got_idle_tick;
  72. /* Idle entry */
  73. seqcount_t idle_sleeptime_seq;
  74. ktime_t idle_entrytime;
  75. /* Tick stop */
  76. unsigned long last_jiffies;
  77. u64 timer_expires_base;
  78. u64 timer_expires;
  79. u64 next_timer;
  80. ktime_t idle_expires;
  81. unsigned long idle_calls;
  82. unsigned long idle_sleeps;
  83. /* Idle exit */
  84. ktime_t idle_exittime;
  85. ktime_t idle_sleeptime;
  86. ktime_t iowait_sleeptime;
  87. /* Full dynticks handling */
  88. atomic_t tick_dep_mask;
  89. /* Clocksource changes */
  90. unsigned long check_clocks;
  91. };
  92. extern struct tick_sched *tick_get_tick_sched(int cpu);
  93. extern void tick_setup_sched_timer(bool hrtimer);
  94. #if defined CONFIG_TICK_ONESHOT
  95. extern void tick_sched_timer_dying(int cpu);
  96. #else
  97. static inline void tick_sched_timer_dying(int cpu) { }
  98. #endif
  99. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  100. extern int __tick_broadcast_oneshot_control(enum tick_broadcast_state state);
  101. #else
  102. static inline int
  103. __tick_broadcast_oneshot_control(enum tick_broadcast_state state)
  104. {
  105. return -EBUSY;
  106. }
  107. #endif
  108. #endif