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