KVM: LAPIC: Micro optimize IPI latency
authorWanpeng Li <wanpengli@tencent.com>
Thu, 5 Sep 2019 06:26:27 +0000 (14:26 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 11 Sep 2019 16:05:29 +0000 (18:05 +0200)
This patch optimizes the virtual IPI emulation sequence:

write ICR2                     write ICR2
write ICR                      read ICR2
read ICR            ==>        send virtual IPI
read ICR2                      write ICR
send virtual IPI

It can reduce kvm-unit-tests/vmexit.flat IPI testing latency(from sender
send IPI to sender receive the ACK) from 3319 cycles to 3203 cycles on
SKylake server.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/lapic.c

index e904ff06a83d84c9ab5ccd08bdfcc14b1cc3768a..559e1c4c0832bf735548c5a900401b2e04f88e19 100644 (file)
@@ -1198,10 +1198,8 @@ void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, int vector)
 }
 EXPORT_SYMBOL_GPL(kvm_apic_set_eoi_accelerated);
 
-static void apic_send_ipi(struct kvm_lapic *apic)
+static void apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high)
 {
-       u32 icr_low = kvm_lapic_get_reg(apic, APIC_ICR);
-       u32 icr_high = kvm_lapic_get_reg(apic, APIC_ICR2);
        struct kvm_lapic_irq irq;
 
        irq.vector = icr_low & APIC_VECTOR_MASK;
@@ -1914,8 +1912,9 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
        }
        case APIC_ICR:
                /* No delay here, so we always clear the pending bit */
-               kvm_lapic_set_reg(apic, APIC_ICR, val & ~(1 << 12));
-               apic_send_ipi(apic);
+               val &= ~(1 << 12);
+               apic_send_ipi(apic, val, kvm_lapic_get_reg(apic, APIC_ICR2));
+               kvm_lapic_set_reg(apic, APIC_ICR, val);
                break;
 
        case APIC_ICR2: