mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 sched_ext/for-7.4-fixes] sched_ext: Fix partial-SMT core counting in calc_shard_layout()
@ 2026-11-10  9:10 Zhang Qiao
  2026-11-10 19:27 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang Qiao @ 2026-11-10  9:10 UTC (permalink / raw)
  To: tj
  Cc: void, arighi, changwoo, sched-ext, linux-kernel, tanghui20, zhangqiao22

calc_shard_layout() counts the cores of an LLC to spread them evenly
across shards. A core is counted when its cpu is the first cpu of
topology_sibling_cpumask(), but the cores scx_cid_init() builds are
the siblings intersected with @llc_cpus.

The sibling mask may contain cpus outside @llc_cpus - siblings which
landed in another node or LLC unit, or offlined siblings on archs
that keep them in the mask (mips, sparc64). A core whose first
sibling is such a cpu is never counted, so cores_per_shard and
nr_large come out too small and the shards end up uneven.

Count a core at its first sibling in @llc_cpus, matching the cores the
build loop constructs.

Fixes: e2c841b91bf9 ("sched_ext: Add CID sharding")
Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
---
 kernel/sched/ext/cid.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/ext/cid.c b/kernel/sched/ext/cid.c
index 8e04a8494e11..0cc397055f57 100644
--- a/kernel/sched/ext/cid.c
+++ b/kernel/sched/ext/cid.c
@@ -64,7 +64,13 @@ static void calc_shard_layout(const struct cpumask *llc_cpus, u32 shard_size,
 
 	for_each_cpu(cpu, llc_cpus) {
 		nr_cpus++;
-		if (cpumask_first(topology_sibling_cpumask(cpu)) == cpu)
+		/*
+		 * scx_cid_init() forms each core from the siblings in
+		 * @llc_cpus. The sibling mask may include cpus outside
+		 * @llc_cpus, so count a core at its first sibling in @llc_cpus.
+		 */
+		if (cpumask_first_and(topology_sibling_cpumask(cpu),
+				      llc_cpus) == cpu)
 			nr_cores++;
 	}
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 sched_ext/for-7.4-fixes] sched_ext: Fix partial-SMT core counting in calc_shard_layout()
  2026-11-10  9:10 [PATCH v2 sched_ext/for-7.4-fixes] sched_ext: Fix partial-SMT core counting in calc_shard_layout() Zhang Qiao
@ 2026-11-10 19:27 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2026-11-10 19:27 UTC (permalink / raw)
  To: Zhang Qiao
  Cc: David Vernet, Andrea Righi, Changwoo Min, sched-ext,
	linux-kernel, Hui Tang

Applied to sched_ext/for-7.4-fixes.

Thanks.

--
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-10 19:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10  9:10 [PATCH v2 sched_ext/for-7.4-fixes] sched_ext: Fix partial-SMT core counting in calc_shard_layout() Zhang Qiao
2026-11-10 19:27 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®