[PATCH 1/7] sched/isolation: Introduce housekeeping_runtime isolation
From: Pierre Gondois
Date: Wed Apr 03 2024 - 11:06:37 EST
CONFIG_CPU_ISOLATION allows to setup various cpu masks to
exclude CPUs from some activities. Masks that are not modified
default to cpu_online_mask.
Masks are set at boot time. If no mask is modified, the static key
'housekeeping_overridden' is left to false, allowing to minimize the
cost of calls to housekeeping_*() functions.
Create a new housekeeping runtime type, whose isolation masks
can be modified at runtime. Also add a set of functions
around this new type. This type is independent from the
'housekeeping_overridden' static key.
Signed-off-by: Pierre Gondois <pierre.gondois@xxxxxxx>
---
include/linux/sched/isolation.h | 28 +++++++++++++++++++++
kernel/sched/isolation.c | 43 +++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+)
diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h
index 2b461129d1fa..5d2f40c6f04c 100644
--- a/include/linux/sched/isolation.h
+++ b/include/linux/sched/isolation.h
@@ -6,6 +6,10 @@
#include <linux/init.h>
#include <linux/tick.h>
+enum hkr_type {
+ HKR_TYPE_MAX
+};
+
enum hk_type {
HK_TYPE_TIMER,
HK_TYPE_RCU,
@@ -26,6 +30,12 @@ extern const struct cpumask *housekeeping_cpumask(enum hk_type type);
extern bool housekeeping_enabled(enum hk_type type);
extern void housekeeping_affine(struct task_struct *t, enum hk_type type);
extern bool housekeeping_test_cpu(int cpu, enum hk_type type);
+
+extern const struct cpumask *housekeeping_runtime_cpumask(enum hkr_type type);
+extern bool housekeeping_runtime_test_cpu(int cpu, enum hkr_type type);
+extern void housekeeping_runtime_set_cpu(int cpu, enum hkr_type type);
+extern void housekeeping_runtime_clear_cpu(int cpu, enum hkr_type type);
+
extern void __init housekeeping_init(void);
#else
@@ -53,6 +63,24 @@ static inline bool housekeeping_test_cpu(int cpu, enum hk_type type)
return true;
}
+static inline const struct cpumask *housekeeping_runtime_cpumask(enum hkr_type type)
+{
+ return cpu_possible_mask;
+}
+
+static inline bool housekeeping_runtime_test_cpu(int cpu, enum hkr_type type)
+{
+ return true;
+}
+
+static inline void housekeeping_runtime_set_cpu(int cpu, enum hkr_type type)
+{
+}
+
+static inline void housekeeping_runtime_clear_cpu(int cpu, enum hkr_type type)
+{
+}
+
static inline void housekeeping_init(void) { }
#endif /* CONFIG_CPU_ISOLATION */
diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index 373d42c707bc..5acbed870c28 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -23,6 +23,13 @@ enum hk_flags {
DEFINE_STATIC_KEY_FALSE(housekeeping_overridden);
EXPORT_SYMBOL_GPL(housekeeping_overridden);
+struct housekeeping_runtime {
+ cpumask_var_t cpumasks[HKR_TYPE_MAX];
+ unsigned long flags;
+};
+
+static struct housekeeping_runtime housekeeping_runtime;
+
struct housekeeping {
cpumask_var_t cpumasks[HK_TYPE_MAX];
unsigned long flags;
@@ -79,10 +86,46 @@ bool housekeeping_test_cpu(int cpu, enum hk_type type)
}
EXPORT_SYMBOL_GPL(housekeeping_test_cpu);
+const struct cpumask *housekeeping_runtime_cpumask(enum hkr_type type)
+{
+ if (housekeeping_runtime.cpumasks[type])
+ return housekeeping_runtime.cpumasks[type];
+ return cpu_possible_mask;
+}
+
+bool housekeeping_runtime_test_cpu(int cpu, enum hkr_type type)
+{
+ if (housekeeping_runtime.cpumasks[type])
+ return cpumask_test_cpu(cpu, housekeeping_runtime.cpumasks[type]);
+ return true;
+}
+
+void housekeeping_runtime_set_cpu(int cpu, enum hkr_type type)
+{
+ if (housekeeping_runtime.cpumasks[type])
+ cpumask_set_cpu(cpu, housekeeping_runtime.cpumasks[type]);
+}
+
+void housekeeping_runtime_clear_cpu(int cpu, enum hkr_type type)
+{
+ if (housekeeping_runtime.cpumasks[type])
+ cpumask_clear_cpu(cpu, housekeeping_runtime.cpumasks[type]);
+}
+
+static void __init housekeeping_runtime_init(void)
+{
+ enum hkr_type type;
+
+ for (type = 0; type < HKR_TYPE_MAX; type++)
+ alloc_cpumask_var(&housekeeping_runtime.cpumasks[type], GFP_KERNEL);
+}
+
void __init housekeeping_init(void)
{
enum hk_type type;
+ housekeeping_runtime_init();
+
if (!housekeeping.flags)
return;
--
2.25.1