Skip to contentSkip to conversation

sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()

PATCH RESEND Applied Yury Norov (NVIDIA) 3 participants 3 messages Dec 7, 2025 – Jan 12 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()

cpumask_empty() call is O(N) and useless because the previous cpumask_and() returns false for empty 'cpus'. Drop it.

---
Rebased and re-tested on top of master. Original patch:
https://lore.kernel.org/all/[email protected]/

 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -3
index e04f94233cda..af9e9dbdaa6d 100644
@@ -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 */
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 8 lines · Yury Norov (NVIDIA)

cpumask_empty() call is O(N) and useless because the previous cpumask_and() returns false for empty 'cpus'. Drop it.

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

#2 lore raw

[tip: sched/core] sched/fair: Drop useless cpumask_empty() in find_energy_efficient_cpu()

In reply to Yury Norov (NVIDIA)
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     ff1de90dd7a69ef43586683535ad87ab899a1214
Gitweb:        https://git.kernel.org/tip/ff1de90dd7a69ef43586683535ad87ab899a1214
Author:        Yury Norov (NVIDIA) <[email protected]>
AuthorDate:    Sat, 06 Dec 2025 23:05:42 -05:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Thu, 08 Jan 2026 12:43:56 +01:00

sched/fair: Drop useless cpumask_empty() in find_energy_efficient_cpu()

cpumask_empty() call is O(N) and useless because the previous cpumask_and() returns false for empty 'cpus'. Drop it.

---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -3
index 7377f91..64275d7 100644
@@ -8359,9 +8359,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 */