Skip to content

Commit 5f29551

Browse files
YuryNorovKAGA-KOKO
authored andcommitted
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
1 parent 09735f0 commit 5f29551

1 file changed

Lines changed: 3 additions & 16 deletions

File tree

kernel/smp.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -741,32 +741,19 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async);
741741
*
742742
* Selection preference:
743743
* 1) current cpu if in @mask
744-
* 2) any cpu of current node if in @mask
745-
* 3) any other online cpu in @mask
744+
* 2) nearest cpu in @mask, based on NUMA topology
746745
*/
747746
int smp_call_function_any(const struct cpumask *mask,
748747
smp_call_func_t func, void *info, int wait)
749748
{
750749
unsigned int cpu;
751-
const struct cpumask *nodemask;
752750
int ret;
753751

754752
/* Try for same CPU (cheapest) */
755753
cpu = get_cpu();
756-
if (cpumask_test_cpu(cpu, mask))
757-
goto call;
758-
759-
/* Try for same node. */
760-
nodemask = cpumask_of_node(cpu_to_node(cpu));
761-
for (cpu = cpumask_first_and(nodemask, mask); cpu < nr_cpu_ids;
762-
cpu = cpumask_next_and(cpu, nodemask, mask)) {
763-
if (cpu_online(cpu))
764-
goto call;
765-
}
754+
if (!cpumask_test_cpu(cpu, mask))
755+
cpu = sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu));
766756

767-
/* Any online will do: smp_call_function_single handles nr_cpu_ids. */
768-
cpu = cpumask_any_and(mask, cpu_online_mask);
769-
call:
770757
ret = smp_call_function_single(cpu, func, info, wait);
771758
put_cpu();
772759
return ret;

0 commit comments

Comments
 (0)