diff mbox series

drivers/cpuidle: Fix guest_halt_poll_ns failed to take effect

Message ID tencent_2ACBECB5B8EF2442CE608CE48F8E6131CC09@qq.com (mailing list archive)
State Changes Requested, archived
Headers show
Series drivers/cpuidle: Fix guest_halt_poll_ns failed to take effect | expand

Commit Message

Yanhao Dong June 28, 2024, 8:49 a.m. UTC
From: ysay <ysaydong@gmail.com>

When guest_halt_poll_allow_shrink=N,setting guest_halt_poll_ns
from a large value to 0 does not reset the CPU polling time,
despite guest_halt_poll_ns being intended as a mandatory maximum
time limit.

The problem was situated in the adjust_poll_limit() within
drivers/cpuidle/governors/haltpoll.c:79.

Specifically, when guest_halt_poll_allow_shrink was set to N,
resetting guest_halt_poll_ns to zero did not lead to executing any
section of code that adjusts dev->poll_limit_ns.

The issue has been resolved by relocating the check and assignment for
dev->poll_limit_ns outside of the conditional block.
This ensures that every modification to guest_halt_poll_ns
properly influences the CPU polling time.

Signed-off-by: ysay <ysaydong@gmail.com>
---
 drivers/cpuidle/governors/haltpoll.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Rafael J. Wysocki July 1, 2024, 5:06 p.m. UTC | #1
On Fri, Jun 28, 2024 at 11:01 AM ysay <570260087@qq.com> wrote:
>
> From: ysay <ysaydong@gmail.com>
>
> When guest_halt_poll_allow_shrink=N,setting guest_halt_poll_ns
> from a large value to 0 does not reset the CPU polling time,
> despite guest_halt_poll_ns being intended as a mandatory maximum
> time limit.
>
> The problem was situated in the adjust_poll_limit() within
> drivers/cpuidle/governors/haltpoll.c:79.
>
> Specifically, when guest_halt_poll_allow_shrink was set to N,
> resetting guest_halt_poll_ns to zero did not lead to executing any
> section of code that adjusts dev->poll_limit_ns.
>
> The issue has been resolved by relocating the check and assignment for
> dev->poll_limit_ns outside of the conditional block.
> This ensures that every modification to guest_halt_poll_ns
> properly influences the CPU polling time.
>
> Signed-off-by: ysay <ysaydong@gmail.com>

This should carry a Fixes: tag pointing to the commit fixed by it.

Also, is it -stable material?

> ---
>  drivers/cpuidle/governors/haltpoll.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c
> index 663b7f164..99c6260d7 100644
> --- a/drivers/cpuidle/governors/haltpoll.c
> +++ b/drivers/cpuidle/governors/haltpoll.c
> @@ -78,26 +78,22 @@ static int haltpoll_select(struct cpuidle_driver *drv,
>
>  static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns)
>  {
> -       unsigned int val;
> +       unsigned int val = dev->poll_limit_ns;
>
>         /* Grow cpu_halt_poll_us if
>          * cpu_halt_poll_us < block_ns < guest_halt_poll_us
>          */
>         if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns) {
> -               val = dev->poll_limit_ns * guest_halt_poll_grow;
> +               val *= 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;
>
>                 trace_guest_halt_poll_ns_grow(val, dev->poll_limit_ns);
> -               dev->poll_limit_ns = val;
>         } 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;
>                 } else {
> @@ -108,8 +104,12 @@ static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns)
>                 }
>
>                 trace_guest_halt_poll_ns_shrink(val, dev->poll_limit_ns);
> -               dev->poll_limit_ns = val;
>         }
> +
> +       if (val > guest_halt_poll_ns)
> +               val = guest_halt_poll_ns;
> +
> +       dev->poll_limit_ns = val;
>  }
>
>  /**
> --
> 2.43.5
>
>
diff mbox series

Patch

diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c
index 663b7f164..99c6260d7 100644
--- a/drivers/cpuidle/governors/haltpoll.c
+++ b/drivers/cpuidle/governors/haltpoll.c
@@ -78,26 +78,22 @@  static int haltpoll_select(struct cpuidle_driver *drv,
 
 static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns)
 {
-	unsigned int val;
+	unsigned int val = dev->poll_limit_ns;
 
 	/* Grow cpu_halt_poll_us if
 	 * cpu_halt_poll_us < block_ns < guest_halt_poll_us
 	 */
 	if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns) {
-		val = dev->poll_limit_ns * guest_halt_poll_grow;
+		val *= 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;
 
 		trace_guest_halt_poll_ns_grow(val, dev->poll_limit_ns);
-		dev->poll_limit_ns = val;
 	} 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;
 		} else {
@@ -108,8 +104,12 @@  static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns)
 		}
 
 		trace_guest_halt_poll_ns_shrink(val, dev->poll_limit_ns);
-		dev->poll_limit_ns = val;
 	}
+
+	if (val > guest_halt_poll_ns)
+		val = guest_halt_poll_ns;
+
+	dev->poll_limit_ns = val;
 }
 
 /**