Skip to content

Commit 832df3d

Browse files
committed
x86/smp: Enhance native_send_call_func_ipi()
Nadav noticed that the cpumask allocations in native_send_call_func_ipi() are noticeable in microbenchmarks. Use the new cpumask_or_equal() function to simplify the decision whether the supplied target CPU mask is either equal to cpu_online_mask or equal to cpu_online_mask except for the CPU on which the function is invoked. cpumask_or_equal() or's the target mask and the cpumask of the current CPU together and compares it to cpu_online_mask. If the result is false, use the mask based IPI function, otherwise check whether the current CPU is set in the target mask and invoke either the send_IPI_all() or the send_IPI_allbutselt() APIC callback. Make the shorthand decision also depend on the static key which enables shorthand mode. That allows to remove the extra cpumask comparison with cpu_callout_mask. Reported-by: Nadav Amit <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent d0a7166 commit 832df3d

File tree

1 file changed

+11
-13
lines changed
  • arch/x86/kernel/apic

1 file changed

+11
-13
lines changed

arch/x86/kernel/apic/ipi.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,21 @@ void native_send_call_func_single_ipi(int cpu)
8383

8484
void native_send_call_func_ipi(const struct cpumask *mask)
8585
{
86-
cpumask_var_t allbutself;
86+
if (static_branch_likely(&apic_use_ipi_shorthand)) {
87+
unsigned int cpu = smp_processor_id();
8788

88-
if (!alloc_cpumask_var(&allbutself, GFP_ATOMIC)) {
89-
apic->send_IPI_mask(mask, CALL_FUNCTION_VECTOR);
89+
if (!cpumask_or_equal(mask, cpumask_of(cpu), cpu_online_mask))
90+
goto sendmask;
91+
92+
if (cpumask_test_cpu(cpu, mask))
93+
apic->send_IPI_all(CALL_FUNCTION_VECTOR);
94+
else if (num_online_cpus() > 1)
95+
apic->send_IPI_allbutself(CALL_FUNCTION_VECTOR);
9096
return;
9197
}
9298

93-
cpumask_copy(allbutself, cpu_online_mask);
94-
__cpumask_clear_cpu(smp_processor_id(), allbutself);
95-
96-
if (cpumask_equal(mask, allbutself) &&
97-
cpumask_equal(cpu_online_mask, cpu_callout_mask))
98-
apic->send_IPI_allbutself(CALL_FUNCTION_VECTOR);
99-
else
100-
apic->send_IPI_mask(mask, CALL_FUNCTION_VECTOR);
101-
102-
free_cpumask_var(allbutself);
99+
sendmask:
100+
apic->send_IPI_mask(mask, CALL_FUNCTION_VECTOR);
103101
}
104102

105103
#endif /* CONFIG_SMP */

0 commit comments

Comments
 (0)