2024-01-11 13:59:47

by Parshuram Sangle

[permalink] [raw]
Subject: [PATCH] cpuidle: do not shrink guest poll_limit_ns below grow_start

While adjusting guest halt poll limit, grow block starts at
guest_halt_poll_grow_start without taking intermediate values.
Similar behavior is expected while shrinking the value. This
avoids short interval values which are really not required.

VCPU1 trace (guest_halt_poll_shrink equals 2):

VCPU1 grow 10000
VCPU1 shrink 5000
VCPU1 shrink 2500
VCPU1 shrink 1250
VCPU1 shrink 625
VCPU1 shrink 312
VCPU1 shrink 156
VCPU1 shrink 78
VCPU1 shrink 39
VCPU1 shrink 19
VCPU1 shrink 9
VCPU1 shrink 4

Similar change is done in KVM halt poll flow with below patch:
Link: https://lore.kernel.org/kvm/[email protected]/

Co-developed-by: Rajendran Jaishankar <[email protected]>
Signed-off-by: Rajendran Jaishankar <[email protected]>
Signed-off-by: Parshuram Sangle <[email protected]>
---
drivers/cpuidle/governors/haltpoll.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c
index 1dff3a52917d..663b7f164d20 100644
--- a/drivers/cpuidle/governors/haltpoll.c
+++ b/drivers/cpuidle/governors/haltpoll.c
@@ -98,10 +98,15 @@ static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns)
unsigned int shrink = guest_halt_poll_shrink;

val = dev->poll_limit_ns;
- if (shrink == 0)
+ if (shrink == 0) {
val = 0;
- else
+ } else {
val /= shrink;
+ /* Reset value to 0 if shrunk below grow_start */
+ if (val < guest_halt_poll_grow_start)
+ val = 0;
+ }
+
trace_guest_halt_poll_ns_shrink(val, dev->poll_limit_ns);
dev->poll_limit_ns = val;
}
--
2.17.1



2024-02-01 20:25:40

by Marcelo Tosatti

[permalink] [raw]
Subject: Re: [PATCH] cpuidle: do not shrink guest poll_limit_ns below grow_start

On Thu, Jan 11, 2024 at 07:29:50PM +0530, Parshuram Sangle wrote:
> While adjusting guest halt poll limit, grow block starts at
> guest_halt_poll_grow_start without taking intermediate values.
> Similar behavior is expected while shrinking the value. This
> avoids short interval values which are really not required.
>
> VCPU1 trace (guest_halt_poll_shrink equals 2):
>
> VCPU1 grow 10000
> VCPU1 shrink 5000
> VCPU1 shrink 2500
> VCPU1 shrink 1250
> VCPU1 shrink 625
> VCPU1 shrink 312
> VCPU1 shrink 156
> VCPU1 shrink 78
> VCPU1 shrink 39
> VCPU1 shrink 19
> VCPU1 shrink 9
> VCPU1 shrink 4
>
> Similar change is done in KVM halt poll flow with below patch:
> Link: https://lore.kernel.org/kvm/[email protected]/
>
> Co-developed-by: Rajendran Jaishankar <[email protected]>
> Signed-off-by: Rajendran Jaishankar <[email protected]>
> Signed-off-by: Parshuram Sangle <[email protected]>
> ---
> drivers/cpuidle/governors/haltpoll.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c
> index 1dff3a52917d..663b7f164d20 100644
> --- a/drivers/cpuidle/governors/haltpoll.c
> +++ b/drivers/cpuidle/governors/haltpoll.c
> @@ -98,10 +98,15 @@ static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns)
> unsigned int shrink = guest_halt_poll_shrink;
>
> val = dev->poll_limit_ns;
> - if (shrink == 0)
> + if (shrink == 0) {
> val = 0;
> - else
> + } else {
> val /= shrink;
> + /* Reset value to 0 if shrunk below grow_start */
> + if (val < guest_halt_poll_grow_start)
> + val = 0;
> + }
> +
> trace_guest_halt_poll_ns_shrink(val, dev->poll_limit_ns);
> dev->poll_limit_ns = val;
> }
> --
> 2.17.1
>
>
>

Looks good.

Reviewed-by: Marcelo Tosatti <[email protected]>


2024-02-12 16:04:22

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] cpuidle: do not shrink guest poll_limit_ns below grow_start

On Thu, Feb 1, 2024 at 8:56 PM Marcelo Tosatti <[email protected]> wrote:
>
> On Thu, Jan 11, 2024 at 07:29:50PM +0530, Parshuram Sangle wrote:
> > While adjusting guest halt poll limit, grow block starts at
> > guest_halt_poll_grow_start without taking intermediate values.
> > Similar behavior is expected while shrinking the value. This
> > avoids short interval values which are really not required.
> >
> > VCPU1 trace (guest_halt_poll_shrink equals 2):
> >
> > VCPU1 grow 10000
> > VCPU1 shrink 5000
> > VCPU1 shrink 2500
> > VCPU1 shrink 1250
> > VCPU1 shrink 625
> > VCPU1 shrink 312
> > VCPU1 shrink 156
> > VCPU1 shrink 78
> > VCPU1 shrink 39
> > VCPU1 shrink 19
> > VCPU1 shrink 9
> > VCPU1 shrink 4
> >
> > Similar change is done in KVM halt poll flow with below patch:
> > Link: https://lore.kernel.org/kvm/20211006133021.271905-3-sashal@kernelorg/
> >
> > Co-developed-by: Rajendran Jaishankar <[email protected]>
> > Signed-off-by: Rajendran Jaishankar <[email protected]>
> > Signed-off-by: Parshuram Sangle <[email protected]>
> > ---
> > drivers/cpuidle/governors/haltpoll.c | 9 +++++++--
> > 1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c
> > index 1dff3a52917d..663b7f164d20 100644
> > --- a/drivers/cpuidle/governors/haltpoll.c
> > +++ b/drivers/cpuidle/governors/haltpoll.c
> > @@ -98,10 +98,15 @@ static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns)
> > unsigned int shrink = guest_halt_poll_shrink;
> >
> > val = dev->poll_limit_ns;
> > - if (shrink == 0)
> > + if (shrink == 0) {
> > val = 0;
> > - else
> > + } else {
> > val /= shrink;
> > + /* Reset value to 0 if shrunk below grow_start */
> > + if (val < guest_halt_poll_grow_start)
> > + val = 0;
> > + }
> > +
> > trace_guest_halt_poll_ns_shrink(val, dev->poll_limit_ns);
> > dev->poll_limit_ns = val;
> > }
> > --
> > 2.17.1
> >
> >
> >
>
> Looks good.
>
> Reviewed-by: Marcelo Tosatti <[email protected]>

Applied as 6.9 (with a minor change in the subject), thanks!