From: Wanpeng Li <wanpengli@xxxxxxxxxxx> Optimizing posted-interrupt delivery especially for the timer fastpath scenario, I observe kvm_x86_ops.deliver_posted_interrupt() has more latency then vmx_sync_pir_to_irr() in the case of timer fastpath scenario, since it needs to wait vmentry, after that it can handle external interrupt, ack the notification vector, read posted-interrupt descriptor etc, it is slower than evaluate and delivery during vmentry immediately approach. Let's skip sending interrupt to notify target pCPU and replace by vmx_sync_pir_to_irr() before each reenter guest. Tested-by: Haiwei Li <lihaiwei@xxxxxxxxxxx> Cc: Haiwei Li <lihaiwei@xxxxxxxxxxx> Signed-off-by: Wanpeng Li <wanpengli@xxxxxxxxxxx> --- arch/x86/kvm/vmx/vmx.c | 12 ++++++++---- virt/kvm/kvm_main.c | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 24cadf4..ce19b0e 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3909,7 +3909,8 @@ static int vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu, int vector) if (pi_test_and_set_on(&vmx->pi_desc)) return 0; - if (!kvm_vcpu_trigger_posted_interrupt(vcpu, false)) + if (vcpu != kvm_get_running_vcpu() && + !kvm_vcpu_trigger_posted_interrupt(vcpu, false)) kvm_vcpu_kick(vcpu); return 0; @@ -6777,9 +6778,12 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) vmx_complete_interrupts(vmx); exit_fastpath = vmx_exit_handlers_fastpath(vcpu); - if (exit_fastpath == EXIT_FASTPATH_REENTER_GUEST && - kvm_vcpu_exit_request(vcpu)) - exit_fastpath = EXIT_FASTPATH_NOP; + if (exit_fastpath == EXIT_FASTPATH_REENTER_GUEST) { + if (!kvm_vcpu_exit_request(vcpu)) + vmx_sync_pir_to_irr(vcpu); + else + exit_fastpath = EXIT_FASTPATH_NOP; + } return exit_fastpath; } diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 33e1eee..2482f3c 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4644,6 +4644,7 @@ struct kvm_vcpu *kvm_get_running_vcpu(void) return vcpu; } +EXPORT_SYMBOL_GPL(kvm_get_running_vcpu); /** * kvm_get_running_vcpus - get the per-CPU array of currently running vcpus. -- 2.7.4