KVM: x86: Take advantage of kvm_arch_dy_has_pending_interrupt()
diff mbox series

Message ID 20210421032513.1921-1-lihaiwei.kernel@gmail.com
State Accepted
Commit 10dbdf98acd620f376313b85b587c9b9563fc170
Headers show
Series
  • KVM: x86: Take advantage of kvm_arch_dy_has_pending_interrupt()
Related show

Commit Message

Haiwei Li April 21, 2021, 3:25 a.m. UTC
From: Haiwei Li <lihaiwei@tencent.com>

`kvm_arch_dy_runnable` checks the pending_interrupt as the code in
`kvm_arch_dy_has_pending_interrupt`. So take advantage of it.

Signed-off-by: Haiwei Li <lihaiwei@tencent.com>
---
 arch/x86/kvm/x86.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Comments

Wanpeng Li April 22, 2021, 9:21 a.m. UTC | #1
On Wed, 21 Apr 2021 at 11:26, <lihaiwei.kernel@gmail.com> wrote:
>
> From: Haiwei Li <lihaiwei@tencent.com>
>
> `kvm_arch_dy_runnable` checks the pending_interrupt as the code in
> `kvm_arch_dy_has_pending_interrupt`. So take advantage of it.
>
> Signed-off-by: Haiwei Li <lihaiwei@tencent.com>

Reviewed-by: Wanpeng Li <wanpengli@tencent.com>
Paolo Bonzini April 22, 2021, 10:35 a.m. UTC | #2
On 21/04/21 05:25, lihaiwei.kernel@gmail.com wrote:
> From: Haiwei Li <lihaiwei@tencent.com>
> 
> `kvm_arch_dy_runnable` checks the pending_interrupt as the code in
> `kvm_arch_dy_has_pending_interrupt`. So take advantage of it.
> 
> Signed-off-by: Haiwei Li <lihaiwei@tencent.com>
> ---
>   arch/x86/kvm/x86.c | 21 +++++++++------------
>   1 file changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d696a9f..08bd616 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -11125,28 +11125,25 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
>   	return kvm_vcpu_running(vcpu) || kvm_vcpu_has_events(vcpu);
>   }
>   
> -bool kvm_arch_dy_runnable(struct kvm_vcpu *vcpu)
> +bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu)
>   {
> -	if (READ_ONCE(vcpu->arch.pv.pv_unhalted))
> -		return true;
> -
> -	if (kvm_test_request(KVM_REQ_NMI, vcpu) ||
> -		kvm_test_request(KVM_REQ_SMI, vcpu) ||
> -		 kvm_test_request(KVM_REQ_EVENT, vcpu))
> -		return true;
> -
>   	if (vcpu->arch.apicv_active && static_call(kvm_x86_dy_apicv_has_pending_interrupt)(vcpu))
>   		return true;
>   
>   	return false;
>   }
>   
> -bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu)
> +bool kvm_arch_dy_runnable(struct kvm_vcpu *vcpu)
>   {
> -	if (vcpu->arch.apicv_active && static_call(kvm_x86_dy_apicv_has_pending_interrupt)(vcpu))
> +	if (READ_ONCE(vcpu->arch.pv.pv_unhalted))
>   		return true;
>   
> -	return false;
> +	if (kvm_test_request(KVM_REQ_NMI, vcpu) ||
> +		kvm_test_request(KVM_REQ_SMI, vcpu) ||
> +		 kvm_test_request(KVM_REQ_EVENT, vcpu))
> +		return true;
> +
> +	return kvm_arch_dy_has_pending_interrupt(vcpu);
>   }
>   
>   bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
> 

Looks good, but I'd like to take a look at the other patches for 
directed yield first.  Thanks!

Paolo

Patch
diff mbox series

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d696a9f..08bd616 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11125,28 +11125,25 @@  int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
 	return kvm_vcpu_running(vcpu) || kvm_vcpu_has_events(vcpu);
 }
 
-bool kvm_arch_dy_runnable(struct kvm_vcpu *vcpu)
+bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu)
 {
-	if (READ_ONCE(vcpu->arch.pv.pv_unhalted))
-		return true;
-
-	if (kvm_test_request(KVM_REQ_NMI, vcpu) ||
-		kvm_test_request(KVM_REQ_SMI, vcpu) ||
-		 kvm_test_request(KVM_REQ_EVENT, vcpu))
-		return true;
-
 	if (vcpu->arch.apicv_active && static_call(kvm_x86_dy_apicv_has_pending_interrupt)(vcpu))
 		return true;
 
 	return false;
 }
 
-bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu)
+bool kvm_arch_dy_runnable(struct kvm_vcpu *vcpu)
 {
-	if (vcpu->arch.apicv_active && static_call(kvm_x86_dy_apicv_has_pending_interrupt)(vcpu))
+	if (READ_ONCE(vcpu->arch.pv.pv_unhalted))
 		return true;
 
-	return false;
+	if (kvm_test_request(KVM_REQ_NMI, vcpu) ||
+		kvm_test_request(KVM_REQ_SMI, vcpu) ||
+		 kvm_test_request(KVM_REQ_EVENT, vcpu))
+		return true;
+
+	return kvm_arch_dy_has_pending_interrupt(vcpu);
 }
 
 bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)