From: Ahmed Abdelraoof <araoof@amazon.de>
To: Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
"K Prateek Nayak" <kprateek.nayak@amd.com>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>, <linux-doc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, Anselm Busse <abusse@amazon.com>,
Ahmed Abdelraoof <araoof@amazon.com>
Subject: [PATCH 4/4] sched/core: Support L2 cache isolation
Date: Thu, 3 Dec 2026 22:13:07 +0000 [thread overview]
Message-ID: <20261203221307.86078-5-araoof@amazon.de> (raw)
In-Reply-To: <20261203221307.86078-1-araoof@amazon.de>
From: Anselm Busse <abusse@amazon.com>
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@amazon.com>
Co-developed-by: Ahmed Abdelraoof <araoof@amazon.com>
Signed-off-by: Ahmed Abdelraoof <araoof@amazon.com>
---
.../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
prev parent reply other threads:[~2026-12-03 22:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 22:13 [PATCH 0/4] sched/core: Core scheduling beyond SMT siblings Ahmed Abdelraoof
2026-12-03 22:13 ` [PATCH 1/4] sched/core: Decouple the core scheduling unit from cpu_smt_mask Ahmed Abdelraoof
2026-12-03 22:13 ` [PATCH 2/4] sched/core: Nest the isolation unit rq locks under one lock for lockdep Ahmed Abdelraoof
2026-12-03 22:13 ` [PATCH 3/4] sched/core: Gate core scheduling on the isolation unit Ahmed Abdelraoof
2026-12-03 22:13 ` Ahmed Abdelraoof [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203221307.86078-5-araoof@amazon.de \
--to=araoof@amazon.de \
--cc=abusse@amazon.com \
--cc=araoof@amazon.com \
--cc=bsegall@google.com \
--cc=corbet@lwn.net \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=skhan@linuxfoundation.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox