[PATCH v1 1/5] cpuidle: governors: teo: Avoid selecting states with zero-size bins

From: Rafael J. Wysocki

Date: Wed Jan 14 2026 - 14:48:56 EST


From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>

If the last two enabled idle states have the same target residency which
is at least equal to TICK_NSET, teo may select the next-to-last one even
though the size of that state's bin is 0, which is confusing.

Prevent that from happening by adding a target residency check to the
relevant code path.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
---
drivers/cpuidle/governors/teo.c | 10 ++++++++++
1 file changed, 10 insertions(+)

--- a/drivers/cpuidle/governors/teo.c
+++ b/drivers/cpuidle/governors/teo.c
@@ -388,6 +388,15 @@ static int teo_select(struct cpuidle_dri
while (min_idx < idx &&
drv->states[min_idx].target_residency_ns < TICK_NSEC)
min_idx++;
+
+ /*
+ * Avoid selecting a state with a lower index, but with
+ * the same target residency as the current candidate
+ * one.
+ */
+ if (drv->states[min_idx].target_residency_ns ==
+ drv->states[idx].target_residency_ns)
+ goto constraint;
}

/*
@@ -410,6 +419,7 @@ static int teo_select(struct cpuidle_dri
}
}

+constraint:
/*
* If there is a latency constraint, it may be necessary to select an
* idle state shallower than the current candidate one.