Re: [PATCH 5/5] cpuidle-haltpoll: fix up the branch check

From: Zhenzhong Duan
Date: Sun Nov 03 2019 - 22:11:18 EST



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@xxxxxxxxxx>
---
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, then block_ns = dev->poll_limit_ns,
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?


@@ -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