xref: /linux/include/linux/sched/isolation.h (revision 1c3329df409b9b50517bf4a1399ed793d277a20c)
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 	 * The following housekeeping types are only set by the nohz_full
25 	 * boot commandline option. So they can share the same value.
26 	 */
27 	HK_TYPE_TICK    = HK_TYPE_KERNEL_NOISE,
28 	HK_TYPE_TIMER   = HK_TYPE_KERNEL_NOISE,
29 	HK_TYPE_RCU     = HK_TYPE_KERNEL_NOISE,
30 	HK_TYPE_MISC    = HK_TYPE_KERNEL_NOISE,
31 	HK_TYPE_WQ      = HK_TYPE_KERNEL_NOISE,
32 	HK_TYPE_KTHREAD = HK_TYPE_KERNEL_NOISE
33 };
34 
35 #ifdef CONFIG_CPU_ISOLATION
36 DECLARE_STATIC_KEY_FALSE(housekeeping_overridden);
37 extern int housekeeping_any_cpu(enum hk_type type);
38 extern const struct cpumask *housekeeping_cpumask(enum hk_type type);
39 extern bool housekeeping_enabled(enum hk_type type);
40 extern void housekeeping_affine(struct task_struct *t, enum hk_type type);
41 extern bool housekeeping_test_cpu(int cpu, enum hk_type type);
42 extern int housekeeping_update(struct cpumask *isol_mask);
43 extern void __init housekeeping_init(void);
44 
45 #else
46 
47 static inline int housekeeping_any_cpu(enum hk_type type)
48 {
49 	return smp_processor_id();
50 }
51 
52 static inline const struct cpumask *housekeeping_cpumask(enum hk_type type)
53 {
54 	return cpu_possible_mask;
55 }
56 
57 static inline bool housekeeping_enabled(enum hk_type type)
58 {
59 	return false;
60 }
61 
62 static inline void housekeeping_affine(struct task_struct *t,
63 				       enum hk_type type) { }
64 
65 static inline bool housekeeping_test_cpu(int cpu, enum hk_type type)
66 {
67 	return true;
68 }
69 
70 static inline int housekeeping_update(struct cpumask *isol_mask) { return 0; }
71 static inline void housekeeping_init(void) { }
72 #endif /* CONFIG_CPU_ISOLATION */
73 
74 static inline bool housekeeping_cpu(int cpu, enum hk_type type)
75 {
76 #ifdef CONFIG_CPU_ISOLATION
77 	if (static_branch_unlikely(&housekeeping_overridden))
78 		return housekeeping_test_cpu(cpu, type);
79 #endif
80 	return true;
81 }
82 
83 static inline bool cpu_is_isolated(int cpu)
84 {
85 	return !housekeeping_test_cpu(cpu, HK_TYPE_DOMAIN);
86 }
87 
88 #endif /* _LINUX_SCHED_ISOLATION_H */
89