Skip to contentSkip to conversation

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

PATCH Superseded Yury Norov 5 participants 5 messages Sep 11, 2025

Subsystems (2)
lore
Share & tools
lore

Yury Norov

author
#0 lore raw

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

From: Yury Norov (NVIDIA) <[email protected]>

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

---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -3
index b173a059315c..7229339cbb1b 100644
@@ -8320,9 +8320,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
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hello Yury,

Quoted 4 lines · Yury Norov

From: Yury Norov (NVIDIA) <[email protected]>

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

I agree. Please feel free to include:

Quoted 21 lines
---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -3
index b173a059315c..7229339cbb1b 100644
@@ -8320,9 +8320,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 · 2 lines
Thanks and Regards,
Prateek
Reviewed-by on v1 1/1
#2 lore raw
In reply to Yury Norov
Quoted 5 lines · Yury Norov

From: Yury Norov (NVIDIA) <[email protected]>

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

LGTM

Thanks,
Madadi Vineeth Reddy

Quoted 20 lines
---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -3
index b173a059315c..7229339cbb1b 100644
@@ -8320,9 +8320,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 */
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Yury Norov
Quoted 7 lines · Yury Norov

From: Yury Norov (NVIDIA) <[email protected]>

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

Quoted 22 lines
---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -4
index b173a059315c..7229339cbb1b 100644
@@ -8320,9 +8320,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

#4 lore raw
In reply to Yury Norov
Quoted 2 lines

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

It seems to be more helpful to reuse a return value from a previous function call. How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc5#n94

Regards,
Markus