Linux Audio

Check our new training course

Loading...
v5.9
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Tick related global functions
 
  4 */
  5#ifndef _LINUX_TICK_H
  6#define _LINUX_TICK_H
  7
  8#include <linux/clockchips.h>
  9#include <linux/irqflags.h>
 10#include <linux/percpu.h>
 11#include <linux/context_tracking_state.h>
 12#include <linux/cpumask.h>
 13#include <linux/sched.h>
 14
 15#ifdef CONFIG_GENERIC_CLOCKEVENTS
 16extern void __init tick_init(void);
 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 */
 20extern void tick_resume_local(void);
 21extern void tick_handover_do_timer(void);
 22extern void tick_cleanup_dead_cpu(int cpu);
 23#else /* CONFIG_GENERIC_CLOCKEVENTS */
 24static inline void tick_init(void) { }
 25static inline void tick_suspend_local(void) { }
 26static inline void tick_resume_local(void) { }
 27static inline void tick_handover_do_timer(void) { }
 28static inline void tick_cleanup_dead_cpu(int cpu) { }
 29#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 30
 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
 39#ifdef CONFIG_TICK_ONESHOT
 40extern void tick_irq_enter(void);
 41#  ifndef arch_needs_cpu
 42#   define arch_needs_cpu() (0)
 43#  endif
 44# else
 45static inline void tick_irq_enter(void) { }
 46#endif
 47
 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
 54enum tick_broadcast_mode {
 55	TICK_BROADCAST_OFF,
 56	TICK_BROADCAST_ON,
 57	TICK_BROADCAST_FORCE,
 58};
 59
 60enum tick_broadcast_state {
 61	TICK_BROADCAST_EXIT,
 62	TICK_BROADCAST_ENTER,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 63};
 64
 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
 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
 77#ifdef CONFIG_GENERIC_CLOCKEVENTS
 78extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
 79#else
 80static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state)
 81{
 82	return 0;
 83}
 84#endif
 85
 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}
 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}
