The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group()
@ 2025-09-11  3:44 Yury Norov
  2025-09-11  6:52 ` K Prateek Nayak
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yury Norov @ 2025-09-11  3:44 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>

In the group_has_spare case, the function creates a temporary cpumask
to just calculate weight of (p->cpus_ptr & sched_group_span(local)).

We've got a dedicated helper for it.

Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 kernel/sched/fair.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 7229339cbb1b..4ec012912cd1 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10821,10 +10821,9 @@ sched_balance_find_dst_group(struct sched_domain *sd, struct task_struct *p, int
 			 * take care of it.
 			 */
 			if (p->nr_cpus_allowed != NR_CPUS) {
-				struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
-
-				cpumask_and(cpus, sched_group_span(local), p->cpus_ptr);
-				imb_numa_nr = min(cpumask_weight(cpus), sd->imb_numa_nr);
+				unsigned w = cpumask_weight_and(p->cpus_ptr,
+								sched_group_span(local));
+				imb_numa_nr = min(w, sd->imb_numa_nr);
 			}
 
 			imbalance = abs(local_sgs.idle_cpus - idlest_sgs.idle_cpus);
-- 
2.43.0


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

* Re: [PATCH] sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group()
  2025-09-11  3:44 [PATCH] sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group() Yury Norov
@ 2025-09-11  6:52 ` K Prateek Nayak
  2025-09-11  8:50 ` Vincent Guittot
  2025-09-11  8:58 ` Fernand Sieber
  2 siblings, 0 replies; 4+ messages in thread
From: K Prateek Nayak @ 2025-09-11  6:52 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 9:14 AM, Yury Norov wrote:
> From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> 
> In the group_has_spare case, the function creates a temporary cpumask
> to just calculate weight of (p->cpus_ptr & sched_group_span(local)).
> 
> We've got a dedicated helper for it.

Neat! I didn't realize this existed back when I added that cpumask_and()
+ cpumask_weight() combo. 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 | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 7229339cbb1b..4ec012912cd1 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -10821,10 +10821,9 @@ sched_balance_find_dst_group(struct sched_domain *sd, struct task_struct *p, int
>  			 * take care of it.
>  			 */
>  			if (p->nr_cpus_allowed != NR_CPUS) {
> -				struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
> -
> -				cpumask_and(cpus, sched_group_span(local), p->cpus_ptr);
> -				imb_numa_nr = min(cpumask_weight(cpus), sd->imb_numa_nr);
> +				unsigned w = cpumask_weight_and(p->cpus_ptr,
> +								sched_group_span(local));
> +				imb_numa_nr = min(w, sd->imb_numa_nr);
>  			}
>  
>  			imbalance = abs(local_sgs.idle_cpus - idlest_sgs.idle_cpus);

-- 
Thanks and Regards,
Prateek


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

* Re: [PATCH] sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group()
  2025-09-11  3:44 [PATCH] sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group() Yury Norov
  2025-09-11  6:52 ` K Prateek Nayak
@ 2025-09-11  8:50 ` Vincent Guittot
  2025-09-11  8:58 ` Fernand Sieber
  2 siblings, 0 replies; 4+ messages in thread
From: Vincent Guittot @ 2025-09-11  8:50 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 05:44, Yury Norov <yury.norov@gmail.com> wrote:
>
> From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
>
> In the group_has_spare case, the function creates a temporary cpumask
> to just calculate weight of (p->cpus_ptr & sched_group_span(local)).
>
> We've got a dedicated helper for it.
>
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>

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

> ---
>  kernel/sched/fair.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 7229339cbb1b..4ec012912cd1 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -10821,10 +10821,9 @@ sched_balance_find_dst_group(struct sched_domain *sd, struct task_struct *p, int
>                          * take care of it.
>                          */
>                         if (p->nr_cpus_allowed != NR_CPUS) {
> -                               struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
> -
> -                               cpumask_and(cpus, sched_group_span(local), p->cpus_ptr);
> -                               imb_numa_nr = min(cpumask_weight(cpus), sd->imb_numa_nr);
> +                               unsigned w = cpumask_weight_and(p->cpus_ptr,
> +                                                               sched_group_span(local));
> +                               imb_numa_nr = min(w, sd->imb_numa_nr);
>                         }
>
>                         imbalance = abs(local_sgs.idle_cpus - idlest_sgs.idle_cpus);
> --
> 2.43.0
>

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

* Re: [PATCH] sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group()
  2025-09-11  3:44 [PATCH] sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group() Yury Norov
  2025-09-11  6:52 ` K Prateek Nayak
  2025-09-11  8:50 ` Vincent Guittot
@ 2025-09-11  8:58 ` Fernand Sieber
  2 siblings, 0 replies; 4+ messages in thread
From: Fernand Sieber @ 2025-09-11  8:58 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel, Yury Norov

On Wed, 10 Sep 2025 23:44:52 -0400, Yury Norov wrote:
> In the group_has_spare case, the function creates a temporary cpumask
> to just calculate weight of (p->cpus_ptr & sched_group_span(local)).
>
> We've got a dedicated helper for it.
>
>

LGTM

Reviewed-by: Fernand Sieber <sieberf@amazon.com>

--
Thanks,
Fernand



Amazon Development Centre (South Africa) (Proprietary) Limited
29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa
Registration Number: 2004 / 034463 / 07

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-11  3:44 [PATCH] sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group() Yury Norov
2025-09-11  6:52 ` K Prateek Nayak
2025-09-11  8:50 ` Vincent Guittot
2025-09-11  8:58 ` Fernand Sieber

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