linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] smp: Improve on cpumasks handling
@ 2025-06-23  0:00 Yury Norov
  2025-06-23  0:00 ` [PATCH v2 1/4] smp: Improve locality in smp_call_function_any() Yury Norov
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Yury Norov @ 2025-06-23  0:00 UTC (permalink / raw)
  To: Paul E. McKenney, Neeraj Upadhyay, Yury Norov [NVIDIA],
	Thomas Gleixner, Thorsten Blum, Zqiang, Mathieu Desnoyers,
	linux-kernel

From: Yury Norov [NVIDIA] <yury.norov@gmail.com>

Switch smp_call_function_*() to use more suitable cpumask API.

v1: https://lore.kernel.org/all/20250606202732.426551-1-yury.norov@gmail.com/
v2: fix conditional expression in patch #4

Yury Norov [NVIDIA] (4):
  smp: Improve locality in smp_call_function_any()
  smp: Use cpumask_any_but() in smp_call_function_many_cond()
  smp: Don't wait until remote work done if not needed in
    smp_call_function_many_cond()
  smp: Defer check for local execution in smp_call_function_many_cond()

 kernel/smp.c | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)

-- 
2.43.0


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

* [PATCH v2 1/4] smp: Improve locality in smp_call_function_any()
  2025-06-23  0:00 [PATCH v2 0/4] smp: Improve on cpumasks handling Yury Norov
@ 2025-06-23  0:00 ` Yury Norov
  2025-06-26 21:55   ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
  2025-06-23  0:00 ` [PATCH v2 2/4] smp: Use cpumask_any_but() in smp_call_function_many_cond() Yury Norov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Yury Norov @ 2025-06-23  0:00 UTC (permalink / raw)
  To: Paul E. McKenney, Neeraj Upadhyay, Yury Norov [NVIDIA],
	Thomas Gleixner, Thorsten Blum, Zqiang, Mathieu Desnoyers,
	linux-kernel

From: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>

smp_call_function_any() tries to make a local call as it's the cheapest
option, or switches to a CPU in the same node. If it's not possible, the
algorithm gives up and searches for any CPU, in a numerical order.

Instead, we can search for the best CPU based on NUMA locality, including
2nd nearest hop (a set of equidistant nodes), and higher.

sched_numa_find_nth_cpu() does exactly that, and also helps to drop most
of housekeeping code.

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

diff --git a/kernel/smp.c b/kernel/smp.c
index 974f3a3962e8..7c8cfab0ce55 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -741,32 +741,19 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async);
  *
  * Selection preference:
  *	1) current cpu if in @mask
- *	2) any cpu of current node if in @mask
- *	3) any other online cpu in @mask
+ *	2) nearest cpu in @mask, based on NUMA topology
  */
 int smp_call_function_any(const struct cpumask *mask,
 			  smp_call_func_t func, void *info, int wait)
 {
 	unsigned int cpu;
-	const struct cpumask *nodemask;
 	int ret;
 
 	/* Try for same CPU (cheapest) */
 	cpu = get_cpu();
-	if (cpumask_test_cpu(cpu, mask))
-		goto call;
-
-	/* Try for same node. */
-	nodemask = cpumask_of_node(cpu_to_node(cpu));
-	for (cpu = cpumask_first_and(nodemask, mask); cpu < nr_cpu_ids;
-	     cpu = cpumask_next_and(cpu, nodemask, mask)) {
-		if (cpu_online(cpu))
-			goto call;
-	}
+	if (!cpumask_test_cpu(cpu, mask))
+		cpu = sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu));
 
-	/* Any online will do: smp_call_function_single handles nr_cpu_ids. */
-	cpu = cpumask_any_and(mask, cpu_online_mask);
-call:
 	ret = smp_call_function_single(cpu, func, info, wait);
 	put_cpu();
 	return ret;
-- 
2.43.0


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

* [PATCH v2 2/4] smp: Use cpumask_any_but() in smp_call_function_many_cond()
  2025-06-23  0:00 [PATCH v2 0/4] smp: Improve on cpumasks handling Yury Norov
  2025-06-23  0:00 ` [PATCH v2 1/4] smp: Improve locality in smp_call_function_any() Yury Norov
