[PATCH 18/22] sched/core: remove unneeded cpumask_weight() in sched_core_cpu_{starting,deactivate}

From: Yury Norov
Date: Tue May 10 2022 - 11:58:01 EST


The following cpumask_any_but() implicitly calculates if number of smt cpus
is equal to 1, therefore we can drop the code that does it explicitly.

CC: Ben Segall <bsegall@xxxxxxxxxx>
CC: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
CC: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
CC: Ingo Molnar <mingo@xxxxxxxxxx>
CC: Juri Lelli <juri.lelli@xxxxxxxxxx>
CC: Mel Gorman <mgorman@xxxxxxx>
CC: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CC: Steven Rostedt <rostedt@xxxxxxxxxxx>
CC: Valentin Schneider <vschneid@xxxxxxxxxx>
CC: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
CC: linux-kernel@xxxxxxxxxxxxxxx
Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
---
This is RFC because it drops WARN_ON_ONCE(rq->core != rq). If this warinig
is important, I'll rework the patch.

kernel/sched/core.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 9700001948d0..07b8f35cbe36 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6133,12 +6133,10 @@ 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)
- goto unlock;
-
/* find the leader */
t = cpumask_any_but(smt_mask, cpu);
+
+ /* if we're the first, we'll be our own leader */
if (t >= nr_cpu_ids)
goto unlock;

@@ -6171,18 +6169,14 @@ static void sched_core_cpu_deactivate(unsigned int cpu)

sched_core_lock(cpu, &flags);

- /* if we're the last man standing, nothing to do */
- if (cpumask_weight(smt_mask) == 1) {
- WARN_ON_ONCE(rq->core != rq);
- goto unlock;
- }
-
/* if we're not the leader, nothing to do */
if (rq->core != rq)
goto unlock;

/* find a new leader */
t = cpumask_any_but(smt_mask, cpu);
+
+ /* if we're the last man standing, nothing to do */
if (t >= nr_cpu_ids)
goto unlock;

--
2.32.0