public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	joao.m.martins@oracle.com, rafael.j.wysocki@intel.com,
	rkrcmar@redhat.com, pbonzini@redhat.com
Subject: Re: [PATCH 5/5] cpuidle-haltpoll: fix up the branch check
Date: Mon, 4 Nov 2019 13:01:06 -0200	[thread overview]
Message-ID: <20191104150103.GA14887@amt.cnet> (raw)
In-Reply-To: <bafc1688-02ea-77a4-fb1c-2fe6afa8a7cc@oracle.com>

On Mon, Nov 04, 2019 at 11:10:25AM +0800, Zhenzhong Duan wrote:
> 
> On 2019/11/2 5:26, Marcelo Tosatti wrote:
> >On Sat, Oct 26, 2019 at 11:23:59AM +0800, Zhenzhong Duan wrote:
> >>Ensure pool time is longer than block_ns, so there is a margin to
> >>avoid vCPU get into block state unnecessorily.
> >>
> >>Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
> >>---
> >>  drivers/cpuidle/governors/haltpoll.c | 6 +++---
> >>  1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >>diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c
> >>index 4b00d7a..59eadaf 100644
> >>--- a/drivers/cpuidle/governors/haltpoll.c
> >>+++ b/drivers/cpuidle/governors/haltpoll.c
> >>@@ -81,9 +81,9 @@ static void adjust_poll_limit(struct cpuidle_device *dev, unsigned int block_us)
> >>  	u64 block_ns = block_us*NSEC_PER_USEC;
> >>  	/* Grow cpu_halt_poll_us if
> >>-	 * cpu_halt_poll_us < block_ns < guest_halt_poll_us
> >>+	 * cpu_halt_poll_us <= block_ns < guest_halt_poll_us
> >>  	 */
> >>-	if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns) {
> >>+	if (block_ns >= dev->poll_limit_ns && block_ns < guest_halt_poll_ns) {
> >					      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> >If block_ns == guest_halt_poll_ns, you won't allow dev->poll_limit_ns to
> >grow. Why is that?
> 
> Maybe I'm too strict here. My understanding is: if block_ns = guest_halt_poll_ns,
> dev->poll_limit_ns will grow to guest_halt_poll_ns, 

OK.

> then block_ns = dev->poll_limit_ns,

block_ns = dev->poll_limit_ns = guest_halt_poll_ns. OK.

> there is not a margin to ensure poll time is enough to cover the equal block time.
> In this case, shrinking may be a better choice?

Ok, so you are considering _on the next_ halt instance, if block_ns =
guest_halt_poll_ns again?

Then without the suggested modification: we don't shrink, poll for
guest_halt_poll_ns again.

With your modification: we shrink, because block_ns ==
guest_halt_poll_ns.

IMO what really clarifies things here is either the real sleep pattern 
or a synthetic sleep pattern similar to the real thing.

Do you have a scenario where the current algorithm is maintaining
a low dev->poll_limit_ns and performance is hurt?

If you could come up with examples, such as the client/server pair at
https://lore.kernel.org/lkml/20190514135022.GD4392@amt.cnet/T/

or just a sequence of delays: 
block_ns, block_ns, block_ns-1,...

It would be easier to visualize this.

> >>@@ -101,7 +101,7 @@ static void adjust_poll_limit(struct cpuidle_device *dev, unsigned int block_us)
> >>  			val = guest_halt_poll_ns;
> >>  		dev->poll_limit_ns = val;
> >>-	} else if (block_ns > guest_halt_poll_ns &&
> >>+	} else if (block_ns >= guest_halt_poll_ns &&
> >>  		   guest_halt_poll_allow_shrink) {
> >>  		unsigned int shrink = guest_halt_poll_shrink;
> >And here you shrink if block_ns == guest_halt_poll_ns. Not sure
> >why that makes sense either.
> 
> See above explanation.
> 
> Zhenzhong


  reply	other threads:[~2019-11-04 15:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-26  3:23 [PATCH 0/5] misc fixes on halt-poll code both KVM and guest Zhenzhong Duan
2019-10-26  3:23 ` [PATCH 1/5] KVM: simplify branch check in host poll code Zhenzhong Duan
2019-11-01 21:03   ` Marcelo Tosatti
2019-11-04  3:49     ` Zhenzhong Duan
2019-10-26  3:23 ` [PATCH 2/5] KVM: add a check to ensure grow start value is nonzero Zhenzhong Duan
2019-11-11 13:49   ` Paolo Bonzini
2019-10-26  3:23 ` [PATCH 3/5] KVM: ensure pool time is longer than block_ns Zhenzhong Duan
2019-11-01 21:16   ` Marcelo Tosatti
2019-11-11 13:53     ` Paolo Bonzini
2019-11-12 12:14       ` Zhenzhong Duan
2019-10-26  3:23 ` [PATCH 4/5] cpuidle-haltpoll: add a check to ensure grow start value is nonzero Zhenzhong Duan
2019-11-01 21:19   ` Marcelo Tosatti
2019-11-04  2:56     ` Zhenzhong Duan
2019-11-11 13:54       ` Paolo Bonzini
2019-10-26  3:23 ` [PATCH 5/5] cpuidle-haltpoll: fix up the branch check Zhenzhong Duan
2019-11-01 21:26   ` Marcelo Tosatti
2019-11-04  3:10     ` Zhenzhong Duan
2019-11-04 15:01       ` Marcelo Tosatti [this message]
2019-11-05  6:49         ` Zhenzhong Duan

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=20191104150103.GA14887@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=joao.m.martins@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rkrcmar@redhat.com \
    --cc=zhenzhong.duan@oracle.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