[PATCH v1 1/2] cpuidle: governors: teo: Fix tick_intercepts handling in teo_update()

Rafael J. Wysocki posted 1 patch 2 months, 3 weeks ago
drivers/cpuidle/governors/teo.c |    2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v1 1/2] cpuidle: governors: teo: Fix tick_intercepts handling in teo_update()
Posted by Rafael J. Wysocki 2 months, 3 weeks ago
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The condition deciding whether or not to increase cpu_data->tick_intercepts
in teo_update() is reverse, so fix it.

Fixes: d619b5cc6780 ("cpuidle: teo: Simplify counting events used for tick management")
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

I'm planning to apply this for 6.19 on top of

https://lore.kernel.org/linux-pm/6228387.lOV4Wx5bFT@rafael.j.wysocki/

because that patch (indirectly) depends on commit d619b5cc6780.

---
 drivers/cpuidle/governors/teo.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/cpuidle/governors/teo.c
+++ b/drivers/cpuidle/governors/teo.c
@@ -251,7 +251,7 @@ static void teo_update(struct cpuidle_dr
 		cpu_data->state_bins[idx_timer].hits += PULSE;
 	} else {
 		cpu_data->state_bins[idx_duration].intercepts += PULSE;
-		if (TICK_NSEC <= measured_ns)
+		if (measured_ns <= TICK_NSEC)
 			cpu_data->tick_intercepts += PULSE;
 	}
 }
Re: [PATCH v1 1/2] cpuidle: governors: teo: Fix tick_intercepts handling in teo_update()
Posted by Christian Loehle 2 months, 3 weeks ago
On 11/16/25 12:34, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> The condition deciding whether or not to increase cpu_data->tick_intercepts
> in teo_update() is reverse, so fix it.
> 
> Fixes: d619b5cc6780 ("cpuidle: teo: Simplify counting events used for tick management")
> Cc: All applicable <stable@vger.kernel.org>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> 
> I'm planning to apply this for 6.19 on top of
> 
> https://lore.kernel.org/linux-pm/6228387.lOV4Wx5bFT@rafael.j.wysocki/
> 
> because that patch (indirectly) depends on commit d619b5cc6780.
> 
> ---
>  drivers/cpuidle/governors/teo.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/drivers/cpuidle/governors/teo.c
> +++ b/drivers/cpuidle/governors/teo.c
> @@ -251,7 +251,7 @@ static void teo_update(struct cpuidle_dr
>  		cpu_data->state_bins[idx_timer].hits += PULSE;
>  	} else {
>  		cpu_data->state_bins[idx_duration].intercepts += PULSE;
> -		if (TICK_NSEC <= measured_ns)
> +		if (measured_ns <= TICK_NSEC)

nit: Why <= instead of <?
I guess it really doesn't matter with measured_ns only being a rough approximation
with an error in the order of wakeup-latency.

Reviewed-by:
Christian Loehle <christian.loehle@arm.com>

Let me go write some tests for all these edge cases :/

IIRC Aboorva's power systems have no idle state deeper than TICK_NSEC, so
this might make a big difference here, hence CCed.
Re: [PATCH v1 1/2] cpuidle: governors: teo: Fix tick_intercepts handling in teo_update()
Posted by Rafael J. Wysocki 2 months, 3 weeks ago
On Mon, Nov 17, 2025 at 10:06 AM Christian Loehle
<christian.loehle@arm.com> wrote:
>
> On 11/16/25 12:34, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > The condition deciding whether or not to increase cpu_data->tick_intercepts
> > in teo_update() is reverse, so fix it.
> >
> > Fixes: d619b5cc6780 ("cpuidle: teo: Simplify counting events used for tick management")
> > Cc: All applicable <stable@vger.kernel.org>
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> >
> > I'm planning to apply this for 6.19 on top of
> >
> > https://lore.kernel.org/linux-pm/6228387.lOV4Wx5bFT@rafael.j.wysocki/
> >
> > because that patch (indirectly) depends on commit d619b5cc6780.
> >
> > ---
> >  drivers/cpuidle/governors/teo.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > --- a/drivers/cpuidle/governors/teo.c
> > +++ b/drivers/cpuidle/governors/teo.c
> > @@ -251,7 +251,7 @@ static void teo_update(struct cpuidle_dr
> >               cpu_data->state_bins[idx_timer].hits += PULSE;
> >       } else {
> >               cpu_data->state_bins[idx_duration].intercepts += PULSE;
> > -             if (TICK_NSEC <= measured_ns)
> > +             if (measured_ns <= TICK_NSEC)
>
> nit: Why <= instead of <?

Because it was <= before.

> I guess it really doesn't matter with measured_ns only being a rough approximation
> with an error in the order of wakeup-latency.

Right and moreover, TICK_NSEC is an upper bound for tick wakeups, they
occur earlier as a rule.

> Reviewed-by:
> Christian Loehle <christian.loehle@arm.com>
>
> Let me go write some tests for all these edge cases :/
>
> IIRC Aboorva's power systems have no idle state deeper than TICK_NSEC, so
> this might make a big difference here, hence CCed.

Like x86 systems with HZ < 1000 which are the majority nowadays AFAICS.

Thanks!