From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=44.246.77.92 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796336021; b=D0wtMQjm+2Ol4+CdG9gd/aCA1tgpzEGSRogxyjlV3KIOeRIagU3pxS7NsvCQN2B3ytMQ kmXVLN+y/+mA3LDv3qzQlkmzlQWEh58gMl7UGH6ORFTchiNRW+qw0JJbJswqgMyjID7FG or25URHrOUbwXe8Wr65DR92dmAKqIzWu44jcFFLBlBdubyZt/5c57tRcXjwS7mD6WULdp lO58VBEXANk26DUUWPZdgEo7wmL7T0vszvEs2okKtnJu7EGb9Js3PUAJ/0sGEtUZf8ksZ 29RHWfsCHNJSYq7UZrJ3IfBhJ5HcfomMMCJ1UDvfEkR+5gNtHmTz8MTZJD8OdiJbx7A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336021; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:Received:Received:X-Farcaster-Flow-ID:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=uIJCnwqJ/gEwvY3wGNuPmAcCs++pmRJPNoP8pv37wY0=; b=TS6VJVyz6Zu5TFRHeLTFjg1v4yf7Yez5H+sk1yBuAP5sDrDv3V9NeLimyOasEd9r2U0s MefofrbLQiCxqIfkUi/GJzpon6vK4AtUlolXNrY3fQrN1kv5JClUb284GFMDa0/D2xYiZ r3kC4JJIQvNNjUOPQjxOLY5YO2Q1k2xyCI5c5xUwWAsO6jRUuzR5Md0+3vVo7sqtwr0eC 8f76+WXTyWvJWi9OCB4mccoqj1x9ESQpscXje5m1Eq/MG2EBQOkcurrsilxCarDmy7+dt vjaFb6RecdxYLfz174ySVB72C4IiTJ02Oezt0YywCgbITzDC2Jq1ZEJ5iYoYoMHUaoA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass header.d=amazon.de header.i=@amazon.de header.a=rsa-sha256 header.s=amazoncorp2 header.b=rjUKkQZC; arc=none smtp.remote-ip=44.246.77.92 Received: from pdx-out-004.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-004.esa.us-west-2.outbound.mail-perimeter.amazon.com [44.246.77.92]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6659E606A322; Thu, 3 Dec 2026 22:13:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6659E606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=amazon.de header.i=@amazon.de header.a=rsa-sha256 header.s=amazoncorp2 header.b=rjUKkQZC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1796336021; x=1827872021; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uIJCnwqJ/gEwvY3wGNuPmAcCs++pmRJPNoP8pv37wY0=; b=rjUKkQZCGDrg666qgdNiQ7HWJZ0/cJsuuOomFEe4H3Z7eZmJFklIYmfS a0D1nCIlEe50dUh8aq7j9hP+2WrQ8Mblt0JPvOzo3Fogz3JtlHR9sDhNL y31Tw8+gRmgSp6EdTRU+j67/3AKvXkyX0ui6p1iCK8p8NfZ79822EL9Ig XHhxbPoyGKlE4CAJr8MuUF/qSZ2OMKk4UN1q1shWkkVSCUSIQ4fxlj7jH 76Vr4EilhC0I7R3WjmzA3Y7r3/Aa5xNwJXLB5iqVw6Cbh6hZTUysHuee6 Ch/K4uiVJwXiGI+4Dc4HiyAMaWFYRCg5Z5s+FFE2luEdmYPeVbUfO4bpj Q==; X-CSE-ConnectionGUID: XMEF+HbHQf6IR4uzkSUbyA== X-CSE-MsgGUID: i0ynyt+rTZWYcmEoVXF2Fg== X-IronPort-AV: E=Sophos;i="6.29,77,1794873600"; d="scan'208";a="35826080" Received: from ip-10-5-9-48.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.9.48]) by internal-pdx-out-004.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:13:39 +0000 Received: from EX19MTAUWB002.ant.amazon.com [205.251.233.111:28417] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.42.230:2525] with esmtp (Farcaster) id 457a9b4a-fe30-4c44-87d5-d252ed84a890; Thu, 3 Dec 2026 22:13:38 +0000 (UTC) X-Farcaster-Flow-ID: 457a9b4a-fe30-4c44-87d5-d252ed84a890 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Thu, 3 Dec 2026 22:13:38 +0000 Received: from dev-dsk-araoof-1b-23e02486.eu-west-1.amazon.com (10.253.65.187) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Thu, 3 Dec 2026 22:13:35 +0000 From: Ahmed Abdelraoof To: Ingo Molnar , Peter Zijlstra CC: Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , "Mel Gorman" , Valentin Schneider , "K Prateek Nayak" , Jonathan Corbet , Shuah Khan , Randy Dunlap , , , Anselm Busse , Ahmed Abdelraoof Subject: [PATCH 1/4] sched/core: Decouple the core scheduling unit from cpu_smt_mask Date: Thu, 3 Dec 2026 22:13:04 +0000 Message-ID: <20261203221307.86078-2-araoof@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203221307.86078-1-araoof@amazon.de> References: <20261203221307.86078-1-araoof@amazon.de> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D031UWA001.ant.amazon.com (10.13.139.88) To EX19D001UWA001.ant.amazon.com (10.13.138.214) From: Anselm Busse 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 Co-developed-by: Ahmed Abdelraoof Signed-off-by: Ahmed Abdelraoof --- 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