1 #ifndef _LINUX_SCHED_ISOLATION_H
2 #define _LINUX_SCHED_ISOLATION_H
3
4 #include <linux/cpumask.h>
5 #include <linux/init.h>
6 #include <linux/tick.h>
7
8 enum hk_type {
9 HK_TYPE_TIMER,
10 HK_TYPE_RCU,
11 HK_TYPE_MISC,
12 HK_TYPE_SCHED,
13 HK_TYPE_TICK,
14 HK_TYPE_DOMAIN,
15 HK_TYPE_WQ,
16 HK_TYPE_MANAGED_IRQ,
17 HK_TYPE_KTHREAD,
18 HK_TYPE_MAX
19 };
20
21 #ifdef CONFIG_CPU_ISOLATION
22 DECLARE_STATIC_KEY_FALSE(housekeeping_overridden);
23 extern int housekeeping_any_cpu(enum hk_type type);
24 extern const struct cpumask *housekeeping_cpumask(enum hk_type type);
25 extern bool housekeeping_enabled(enum hk_type type);
26 extern void housekeeping_affine(struct task_struct *t, enum hk_type type);
27 extern bool housekeeping_test_cpu(int cpu, enum hk_type type);
28 extern void __init housekeeping_init(void);
29
30 #else
31
32 #ifdef CONFIG_CPU_ISOLATION_OPT
housekeeping_any_cpu(enum hk_type type)33 static inline int housekeeping_any_cpu(enum hk_type type)
34 {
35 cpumask_t available;
36 int cpu;
37
38 cpumask_andnot(&available, cpu_online_mask, cpu_isolated_mask);
39 cpu = cpumask_any(&available);
40 if (cpu >= nr_cpu_ids)
41 cpu = smp_processor_id();
42
43 return cpu;
44 }
45 #else
housekeeping_any_cpu(enum hk_type type)46 static inline int housekeeping_any_cpu(enum hk_type type)
47 {
48 return smp_processor_id();
49 }
50 #endif
51
housekeeping_cpumask(enum hk_type type)52 static inline const struct cpumask *housekeeping_cpumask(enum hk_type type)
53 {
54 return cpu_possible_mask;
55 }
56
housekeeping_enabled(enum hk_type type)57 static inline bool housekeeping_enabled(enum hk_type type)
58 {
59 return false;
60 }
61
housekeeping_affine(struct task_struct * t,enum hk_type type)62 static inline void housekeeping_affine(struct task_struct *t,
63 enum hk_type type) { }
64
housekeeping_test_cpu(int cpu,enum hk_type type)65 static inline bool housekeeping_test_cpu(int cpu, enum hk_type type)
66 {
67 return true;
68 }
69
housekeeping_init(void)70 static inline void housekeeping_init(void) { }
71 #endif /* CONFIG_CPU_ISOLATION */
72
housekeeping_cpu(int cpu,enum hk_type type)73 static inline bool housekeeping_cpu(int cpu, enum hk_type type)
74 {
75 #ifdef CONFIG_CPU_ISOLATION
76 if (static_branch_unlikely(&housekeeping_overridden))
77 return housekeeping_test_cpu(cpu, type);
78 #endif
79 #ifdef CONFIG_CPU_ISOLATION_OPT
80 return !cpu_isolated(cpu);
81 #else
82 return true;
83 #endif
84 }
85
cpu_is_isolated(int cpu)86 static inline bool cpu_is_isolated(int cpu)
87 {
88 return !housekeeping_test_cpu(cpu, HK_TYPE_DOMAIN) ||
89 !housekeeping_test_cpu(cpu, HK_TYPE_TICK);
90 }
91
92 #endif /* _LINUX_SCHED_ISOLATION_H */
93