[PATCH v3 1/3] sched/topology: pre-compute topology_span_sane() loop params
From: Yury Norov
Date: Mon Sep 02 2024 - 14:36:32 EST
tl->mask() is called inside the loop with the same parameters more than
once. We can pre-calculate it. After that, 'cpu' doesn't have to keep its
value while running the loop iterations. We can drop the 'i' iterator,
and re-use 'cpu' in the for_each_cpu_from() loop.
Reviewed-by: Chen Yu <yu.c.chen@xxxxxxxxx>
Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
---
kernel/sched/topology.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 76504b776d03..ffbe3a28d2d4 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2353,27 +2353,30 @@ static struct sched_domain *build_sched_domain(struct sched_domain_topology_leve
static bool topology_span_sane(struct sched_domain_topology_level *tl,
const struct cpumask *cpu_map, int cpu)
{
- int i = cpu + 1;
+ const struct cpumask *mi, *mc;
/* NUMA levels are allowed to overlap */
if (tl->flags & SDTL_OVERLAP)
return true;
+ mc = tl->mask(cpu++);
+
/*
* Non-NUMA levels cannot partially overlap - they must be either
* completely equal or completely disjoint. Otherwise we can end up
* breaking the sched_group lists - i.e. a later get_group() pass
* breaks the linking done for an earlier span.
*/
- for_each_cpu_from(i, cpu_map) {
+ for_each_cpu_from(cpu, cpu_map) {
+ mi = tl->mask(cpu);
+
/*
* We should 'and' all those masks with 'cpu_map' to exactly
* match the topology we're about to build, but that can only
* remove CPUs, which only lessens our ability to detect
* overlaps
*/
- if (!cpumask_equal(tl->mask(cpu), tl->mask(i)) &&
- cpumask_intersects(tl->mask(cpu), tl->mask(i)))
+ if (!cpumask_equal(mc, mi) && cpumask_intersects(mc, mi))
return false;
}
--
2.43.0