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 /* Inverse of boot-time isolcpus= argument */
10 HK_TYPE_DOMAIN_BOOT,
11 /*
12 * Same as HK_TYPE_DOMAIN_BOOT but also includes the
13 * inverse of cpuset isolated partitions. As such it
14 * is always a subset of HK_TYPE_DOMAIN_BOOT.
15 */
16 HK_TYPE_DOMAIN,
17 /* Inverse of boot-time isolcpus=managed_irq argument */
18 HK_TYPE_MANAGED_IRQ,
19 /* Inverse of boot-time nohz_full= or isolcpus=nohz arguments */
20 HK_TYPE_KERNEL_NOISE,
21 HK_TYPE_MAX,
22
23 /*
24 * HK_TYPE_KTHREAD is now an alias of HK_TYPE_DOMAIN
25 */
26 HK_TYPE_KTHREAD = HK_TYPE_DOMAIN,
27
28 /*
29 * The following housekeeping types are only set by the nohz_full
30 * boot commandline option. So they can share the same value.
31 */
32 HK_TYPE_TICK = HK_TYPE_KERNEL_NOISE,
33 HK_TYPE_TIMER = HK_TYPE_KERNEL_NOISE,
34 HK_TYPE_RCU = HK_TYPE_KERNEL_NOISE,
35 HK_TYPE_MISC = HK_TYPE_KERNEL_NOISE,
36 HK_TYPE_WQ = HK_TYPE_KERNEL_NOISE,
37 };
38
39 #ifdef CONFIG_CPU_ISOLATION
40 DECLARE_STATIC_KEY_FALSE(housekeeping_overridden);
41 extern int housekeeping_any_cpu(enum hk_type type);
42 extern const struct cpumask *housekeeping_cpumask(enum hk_type type);
43 extern bool housekeeping_enabled(enum hk_type type);
44 extern void housekeeping_affine(struct task_struct *t, enum hk_type type);
45 extern bool housekeeping_test_cpu(int cpu, enum hk_type type);
46 extern int housekeeping_update(struct cpumask *isol_mask);
47 extern void __init housekeeping_init(void);
48
49 #else
50
housekeeping_any_cpu(enum hk_type type)51 static inline int housekeeping_any_cpu(enum hk_type type)
52 {
53 return smp_processor_id();
54 }
55
housekeeping_cpumask(enum hk_type type)56 static inline const struct cpumask *housekeeping_cpumask(enum hk_type type)
57 {
58 return cpu_possible_mask;
59 }
60
housekeeping_enabled(enum hk_type type)61 static inline bool housekeeping_enabled(enum hk_type type)
62 {
63 return false;
64 }
65
housekeeping_affine(struct task_struct * t,enum hk_type type)66 static inline void housekeeping_affine(struct task_struct *t,
67 enum hk_type type) { }
68
housekeeping_test_cpu(int cpu,enum hk_type type)69 static inline bool housekeeping_test_cpu(int cpu, enum hk_type type)
70 {
71 return true;
72 }
73
housekeeping_update(struct cpumask * isol_mask)74 static inline int housekeeping_update(struct cpumask *isol_mask) { return 0; }
housekeeping_init(void)75 static inline void housekeeping_init(void) { }
76 #endif /* CONFIG_CPU_ISOLATION */
77
housekeeping_cpu(int cpu,enum hk_type type)78 static inline bool housekeeping_cpu(int cpu, enum hk_type type)
79 {
80 #ifdef CONFIG_CPU_ISOLATION
81 if (static_branch_unlikely(&housekeeping_overridden))
82 return housekeeping_test_cpu(cpu, type);
83 #endif
84 return true;
85 }
86
cpu_is_isolated(int cpu)87 static inline bool cpu_is_isolated(int cpu)
88 {
89 return !housekeeping_test_cpu(cpu, HK_TYPE_DOMAIN);
90 }
91
92 #endif /* _LINUX_SCHED_ISOLATION_H */
93