Skip to content

Commit 379a3c8

Browse files
Wanpeng Libonzini
authored andcommitted
KVM: VMX: Optimize posted-interrupt delivery for timer fastpath
While optimizing posted-interrupt delivery especially for the timer fastpath scenario, I measured kvm_x86_ops.deliver_posted_interrupt() to introduce substantial latency because the processor has to perform all vmentry tasks, ack the posted interrupt notification vector, read the posted-interrupt descriptor etc. This is not only slow, it is also unnecessary when delivering an interrupt to the current CPU (as is the case for the LAPIC timer) because PIR->IRR and IRR->RVI synchronization is already performed on vmentry Therefore skip kvm_vcpu_trigger_posted_interrupt in this case, and instead do vmx_sync_pir_to_irr() on the EXIT_FASTPATH_REENTER_GUEST fastpath as well. Tested-by: Haiwei Li <lihaiwei@tencent.com> Cc: Haiwei Li <lihaiwei@tencent.com> Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Wanpeng Li <wanpengli@tencent.com> Message-Id: <1588055009-12677-6-git-send-email-wanpengli@tencent.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 404d5d7 commit 379a3c8

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎arch/x86/kvm/vmx/vmx.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3936,7 +3936,8 @@ static int vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu, int vector)
39363936
if (pi_test_and_set_on(&vmx->pi_desc))
39373937
return 0;
39383938

3939-
if (!kvm_vcpu_trigger_posted_interrupt(vcpu, false))
3939+
if (vcpu != kvm_get_running_vcpu() &&
3940+
!kvm_vcpu_trigger_posted_interrupt(vcpu, false))
39403941
kvm_vcpu_kick(vcpu);
39413942

39423943
return 0;
@@ -6812,6 +6813,8 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
68126813
* but it would incur the cost of a retpoline for now.
68136814
* Revisit once static calls are available.
68146815
*/
6816+
if (vcpu->arch.apicv_active)
6817+
vmx_sync_pir_to_irr(vcpu);
68156818
goto reenter_guest;
68166819
}
68176820
exit_fastpath = EXIT_FASTPATH_EXIT_HANDLED;

‎virt/kvm/kvm_main.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4646,6 +4646,7 @@ struct kvm_vcpu *kvm_get_running_vcpu(void)
46464646

46474647
return vcpu;
46484648
}
4649+
EXPORT_SYMBOL_GPL(kvm_get_running_vcpu);
46494650

46504651
/**
46514652
* kvm_get_running_vcpus - get the per-CPU array of currently running vcpus.

0 commit comments

Comments
 (0)