linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhenzhong Duan <zhenzhong.duan@oracle.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: linux-kernel@vger.kernel.org, pbonzini@redhat.com,
	rkrcmar@redhat.com, rafael.j.wysocki@intel.com,
	joao.m.martins@oracle.com, mtosatti@redhat.com,
	kvm@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH RESEND v2 3/4] cpuidle-haltpoll: ensure cpu_halt_poll_us in right scope
Date: Sun, 17 Nov 2019 16:57:57 +0800	[thread overview]
Message-ID: <5ff7cb30-b6fb-d9df-ee8d-bf21b95c9cb1@oracle.com> (raw)
In-Reply-To: <6161954.sKiXg2khOt@kreacher>

On 2019/11/15 18:45, Rafael J. Wysocki wrote:

> On Wednesday, November 6, 2019 12:55:01 PM CET Zhenzhong Duan wrote:
>> As user can adjust guest_halt_poll_grow_start and guest_halt_poll_ns
>> which leads to cpu_halt_poll_us beyond the two boundaries. This patch
>> ensures cpu_halt_poll_us in that scope.
>>
>> If guest_halt_poll_shrink is 0, shrink the cpu_halt_poll_us to
>> guest_halt_poll_grow_start instead of 0. To disable poll we can set
>> guest_halt_poll_ns to 0.
>>
>> If user wrongly set guest_halt_poll_grow_start > guest_halt_poll_ns > 0,
>> guest_halt_poll_ns take precedency and poll time is a fixed value of
>> guest_halt_poll_ns.
>>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
>> ---
>>   drivers/cpuidle/governors/haltpoll.c | 28 +++++++++++++---------------
>>   1 file changed, 13 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c
>> index 660859d..4a39df4 100644
>> --- a/drivers/cpuidle/governors/haltpoll.c
>> +++ b/drivers/cpuidle/governors/haltpoll.c
>> @@ -97,32 +97,30 @@ static int haltpoll_select(struct cpuidle_driver *drv,
>>   
>>   static void adjust_poll_limit(struct cpuidle_device *dev, unsigned int block_us)
>>   {
>> -	unsigned int val;
>> +	unsigned int val = dev->poll_limit_ns;
> Not necessary to initialize it here.

Then an random val may bypass all the check and get assigned to dev->poll_limit_ns

if guest_halt_poll_grow_start< block_ns< uninitialized val< guest_halt_poll_ns

With my change, dev->poll_limit_ns will not be changed in that case, logic same as original code.

>
>>   	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
> You could update the comment to say "dev->poll_limit_ns" instead of
> "cpu_halt_poll_us" while at it.

Will do, also guest_halt_poll_us to guest_halt_poll_ns

>
>>   	 */
>> -	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 &&
>> +	    guest_halt_poll_grow)
> The "{" brace is still needed as per the coding style and I'm not sure why
> to avoid guest_halt_poll_grow equal to zero here?

Will add "{}" and remove guest_halt_poll_grow check. My inital thought was to prevent

dev->poll_limit_ns get shrinked with guest_halt_poll_grow=0.

>
>>   		val = dev->poll_limit_ns * guest_halt_poll_grow;
>> -
>> -		if (val < guest_halt_poll_grow_start)
>> -			val = guest_halt_poll_grow_start;
>> -		if (val > guest_halt_poll_ns)
>> -			val = guest_halt_poll_ns;
>> -
>> -		dev->poll_limit_ns = val;
>> -	} else if (block_ns > guest_halt_poll_ns &&
>> -		   guest_halt_poll_allow_shrink) {
>> +	else if (block_ns > guest_halt_poll_ns &&
>> +		 guest_halt_poll_allow_shrink) {
>>   		unsigned int shrink = guest_halt_poll_shrink;
>>   
>> -		val = dev->poll_limit_ns;
>>   		if (shrink == 0)
>> -			val = 0;
>> +			val = guest_halt_poll_grow_start;
> That's going to be corrected below, so the original code would be fine.

val was assigned twice using 'val = 0' while it's once with my change, optimal a bit?

>
>>   		else
>>   			val /= shrink;
> Here you can do
>
> 			val = dev->poll_limit_ns / shrink;

Any special reason?Looks no difference for me.

>
>> -		dev->poll_limit_ns = val;
>>   	}
>> +	if (val < guest_halt_poll_grow_start)
>> +		val = guest_halt_poll_grow_start;
> Note that guest_halt_poll_grow_start is in us (as per the comment next to its
> definition and the initial value).  That is a bug in the original code too,
> but anyway.

Good catch! will fix the comment. The default 50000ns vs 50000us, looks author means ns.
guest_halt_poll_ns defaults to 200000, also hints ns for guest_halt_poll_grow_start.

Thanks

Zhenzhong


  reply	other threads:[~2019-11-17  8:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-06 11:54 [PATCH RESEND v2 0/4] misc fixes on halt-poll code for both KVM and guest Zhenzhong Duan
2019-11-06 11:54 ` [PATCH RESEND v2 1/4] cpuidle-haltpoll: ensure grow start value is nonzero Zhenzhong Duan
2019-11-15 10:06   ` Rafael J. Wysocki
2019-11-15 10:16     ` Rafael J. Wysocki
2019-11-15 10:26   ` Rafael J. Wysocki
2019-11-17  9:02     ` Zhenzhong Duan
2019-11-06 11:55 ` [PATCH RESEND v2 2/4] KVM: " Zhenzhong Duan
2019-11-11 20:13   ` Sean Christopherson
2019-11-12 12:19     ` Zhenzhong Duan
2019-11-06 11:55 ` [PATCH RESEND v2 3/4] cpuidle-haltpoll: ensure cpu_halt_poll_us in right scope Zhenzhong Duan
2019-11-15 10:45   ` Rafael J. Wysocki
2019-11-17  8:57     ` Zhenzhong Duan [this message]
2019-11-06 11:55 ` [PATCH RESEND v2 4/4] KVM: ensure vCPU halt_poll_us " 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=5ff7cb30-b6fb-d9df-ee8d-bf21b95c9cb1@oracle.com \
    --to=zhenzhong.duan@oracle.com \
    --cc=joao.m.martins@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rjw@rjwysocki.net \
    --cc=rkrcmar@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;
as well as URLs for NNTP newsgroup(s).