Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / include / linux / tick.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
c1797baf
TG
2/*
3 * Tick related global functions
906568c9
TG
4 */
5#ifndef _LINUX_TICK_H
6#define _LINUX_TICK_H
7
8#include <linux/clockchips.h>
2bbb6817 9#include <linux/irqflags.h>
33a5f626 10#include <linux/percpu.h>
460775df
FW
11#include <linux/context_tracking_state.h>
12#include <linux/cpumask.h>
c0f489d2 13#include <linux/sched.h>
906568c9 14
c1797baf
TG
15#ifdef CONFIG_GENERIC_CLOCKEVENTS
16extern void __init tick_init(void);
7270d11c
TG
17/* Should be core only, but ARM BL switcher requires it */
18extern void tick_suspend_local(void);
19/* Should be core only, but XEN resume magic and ARM BL switcher require it */
f46481d0 20extern void tick_resume_local(void);
52c063d1 21extern void tick_handover_do_timer(void);
a49b116d 22extern void tick_cleanup_dead_cpu(int cpu);
c1797baf
TG
23#else /* CONFIG_GENERIC_CLOCKEVENTS */
24static inline void tick_init(void) { }
7270d11c 25static inline void tick_suspend_local(void) { }
f46481d0 26static inline void tick_resume_local(void) { }
52c063d1 27static inline void tick_handover_do_timer(void) { }
a49b116d 28static inline void tick_cleanup_dead_cpu(int cpu) { }
c1797baf 29#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
124cf911 30
87e9b9f1
RW
31#if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_SUSPEND)
32extern void tick_freeze(void);
33extern void tick_unfreeze(void);
34#else
35static inline void tick_freeze(void) { }
36static inline void tick_unfreeze(void) { }
37#endif
38
c1797baf 39#ifdef CONFIG_TICK_ONESHOT
5acac1be 40extern void tick_irq_enter(void);
3c5d92a0 41# ifndef arch_needs_cpu
fe0f4976 42# define arch_needs_cpu() (0)
3c5d92a0 43# endif
79bf2bb3 44# else
5acac1be 45static inline void tick_irq_enter(void) { }
c1797baf 46#endif
33a5f626 47
345527b1
PM
48#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
49extern void hotplug_cpu__broadcast_tick_pull(int dead_cpu);
50#else
51static inline void hotplug_cpu__broadcast_tick_pull(int dead_cpu) { }
52#endif
53
592a438f
TG
54enum tick_broadcast_mode {
55 TICK_BROADCAST_OFF,
56 TICK_BROADCAST_ON,
57 TICK_BROADCAST_FORCE,
58};
59
1fe5d5c3
TG
60enum tick_broadcast_state {
61 TICK_BROADCAST_EXIT,
62 TICK_BROADCAST_ENTER,
63};
64
592a438f
TG
65#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
66extern void tick_broadcast_control(enum tick_broadcast_mode mode);
67#else
68static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
69#endif /* BROADCAST */
70
1b72d432
TG
71#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_HOTPLUG_CPU)
72extern void tick_offline_cpu(unsigned int cpu);
73#else
74static inline void tick_offline_cpu(unsigned int cpu) { }
75#endif
76
37b64a42 77#ifdef CONFIG_GENERIC_CLOCKEVENTS
1fe5d5c3 78extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
37b64a42
TG
79#else
80static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state)
81{
82 return 0;
83}
84#endif
1fe5d5c3 85
592a438f
TG
86static inline void tick_broadcast_enable(void)
87{
88 tick_broadcast_control(TICK_BROADCAST_ON);
89}
90static inline void tick_broadcast_disable(void)
91{
92 tick_broadcast_control(TICK_BROADCAST_OFF);
93}
94static inline void tick_broadcast_force(void)
95{
96 tick_broadcast_control(TICK_BROADCAST_FORCE);
97}
1fe5d5c3
TG
98static inline int tick_broadcast_enter(void)
99{
100 return tick_broadcast_oneshot_control(TICK_BROADCAST_ENTER);
101}
102static inline void tick_broadcast_exit(void)
103{
104 tick_broadcast_oneshot_control(TICK_BROADCAST_EXIT);
105}
592a438f 106
d027d45d
FW
107enum tick_dep_bits {
108 TICK_DEP_BIT_POSIX_TIMER = 0,
109 TICK_DEP_BIT_PERF_EVENTS = 1,
110 TICK_DEP_BIT_SCHED = 2,
111 TICK_DEP_BIT_CLOCK_UNSTABLE = 3
112};
113
e6e6cc22 114#define TICK_DEP_MASK_NONE 0
d027d45d
FW
115#define TICK_DEP_MASK_POSIX_TIMER (1 << TICK_DEP_BIT_POSIX_TIMER)
116#define TICK_DEP_MASK_PERF_EVENTS (1 << TICK_DEP_BIT_PERF_EVENTS)
117#define TICK_DEP_MASK_SCHED (1 << TICK_DEP_BIT_SCHED)
118#define TICK_DEP_MASK_CLOCK_UNSTABLE (1 << TICK_DEP_BIT_CLOCK_UNSTABLE)
119
c1797baf 120#ifdef CONFIG_NO_HZ_COMMON
4cc7ecb7 121extern bool tick_nohz_enabled;
a3642983 122extern bool tick_nohz_tick_stopped(void);
22ab8bc0 123extern bool tick_nohz_tick_stopped_cpu(int cpu);
0e776768 124extern void tick_nohz_idle_stop_tick(void);
554c8aa8 125extern void tick_nohz_idle_retain_tick(void);
2aaf709a 126extern void tick_nohz_idle_restart_tick(void);
1268fbc7 127extern void tick_nohz_idle_enter(void);
280f0677
FW
128extern void tick_nohz_idle_exit(void);
129extern void tick_nohz_irq_exit(void);
45f1ff59 130extern bool tick_nohz_idle_got_tick(void);
6f9b83ac 131extern ktime_t tick_nohz_get_next_hrtimer(void);
296bb1e5 132extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next);
b7eaf1aa 133extern unsigned long tick_nohz_get_idle_calls(void);
466a2b42 134extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu);
6378ddb5 135extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
0224cf4c 136extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
0e776768
RW
137
138static inline void tick_nohz_idle_stop_tick_protected(void)
139{
140 local_irq_disable();
141 tick_nohz_idle_stop_tick();
142 local_irq_enable();
143}
144
c1797baf 145#else /* !CONFIG_NO_HZ_COMMON */
46373a15 146#define tick_nohz_enabled (0)
c1797baf 147static inline int tick_nohz_tick_stopped(void) { return 0; }
22ab8bc0 148static inline int tick_nohz_tick_stopped_cpu(int cpu) { return 0; }
0e776768 149static inline void tick_nohz_idle_stop_tick(void) { }
554c8aa8 150static inline void tick_nohz_idle_retain_tick(void) { }
2aaf709a 151static inline void tick_nohz_idle_restart_tick(void) { }
2bbb6817
FW
152static inline void tick_nohz_idle_enter(void) { }
153static inline void tick_nohz_idle_exit(void) { }
45f1ff59 154static inline bool tick_nohz_idle_got_tick(void) { return false; }
6f9b83ac
UH
155static inline ktime_t tick_nohz_get_next_hrtimer(void)
156{
157 /* Next wake up is the tick period, assume it starts now */
158 return ktime_add(ktime_get(), TICK_NSEC);
159}
296bb1e5 160static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next)
4f86d3a8 161{
296bb1e5
RW
162 *delta_next = TICK_NSEC;
163 return *delta_next;
4f86d3a8 164}
8083e4ad 165static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
0224cf4c 166static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
0e776768
RW
167
168static inline void tick_nohz_idle_stop_tick_protected(void) { }
c1797baf 169#endif /* !CONFIG_NO_HZ_COMMON */
906568c9 170
c5bfece2 171#ifdef CONFIG_NO_HZ_FULL
460775df
FW
172extern bool tick_nohz_full_running;
173extern cpumask_var_t tick_nohz_full_mask;
174
175static inline bool tick_nohz_full_enabled(void)
176{
58135f57 177 if (!context_tracking_is_enabled())
460775df
FW
178 return false;
179
180 return tick_nohz_full_running;
181}
182
183static inline bool tick_nohz_full_cpu(int cpu)
184{
185 if (!tick_nohz_full_enabled())
186 return false;
187
188 return cpumask_test_cpu(cpu, tick_nohz_full_mask);
189}
190
83dedea8
CM
191static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask)
192{
193 if (tick_nohz_full_enabled())
194 cpumask_or(mask, mask, tick_nohz_full_mask);
195}
196
d027d45d
FW
197extern void tick_nohz_dep_set(enum tick_dep_bits bit);
198extern void tick_nohz_dep_clear(enum tick_dep_bits bit);
199extern void tick_nohz_dep_set_cpu(int cpu, enum tick_dep_bits bit);
200extern void tick_nohz_dep_clear_cpu(int cpu, enum tick_dep_bits bit);
201extern void tick_nohz_dep_set_task(struct task_struct *tsk,
202 enum tick_dep_bits bit);
203extern void tick_nohz_dep_clear_task(struct task_struct *tsk,
204 enum tick_dep_bits bit);
205extern void tick_nohz_dep_set_signal(struct signal_struct *signal,
206 enum tick_dep_bits bit);
207extern void tick_nohz_dep_clear_signal(struct signal_struct *signal,
208 enum tick_dep_bits bit);
209
210/*
211 * The below are tick_nohz_[set,clear]_dep() wrappers that optimize off-cases
212 * on top of static keys.
213 */
214static inline void tick_dep_set(enum tick_dep_bits bit)
215{
216 if (tick_nohz_full_enabled())
217 tick_nohz_dep_set(bit);
218}
219
220static inline void tick_dep_clear(enum tick_dep_bits bit)
221{
222 if (tick_nohz_full_enabled())
223 tick_nohz_dep_clear(bit);
224}
225
226static inline void tick_dep_set_cpu(int cpu, enum tick_dep_bits bit)
227{
228 if (tick_nohz_full_cpu(cpu))
229 tick_nohz_dep_set_cpu(cpu, bit);
230}
231
232static inline void tick_dep_clear_cpu(int cpu, enum tick_dep_bits bit)
233{
234 if (tick_nohz_full_cpu(cpu))
235 tick_nohz_dep_clear_cpu(cpu, bit);
236}
237
238static inline void tick_dep_set_task(struct task_struct *tsk,
239 enum tick_dep_bits bit)
240{
241 if (tick_nohz_full_enabled())
242 tick_nohz_dep_set_task(tsk, bit);
243}
244static inline void tick_dep_clear_task(struct task_struct *tsk,
245 enum tick_dep_bits bit)
246{
247 if (tick_nohz_full_enabled())
248 tick_nohz_dep_clear_task(tsk, bit);
249}
250static inline void tick_dep_set_signal(struct signal_struct *signal,
251 enum tick_dep_bits bit)
252{
253 if (tick_nohz_full_enabled())
254 tick_nohz_dep_set_signal(signal, bit);
255}
256static inline void tick_dep_clear_signal(struct signal_struct *signal,
257 enum tick_dep_bits bit)
258{
259 if (tick_nohz_full_enabled())
260 tick_nohz_dep_clear_signal(signal, bit);
261}
262
3d36aebc 263extern void tick_nohz_full_kick_cpu(int cpu);
de734f89 264extern void __tick_nohz_task_switch(void);
6f1982fe 265extern void __init tick_nohz_full_setup(cpumask_var_t cpumask);
a831881b 266#else
460775df
FW
267static inline bool tick_nohz_full_enabled(void) { return false; }
268static inline bool tick_nohz_full_cpu(int cpu) { return false; }
83dedea8 269static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { }
d027d45d
FW
270
271static inline void tick_dep_set(enum tick_dep_bits bit) { }
272static inline void tick_dep_clear(enum tick_dep_bits bit) { }
273static inline void tick_dep_set_cpu(int cpu, enum tick_dep_bits bit) { }
274static inline void tick_dep_clear_cpu(int cpu, enum tick_dep_bits bit) { }
275static inline void tick_dep_set_task(struct task_struct *tsk,
276 enum tick_dep_bits bit) { }
277static inline void tick_dep_clear_task(struct task_struct *tsk,
278 enum tick_dep_bits bit) { }
279static inline void tick_dep_set_signal(struct signal_struct *signal,
280 enum tick_dep_bits bit) { }
281static inline void tick_dep_clear_signal(struct signal_struct *signal,
282 enum tick_dep_bits bit) { }
283
3d36aebc 284static inline void tick_nohz_full_kick_cpu(int cpu) { }
de734f89 285static inline void __tick_nohz_task_switch(void) { }
6f1982fe 286static inline void tick_nohz_full_setup(cpumask_var_t cpumask) { }
a831881b
FW
287#endif
288
de734f89 289static inline void tick_nohz_task_switch(void)
d13508f9
FW
290{
291 if (tick_nohz_full_enabled())
de734f89 292 __tick_nohz_task_switch();
d13508f9
FW
293}
294
906568c9 295#endif