@ 2025-06-23  0:00 ` Yury Norov
  2025-06-26 21:55   ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
  2025-06-23  0:00 ` [PATCH v2 3/4] smp: Don't wait for remote work done if not needed " Yury Norov
  2025-06-23  0:00 ` [PATCH v2 4/4] smp: Defer check for local execution " Yury Norov
  3 siblings, 1 reply; 10+ messages in thread
From: Yury Norov @ 2025-06-23  0:00 UTC (permalink / raw)
  To: Paul E. McKenney, Neeraj Upadhyay, Yury Norov [NVIDIA],
	Thomas Gleixner, Thorsten Blum, Zqiang, Mathieu Desnoyers,
	linux-kernel

From: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>

smp_call_function_many_cond() opencodes cpumask_any_but().

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

diff --git a/kernel/smp.c b/kernel/smp.c
index 7c8cfab0ce55..5871acf3cd45 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -807,13 +807,8 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
 		run_local = true;
 
 	/* Check if we need remote execution, i.e., any CPU excluding this one. */
-	cpu = cpumask_first_and(mask, cpu_online_mask);
-	if (cpu == this_cpu)
-		cpu = cpumask_next_and(cpu, mask, cpu_online_mask);
-	if (cpu < nr_cpu_ids)
+	if (cpumask_any_and_but(mask, cpu_online_mask, this_cpu) < nr_cpu_ids) {
 		run_remote = true;
-
-	if (run_remote) {
 		cfd = this_cpu_ptr(&cfd_data);
 		cpumask_and(cfd->cpumask, mask, cpu_online_mask);
 		__cpumask_clear_cpu(this_cpu, cfd->cpumask);
-- 
2.43.0


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

* [PATCH v2 3/4] smp: Don't wait for remote work done if not needed in smp_call_function_many_cond()
  2025-06-23  0:00 [PATCH v2 0/4] smp: Improve on cpumasks handling Yury Norov
  2025-06-23  0:00 ` [PATCH v2 1/4] smp: Improve locality in smp_call_function_any() Yury Norov
  2025-06-23  0:00 ` [PATCH v2 2/4] smp: Use cpumask_any_but() in smp_call_function_many_cond() Yury Norov
@ 2025-06-23  0:00 ` Yury Norov
  2025-06-26 21:55   ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
  2025-06-23  0:00 ` [PATCH v2 4/4] smp: Defer check for local execution " Yury Norov
  3 siblings, 1 reply; 10+ messages in thread
From: Yury Norov @ 2025-06-23  0:00 UTC (permalink / raw)
  To: Paul E. McKenney, Neeraj Upadhyay, Yury Norov [NVIDIA],
	Thomas Gleixner, Thorsten Blum, Zqiang, Mathieu Desnoyers,
	linux-kernel

From: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>

If we don't actually send any IPIs, there's no need to wait for a job
completion.

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

diff --git a/kernel/smp.c b/kernel/smp.c
index 5871acf3cd45..715190669e94 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -849,6 +849,8 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
 			send_call_function_single_ipi(last_cpu);
 		else if (likely(nr_cpus > 1))
 			send_call_function_ipi_mask(cfd->cpumask_ipi);
+		else
+			run_remote = false;
 	}
 
 	if (run_local) {
-- 
2.43.0


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

* [PATCH v2 4/4] smp: Defer check for local execution in smp_call_function_many_cond()
  2025-06-23  0:00 [PATCH v2 0/4] smp: Improve on cpumasks handling Yury Norov
                   ` (2 preceding siblings ...)
  2025-06-23  0:00 ` [PATCH v2 3/4] smp: Don't wait for remote work done if not needed " Yury Norov
@ 2025-06-23  0:00 ` Yury Norov
  2025-06-26 21:55   ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
  2025-07-02 17:23   ` tip-bot2 for Yury Norov [NVIDIA]
  3 siblings, 2 replies; 10+ messages in thread
From: Yury Norov @ 2025-06-23  0:00 UTC (permalink / raw)
  To: Paul E. McKenney, Neeraj Upadhyay, Yury Norov [NVIDIA],
	Thomas Gleixner, Thorsten Blum, Zqiang, Mathieu Desnoyers,
	linux-kernel

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..84561258cd22 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


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

* [tip: smp/core] smp: Defer check for local execution in smp_call_function_many_cond()
  2025-06-23  0:00 ` [PATCH v2 4/4] smp: Defer check for local execution " Yury Norov
@ 2025-06-26 21:55   ` tip-bot2 for Yury Norov [NVIDIA]
  2025-07-02 17:23   ` tip-bot2 for Yury Norov [NVIDIA]
  1 sibling, 0 replies; 10+ messages in thread
From: tip-bot2 for Yury Norov [NVIDIA] @ 2025-06-26 21:55 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Yury Norov [NVIDIA], Thomas Gleixner, x86, linux-kernel

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

