Skip to content

Commit b264f57

Browse files
vittyvkKAGA-KOKO
authored andcommitted
x86/hyperv: Micro-optimize send_ipi_one()
When sending an IPI to a single CPU there is no need to deal with cpumasks. With 2 CPU guest on WS2019 a minor (like 3%, 8043 -> 7761 CPU cycles) improvement with smp_call_function_single() loop benchmark can be seeb. The optimization, however, is tiny and straitforward. Also, send_ipi_one() is important for PV spinlock kick. Switching to the regular APIC IPI send for CPU > 64 case does not make sense as it is twice as expesive (12650 CPU cycles for __send_ipi_mask_ex() call, 26000 for orig_apic.send_IPI(cpu, vector)). Signed-off-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Reviewed-by: Roman Kagan <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 83527ef commit b264f57

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

arch/x86/hyperv/hv_apic.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,20 @@ static bool __send_ipi_mask(const struct cpumask *mask, int vector)
194194

195195
static bool __send_ipi_one(int cpu, int vector)
196196
{
197-
struct cpumask mask = CPU_MASK_NONE;
197+
int vp = hv_cpu_number_to_vp_number(cpu);
198198

199-
cpumask_set_cpu(cpu, &mask);
200-
return __send_ipi_mask(&mask, vector);
199+
trace_hyperv_send_ipi_one(cpu, vector);
200+
201+
if (!hv_hypercall_pg || (vp == VP_INVAL))
202+
return false;
203+
204+
if ((vector < HV_IPI_LOW_VECTOR) || (vector > HV_IPI_HIGH_VECTOR))
205+
return false;
206+
207+
if (vp >= 64)
208+
return __send_ipi_mask_ex(cpumask_of(cpu), vector);
209+
210+
return !hv_do_fast_hypercall16(HVCALL_SEND_IPI, vector, BIT_ULL(vp));
201211
}
202212

203213
static void hv_send_ipi(int cpu, int vector)

arch/x86/include/asm/trace/hyperv.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ TRACE_EVENT(hyperv_send_ipi_mask,
7171
__entry->ncpus, __entry->vector)
7272
);
7373

74+
TRACE_EVENT(hyperv_send_ipi_one,
75+
TP_PROTO(int cpu,
76+
int vector),
77+
TP_ARGS(cpu, vector),
78+
TP_STRUCT__entry(
79+
__field(int, cpu)
80+
__field(int, vector)
81+
),
82+
TP_fast_assign(__entry->cpu = cpu;
83+
__entry->vector = vector;
84+
),
85+
TP_printk("cpu %d vector %x",
86+
__entry->cpu, __entry->vector)
87+
);
88+
7489
#endif /* CONFIG_HYPERV */
7590

7691
#undef TRACE_INCLUDE_PATH

0 commit comments

Comments
 (0)