1
2
3
4
5
6#ifndef _LINUX_TICK_H
7#define _LINUX_TICK_H
8
9#include <linux/clockchips.h>
10#include <linux/irqflags.h>
11#include <linux/percpu.h>
12#include <linux/hrtimer.h>
13#include <linux/context_tracking_state.h>
14#include <linux/cpumask.h>
15#include <linux/sched.h>
16
17#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
18extern void hotplug_cpu__broadcast_tick_pull(int dead_cpu);
19#else
20static inline void hotplug_cpu__broadcast_tick_pull(int dead_cpu) { }
21#endif
22
23#ifdef CONFIG_GENERIC_CLOCKEVENTS
24
25enum tick_device_mode {
26 TICKDEV_MODE_PERIODIC,
27 TICKDEV_MODE_ONESHOT,
28};
29
30struct tick_device {
31 struct clock_event_device *evtdev;
32 enum tick_device_mode mode;
33};
34
35enum tick_nohz_mode {
36 NOHZ_MODE_INACTIVE,
37 NOHZ_MODE_LOWRES,
38 NOHZ_MODE_HIGHRES,
39};
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62struct tick_sched {
63 struct hrtimer sched_timer;
64 unsigned long check_clocks;
65 enum tick_nohz_mode nohz_mode;
66 ktime_t last_tick;
67 ktime_t next_tick;
68 int inidle;
69 int tick_stopped;
70 unsigned long idle_jiffies;
71 unsigned long idle_calls;
72 unsigned long idle_sleeps;
73 int idle_active;
74 ktime_t idle_entrytime;
75 ktime_t idle_waketime;
76 ktime_t idle_exittime;
77 ktime_t idle_sleeptime;
78 ktime_t iowait_sleeptime;
79 ktime_t sleep_length;
80 unsigned long last_jiffies;
81 u64 next_timer;
82 ktime_t idle_expires;
83 int do_timer_last;
84};
85
86extern void __init tick_init(void);
87extern int tick_is_oneshot_available(void);
88extern struct tick_device *tick_get_device(int cpu);
89
90# ifdef CONFIG_HIGH_RES_TIMERS
91extern int tick_init_highres(void);
92extern int tick_program_event(ktime_t expires, int force);
93extern void tick_setup_sched_timer(void);
94# endif
95
96# if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
97extern void tick_cancel_sched_timer(int cpu);
98# else
99static inline void tick_cancel_sched_timer(int cpu) { }
100# endif
101
102# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
103extern struct tick_device *tick_get_broadcast_device(void);
104extern struct cpumask *tick_get_broadcast_mask(void);
105
106# ifdef CONFIG_TICK_ONESHOT
107extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
108# endif
109
110# endif
111
112# ifdef CONFIG_TICK_ONESHOT
113extern void tick_clock_notify(void);
114extern int tick_check_oneshot_change(int allow_nohz);
115extern struct tick_sched *tick_get_tick_sched(int cpu);
116extern void tick_check_idle(void);
117extern int tick_oneshot_mode_active(void);
118# ifndef arch_needs_cpu
119# define arch_needs_cpu(cpu) (0)
120# endif
121# else
122static inline void tick_clock_notify(void) { }
123static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
124static inline void tick_check_idle(void) { }
125static inline int tick_oneshot_mode_active(void) { return 0; }
126# endif
127
128#else
129static inline void tick_init(void) { }
130static inline void tick_cancel_sched_timer(int cpu) { }
131static inline void tick_clock_notify(void) { }
132static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
133static inline void tick_check_idle(void) { }
134static inline int tick_oneshot_mode_active(void) { return 0; }
135#endif
136
137# ifdef CONFIG_NO_HZ_COMMON
138DECLARE_PER_CPU(struct tick_sched, tick_cpu_sched);
139
140static inline int tick_nohz_tick_stopped(void)
141{
142 return __this_cpu_read(tick_cpu_sched.tick_stopped);
143}
144
145extern void tick_nohz_idle_enter(void);
146extern void tick_nohz_idle_exit(void);
147extern void tick_nohz_irq_exit(void);
148extern ktime_t tick_nohz_get_sleep_length(void);
149extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
150extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
151
152# else
153static inline int tick_nohz_tick_stopped(void)
154{
155 return 0;
156}
157
158static inline void tick_nohz_idle_enter(void) { }
159static inline void tick_nohz_idle_exit(void) { }
160
161static inline ktime_t tick_nohz_get_sleep_length(void)
162{
163 ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
164
165 return len;
166}
167static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
168static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
169# endif
170
171#ifdef CONFIG_NO_HZ_FULL
172extern bool tick_nohz_full_running;
173extern cpumask_var_t tick_nohz_full_mask;
174extern cpumask_var_t housekeeping_mask;
175
176static inline bool tick_nohz_full_enabled(void)
177{
178 if (!context_tracking_is_enabled())
179 return false;
180
181 return tick_nohz_full_running;
182}
183
184static inline bool tick_nohz_full_cpu(int cpu)
185{
186 if (!tick_nohz_full_enabled())
187 return false;
188
189 return cpumask_test_cpu(cpu, tick_nohz_full_mask);
190}
191
192static inline int housekeeping_any_cpu(void)
193{
194 return cpumask_any_and(housekeeping_mask, cpu_online_mask);
195}
196
197extern void tick_nohz_init(void);
198extern void __tick_nohz_full_check(void);
199extern void tick_nohz_full_kick(void);
200extern void tick_nohz_full_kick_cpu(int cpu);
201extern void tick_nohz_full_kick_all(void);
202extern void __tick_nohz_task_switch(struct task_struct *tsk);
203#else
204static inline int housekeeping_any_cpu(void)
205{
206 return smp_processor_id();
207}
208
209static inline void tick_nohz_init(void) { }
210static inline bool tick_nohz_full_enabled(void) { return false; }
211static inline bool tick_nohz_full_cpu(int cpu) { return false; }
212static inline void __tick_nohz_full_check(void) { }
213static inline void tick_nohz_full_kick_cpu(int cpu) { }
214static inline void tick_nohz_full_kick(void) { }
215static inline void tick_nohz_full_kick_all(void) { }
216static inline void __tick_nohz_task_switch(struct task_struct *tsk) { }
217#endif
218
219static inline bool is_housekeeping_cpu(int cpu)
220{
221#ifdef CONFIG_NO_HZ_FULL
222 if (tick_nohz_full_enabled())
223 return cpumask_test_cpu(cpu, housekeeping_mask);
224#endif
225 return true;
226}
227
228static inline void tick_nohz_full_check(void)
229{
230 if (tick_nohz_full_enabled())
231 __tick_nohz_full_check();
232}
233
234static inline void tick_nohz_task_switch(struct task_struct *tsk)
235{
236 if (tick_nohz_full_enabled())
237 __tick_nohz_task_switch(tsk);
238}
239
240
241#endif
242