Commit-ID:     b4d6510684bf040c24dead879cce29035ef45826
Gitweb:        https://git.kernel.org/tip/b4d6510684bf040c24dead879cce29035ef45826
Author:        Yury Norov [NVIDIA] <yury.norov@gmail.com>
AuthorDate:    Sun, 22 Jun 2025 20:00:09 -04:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 26 Jun 2025 23:46:35 +02:00

smp: Defer check for local execution in smp_call_function_many_cond()

Defer check for local execution to the actual place where it is needed,
which removes the extra local variable.

Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250623000010.10124-5-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 7151906..8456125 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);

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

* [tip: smp/core] smp: Don't wait for remote work done if not needed in smp_call_function_many_cond()
  2025-06-23  0:00 ` [PATCH v2 3/4] smp: Don't wait for remote work done if not needed " Yury Norov
@ 2025-06-26 21:55   ` tip-bot2 for Yury Norov [NVIDIA]
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot2 for Yury Norov [NVIDIA] @ 2025-06-26 21:55 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Yury Norov [NVIDIA], Thomas Gleixner, x86, linux-kernel

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

Commit-ID:     a12a498a9738db65152203467820bb15b6102bd2
Gitweb:        https://git.kernel.org/tip/a12a498a9738db65152203467820bb15b6102bd2
Author:        Yury Norov [NVIDIA] <yury.norov@gmail.com>
AuthorDate:    Sun, 22 Jun 2025 20:00:08 -04:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 26 Jun 2025 23:46:35 +02:00

smp: Don't wait for remote work done if not needed in smp_call_function_many_cond()

If there are no IPIs sent, then there is no need to wait for a job
completion of non existant remote execution.

Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250623000010.10124-4-yury.norov@gmail.com

---
 kernel/smp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/smp.c b/kernel/smp.c
index 5871acf..7151906 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -849,6 +849,8 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
 			send_call_function_single_ipi(last_cpu);
 		else if (likely(nr_cpus > 1))
 			send_call_function_ipi_mask(cfd->cpumask_ipi);
+		else
+			run_remote = false;
 	}
 
 	if (run_local) {

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

* [tip: smp/core] smp: Use cpumask_any_but() in smp_call_function_many_cond()
  2025-06-23  0:00 ` [PATCH v2 2/4] smp: Use cpumask_any_but() in smp_call_function_many_cond() Yury Norov
@ 2025-06-26 21:55   ` tip-bot2 for Yury Norov [NVIDIA]
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot2 for Yury Norov [NVIDIA] @ 2025-06-26 21:55 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Yury Norov [NVIDIA], Thomas Gleixner, x86, linux-kernel

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

Commit-ID:     976e0e3103e463725e19a5493d02ce7b7b380663
Gitweb:        https://git.kernel.org/tip/976e0e3103e463725e19a5493d02ce7b7b380663
Author:        Yury Norov [NVIDIA] <yury.norov@gmail.com>
AuthorDate:    Sun, 22 Jun 2025 20:00:07 -04:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 26 Jun 2025 23:46:34 +02:00

smp: Use cpumask_any_but() in smp_call_function_many_cond()

smp_call_function_many_cond() opencodes cpumask_any_but().

Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250623000010.10124-3-yury.norov@gmail.com

---
 kernel/smp.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index 7c8cfab..5871acf 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -807,13 +807,8 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
 		run_local = true;
 
 	/* Check if we need remote execution, i.e., any CPU excluding this one. */
-	cpu = cpumask_first_and(mask, cpu_online_mask);
-	if (cpu == this_cpu)
-		cpu = cpumask_next_and(cpu, mask, cpu_online_mask);
-	if (cpu < nr_cpu_ids)
+	if (cpumask_any_and_but(mask, cpu_online_mask, this_cpu) < nr_cpu_ids) {
 		run_remote = true;
-
-	if (run_remote) {
 		cfd = this_cpu_ptr(&cfd_data);
 		cpumask_and(cfd->cpumask, mask, cpu_online_mask);
 		__cpumask_clear_cpu(this_cpu, cfd->cpumask);

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

* [tip: smp/core] smp: Improve locality in smp_call_function_any()
  2025-06-23  0:00 ` [PATCH v2 1/4] smp: Improve locality in smp_call_function_any() Yury Norov
@ 2025-06-26 21:55   ` tip-bot2 for Yury Norov [NVIDIA]
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot2 for Yury Norov [NVIDIA] @ 2025-06-26 21:55 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Yury Norov [NVIDIA], Thomas Gleixner, x86, linux-kernel

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

Commit-ID:     5f295519b42f100c735a1e8e1a70060e26f30c3f
Gitweb:        https://git.kernel.org/tip/5f295519b42f100c735a1e8e1a70060e26f30c3f
Author:        Yury Norov [NVIDIA] <yury.norov@gmail.com>
AuthorDate:    Sun, 22 Jun 2025 20:00:06 -04:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 26 Jun 2025 23:46:34 +02:00

smp: Improve locality in smp_call_function_any()

smp_call_function_any() tries to make a local call as it's the cheapest
option, or switches to a CPU in the same node. If it's not possible, the
algorithm gives up and searches for any CPU, in a numerical order.

Instead, it can search for the best CPU based on NUMA locality, including
the 2nd nearest hop (a set of equidistant nodes), and higher.

sched_numa_find_nth_cpu() does exactly that, and also helps to drop most
of the housekeeping code.

Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250623000010.10124-2-yury.norov@gmail.com

---
 kernel/smp.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index 974f3a3..7c8cfab 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -741,32 +741,19 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async);
  *
  * Selection preference:
  *	1) current cpu if in @mask
- *	2) any cpu of current node if in @mask
- *	3) any other online cpu in @mask
+ *	2) nearest cpu in @mask, based on NUMA topology
  */
 int smp_call_function_any(const struct cpumask *mask,
 			  smp_call_func_t func, void *info, int wait)
 {
 	unsigned int cpu;
-	const struct cpumask *nodemask;
 	int ret;
 
 	/* Try for same CPU (cheapest) */
 	cpu = get_cpu();
-	if (cpumask_test_cpu(cpu, mask))
-		goto call;
-
-	/* Try for same node. */
-	nodemask = cpumask_of_node(cpu_to_node(cpu));
-	for (cpu = cpumask_first_and(nodemask, mask); cpu < nr_cpu_ids;
-	     cpu = cpumask_next_and(cpu, nodemask, mask)) {
-		if (cpu_online(cpu))
-			goto call;
-	}
+	if (!cpumask_test_cpu(cpu, mask))
+		cpu = sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu));
 
