diff mbox series

[RFC,v2,5/5] cpuidle,teo: Improve state selection

Message ID 20230802132925.824393002@infradead.org
State New
Headers show
Series cpuidle,teo: Improve TEO vs NOHZ | expand

Commit Message

Peter Zijlstra Aug. 2, 2023, 1:24 p.m. UTC
When selecting a state, stop when history tells us 66% of recent idles
were at or below our current state.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 drivers/cpuidle/governors/teo.c |    6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

--- a/drivers/cpuidle/governors/teo.c
+++ b/drivers/cpuidle/governors/teo.c
@@ -361,6 +361,7 @@  static int teo_select(struct cpuidle_dri
 	unsigned int recent_sum = 0;
 	unsigned int idx_hit_sum = 0;
 	unsigned int hit_sum = 0;
+	unsigned int thresh_sum = 0;
 	int constraint_idx = 0;
 	int idx0 = 0, idx = -1;
 	bool alt_intercepts, alt_recent;
@@ -376,6 +377,8 @@  static int teo_select(struct cpuidle_dri
 
 	duration_ns = tick_ns = tick_get_sleep_length(false);
 
+	thresh_sum = 2 * cpu_data->total / 3; /* 66% */
+
 	/*
 	 * Find the deepest idle state whose target residency does not exceed
 	 * the current sleep length and the deepest idle state not deeper than
@@ -406,6 +409,9 @@  static int teo_select(struct cpuidle_dri
 		if (s->target_residency_ns > duration_ns)
 			break;
 
+		if (intercept_sum + hit_sum > thresh_sum)
+			break;
+
 		if (s->target_residency_ns == SHORT_TICK_NSEC) {
 			/*
 			 * We hit the tick state, see if it makes sense to