106
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	TICK_DEP_BIT_RCU		= 4,
113	TICK_DEP_BIT_RCU_EXP		= 5
114};
115#define TICK_DEP_BIT_MAX TICK_DEP_BIT_RCU_EXP
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
117#define TICK_DEP_MASK_NONE		0
118#define TICK_DEP_MASK_POSIX_TIMER	(1 << TICK_DEP_BIT_POSIX_TIMER)
119#define TICK_DEP_MASK_PERF_EVENTS	(1 << TICK_DEP_BIT_PERF_EVENTS)
120#define TICK_DEP_MASK_SCHED		(1 << TICK_DEP_BIT_SCHED)
121#define TICK_DEP_MASK_CLOCK_UNSTABLE	(1 << TICK_DEP_BIT_CLOCK_UNSTABLE)
122#define TICK_DEP_MASK_RCU		(1 << TICK_DEP_BIT_RCU)
123#define TICK_DEP_MASK_RCU_EXP		(1 << TICK_DEP_BIT_RCU_EXP)
124
125#ifdef CONFIG_NO_HZ_COMMON
126extern bool tick_nohz_enabled;
127extern bool tick_nohz_tick_stopped(void);
128extern bool tick_nohz_tick_stopped_cpu(int cpu);
129extern void tick_nohz_idle_stop_tick(void);
130extern void tick_nohz_idle_retain_tick(void);
131extern void tick_nohz_idle_restart_tick(void);
132extern void tick_nohz_idle_enter(void);
133extern void tick_nohz_idle_exit(void);
134extern void tick_nohz_irq_exit(void);
135extern bool tick_nohz_idle_got_tick(void);
136extern ktime_t tick_nohz_get_next_hrtimer(void);
137extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next);
138extern unsigned long tick_nohz_get_idle_calls(void);
139extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu);
140extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
141extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
142
143static inline void tick_nohz_idle_stop_tick_protected(void)
144{
145	local_irq_disable();
146	tick_nohz_idle_stop_tick();
147	local_irq_enable();
148}
149
150#else /* !CONFIG_NO_HZ_COMMON */
151#define tick_nohz_enabled (0)
152static inline int tick_nohz_tick_stopped(void) { return 0; }
153static inline int tick_nohz_tick_stopped_cpu(int cpu) { return 0; }
154static inline void tick_nohz_idle_stop_tick(void) { }
155static inline void tick_nohz_idle_retain_tick(void) { }
156static inline void tick_nohz_idle_restart_tick(void) { }
157static inline void tick_nohz_idle_enter(void) { }
158static inline void tick_nohz_idle_exit(void) { }
159static inline bool tick_nohz_idle_got_tick(void) { return false; }
160static inline ktime_t tick_nohz_get_next_hrtimer(void)
161{
162	/* Next wake up is the tick period, assume it starts now */
163	return ktime_add(ktime_get(), TICK_NSEC);
164}
165static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next)
166{
167	*delta_next = TICK_NSEC;
168	return *delta_next;
169}
170static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
171static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
172
173static inline void tick_nohz_idle_stop_tick_protected(void) { }
174#endif /* !CONFIG_NO_HZ_COMMON */
175
176#ifdef CONFIG_NO_HZ_FULL
177extern bool tick_nohz_full_running;
178extern cpumask_var_t tick_nohz_full_mask;
179
180static inline bool tick_nohz_full_enabled(void)
181{
182	if (!context_tracking_enabled())
183		return false;
184
185	return tick_nohz_full_running;
186}
187
188static inline bool tick_nohz_full_cpu(int cpu)
189{
190	if (!tick_nohz_full_enabled())
191		return false;
192
193	return cpumask_test_cpu(cpu, tick_nohz_full_mask);
194}
195
196static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask)
197{
198	if (tick_nohz_full_enabled())
199		cpumask_or(mask, mask, tick_nohz_full_mask);
200}
201
202extern void tick_nohz_dep_set(enum tick_dep_bits bit);
203extern void tick_nohz_dep_clear(enum tick_dep_bits bit);
204extern void tick_nohz_dep_set_cpu(int cpu, enum tick_dep_bits bit);
205extern void tick_nohz_dep_clear_cpu(int cpu, enum tick_dep_bits bit);
206extern void tick_nohz_dep_set_task(struct task_struct *tsk,
207				   enum tick_dep_bits bit);
208extern void tick_nohz_dep_clear_task(struct task_struct *tsk,
209				     enum tick_dep_bits bit);
210extern void tick_nohz_dep_set_signal(struct signal_struct *signal,
211				     enum tick_dep_bits bit);
212extern void tick_nohz_dep_clear_signal(struct signal_struct *signal,
213				       enum tick_dep_bits bit);
214
215/*
216 * The below are tick_nohz_[set,clear]_dep() wrappers that optimize off-cases
217 * on top of static keys.
218 */
219static inline void tick_dep_set(enum tick_dep_bits bit)
220{
221	if (tick_nohz_full_enabled())
222		tick_nohz_dep_set(bit);
223}
224
225static inline void tick_dep_clear(enum tick_dep_bits bit)
226{
227	if (tick_nohz_full_enabled())
228		tick_nohz_dep_clear(bit);
229}
230
231static inline void tick_dep_set_cpu(int cpu, enum tick_dep_bits bit)
232{
233	if (tick_nohz_full_cpu(cpu))
234		tick_nohz_dep_set_cpu(cpu, bit);
235}
236
237static inline void tick_dep_clear_cpu(int cpu, enum tick_dep_bits bit)
238{
239	if (tick_nohz_full_cpu(cpu))
240		tick_nohz_dep_clear_cpu(cpu, bit);
241}
242
243static inline void tick_dep_set_task(struct task_struct *tsk,
244				     enum tick_dep_bits bit)
245{
246	if (tick_nohz_full_enabled())
247		tick_nohz_dep_set_task(tsk, bit);
248}
249static inline void tick_dep_clear_task(struct task_struct *tsk,
250				       enum tick_dep_bits bit)
251{
252	if (tick_nohz_full_enabled())
253		tick_nohz_dep_clear_task(tsk, bit);
254}
255static inline void tick_dep_set_signal(struct signal_struct *signal,
256				       enum tick_dep_bits bit)
257{
258	if (tick_nohz_full_enabled())
259		tick_nohz_dep_set_signal(signal, bit);
260}
261static inline void tick_dep_clear_signal(struct signal_struct *signal,
262					 enum tick_dep_bits bit)
263{
264	if (tick_nohz_full_enabled())
265		tick_nohz_dep_clear_signal(signal, bit);
266}
267
268extern void tick_nohz_full_kick_cpu(int cpu);
269extern void __tick_nohz_task_switch(void);
270extern void __init tick_nohz_full_setup(cpumask_var_t cpumask);
271#else
272static inline bool tick_nohz_full_enabled(void) { return false; }
273static inline bool tick_nohz_full_cpu(int cpu) { return false; }
274static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { }
275
276static inline void tick_nohz_dep_set_cpu(int cpu, enum tick_dep_bits bit) { }
277static inline void tick_nohz_dep_clear_cpu(int cpu, enum tick_dep_bits bit) { }
278
279static inline void tick_dep_set(enum tick_dep_bits bit) { }
280static inline void tick_dep_clear(enum tick_dep_bits bit) { }
281static inline void tick_dep_set_cpu(int cpu, enum tick_dep_bits bit) { }
282static inline void tick_dep_clear_cpu(int cpu, enum tick_dep_bits bit) { }
283static inline void tick_dep_set_task(struct task_struct *tsk,
284				     enum tick_dep_bits bit) { }
285static inline void tick_dep_clear_task(struct task_struct *tsk,
286				       enum tick_dep_bits bit) { }
287static inline void tick_dep_set_signal(struct signal_struct *signal,
288				       enum tick_dep_bits bit) { }
289static inline void tick_dep_clear_signal(struct signal_struct *signal,
290					 enum tick_dep_bits bit) { }
291
292static inline void tick_nohz_full_kick_cpu(int cpu) { }
293static inline void __tick_nohz_task_switch(void) { }
294static inline void tick_nohz_full_setup(cpumask_var_t cpumask) { }
295#endif
296
297static inline void tick_nohz_task_switch(void)
298{
299	if (tick_nohz_full_enabled())
300		__tick_nohz_task_switch();
301}
 
 
 
