Linux Documentation
 help / color / mirror / Atom feed
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 1/4] sched/core: Decouple the core scheduling unit from cpu_smt_mask
Date: Thu, 3 Dec 2026 22:13:04 +0000	[thread overview]
Message-ID: <20261203221307.86078-2-araoof@amazon.de> (raw)
In-Reply-To: <20261203221307.86078-1-araoof@amazon.de>

From: Anselm Busse <abusse@amazon.com>

Core scheduling uses cpu_smt_mask() to identify which CPUs (SMT threads)
belong to the same core scheduling equivalence group. That said, SMT
siblings are not the only CPUs that share microarchitectural state.
Cores behind a shared L2 cache can observe each other through it much
as SMT siblings can through the core.

Add sched_core_isolation_mask() as the single definition of that unit
and use it for every core scheduling user of cpu_smt_mask(). The helper
returns cpu_smt_mask() for now, so there is no functional change.

Signed-off-by: Anselm Busse <abusse@amazon.com>
Co-developed-by: Ahmed Abdelraoof <araoof@amazon.com>
Signed-off-by: Ahmed Abdelraoof <araoof@amazon.com>
---
 kernel/sched/core.c  | 33 ++++++++++++++++++---------------
 kernel/sched/sched.h | 18 ++++++++++++++----
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ea89471d4743..cdd944bb274d 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -433,11 +433,11 @@ static void sched_core_lock(int cpu, unsigned long *flags)
 	__context_unsafe(/* acquires multiple */)
 	__acquires(&runqueues.__lock) /* overapproximation */
 {
-	const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+	const struct cpumask *isolation_mask = sched_core_isolation_mask(cpu);
 	int t, i = 0;
 
 	local_irq_save(*flags);
-	for_each_cpu(t, smt_mask)
+	for_each_cpu(t, isolation_mask)
 		raw_spin_lock_nested(&cpu_rq(t)->__lock, i++);
 }
 
@@ -445,10 +445,10 @@ static void sched_core_unlock(int cpu, unsigned long *flags)
 	__context_unsafe(/* releases multiple */)
 	__releases(&runqueues.__lock) /* overapproximation */
 {
-	const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+	const struct cpumask *isolation_mask = sched_core_isolation_mask(cpu);
 	int t;
 
-	for_each_cpu(t, smt_mask)
+	for_each_cpu(t, isolation_mask)
 		raw_spin_unlock(&cpu_rq(t)->__lock);
 	local_irq_restore(*flags);
 }
@@ -465,7 +465,7 @@ static void __sched_core_flip(bool enabled)
 	 */
 	cpumask_copy(&sched_core_mask, cpu_online_mask);
 	for_each_cpu(cpu, &sched_core_mask) {
-		const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+		const struct cpumask *isolation_mask = sched_core_isolation_mask(cpu);
 
 		sched_core_lock(cpu, &flags);
 
@@ -480,14 +480,17 @@ static void __sched_core_flip(bool enabled)
 			sched_core_lock(cpu, &flags);
 		}
 
-		for_each_cpu(t, smt_mask)
+		for_each_cpu(t, isolation_mask)
 			cpu_rq(t)->core_enabled = enabled;
 
 		cpu_rq(cpu)->core->core_forceidle_start = 0;
 
 		sched_core_unlock(cpu, &flags);
 
-		cpumask_andnot(&sched_core_mask, &sched_core_mask, smt_mask);
+		/*
+		 * Skip already toggled cores
+		 */
+		cpumask_andnot(&sched_core_mask, &sched_core_mask, isolation_mask);
 	}
 
 	/*
@@ -6700,7 +6703,7 @@ DEFINE_LOCK_GUARD_1(core_lock, int,
 
 static void sched_core_cpu_starting(unsigned int cpu)
 {
-	const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+	const struct cpumask *isolation_mask = sched_core_isolation_mask(cpu);
 	struct rq *rq = cpu_rq(cpu), *core_rq = NULL;
 	int t;
 
@@ -6709,11 +6712,11 @@ static void sched_core_cpu_starting(unsigned int cpu)
 	WARN_ON_ONCE(rq->core != rq);
 
 	/* if we're the first, we'll be our own leader */
-	if (cpumask_weight(smt_mask) == 1)
+	if (cpumask_weight(isolation_mask) == 1)
 		return;
 
 	/* find the leader */
