[PATCH 4/4] sched/core: Support L2 cache isolation
From: Ahmed Abdelraoof
Date: Thu Dec 03 2026 - 17:15:12 EST
From: Anselm Busse <abusse@xxxxxxxxxx>
Core scheduling only isolates SMT siblings from each other. Cores that
share an L2 cache can observe each other through it much as SMT siblings
can through the core, so on processors that pair cores around a shared
L2 core scheduling leaves that path open.
Add a kernel command-line parameter "sched_core_unit=X", where X can be
"smt" (the default) to keep the SMT siblings as the isolation unit, or
"cluster" to use the CPUs of a cluster as reported by
topology_cluster_cpumask(). On x86 a cluster is the set of CPUs that
share an L2 cache. All CPUs of a unit share one rq lock, so a wider
unit trades some lock contention for the isolation.
If "cluster" is selected but no cluster spans more than one CPU, warn
that no clusters were reported and core scheduling is unavailable.
Signed-off-by: Anselm Busse <abusse@xxxxxxxxxx>
Co-developed-by: Ahmed Abdelraoof <araoof@xxxxxxxxxx>
Signed-off-by: Ahmed Abdelraoof <araoof@xxxxxxxxxx>
---
.../admin-guide/kernel-parameters.txt | 12 +++++
kernel/sched/core.c | 44 +++++++++++++++++++
kernel/sched/sched.h | 18 ++++++++
3 files changed, 74 insertions(+)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 176648941aec..faaeb4812b60 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -6801,6 +6801,18 @@ Kernel parameters
cost of significant additional memory use for tables.
+ sched_core_unit=
+ [KNL,EARLY] Select the CPUs that core scheduling treats
+ as one isolation unit, i.e. that never run tasks with
+ different core scheduling cookies at the same time.
+ Format: { smt | cluster }
+ smt - SMT siblings (default).
+ cluster - CPUs in the same cluster, as reported by the
+ CPU topology (on x86, the CPUs that share an L2
+ cache); for processors that pair cores around a
+ shared L2 without SMT.
+ See Documentation/admin-guide/hw-vuln/core-scheduling.rst.
+
sched_proxy_exec= [KNL]
Enables or disables "proxy execution" style
solution to mutex-based priority inversion.
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index c69f40e7b93a..6640ea861818 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -429,6 +429,50 @@ static DEFINE_MUTEX(sched_core_mutex);
static atomic_t sched_core_count;
static struct cpumask sched_core_mask;
+enum sched_core_unit_type sched_core_unit __ro_after_init = SCHED_CORE_UNIT_SMT;
+
+static int __init sched_core_unit_setup(char *str)
+{
+ /* A bare "sched_core_unit" with no value arrives here as NULL. */
+ if (!str)
+ return 0;
+
+ if (!strcmp(str, "smt")) {
+ sched_core_unit = SCHED_CORE_UNIT_SMT;
+ } else if (!strcmp(str, "cluster")) {
+ sched_core_unit = SCHED_CORE_UNIT_CLUSTER;
+ } else {
+ pr_warn("sched_core_unit=%s unrecognised, using smt\n", str);
+ return 0;
+ }
+
+ pr_info("core scheduling isolation unit: %s\n", str);
+ return 0;
+}
+
+/*
+ * Parsed from start_kernel(), so the value is stable well before the first
+ * sched_core_cpu_starting() elects any rq->core leader.
+ */
+early_param("sched_core_unit", sched_core_unit_setup);
+
+static int __init sched_core_unit_check(void)
+{
+ int cpu;
+
+ if (sched_core_unit != SCHED_CORE_UNIT_CLUSTER)
+ return 0;
+
+ for_each_online_cpu(cpu) {
+ if (cpumask_weight(sched_core_isolation_mask(cpu)) > 1)
+ return 0;
+ }
+
+ pr_warn("sched_core: cluster unit spans a single CPU everywhere; no clusters reported, core scheduling unavailable\n");
+ return 0;
+}
+late_initcall(sched_core_unit_check);
+
/*
* The rq locks of a unit share one lockdep class, and a subclass per CPU
* would overflow MAX_LOCKDEP_SUBCLASSES on units wider than eight CPUs. So
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 97126c1dcb09..bc7030b4ff75 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1588,13 +1588,31 @@ cfs_prio_less(const struct task_struct *a, const struct task_struct *b, bool fi)
extern void task_vruntime_update(struct rq *rq, struct task_struct *p, bool in_fi);
+/*
+ * Which topology level core scheduling treats as its isolation unit.
+ */
+enum sched_core_unit_type {
+ SCHED_CORE_UNIT_SMT,
+ SCHED_CORE_UNIT_CLUSTER,
+};
+
+extern enum sched_core_unit_type sched_core_unit;
+
/*
* The core scheduling isolation unit: the set of CPUs that share one runqueue
* lock and that are constrained to run tasks carrying a single cookie at any
* instant.
+ *
+ * On x86 topology_cluster_cpumask() is cpu_l2c_shared_mask(), which is built
+ * from the CPUID leaf 4 L2 descriptor whenever there is more than one core per
+ * package, independently of CONFIG_SCHED_CLUSTER. So the cluster unit does not
+ * require a cluster sched domain to exist.
*/
static inline const struct cpumask *sched_core_isolation_mask(int cpu)
{
+ if (sched_core_unit == SCHED_CORE_UNIT_CLUSTER)
+ return topology_cluster_cpumask(cpu);
+
return cpu_smt_mask(cpu);
}
--
2.47.3