-	/* Any online will do: smp_call_function_single handles nr_cpu_ids. */
-	cpu = cpumask_any_and(mask, cpu_online_mask);
-call:
 	ret = smp_call_function_single(cpu, func, info, wait);
 	put_cpu();
 	return ret;

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

* [tip: smp/core] smp: Defer check for local execution in smp_call_function_many_cond()
  2025-06-23  0:00 ` [PATCH v2 4/4] smp: Defer check for local execution " Yury Norov
  2025-06-26 21:55   ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
@ 2025-07-02 17:23   ` tip-bot2 for Yury Norov [NVIDIA]
  1 sibling, 0 replies; 10+ messages in thread
From: tip-bot2 for Yury Norov [NVIDIA] @ 2025-07-02 17:23 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Yury Norov [NVIDIA], Thomas Gleixner, x86, linux-kernel

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

Commit-ID:     e0e9506523fea415e0d5abaa103fd67dc8a39696
Gitweb:        https://git.kernel.org/tip/e0e9506523fea415e0d5abaa103fd67dc8a39696
Author:        Yury Norov [NVIDIA] <yury.norov@gmail.com>
AuthorDate:    Sun, 22 Jun 2025 20:00:09 -04:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 02 Jul 2025 19:13:14 +02:00

smp: Defer check for local execution in smp_call_function_many_cond()

Defer check for local execution to the actual place where it is needed,
which removes the extra local variable.

Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250623000010.10124-5-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 5871acf..99d1fd0 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;
@@ -851,7 +845,9 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
 			send_call_function_ipi_mask(cfd->cpumask_ipi);
 	}
 
-	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);

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

end of thread, other threads:[~2025-07-02 17:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-23  0:00 [PATCH v2 0/4] smp: Improve on cpumasks handling Yury Norov
2025-06-23  0:00 ` [PATCH v2 1/4] smp: Improve locality in smp_call_function_any() Yury Norov
2025-06-26 21:55   ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
2025-06-23  0:00 ` [PATCH v2 2/4] smp: Use cpumask_any_but() in smp_call_function_many_cond() Yury Norov
2025-06-26 21:55   ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
2025-06-23  0:00 ` [PATCH v2 3/4] smp: Don't wait for remote work done if not needed " Yury Norov
2025-06-26 21:55   ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
2025-06-23  0:00 ` [PATCH v2 4/4] smp: Defer check for local execution " Yury Norov
2025-06-26 21:55   ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
2025-07-02 17:23   ` tip-bot2 for Yury Norov [NVIDIA]

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).