2 * Tick related global functions
7 #include <linux/clockchips.h>
8 #include <linux/irqflags.h>
9 #include <linux/percpu.h>
10 #include <linux/context_tracking_state.h>
11 #include <linux/cpumask.h>
12 #include <linux/sched.h>
14 #ifdef CONFIG_GENERIC_CLOCKEVENTS
15 extern void __init tick_init(void);
16 extern void tick_freeze(void);
17 extern void tick_unfreeze(void);
18 /* Should be core only, but ARM BL switcher requires it */
19 extern void tick_suspend_local(void);
20 /* Should be core only, but XEN resume magic and ARM BL switcher require it */
21 extern void tick_resume_local(void);
22 #else /* CONFIG_GENERIC_CLOCKEVENTS */
23 static inline void tick_init(void) { }
24 static inline void tick_freeze(void) { }
25 static inline void tick_unfreeze(void) { }
26 static inline void tick_suspend_local(void) { }
27 static inline void tick_resume_local(void) { }
28 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
30 #ifdef CONFIG_TICK_ONESHOT
31 extern void tick_irq_enter(void);
32 # ifndef arch_needs_cpu
33 # define arch_needs_cpu() (0)
36 static inline void tick_irq_enter(void) { }
39 #ifdef CONFIG_NO_HZ_COMMON
40 extern int tick_nohz_tick_stopped(void);
41 extern void tick_nohz_idle_enter(void);
42 extern void tick_nohz_idle_exit(void);
43 extern void tick_nohz_irq_exit(void);
44 extern ktime_t tick_nohz_get_sleep_length(void);
45 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
46 extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
47 #else /* !CONFIG_NO_HZ_COMMON */
48 static inline int tick_nohz_tick_stopped(void) { return 0; }
49 static inline void tick_nohz_idle_enter(void) { }
50 static inline void tick_nohz_idle_exit(void) { }
52 static inline ktime_t tick_nohz_get_sleep_length(void)
54 ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
58 static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
59 static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
60 #endif /* !CONFIG_NO_HZ_COMMON */
62 #ifdef CONFIG_NO_HZ_FULL
63 extern bool tick_nohz_full_running;
64 extern cpumask_var_t tick_nohz_full_mask;
65 extern cpumask_var_t housekeeping_mask;
67 static inline bool tick_nohz_full_enabled(void)
69 if (!context_tracking_is_enabled())
72 return tick_nohz_full_running;
75 static inline bool tick_nohz_full_cpu(int cpu)
77 if (!tick_nohz_full_enabled())
80 return cpumask_test_cpu(cpu, tick_nohz_full_mask);
83 extern void __tick_nohz_full_check(void);
84 extern void tick_nohz_full_kick(void);
85 extern void tick_nohz_full_kick_cpu(int cpu);
86 extern void tick_nohz_full_kick_all(void);
87 extern void __tick_nohz_task_switch(struct task_struct *tsk);
89 static inline bool tick_nohz_full_enabled(void) { return false; }
90 static inline bool tick_nohz_full_cpu(int cpu) { return false; }
91 static inline void __tick_nohz_full_check(void) { }
92 static inline void tick_nohz_full_kick_cpu(int cpu) { }
93 static inline void tick_nohz_full_kick(void) { }
94 static inline void tick_nohz_full_kick_all(void) { }
95 static inline void __tick_nohz_task_switch(struct task_struct *tsk) { }
98 static inline bool is_housekeeping_cpu(int cpu)
100 #ifdef CONFIG_NO_HZ_FULL
101 if (tick_nohz_full_enabled())
102 return cpumask_test_cpu(cpu, housekeeping_mask);
107 static inline void housekeeping_affine(struct task_struct *t)
109 #ifdef CONFIG_NO_HZ_FULL
110 if (tick_nohz_full_enabled())
111 set_cpus_allowed_ptr(t, housekeeping_mask);
116 static inline void tick_nohz_full_check(void)
118 if (tick_nohz_full_enabled())
119 __tick_nohz_full_check();
122 static inline void tick_nohz_task_switch(struct task_struct *tsk)
124 if (tick_nohz_full_enabled())
125 __tick_nohz_task_switch(tsk);