Skip to contentSkip to conversation

sched_ext: Fix partial-SMT core counting in calc_shard_layout()

PATCH Applied Zhang Qiao 2 participants 2 messages Nov 10

Subsystems (2)
lore
Share & tools
lore

Zhang Qiao

author
#0 lore raw

PATCH v2 1/1 sched_ext: Fix partial-SMT core counting in calc_shard_layout()

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")
---
 kernel/sched/ext/cid.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
kernel/sched/ext/cid.c +7 -1
index 8e04a8494e11..0cc397055f57 100644
@@ -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++;
 	}
 
Signature · 1 line
2.43.0
reviewer Applied
#1 lore raw

Applied to sched_ext/for-7.4-fixes.

Thanks.

--
tejun