Skip to content

Commit 946a728

Browse files
rikvanrielKAGA-KOKO
authored andcommitted
smp: Wait only if work was enqueued
Whenever work is enqueued for a remote CPU, smp_call_function_many_cond() may need to wait for that work to be completed. However, if no work is enqueued for a remote CPU, because the condition func() evaluated to false for all CPUs, there is no need to wait. Set run_remote only if work was enqueued on remote CPUs. Document the difference between "work enqueued", and "CPU needs to be woken up" Suggested-by: Jann Horn <jannh@google.com> Signed-off-by: Rik van Riel <riel@surriel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Yury Norov (NVIDIA) <yury.norov@gmail.com> Link: https://lore.kernel.org/all/20250703203019.11331ac3@fangorn
1 parent e0e9506 commit 946a728

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

kernel/smp.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,6 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
802802

803803
/* Check if we need remote execution, i.e., any CPU excluding this one. */
804804
if (cpumask_any_and_but(mask, cpu_online_mask, this_cpu) < nr_cpu_ids) {
805-
run_remote = true;
806805
cfd = this_cpu_ptr(&cfd_data);
807806
cpumask_and(cfd->cpumask, mask, cpu_online_mask);
808807
__cpumask_clear_cpu(this_cpu, cfd->cpumask);
@@ -816,6 +815,9 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
816815
continue;
817816
}
818817

818+
/* Work is enqueued on a remote CPU. */
819+
run_remote = true;
820+
819821
csd_lock(csd);
820822
if (wait)
821823
csd->node.u_flags |= CSD_TYPE_SYNC;
@@ -827,6 +829,10 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
827829
#endif
828830
trace_csd_queue_cpu(cpu, _RET_IP_, func, csd);
829831

832+
/*
833+
* Kick the remote CPU if this is the first work
834+
* item enqueued.
835+
*/
830836
if (llist_add(&csd->node.llist, &per_cpu(call_single_queue, cpu))) {
831837
__cpumask_set_cpu(cpu, cfd->cpumask_ipi);
832838
nr_cpus++;

0 commit comments

Comments
 (0)