The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()
@ 2025-09-11  2:34 Yury Norov
  2025-09-11  6:44 ` K Prateek Nayak
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Yury Norov @ 2025-09-11  2:34 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel
  Cc: Yury Norov

From: Yury Norov (NVIDIA) <yury.norov@gmail.com>

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

Signed-off-by: Yury Norov (NVIDIA) <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 b173a059315c..7229339cbb1b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()
  2025-09-11  2:34 [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu() Yury Norov
@ 2025-09-11  6:44 ` K Prateek Nayak
  2025-09-11  6:45 ` Madadi Vineeth Reddy
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: K Prateek Nayak @ 2025-09-11  6:44 UTC (permalink / raw)
  To: Yury Norov, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Valentin Schneider, linux-kernel

Hello Yury,

On 9/11/2025 8:04 AM, Yury Norov wrote:
> From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> 
> 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:

Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>

> 
> Signed-off-by: Yury Norov (NVIDIA) <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 b173a059315c..7229339cbb1b 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -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 */

-- 
Thanks and Regards,
Prateek


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()
  2025-09-11  2:34 [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu() Yury Norov
  2025-09-11  6:44 ` K Prateek Nayak
@ 2025-09-11  6:45 ` Madadi Vineeth Reddy
  2025-09-11  8:28 ` Vincent Guittot
  2025-09-11 14:00 ` Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: Madadi Vineeth Reddy @ 2025-09-11  6:45 UTC (permalink / raw)
  To: Yury Norov
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel, Madadi Vineeth Reddy

On 11/09/25 08:04, Yury Norov wrote:
> From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> 
> cpumask_empty() call is O(N) and useless, because the previous
> cpumask_and() returns false for empty 'cpus'.
> 

LGTM

Reviewed-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>

Thanks,
Madadi Vineeth Reddy

> Signed-off-by: Yury Norov (NVIDIA) <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 b173a059315c..7229339cbb1b 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -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 */


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()
  2025-09-11  2:34 [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu() Yury Norov
  2025-09-11  6:44 ` K Prateek Nayak
  2025-09-11  6:45 ` Madadi Vineeth Reddy
@ 2025-09-11  8:28 ` Vincent Guittot
  2025-09-11 14:00 ` Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: Vincent Guittot @ 2025-09-11  8:28 UTC (permalink / raw)
  To: Yury Norov
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	linux-kernel

On Thu, 11 Sept 2025 at 04:34, Yury Norov <yury.norov@gmail.com> wrote:
>
> From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
>
> cpumask_empty() call is O(N) and useless, because the previous
> cpumask_and() returns false for empty 'cpus'.
>
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>

Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>

> ---
>  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 b173a059315c..7229339cbb1b 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu()
  2025-09-11  2:34 [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu() Yury Norov
                   ` (2 preceding siblings ...)
  2025-09-11  8:28 ` Vincent Guittot
@ 2025-09-11 14:00 ` Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2025-09-11 14:00 UTC (permalink / raw)
  To: Yury Norov, kernel-janitors, Ben Segall, Dietmar Eggemann,
	Ingo Molnar, Juri Lelli, Mel Gorman, Peter Zijlstra,
	Steven Rostedt, Valentin Schneider, Vincent Guittot
  Cc: LKML, K Prateek Nayak, Madadi Vineeth Reddy

> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-11 14:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-11  2:34 [PATCH] sched: fair: drop useless cpumask_empty() in find_energy_efficient_cpu() Yury Norov
2025-09-11  6:44 ` K Prateek Nayak
2025-09-11  6:45 ` Madadi Vineeth Reddy
2025-09-11  8:28 ` Vincent Guittot
2025-09-11 14:00 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox