[PATCH 4/4] smp: Defer check for local execution in smp_call_function_many_cond()

Yury Norov posted 4 patches 6 months, 2 weeks ago
There is a newer version of this series
[PATCH 4/4] smp: Defer check for local execution in smp_call_function_many_cond()
Posted by Yury Norov 6 months, 2 weeks ago
From: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>

Defer check for local execution to the actual place where it is needed,
and save some stack on a useless local variable.

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

diff --git a/kernel/smp.c b/kernel/smp.c
index 715190669e94..867f79689684 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -779,7 +779,6 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
 	bool wait = scf_flags & SCF_WAIT;
 	int nr_cpus = 0;
 	bool run_remote = false;
-	bool run_local = false;
 
 	lockdep_assert_preemption_disabled();
 
@@ -801,11 +800,6 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
 	 */
 	WARN_ON_ONCE(!in_task());
 
-	/* Check if we need local execution. */
-	if ((scf_flags & SCF_RUN_LOCAL) && cpumask_test_cpu(this_cpu, mask) &&
-	    (!cond_func || cond_func(this_cpu, info)))
-		run_local = true;
-
 	/* Check if we need remote execution, i.e., any CPU excluding this one. */
 	if (cpumask_any_and_but(mask, cpu_online_mask, this_cpu) < nr_cpu_ids) {
 		run_remote = true;
@@ -853,7 +847,9 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
 			run_remote = false;
 	}
 
-	if (run_local) {
+	/* Check if we need local execution. */
+	if ((scf_flags & SCF_RUN_LOCAL) & cpumask_test_cpu(this_cpu, mask) &&
+	    (!cond_func || cond_func(this_cpu, info))) {
 		unsigned long flags;
 
 		local_irq_save(flags);
-- 
2.43.0
Re: [PATCH 4/4] smp: Defer check for local execution in smp_call_function_many_cond()
Posted by Yury Norov 6 months, 1 week ago
On Fri, Jun 06, 2025 at 04:27:31PM -0400, Yury Norov wrote:
> From: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>
> 
> Defer check for local execution to the actual place where it is needed,
> and save some stack on a useless local variable.
> 
> Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
> ---
>  kernel/smp.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/kernel/smp.c b/kernel/smp.c
> index 715190669e94..867f79689684 100644
> --- a/kernel/smp.c
> +++ b/kernel/smp.c
> @@ -779,7 +779,6 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
>  	bool wait = scf_flags & SCF_WAIT;
>  	int nr_cpus = 0;
>  	bool run_remote = false;
> -	bool run_local = false;
>  
>  	lockdep_assert_preemption_disabled();
>  
> @@ -801,11 +800,6 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
>  	 */
>  	WARN_ON_ONCE(!in_task());
>  
> -	/* Check if we need local execution. */
> -	if ((scf_flags & SCF_RUN_LOCAL) && cpumask_test_cpu(this_cpu, mask) &&
> -	    (!cond_func || cond_func(this_cpu, info)))
> -		run_local = true;
> -
>  	/* Check if we need remote execution, i.e., any CPU excluding this one. */
>  	if (cpumask_any_and_but(mask, cpu_online_mask, this_cpu) < nr_cpu_ids) {
>  		run_remote = true;
> @@ -853,7 +847,9 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
>  			run_remote = false;
>  	}
>  
> -	if (run_local) {
> +	/* Check if we need local execution. */
> +	if ((scf_flags & SCF_RUN_LOCAL) & cpumask_test_cpu(this_cpu, mask) &&
> +	    (!cond_func || cond_func(this_cpu, info))) {

Dan Carpenter's robot pointed the bug here: it should be:

        (scf_flags & SCF_RUN_LOCAL) && cpumask_test_cpu(this_cpu, mask)

I'll resend it shortly.

Thanks, Dan!

>  		unsigned long flags;
>  
>  		local_irq_save(flags);
> -- 
> 2.43.0