Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 2 | #ifndef _TICK_SCHED_H |
| 3 | #define _TICK_SCHED_H |
| 4 | |
| 5 | #include <linux/hrtimer.h> |
| 6 | |
Thomas Gleixner | 7270d11 | 2015-03-25 13:11:52 +0100 | [diff] [blame] | 7 | enum tick_device_mode { |
| 8 | TICKDEV_MODE_PERIODIC, |
| 9 | TICKDEV_MODE_ONESHOT, |
| 10 | }; |
| 11 | |
| 12 | struct tick_device { |
| 13 | struct clock_event_device *evtdev; |
| 14 | enum tick_device_mode mode; |
| 15 | }; |
| 16 | |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 17 | enum tick_nohz_mode { |
| 18 | NOHZ_MODE_INACTIVE, |
| 19 | NOHZ_MODE_LOWRES, |
| 20 | NOHZ_MODE_HIGHRES, |
| 21 | }; |
| 22 | |
| 23 | /** |
| 24 | * struct tick_sched - sched tick emulation and no idle tick control/stats |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 25 | * |
Anna-Maria Gleixner | d6b87ea | 2019-03-21 13:09:18 +0100 | [diff] [blame] | 26 | * @inidle: Indicator that the CPU is in the tick idle mode |
| 27 | * @tick_stopped: Indicator that the idle tick has been stopped |
| 28 | * @idle_active: Indicator that the CPU is actively in the tick idle mode; |
Ingo Molnar | 4bf07f6 | 2021-03-22 22:39:03 +0100 | [diff] [blame] | 29 | * it is reset during irq handling phases. |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 30 | * @do_timer_last: CPU was the last one doing do_timer before going idle |
Anna-Maria Gleixner | d6b87ea | 2019-03-21 13:09:18 +0100 | [diff] [blame] | 31 | * @got_idle_tick: Tick timer function has run with @inidle set |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 32 | * @stalled_jiffies: Number of stalled jiffies detected across ticks |
| 33 | * @last_tick_jiffies: Value of jiffies seen on last tick |
| 34 | * @sched_timer: hrtimer to schedule the periodic tick in high |
| 35 | * resolution mode |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 36 | * @last_tick: Store the last tick expiry time when the tick |
| 37 | * timer is modified for nohz sleeps. This is necessary |
| 38 | * to resume the tick timer operation in the timeline |
| 39 | * when the CPU returns from nohz sleep. |
Frederic Weisbecker | 411fe24 | 2017-04-21 16:00:54 +0200 | [diff] [blame] | 40 | * @next_tick: Next tick to be fired when in dynticks mode. |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 41 | * @idle_jiffies: jiffies at the entry to idle for idle time accounting |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 42 | * @idle_waketime: Time when the idle was interrupted |
| 43 | * @idle_entrytime: Time when the idle call was entered |
| 44 | * @nohz_mode: Mode - one state of tick_nohz_mode |
| 45 | * @last_jiffies: Base jiffies snapshot when next event was last computed |
| 46 | * @timer_expires_base: Base time clock monotonic for @timer_expires |
| 47 | * @timer_expires: Anticipated timer expiration time (in case sched tick is stopped) |
| 48 | * @next_timer: Expiry time of next expiring timer for debugging purpose only |
| 49 | * @idle_expires: Next tick in idle, for debugging purpose only |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 50 | * @idle_calls: Total number of idle calls |
| 51 | * @idle_sleeps: Number of idle calls, where the sched tick was stopped |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 52 | * @idle_exittime: Time when the idle state was left |
| 53 | * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped |
| 54 | * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding |
Anna-Maria Gleixner | d6b87ea | 2019-03-21 13:09:18 +0100 | [diff] [blame] | 55 | * @tick_dep_mask: Tick dependency mask - is set, if someone needs the tick |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 56 | * @check_clocks: Notification mechanism about clocksource changes |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 57 | */ |
| 58 | struct tick_sched { |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 59 | /* Common flags */ |
Frederic Weisbecker | 2bc629a | 2018-04-06 04:32:37 +0200 | [diff] [blame] | 60 | unsigned int inidle : 1; |
| 61 | unsigned int tick_stopped : 1; |
| 62 | unsigned int idle_active : 1; |
| 63 | unsigned int do_timer_last : 1; |
| 64 | unsigned int got_idle_tick : 1; |
| 65 | |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 66 | /* Tick handling: jiffies stall check */ |
| 67 | unsigned int stalled_jiffies; |
| 68 | unsigned long last_tick_jiffies; |
| 69 | |
| 70 | /* Tick handling */ |
| 71 | struct hrtimer sched_timer; |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 72 | ktime_t last_tick; |
Frederic Weisbecker | 411fe24 | 2017-04-21 16:00:54 +0200 | [diff] [blame] | 73 | ktime_t next_tick; |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 74 | unsigned long idle_jiffies; |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 75 | ktime_t idle_waketime; |
| 76 | |
| 77 | /* Idle entry */ |
Frederic Weisbecker | 620a30f | 2023-02-22 15:46:44 +0100 | [diff] [blame] | 78 | seqcount_t idle_sleeptime_seq; |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 79 | ktime_t idle_entrytime; |
| 80 | |
| 81 | /* Tick stop */ |
| 82 | enum tick_nohz_mode nohz_mode; |
| 83 | unsigned long last_jiffies; |
| 84 | u64 timer_expires_base; |
| 85 | u64 timer_expires; |
| 86 | u64 next_timer; |
| 87 | ktime_t idle_expires; |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 88 | unsigned long idle_calls; |
| 89 | unsigned long idle_sleeps; |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 90 | |
| 91 | /* Idle exit */ |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 92 | ktime_t idle_exittime; |
| 93 | ktime_t idle_sleeptime; |
| 94 | ktime_t iowait_sleeptime; |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 95 | |
| 96 | /* Full dynticks handling */ |
Frederic Weisbecker | f009a7a7 | 2016-03-24 15:38:00 +0100 | [diff] [blame] | 97 | atomic_t tick_dep_mask; |
Frederic Weisbecker | 605da84 | 2023-02-22 15:46:42 +0100 | [diff] [blame] | 98 | |
| 99 | /* Clocksource changes */ |
| 100 | unsigned long check_clocks; |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | extern struct tick_sched *tick_get_tick_sched(int cpu); |
| 104 | |
| 105 | extern void tick_setup_sched_timer(void); |
| 106 | #if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS |
| 107 | extern void tick_cancel_sched_timer(int cpu); |
| 108 | #else |
| 109 | static inline void tick_cancel_sched_timer(int cpu) { } |
| 110 | #endif |
| 111 | |
Thomas Gleixner | f32dd11 | 2015-07-07 16:29:38 +0200 | [diff] [blame] | 112 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
| 113 | extern int __tick_broadcast_oneshot_control(enum tick_broadcast_state state); |
| 114 | #else |
| 115 | static inline int |
| 116 | __tick_broadcast_oneshot_control(enum tick_broadcast_state state) |
| 117 | { |
| 118 | return -EBUSY; |
| 119 | } |
| 120 | #endif |
| 121 | |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame] | 122 | #endif |