* [PATCH v3 1/2] KVM: X86: Less kvmclock sync induced vmexits after VM boots
@ 2020-02-17 10:36 Wanpeng Li
2020-02-17 10:40 ` Wanpeng Li
2020-02-17 11:23 ` Paolo Bonzini
0 siblings, 2 replies; 4+ messages in thread
From: Wanpeng Li @ 2020-02-17 10:36 UTC (permalink / raw)
To: LKML, kvm
Cc: Paolo Bonzini, Sean Christopherson, Wanpeng Li, Vitaly Kuznetsov,
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. Each worker will be scheduled
after 300 * HZ delay and request a kvmclock update for all vCPUs and kick them
out. This is especially worse when scaling to large VMs due to a lot of vmexits.
Just one worker as a leader to trigger the kvmclock sync request for
all vCPUs is
enough.
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
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..d0ba2d4 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 (kvm->created_vcpus == 1)
+ 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] 4+ messages in thread
* Re: [PATCH v3 1/2] KVM: X86: Less kvmclock sync induced vmexits after VM boots
2020-02-17 10:36 [PATCH v3 1/2] KVM: X86: Less kvmclock sync induced vmexits after VM boots Wanpeng Li
@ 2020-02-17 10:40 ` Wanpeng Li
2020-02-17 11:23 ` Paolo Bonzini
1 sibling, 0 replies; 4+ messages in thread
From: Wanpeng Li @ 2020-02-17 10:40 UTC (permalink / raw)
To: LKML, kvm
Cc: Paolo Bonzini, Sean Christopherson, Wanpeng Li, Vitaly Kuznetsov,
Jim Mattson, Joerg Roedel
On Mon, 17 Feb 2020 at 18:36, Wanpeng Li <kernellwp@gmail.com> wrote:
>
> 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. Each worker will be scheduled
> after 300 * HZ delay and request a kvmclock update for all vCPUs and kick them
> out. This is especially worse when scaling to large VMs due to a lot of vmexits.
> Just one worker as a leader to trigger the kvmclock sync request for
> all vCPUs is
> enough.
Sorry for the alignment.
>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> 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..d0ba2d4 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 (kvm->created_vcpus == 1)
> + 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 [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/2] KVM: X86: Less kvmclock sync induced vmexits after VM boots
2020-02-17 10:36 [PATCH v3 1/2] KVM: X86: Less kvmclock sync induced vmexits after VM boots Wanpeng Li
2020-02-17 10:40 ` Wanpeng Li
@ 2020-02-17 11:23 ` Paolo Bonzini
2020-02-17 13:12 ` Wanpeng Li
1 sibling, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2020-02-17 11:23 UTC (permalink / raw)
To: Wanpeng Li, LKML, kvm
Cc: Sean Christopherson, Wanpeng Li, Vitaly Kuznetsov, Jim Mattson,
Joerg Roedel
On 17/02/20 11:36, Wanpeng Li wrote:
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index fb5d64e..d0ba2d4 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 (kvm->created_vcpus == 1)
> + schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
> + KVMCLOCK_SYNC_PERIOD);
This is called with kvm->lock not held, so you can have
kvm->created_vcpus == 2 by the time you get here. You can test instead
"if (vcpu->vcpu_idx == 0)".
Thanks,
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/2] KVM: X86: Less kvmclock sync induced vmexits after VM boots
2020-02-17 11:23 ` Paolo Bonzini
@ 2020-02-17 13:12 ` Wanpeng Li
0 siblings, 0 replies; 4+ messages in thread
From: Wanpeng Li @ 2020-02-17 13:12 UTC (permalink / raw)
To: Paolo Bonzini
Cc: LKML, kvm, Sean Christopherson, Wanpeng Li, Vitaly Kuznetsov,
Jim Mattson, Joerg Roedel
On Mon, 17 Feb 2020 at 19:23, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 17/02/20 11:36, Wanpeng Li wrote:
> >
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index fb5d64e..d0ba2d4 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 (kvm->created_vcpus == 1)
> > + schedule_delayed_work(&kvm->arch.kvmclock_sync_work,
> > + KVMCLOCK_SYNC_PERIOD);
>
> This is called with kvm->lock not held, so you can have
> kvm->created_vcpus == 2 by the time you get here. You can test instead
> "if (vcpu->vcpu_idx == 0)".
Agreed.
Wanpeng
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-02-17 13:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-17 10:36 [PATCH v3 1/2] KVM: X86: Less kvmclock sync induced vmexits after VM boots Wanpeng Li
2020-02-17 10:40 ` Wanpeng Li
2020-02-17 11:23 ` Paolo Bonzini
2020-02-17 13:12 ` Wanpeng Li
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).