kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Wanpeng Li <wanpeng.li@hotmail.com>
Cc: David Matlack <dmatlack@google.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 2/3] KVM: dynamic halt-polling
Date: Sun, 6 Sep 2015 16:32:03 +0200	[thread overview]
Message-ID: <55EC4E63.8030504@redhat.com> (raw)
In-Reply-To: <BLU436-SMTP237F3D6EFE0CCEE884C904780570@phx.gbl>



On 05/09/2015 00:38, Wanpeng Li wrote:
>>
>> @@ -1940,11 +1975,16 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
>>                * arrives.
>>                */
>>               if (kvm_vcpu_check_block(vcpu) < 0) {
>> +                polled = true;
>>                   ++vcpu->stat.halt_successful_poll;
>> -                goto out;
>> +                break;
>>               }
>>               cur = ktime_get();
>>           } while (single_task_running() && ktime_before(cur, stop));
>> +
>> +        poll_ns = ktime_to_ns(cur) - ktime_to_ns(start);
>> +        if (polled)
>> +            goto out;
>>
> 
> Please move poll_ns caculation under if() when you applied, as I
> explained in reply to v6.

You can do much more than just that, the patch reduces to this:

@@ -1929,6 +1963,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
 	ktime_t start, cur;
 	DEFINE_WAIT(wait);
 	bool waited = false;
+	u64 block_ns;
 
 	start = cur = ktime_get();
 	if (vcpu->halt_poll_ns) {
@@ -1961,7 +1996,21 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
 	cur = ktime_get();
 
 out:
-	trace_kvm_vcpu_wakeup(ktime_to_ns(cur) - ktime_to_ns(start), waited);
+	block_ns = ktime_to_ns(cur) - ktime_to_ns(start);
+
+	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);
+	}
+
+	trace_kvm_vcpu_wakeup(block_ns, waited);
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_block);
 

Paolo

  reply	other threads:[~2015-09-06 14:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1441289259-32072-1-git-send-email-wanpeng.li@hotmail.com>
2015-09-03 14:07 ` [PATCH v7 1/3] KVM: make halt_poll_ns per-vCPU Wanpeng Li
2015-09-06 14:33   ` Paolo Bonzini
2015-09-03 14:07 ` [PATCH v7 2/3] KVM: dynamic halt-polling Wanpeng Li
2015-09-04 22:38   ` Wanpeng Li
2015-09-06 14:32     ` Paolo Bonzini [this message]
2015-09-06 22:23       ` Wanpeng Li
2015-09-03 14:07 ` [PATCH v7 3/3] KVM: trace kvm_halt_poll_ns grow/shrink Wanpeng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55EC4E63.8030504@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wanpeng.li@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).