[PATCH 1/2] sched/topology: pre-compute topology_span_sane() loop params

From: Yury Norov
Date: Fri Aug 02 2024 - 13:58:20 EST


tl->mask(cpu) is used unchanged in the loop, and tl->mask(i) in worst
case may be calculated twice as parameters for cpumask_equal() and
cpumask_intersects(). So, precalculate both.

Suggested-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
Suggested-by: Leonardo Bras <leobras@xxxxxxxxxx>
Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
---
kernel/sched/topology.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 76504b776d03..754ad5fa3c99 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2353,6 +2353,7 @@ 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)
{
+ const struct cpumask *mi, *mc = tl->mask(cpu);
int i = cpu + 1;

/* NUMA levels are allowed to overlap */
@@ -2366,14 +2367,15 @@ static bool topology_span_sane(struct sched_domain_topology_level *tl,
* breaks the linking done for an earlier span.
*/
for_each_cpu_from(i, cpu_map) {
+ mi = tl->mask(i);
+
/*
* 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