diff mbox series

[3/5] KVM: ensure pool time is longer than block_ns

Message ID 1572060239-17401-4-git-send-email-zhenzhong.duan@oracle.com (mailing list archive)
State New, archived
Headers show
Series misc fixes on halt-poll code both KVM and guest | expand

Commit Message

Zhenzhong Duan Oct. 26, 2019, 3:23 a.m. UTC
When (block_ns == vcpu->halt_poll_ns), there is not a margin so that
vCPU may still get into block state unnecessorily.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Marcelo Tosatti Nov. 1, 2019, 9:16 p.m. UTC | #1
On Sat, Oct 26, 2019 at 11:23:57AM +0800, Zhenzhong Duan wrote:
> When (block_ns == vcpu->halt_poll_ns), there is not a margin so that
> vCPU may still get into block state unnecessorily.
> 
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
> ---
>  virt/kvm/kvm_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 1b6fe3b..48a1f1a 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2371,7 +2371,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
>  		if (!vcpu_valid_wakeup(vcpu)) {
>  			shrink_halt_poll_ns(vcpu);
>  		} else if (halt_poll_ns) {
> -			if (block_ns <= vcpu->halt_poll_ns)
> +			if (block_ns < vcpu->halt_poll_ns)
>  				;
>  			/* we had a short halt and our poll time is too small */
>  			else if (block_ns < halt_poll_ns)
> -- 
> 1.8.3.1

Makes sense.
Paolo Bonzini Nov. 11, 2019, 1:53 p.m. UTC | #2
On 01/11/19 22:16, Marcelo Tosatti wrote:
>  		if (!vcpu_valid_wakeup(vcpu)) {
>  			shrink_halt_poll_ns(vcpu);
>  		} else if (halt_poll_ns) {
> -			if (block_ns <= vcpu->halt_poll_ns)
> +			if (block_ns < vcpu->halt_poll_ns)
>  				;
>  			/* we had a short halt and our poll time is too small */
>  			else if (block_ns < halt_poll_ns)

What about making this "if (!waited)"?  The result would be very readable:

                        if (!waited)
                                ;
                        /* we had a long block, shrink polling */
                        else if (block_ns > halt_poll_ns && vcpu->halt_poll_ns)
                                shrink_halt_poll_ns(vcpu);
                        /* we had a short halt and our poll time is too small */
                        else if (block_ns < halt_poll_ns && vcpu->halt_poll_ns < halt_poll_ns)
                                grow_halt_poll_ns(vcpu);

Paolo
Zhenzhong Duan Nov. 12, 2019, 12:14 p.m. UTC | #3
On 2019/11/11 21:53, Paolo Bonzini wrote:
> On 01/11/19 22:16, Marcelo Tosatti wrote:
>>   		if (!vcpu_valid_wakeup(vcpu)) {
>>   			shrink_halt_poll_ns(vcpu);
>>   		} else if (halt_poll_ns) {
>> -			if (block_ns <= vcpu->halt_poll_ns)
>> +			if (block_ns < vcpu->halt_poll_ns)
>>   				;
>>   			/* we had a short halt and our poll time is too small */
>>   			else if (block_ns < halt_poll_ns)
> What about making this "if (!waited)"?  The result would be very readable:
>
>                          if (!waited)
>                                  ;
>                          /* we had a long block, shrink polling */
>                          else if (block_ns > halt_poll_ns && vcpu->halt_poll_ns)
>                                  shrink_halt_poll_ns(vcpu);
>                          /* we had a short halt and our poll time is too small */
>                          else if (block_ns < halt_poll_ns && vcpu->halt_poll_ns < halt_poll_ns)
>                                  grow_halt_poll_ns(vcpu);

This patch is dropped in v2 as it rarely happen in real scenario.

Appreciate you reviewing v2 in https://lkml.org/lkml/2019/11/6/447

Thanks

Zhenzhong
diff mbox series

Patch

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 1b6fe3b..48a1f1a 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2371,7 +2371,7 @@  void kvm_vcpu_block(struct kvm_vcpu *vcpu)
 		if (!vcpu_valid_wakeup(vcpu)) {
 			shrink_halt_poll_ns(vcpu);
 		} else if (halt_poll_ns) {
-			if (block_ns <= vcpu->halt_poll_ns)
+			if (block_ns < vcpu->halt_poll_ns)
 				;
 			/* we had a short halt and our poll time is too small */
 			else if (block_ns < halt_poll_ns)