Skip to content

Commit

Permalink
x86/hyperv: Micro-optimize send_ipi_one()
Browse files Browse the repository at this point in the history
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 <vkuznets@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
Link: https://lkml.kernel.org/r/20191027151938.7296-1-vkuznets@redhat.com
  • Loading branch information
Vitaly Kuznetsov authored and Thomas Gleixner committed Nov 12, 2019
1 parent 83527ef commit b264f57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
16 changes: 13 additions & 3 deletions arch/x86/hyperv/hv_apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,20 @@ static bool __send_ipi_mask(const struct cpumask *mask, int vector)

static bool __send_ipi_one(int cpu, int vector)
{
struct cpumask mask = CPU_MASK_NONE;
int vp = hv_cpu_number_to_vp_number(cpu);

cpumask_set_cpu(cpu, &mask);
return __send_ipi_mask(&mask, vector);
trace_hyperv_send_ipi_one(cpu, vector);

if (!hv_hypercall_pg || (vp == VP_INVAL))
return false;

if ((vector < HV_IPI_LOW_VECTOR) || (vector > HV_IPI_HIGH_VECTOR))
return false;

if (vp >= 64)
return __send_ipi_mask_ex(cpumask_of(cpu), vector);

return !hv_do_fast_hypercall16(HVCALL_SEND_IPI, vector, BIT_ULL(vp));
}

static void hv_send_ipi(int cpu, int vector)
Expand Down
15 changes: 15 additions & 0 deletions arch/x86/include/asm/trace/hyperv.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ TRACE_EVENT(hyperv_send_ipi_mask,
__entry->ncpus, __entry->vector)
);

TRACE_EVENT(hyperv_send_ipi_one,
TP_PROTO(int cpu,
int vector),
TP_ARGS(cpu, vector),
TP_STRUCT__entry(
__field(int, cpu)
__field(int, vector)
),
TP_fast_assign(__entry->cpu = cpu;
__entry->vector = vector;
),
TP_printk("cpu %d vector %x",
__entry->cpu, __entry->vector)
);

#endif /* CONFIG_HYPERV */

#undef TRACE_INCLUDE_PATH
Expand Down

0 comments on commit b264f57

Please sign in to comment.