diff mbox series

[v4,5/7] KVM: VMX: Optimize posted-interrupt delivery for timer fastpath

Message ID 1588055009-12677-6-git-send-email-wanpengli@tencent.com (mailing list archive)
State New, archived
Headers show
Series KVM: VMX: Tscdeadline timer emulation fastpath | expand

Commit Message

Wanpeng Li April 28, 2020, 6:23 a.m. UTC
From: Wanpeng Li <wanpengli@tencent.com>

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@tencent.com>
Cc: Haiwei Li <lihaiwei@tencent.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
 arch/x86/kvm/vmx/vmx.c | 12 ++++++++----
 virt/kvm/kvm_main.c    |  1 +
 2 files changed, 9 insertions(+), 4 deletions(-)

Comments

Paolo Bonzini April 30, 2020, 1:32 p.m. UTC | #1
On 28/04/20 08:23, Wanpeng Li wrote:
> -	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;
> +	}

This part should be in patch 3; not a big deal, I can reorganize that
myself.

Paolo
Wanpeng Li April 30, 2020, 11:43 p.m. UTC | #2
On Thu, 30 Apr 2020 at 21:32, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 28/04/20 08:23, Wanpeng Li wrote:
> > -     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;
> > +     }
>
> This part should be in patch 3; not a big deal, I can reorganize that
> myself.

Great, thanks.

    Wanpeng
diff mbox series

Patch

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.