302
303#endif
v3.5.6
  1/*  linux/include/linux/tick.h
  2 *
  3 *  This file contains the structure definitions for tick related functions
  4 *
  5 */
  6#ifndef _LINUX_TICK_H
  7#define _LINUX_TICK_H
  8
  9#include <linux/clockchips.h>
 10#include <linux/irqflags.h>
 
 
 
 
 11
 12#ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 13
 14enum tick_device_mode {
 15	TICKDEV_MODE_PERIODIC,
 16	TICKDEV_MODE_ONESHOT,
 17};
 
 
 
 18
 19struct tick_device {
 20	struct clock_event_device *evtdev;
 21	enum tick_device_mode mode;
 22};
 
 
 
 
 23
 24enum tick_nohz_mode {
 25	NOHZ_MODE_INACTIVE,
 26	NOHZ_MODE_LOWRES,
 27	NOHZ_MODE_HIGHRES,
 
 
 
 
 
 
 28};
 29
 30/**
 31 * struct tick_sched - sched tick emulation and no idle tick control/stats
 32 * @sched_timer:	hrtimer to schedule the periodic tick in high
 33 *			resolution mode
 34 * @idle_tick:		Store the last idle tick expiry time when the tick
 35 *			timer is modified for idle sleeps. This is necessary
 36 *			to resume the tick timer operation in the timeline
 37 *			when the CPU returns from idle
 38 * @tick_stopped:	Indicator that the idle tick has been stopped
 39 * @idle_jiffies:	jiffies at the entry to idle for idle time accounting
 40 * @idle_calls:		Total number of idle calls
 41 * @idle_sleeps:	Number of idle calls, where the sched tick was stopped
 42 * @idle_entrytime:	Time when the idle call was entered
 43 * @idle_waketime:	Time when the idle was interrupted
 44 * @idle_exittime:	Time when the idle state was left
 45 * @idle_sleeptime:	Sum of the time slept in idle with sched tick stopped
 46 * @iowait_sleeptime:	Sum of the time slept in idle with sched tick stopped, with IO outstanding
 47 * @sleep_length:	Duration of the current idle sleep
 48 * @do_timer_lst:	CPU was the last one doing do_timer before going idle
 49 */
 50struct tick_sched {
 51	struct hrtimer			sched_timer;
 52	unsigned long			check_clocks;
 53	enum tick_nohz_mode		nohz_mode;
 54	ktime_t				idle_tick;
 55	int				inidle;
 56	int				tick_stopped;
 57	unsigned long			idle_jiffies;
 58	unsigned long			idle_calls;
 59	unsigned long			idle_sleeps;
 60	int				idle_active;
 61	ktime_t				idle_entrytime;
 62	ktime_t				idle_waketime;
 63	ktime_t				idle_exittime;
 64	ktime_t				idle_sleeptime;
 65	ktime_t				iowait_sleeptime;
 66	ktime_t				sleep_length;
 67	unsigned long			last_jiffies;
 68	unsigned long			next_jiffies;
 69	ktime_t				idle_expires;
 70	int				do_timer_last;
 71};
 72
 73extern void __init tick_init(void);
 74extern int tick_is_oneshot_available(void);
 75extern struct tick_device *tick_get_device(int cpu);
 
 
 
 
 
 
 
 
 76
 77# ifdef CONFIG_HIGH_RES_TIMERS
 78extern int tick_init_highres(void);
 79extern int tick_program_event(ktime_t expires, int force);
 80extern void tick_setup_sched_timer(void);
 81# endif
 
 
 
 82
 83# if defined CONFIG_NO_HZ || defined CONFIG_HIGH_RES_TIMERS
 84extern void tick_cancel_sched_timer(int cpu);
 85# else
 86static inline void tick_cancel_sched_timer(int cpu) { }
 87# endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 88
 89# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 90extern struct tick_device *tick_get_broadcast_device(void);
 91extern struct cpumask *tick_get_broadcast_mask(void);
 92
 93#  ifdef CONFIG_TICK_ONESHOT
 94extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
 95#  endif
 96
 97# endif /* BROADCAST */
 98
 99# ifdef CONFIG_TICK_ONESHOT
