linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] KVM: X86: Just one leader to trigger kvmclock sync request
@ 2020-02-28  3:18 Wanpeng Li
  2020-03-02 13:01 ` Vitaly Kuznetsov
  0 siblings, 1 reply; 3+ messages in thread
From: Wanpeng Li @ 2020-02-28  3:18 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

From: Wanpeng Li <wanpengli@tencent.com>

In the progress of vCPUs creation, it queues a kvmclock sync worker to the global
workqueue before each vCPU creation completes. The workqueue subsystem guarantees 
not to queue the already queued work, however, we can make the logic more clear by 
make just one leader to trigger this kvmclock sync request and save on cacheline 
boucing due to test_and_set_bit.

Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
v2 -> v3:
 * update patch description
v1 -> v2:
 * check vcpu->vcpu_idx

 arch/x86/kvm/x86.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index fb5d64e..79bc995 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9390,8 +9390,9 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
 	if (!kvmclock_periodic_sync)
 		return;
 
-	schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
-					KVMCLOCK_SYNC_PERIOD);
+	if (vcpu->vcpu_idx == 0)
+		schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
+						KVMCLOCK_SYNC_PERIOD);
 }
 
 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] KVM: X86: Just one leader to trigger kvmclock sync request
  2020-02-28  3:18 [PATCH v3] KVM: X86: Just one leader to trigger kvmclock sync request Wanpeng Li
@ 2020-03-02 13:01 ` Vitaly Kuznetsov
  2020-03-02 18:22   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Vitaly Kuznetsov @ 2020-03-02 13:01 UTC (permalink / raw)
  To: Wanpeng Li
  Cc: Paolo Bonzini, Sean Christopherson, Wanpeng Li, Jim Mattson,
	Joerg Roedel, linux-kernel, kvm

Wanpeng Li <kernellwp@gmail.com> writes:

> From: Wanpeng Li <wanpengli@tencent.com>
>
> In the progress of vCPUs creation, it queues a kvmclock sync worker to the global
> workqueue before each vCPU creation completes. The workqueue subsystem guarantees 
> not to queue the already queued work, however, we can make the logic more clear by 
> make just one leader to trigger this kvmclock sync request and save on cacheline 
> boucing due to test_and_set_bit.
>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> v2 -> v3:
>  * update patch description
> v1 -> v2:
>  * check vcpu->vcpu_idx
>
>  arch/x86/kvm/x86.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index fb5d64e..79bc995 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9390,8 +9390,9 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
>  	if (!kvmclock_periodic_sync)
>  		return;
>  
> -	schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
> -					KVMCLOCK_SYNC_PERIOD);
> +	if (vcpu->vcpu_idx == 0)
> +		schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
> +						KVMCLOCK_SYNC_PERIOD);

I would've merged this new check with !kvmclock_periodic_sync above
making it more obvious when the work is scheduled

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5de200663f51..93550976f991 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9389,11 +9389,9 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
 
        mutex_unlock(&vcpu->mutex);
 
-       if (!kvmclock_periodic_sync)
-               return;
-
-       schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
-                                       KVMCLOCK_SYNC_PERIOD);
+       if (vcpu->vcpu_idx == 0 && kvmclock_periodic_sync)
+               schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
+                                     KVMCLOCK_SYNC_PERIOD);
 }

>  }
>  
>  void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)

With or without the change mentioned above,
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

-- 
Vitaly


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] KVM: X86: Just one leader to trigger kvmclock sync request
  2020-03-02 13:01 ` Vitaly Kuznetsov
@ 2020-03-02 18:22   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-03-02 18:22 UTC (permalink / raw)
  To: Vitaly Kuznetsov, Wanpeng Li
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Joerg Roedel,
	linux-kernel, kvm

On 02/03/20 14:01, Vitaly Kuznetsov wrote:
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9389,11 +9389,9 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
>  
>         mutex_unlock(&vcpu->mutex);
>  
> -       if (!kvmclock_periodic_sync)
> -               return;
> -
> -       schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
> -                                       KVMCLOCK_SYNC_PERIOD);
> +       if (vcpu->vcpu_idx == 0 && kvmclock_periodic_sync)
> +               schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
> +                                     KVMCLOCK_SYNC_PERIOD);
>  }

> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

Good idea, I squashed the change.

Paolo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-02 18:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-28  3:18 [PATCH v3] KVM: X86: Just one leader to trigger kvmclock sync request Wanpeng Li
2020-03-02 13:01 ` Vitaly Kuznetsov
2020-03-02 18:22   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).