* [PATCH] KVM: Don't shrink/grow vCPU halt_poll_ns if host side polling is disabled
@ 2019-09-27 8:27 Wanpeng Li
2019-09-27 14:42 ` Sean Christopherson
2019-09-27 15:50 ` Marcelo Tosatti
0 siblings, 2 replies; 5+ messages in thread
From: Wanpeng Li @ 2019-09-27 8:27 UTC (permalink / raw)
To: linux-kernel, kvm
Cc: Paolo Bonzini, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, Marcelo Tosatti
From: Wanpeng Li <wanpengli@tencent.com>
Don't waste cycles to shrink/grow vCPU halt_poll_ns if host
side polling is disabled.
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
virt/kvm/kvm_main.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e6de315..b368be4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2359,20 +2359,22 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
kvm_arch_vcpu_unblocking(vcpu);
block_ns = ktime_to_ns(cur) - ktime_to_ns(start);
- if (!vcpu_valid_wakeup(vcpu))
- shrink_halt_poll_ns(vcpu);
- else if (halt_poll_ns) {
- if (block_ns <= vcpu->halt_poll_ns)
- ;
- /* we had a long block, shrink polling */
- else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
+ if (!kvm_arch_no_poll(vcpu)) {
+ if (!vcpu_valid_wakeup(vcpu))
shrink_halt_poll_ns(vcpu);
- /* we had a short halt and our poll time is too small */
- else if (vcpu->halt_poll_ns < halt_poll_ns &&
- block_ns < halt_poll_ns)
- grow_halt_poll_ns(vcpu);
- } else
- vcpu->halt_poll_ns = 0;
+ else if (halt_poll_ns) {
+ if (block_ns <= vcpu->halt_poll_ns)
+ ;
+ /* we had a long block, shrink polling */
+ else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
+ shrink_halt_poll_ns(vcpu);
+ /* we had a short halt and our poll time is too small */
+ else if (vcpu->halt_poll_ns < halt_poll_ns &&
+ block_ns < halt_poll_ns)
+ grow_halt_poll_ns(vcpu);
+ } else
+ vcpu->halt_poll_ns = 0;
+ }
trace_kvm_vcpu_wakeup(block_ns, waited, vcpu_valid_wakeup(vcpu));
kvm_arch_vcpu_block_finish(vcpu);
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: Don't shrink/grow vCPU halt_poll_ns if host side polling is disabled
2019-09-27 8:27 [PATCH] KVM: Don't shrink/grow vCPU halt_poll_ns if host side polling is disabled Wanpeng Li
@ 2019-09-27 14:42 ` Sean Christopherson
2019-09-29 0:57 ` Wanpeng Li
2019-09-27 15:50 ` Marcelo Tosatti
1 sibling, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2019-09-27 14:42 UTC (permalink / raw)
To: Wanpeng Li
Cc: linux-kernel, kvm, Paolo Bonzini, Radim Krčmář,
Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel,
Marcelo Tosatti
On Fri, Sep 27, 2019 at 04:27:02PM +0800, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
>
> Don't waste cycles to shrink/grow vCPU halt_poll_ns if host
> side polling is disabled.
>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> virt/kvm/kvm_main.c | 28 +++++++++++++++-------------
> 1 file changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index e6de315..b368be4 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2359,20 +2359,22 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
> kvm_arch_vcpu_unblocking(vcpu);
> block_ns = ktime_to_ns(cur) - ktime_to_ns(start);
>
> - if (!vcpu_valid_wakeup(vcpu))
> - shrink_halt_poll_ns(vcpu);
> - else if (halt_poll_ns) {
> - if (block_ns <= vcpu->halt_poll_ns)
> - ;
> - /* we had a long block, shrink polling */
> - else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
> + if (!kvm_arch_no_poll(vcpu)) {
Can vcpu->halt_poll_ns be cached and used both here and in the similar
check above? E.g.:
unsigned int vcpu_halt_poll_ns;
vcpu_halt_poll_ns = kvm_arch_no_poll(vcpu) ? 0 : vcpu->halt_poll_ns;
if (vcpu_halt_poll_ns) {
...
}
> + if (!vcpu_valid_wakeup(vcpu))
> shrink_halt_poll_ns(vcpu);
> - /* we had a short halt and our poll time is too small */
> - else if (vcpu->halt_poll_ns < halt_poll_ns &&
> - block_ns < halt_poll_ns)
> - grow_halt_poll_ns(vcpu);
> - } else
> - vcpu->halt_poll_ns = 0;
> + else if (halt_poll_ns) {
> + if (block_ns <= vcpu->halt_poll_ns)
> + ;
> + /* we had a long block, shrink polling */
> + else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
> + shrink_halt_poll_ns(vcpu);
> + /* we had a short halt and our poll time is too small */
> + else if (vcpu->halt_poll_ns < halt_poll_ns &&
> + block_ns < halt_poll_ns)
> + grow_halt_poll_ns(vcpu);
> + } else
> + vcpu->halt_poll_ns = 0;
Not your code, but it'd be a good time to add braces to the 'if' and
'else'. Per Documentation/process/coding-style.rst:
Do not unnecessarily use braces where a single statement will do.
...
This does not apply if only one branch of a conditional statement is a single
statement; in the latter case use braces in both branches:
if (condition) {
do_this();
do_that();
} else {
otherwise();
}
> + }
>
> trace_kvm_vcpu_wakeup(block_ns, waited, vcpu_valid_wakeup(vcpu));
> kvm_arch_vcpu_block_finish(vcpu);
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: Don't shrink/grow vCPU halt_poll_ns if host side polling is disabled
2019-09-27 8:27 [PATCH] KVM: Don't shrink/grow vCPU halt_poll_ns if host side polling is disabled Wanpeng Li
2019-09-27 14:42 ` Sean Christopherson
@ 2019-09-27 15:50 ` Marcelo Tosatti
2019-09-29 1:03 ` Wanpeng Li
1 sibling, 1 reply; 5+ messages in thread
From: Marcelo Tosatti @ 2019-09-27 15:50 UTC (permalink / raw)
To: Wanpeng Li
Cc: linux-kernel, kvm, Paolo Bonzini, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel
On Fri, Sep 27, 2019 at 04:27:02PM +0800, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
>
> Don't waste cycles to shrink/grow vCPU halt_poll_ns if host
> side polling is disabled.
>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> virt/kvm/kvm_main.c | 28 +++++++++++++++-------------
> 1 file changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index e6de315..b368be4 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2359,20 +2359,22 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
> kvm_arch_vcpu_unblocking(vcpu);
> block_ns = ktime_to_ns(cur) - ktime_to_ns(start);
>
> - if (!vcpu_valid_wakeup(vcpu))
> - shrink_halt_poll_ns(vcpu);
> - else if (halt_poll_ns) {
> - if (block_ns <= vcpu->halt_poll_ns)
> - ;
> - /* we had a long block, shrink polling */
> - else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
> + if (!kvm_arch_no_poll(vcpu)) {
> + if (!vcpu_valid_wakeup(vcpu))
> shrink_halt_poll_ns(vcpu);
> - /* we had a short halt and our poll time is too small */
> - else if (vcpu->halt_poll_ns < halt_poll_ns &&
> - block_ns < halt_poll_ns)
> - grow_halt_poll_ns(vcpu);
> - } else
> - vcpu->halt_poll_ns = 0;
> + else if (halt_poll_ns) {
> + if (block_ns <= vcpu->halt_poll_ns)
> + ;
> + /* we had a long block, shrink polling */
> + else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
> + shrink_halt_poll_ns(vcpu);
> + /* we had a short halt and our poll time is too small */
> + else if (vcpu->halt_poll_ns < halt_poll_ns &&
> + block_ns < halt_poll_ns)
> + grow_halt_poll_ns(vcpu);
> + } else
> + vcpu->halt_poll_ns = 0;
> + }
>
> trace_kvm_vcpu_wakeup(block_ns, waited, vcpu_valid_wakeup(vcpu));
> kvm_arch_vcpu_block_finish(vcpu);
> --
> 2.7.4
Looks good.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: Don't shrink/grow vCPU halt_poll_ns if host side polling is disabled
2019-09-27 14:42 ` Sean Christopherson
@ 2019-09-29 0:57 ` Wanpeng Li
0 siblings, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2019-09-29 0:57 UTC (permalink / raw)
To: Sean Christopherson
Cc: LKML, kvm, Paolo Bonzini, Radim Krčmář,
Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel,
Marcelo Tosatti
On Fri, 27 Sep 2019 at 22:42, Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
>
> On Fri, Sep 27, 2019 at 04:27:02PM +0800, Wanpeng Li wrote:
> > From: Wanpeng Li <wanpengli@tencent.com>
> >
> > Don't waste cycles to shrink/grow vCPU halt_poll_ns if host
> > side polling is disabled.
> >
> > Cc: Marcelo Tosatti <mtosatti@redhat.com>
> > Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> > ---
> > virt/kvm/kvm_main.c | 28 +++++++++++++++-------------
> > 1 file changed, 15 insertions(+), 13 deletions(-)
> >
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index e6de315..b368be4 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -2359,20 +2359,22 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
> > kvm_arch_vcpu_unblocking(vcpu);
> > block_ns = ktime_to_ns(cur) - ktime_to_ns(start);
> >
> > - if (!vcpu_valid_wakeup(vcpu))
> > - shrink_halt_poll_ns(vcpu);
> > - else if (halt_poll_ns) {
> > - if (block_ns <= vcpu->halt_poll_ns)
> > - ;
> > - /* we had a long block, shrink polling */
> > - else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
> > + if (!kvm_arch_no_poll(vcpu)) {
>
> Can vcpu->halt_poll_ns be cached and used both here and in the similar
> check above? E.g.:
>
> unsigned int vcpu_halt_poll_ns;
>
> vcpu_halt_poll_ns = kvm_arch_no_poll(vcpu) ? 0 : vcpu->halt_poll_ns;
>
> if (vcpu_halt_poll_ns) {
> ...
> }
This is not correct, !kvm_arch_no_poll(vcpu) && vcpu->halt_poll_ns ==
0, you will stop grow.
>
> > + if (!vcpu_valid_wakeup(vcpu))
> > shrink_halt_poll_ns(vcpu);
> > - /* we had a short halt and our poll time is too small */
> > - else if (vcpu->halt_poll_ns < halt_poll_ns &&
> > - block_ns < halt_poll_ns)
> > - grow_halt_poll_ns(vcpu);
> > - } else
> > - vcpu->halt_poll_ns = 0;
> > + else if (halt_poll_ns) {
> > + if (block_ns <= vcpu->halt_poll_ns)
> > + ;
> > + /* we had a long block, shrink polling */
> > + else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
> > + shrink_halt_poll_ns(vcpu);
> > + /* we had a short halt and our poll time is too small */
> > + else if (vcpu->halt_poll_ns < halt_poll_ns &&
> > + block_ns < halt_poll_ns)
> > + grow_halt_poll_ns(vcpu);
> > + } else
> > + vcpu->halt_poll_ns = 0;
>
>
> Not your code,
Not the truth. :)
>but it'd be a good time to add braces to the 'if' and
> 'else'. Per Documentation/process/coding-style.rst:
>
> Do not unnecessarily use braces where a single statement will do.
>
> ...
>
> This does not apply if only one branch of a conditional statement is a single
> statement; in the latter case use braces in both branches:
>
> if (condition) {
> do_this();
> do_that();
> } else {
> otherwise();
> }
Will do in v2.
Wanpeng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: Don't shrink/grow vCPU halt_poll_ns if host side polling is disabled
2019-09-27 15:50 ` Marcelo Tosatti
@ 2019-09-29 1:03 ` Wanpeng Li
0 siblings, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2019-09-29 1:03 UTC (permalink / raw)
To: Marcelo Tosatti
Cc: LKML, kvm, Paolo Bonzini, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel
On Sat, 28 Sep 2019 at 01:24, Marcelo Tosatti <mtosatti@redhat.com> wrote:
>
> On Fri, Sep 27, 2019 at 04:27:02PM +0800, Wanpeng Li wrote:
> > From: Wanpeng Li <wanpengli@tencent.com>
> >
> > Don't waste cycles to shrink/grow vCPU halt_poll_ns if host
> > side polling is disabled.
> >
> > Cc: Marcelo Tosatti <mtosatti@redhat.com>
> > Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> > ---
> > virt/kvm/kvm_main.c | 28 +++++++++++++++-------------
> > 1 file changed, 15 insertions(+), 13 deletions(-)
> >
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index e6de315..b368be4 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -2359,20 +2359,22 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
> > kvm_arch_vcpu_unblocking(vcpu);
> > block_ns = ktime_to_ns(cur) - ktime_to_ns(start);
> >
> > - if (!vcpu_valid_wakeup(vcpu))
> > - shrink_halt_poll_ns(vcpu);
> > - else if (halt_poll_ns) {
> > - if (block_ns <= vcpu->halt_poll_ns)
> > - ;
> > - /* we had a long block, shrink polling */
> > - else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
> > + if (!kvm_arch_no_poll(vcpu)) {
> > + if (!vcpu_valid_wakeup(vcpu))
> > shrink_halt_poll_ns(vcpu);
> > - /* we had a short halt and our poll time is too small */
> > - else if (vcpu->halt_poll_ns < halt_poll_ns &&
> > - block_ns < halt_poll_ns)
> > - grow_halt_poll_ns(vcpu);
> > - } else
> > - vcpu->halt_poll_ns = 0;
> > + else if (halt_poll_ns) {
> > + if (block_ns <= vcpu->halt_poll_ns)
> > + ;
> > + /* we had a long block, shrink polling */
> > + else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
> > + shrink_halt_poll_ns(vcpu);
> > + /* we had a short halt and our poll time is too small */
> > + else if (vcpu->halt_poll_ns < halt_poll_ns &&
> > + block_ns < halt_poll_ns)
> > + grow_halt_poll_ns(vcpu);
> > + } else
> > + vcpu->halt_poll_ns = 0;
> > + }
> >
> > trace_kvm_vcpu_wakeup(block_ns, waited, vcpu_valid_wakeup(vcpu));
> > kvm_arch_vcpu_block_finish(vcpu);
> > --
> > 2.7.4
>
> Looks good.
I will add your ACK in v2.
Wanpeng
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-09-29 1:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-27 8:27 [PATCH] KVM: Don't shrink/grow vCPU halt_poll_ns if host side polling is disabled Wanpeng Li
2019-09-27 14:42 ` Sean Christopherson
2019-09-29 0:57 ` Wanpeng Li
2019-09-27 15:50 ` Marcelo Tosatti
2019-09-29 1:03 ` 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).