100extern void tick_clock_notify(void);
101extern int tick_check_oneshot_change(int allow_nohz);
102extern struct tick_sched *tick_get_tick_sched(int cpu);
103extern void tick_check_idle(int cpu);
104extern int tick_oneshot_mode_active(void);
105#  ifndef arch_needs_cpu
106#   define arch_needs_cpu(cpu) (0)
107#  endif
108# else
109static inline void tick_clock_notify(void) { }
110static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
111static inline void tick_check_idle(int cpu) { }
112static inline int tick_oneshot_mode_active(void) { return 0; }
113# endif
114
115#else /* CONFIG_GENERIC_CLOCKEVENTS */
116static inline void tick_init(void) { }
117static inline void tick_cancel_sched_timer(int cpu) { }
118static inline void tick_clock_notify(void) { }
119static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
120static inline void tick_check_idle(int cpu) { }
121static inline int tick_oneshot_mode_active(void) { return 0; }
122#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
123
124# ifdef CONFIG_NO_HZ
 
 
 
 
 
125extern void tick_nohz_idle_enter(void);
126extern void tick_nohz_idle_exit(void);
127extern void tick_nohz_irq_exit(void);
128extern ktime_t tick_nohz_get_sleep_length(void);
 
 
 
 
129extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
130extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
131# else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132static inline void tick_nohz_idle_enter(void) { }
133static inline void tick_nohz_idle_exit(void) { }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
135static inline ktime_t tick_nohz_get_sleep_length(void)
136{
137	ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
 
 
138
139	return len;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140}
141static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
142static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
143# endif /* !NO_HZ */
144
145#endif