mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wanpeng Li <wanpeng.li@hotmail.com>
To: David Matlack <dmatlack@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm list <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 2/3] KVM: dynamic halt_poll_ns adjustment
Date: Fri, 4 Sep 2015 09:42:10 +0800	[thread overview]
Message-ID: <BLU436-SMTP48C469210EC2FC5B0AB64F80570@phx.gbl> (raw)
In-Reply-To: <BLU436-SMTP132C316315912A92D8AA61480570@phx.gbl>

On 9/4/15 9:16 AM, Wanpeng Li wrote:
> [...]
>>> +
>>>   static int kvm_vcpu_check_block(struct kvm_vcpu *vcpu)
>>>   {
>>>          if (kvm_arch_vcpu_runnable(vcpu)) {
>>> @@ -1929,6 +1963,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
>>>          ktime_t start, cur;
>>>          DEFINE_WAIT(wait);
>>>          bool waited = false;
>>> +       u64 poll_ns = 0, wait_ns = 0, block_ns = 0;
>>>
>>>          start = cur = ktime_get();
>>>          if (vcpu->halt_poll_ns) {
>>> @@ -1941,10 +1976,15 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
>>>                           */
>>>                          if (kvm_vcpu_check_block(vcpu) < 0) {
>>> ++vcpu->stat.halt_successful_poll;
>>> -                               goto out;
>>> +                               break;
>>>                          }
>>>                          cur = ktime_get();
>>>                  } while (single_task_running() && ktime_before(cur, 
>>> stop));
>>> +
>>> +               if (ktime_before(cur, stop)) {
>> You can't use 'cur' to tell if the interrupt arrived. 
>> single_task_running()
>> can break us out of the loop before 'stop'.
>>
>>> +                       poll_ns = ktime_to_ns(cur) - 
>>> ktime_to_ns(start);
>> Put this line before the if(). block_ns should always include the time
>> spent polling; even if polling does not succeed.
>
> Ah, I remember why I keep poll_ns calculation in if(). Actually 
> poll_ns has already been accumulated into wait_ns(see how wait_ns is 
> calculated) if polling does not succeed. If put poll_ns calculation 
> before if() I need to reset variable 'start' to ktime_get().

So how about something like:

@@ -1928,7 +1962,8 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
  {
         ktime_t start, cur;
         DEFINE_WAIT(wait);
-       bool waited = false;
+       bool polled = false, waited = false;
+       u64 poll_ns = 0, wait_ns = 0, block_ns = 0;

         start = cur = ktime_get();
         if (vcpu->halt_poll_ns) {
@@ -1940,11 +1975,17 @@ 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));
+
+               if (polled) {
+                       poll_ns = ktime_to_ns(cur) - ktime_to_ns(start);
+                       goto out;
+               }
         }


Regards,
Wanpeng Li


      reply	other threads:[~2015-09-04  1:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1441178971-3836-1-git-send-email-wanpeng.li@hotmail.com>
2015-09-02  7:29 ` [PATCH v6 1/3] KVM: make halt_poll_ns per-vCPU Wanpeng Li
2015-09-02  7:29 ` [PATCH v6 2/3] KVM: dynamic halt_poll_ns adjustment Wanpeng Li
2015-09-02 18:09   ` David Matlack
2015-09-02 19:12     ` Paolo Bonzini
2015-09-02 19:23       ` David Matlack
2015-09-03  7:31         ` Paolo Bonzini
2015-09-03  8:52           ` Wanpeng Li
2015-09-03  9:23     ` Wanpeng Li
2015-09-03 16:07       ` David Matlack
2015-09-04  0:15         ` Wanpeng Li
2015-09-04  1:16     ` Wanpeng Li
2015-09-04  1:42       ` Wanpeng Li [this message]

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=BLU436-SMTP48C469210EC2FC5B0AB64F80570@phx.gbl \
    --to=wanpeng.li@hotmail.com \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.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

all inboxes | Powered by JetHome®