[PATCH RESEND] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()

Yury Norov (NVIDIA) posted 1 patch 1 week, 2 days ago
kernel/sched/fair.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
[PATCH RESEND] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()
Posted by Yury Norov (NVIDIA) 1 week, 2 days ago
cpumask_empty() call is O(N) and useless because the previous
cpumask_and() returns false for empty 'cpus'. Drop it.

CC: Markus Elfring <Markus.Elfring@web.de>
Reviewed-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
Rebased and re-tested on top of master. Original patch:
https://lore.kernel.org/all/20250911023426.457745-1-yury.norov@gmail.com/

 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index e04f94233cda..af9e9dbdaa6d 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8362,9 +8362,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
 		int max_spare_cap_cpu = -1;
 		int fits, max_fits = -1;
 
-		cpumask_and(cpus, perf_domain_span(pd), cpu_online_mask);
-
-		if (cpumask_empty(cpus))
+		if (!cpumask_and(cpus, perf_domain_span(pd), cpu_online_mask))
 			continue;
 
 		/* Account external pressure for the energy estimation */
-- 
2.43.0
Re: [PATCH RESEND] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()
Posted by Peter Zijlstra 1 week, 1 day ago
On Sat, Dec 06, 2025 at 11:05:42PM -0500, Yury Norov (NVIDIA) wrote:
> cpumask_empty() call is O(N) and useless because the previous
> cpumask_and() returns false for empty 'cpus'. Drop it.
> 
> CC: Markus Elfring <Markus.Elfring@web.de>
> Reviewed-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
> Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>

Picked it (and the other two) up for processing after rc1.