-	for_each_cpu(t, smt_mask) {
+	for_each_cpu(t, isolation_mask) {
 		if (t == cpu)
 			continue;
 		rq = cpu_rq(t);
@@ -6727,7 +6730,7 @@ static void sched_core_cpu_starting(unsigned int cpu)
 		return;
 
 	/* install and validate core_rq */
-	for_each_cpu(t, smt_mask) {
+	for_each_cpu(t, isolation_mask) {
 		rq = cpu_rq(t);
 
 		if (t == cpu)
@@ -6739,14 +6742,14 @@ static void sched_core_cpu_starting(unsigned int cpu)
 
 static void sched_core_cpu_deactivate(unsigned int cpu)
 {
-	const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+	const struct cpumask *isolation_mask = sched_core_isolation_mask(cpu);
 	struct rq *rq = cpu_rq(cpu), *core_rq = NULL;
 	int t;
 
 	guard(core_lock)(&cpu);
 
 	/* if we're the last man standing, nothing to do */
-	if (cpumask_weight(smt_mask) == 1) {
+	if (cpumask_weight(isolation_mask) == 1) {
 		WARN_ON_ONCE(rq->core != rq);
 		return;
 	}
@@ -6756,7 +6759,7 @@ static void sched_core_cpu_deactivate(unsigned int cpu)
 		return;
 
 	/* find a new leader */
-	for_each_cpu(t, smt_mask) {
+	for_each_cpu(t, isolation_mask) {
 		if (t == cpu)
 			continue;
 		core_rq = cpu_rq(t);
@@ -6789,7 +6792,7 @@ static void sched_core_cpu_deactivate(unsigned int cpu)
 	core_rq->core_forceidle_start = 0;
 
 	/* install new leader */
-	for_each_cpu(t, smt_mask) {
+	for_each_cpu(t, isolation_mask) {
 		rq = cpu_rq(t);
 		rq->core = core_rq;
 	}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 32f76551a0c5..948f70af6fa6 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1565,7 +1565,7 @@ static inline raw_spinlock_t *__rq_lockp(struct rq *rq)
 }
 
 /*
- * A CPU coming online is set in cpu_smt_mask() before
+ * A CPU coming online is set in sched_core_isolation_mask() before
  * sched_core_cpu_starting() links its rq->core to the core leader.
  * Until then it does not share the core-wide lock, so it must not be
  * touched as part of the core.
@@ -1576,11 +1576,11 @@ static inline bool sched_core_sibling(struct rq *rq, struct rq *rq_i)
 }
 
 #define for_each_core_cpu(i, rq) \
-	for_each_cpu(i, cpu_smt_mask(rq->cpu)) \
+	for_each_cpu(i, sched_core_isolation_mask(rq->cpu)) \
 		if (sched_core_sibling(rq, cpu_rq(i)))
 
 #define for_each_core_cpu_wrap(i, rq) \
-	for_each_cpu_wrap(i, cpu_smt_mask(rq->cpu), rq->cpu) \
+	for_each_cpu_wrap(i, sched_core_isolation_mask(rq->cpu), rq->cpu) \
 		if (sched_core_sibling(rq, cpu_rq(i)))
 
 extern bool
@@ -1588,6 +1588,16 @@ 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);
 
+/*
+ * 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.
+ */
+static inline const struct cpumask *sched_core_isolation_mask(int cpu)
+{
+	return cpu_smt_mask(cpu);
+}
+
 /*
  * Helpers to check if the CPU's core cookie matches with the task's cookie
  * when core scheduling is enabled.
@@ -1615,7 +1625,7 @@ static inline bool sched_core_cookie_match(struct rq *rq, struct task_struct *p)
 	if (rq->core->core_cookie == p->core_cookie)
 		return true;
 
-	for_each_cpu(cpu, cpu_smt_mask(cpu_of(rq))) {
+	for_each_cpu(cpu, sched_core_isolation_mask(cpu_of(rq))) {
 		if (!available_idle_cpu(cpu)) {
 			idle_core = false;
 			break;
-- 
2.47.3


  reply	other threads:[~2026-12-03 22:13 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 ` Ahmed Abdelraoof [this message]
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 ` [PATCH 4/4] sched/core: Support L2 cache isolation Ahmed Abdelraoof

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-2-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