diff mbox series

[3/3] cpuidle: teo: Don't count non-existent intercepts

Message ID 20240628095955.34096-4-christian.loehle@arm.com (mailing list archive)
State Superseded, archived
Headers show
Series cpuidle: teo: Fixing utilization and intercept logic | expand

Commit Message

Christian Loehle June 28, 2024, 9:59 a.m. UTC
When bailing out early, teo will not query the sleep length anymore
since commit 6da8f9ba5a87 ("cpuidle: teo:
Skip tick_nohz_get_sleep_length() call in some cases") with an
expected sleep_length_ns value of KTIME_MAX.
This lead to state0 accumulating lots of 'intercepts' because
the actually measured sleep length was < KTIME_MAX, so query the sleep
length instead for teo to recognize if it still is in an
intercept-likely scenario without alternating between the two modes.

Fundamentally we can only do one of the two:
1. Skip sleep_length_ns query when we think intercept is likely
2. Have accurate data if sleep_length_ns is actually intercepted when
we believe it is currently intercepted.

Previously teo did the former while this patch chooses the latter as
the additional time it takes to query the sleep length was found to be
negligible and the variants of option 1 (count all unknowns as misses
or count all unknown as hits) had significant regressions (as misses
had lots of too shallow idle state selections and as hits had terrible
performance in intercept-heavy workloads).

Fixes: 6da8f9ba5a87 ("cpuidle: teo: Skip tick_nohz_get_sleep_length() call in some cases")
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
---
v3:
Drop counting KTIME_MAX as hit and reword commit accordingly

 drivers/cpuidle/governors/teo.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

--
2.34.1

Comments

Rafael J. Wysocki June 28, 2024, 6:48 p.m. UTC | #1
On Fri, Jun 28, 2024 at 12:02 PM Christian Loehle
<christian.loehle@arm.com> wrote:
>
> When bailing out early, teo will not query the sleep length anymore
> since commit 6da8f9ba5a87 ("cpuidle: teo:
> Skip tick_nohz_get_sleep_length() call in some cases") with an
> expected sleep_length_ns value of KTIME_MAX.
> This lead to state0 accumulating lots of 'intercepts' because
> the actually measured sleep length was < KTIME_MAX, so query the sleep
> length instead for teo to recognize if it still is in an
> intercept-likely scenario without alternating between the two modes.
>
> Fundamentally we can only do one of the two:
> 1. Skip sleep_length_ns query when we think intercept is likely
> 2. Have accurate data if sleep_length_ns is actually intercepted when
> we believe it is currently intercepted.
>
> Previously teo did the former while this patch chooses the latter as
> the additional time it takes to query the sleep length was found to be
> negligible and the variants of option 1 (count all unknowns as misses
> or count all unknown as hits) had significant regressions (as misses
> had lots of too shallow idle state selections and as hits had terrible
> performance in intercept-heavy workloads).
>
> Fixes: 6da8f9ba5a87 ("cpuidle: teo: Skip tick_nohz_get_sleep_length() call in some cases")
> Signed-off-by: Christian Loehle <christian.loehle@arm.com>
> ---
> v3:
> Drop counting KTIME_MAX as hit and reword commit accordingly
>
>  drivers/cpuidle/governors/teo.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c
> index 200a3598cbcf..c2d73507d23b 100644
> --- a/drivers/cpuidle/governors/teo.c
> +++ b/drivers/cpuidle/governors/teo.c
> @@ -287,6 +287,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
>         unsigned int hit_sum = 0;
>         int constraint_idx = 0;
>         int idx0 = 0, idx = -1;
> +       int prev_intercept_idx;
>         s64 duration_ns;
>         int i;
>
> @@ -364,6 +365,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
>          * all of the deeper states a shallower idle state is likely to be a
>          * better choice.
>          */
> +       prev_intercept_idx = idx;
>         if (2 * idx_intercept_sum > cpu_data->total - idx_hit_sum) {
>                 int first_suitable_idx = idx;
>
> @@ -415,6 +417,14 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
>                         first_suitable_idx = i;
>                 }
>         }
> +       if (!idx && prev_intercept_idx) {
> +               /*
> +                * We have to query the sleep length here otherwise we don't
> +                * know after wakeup if our guess was correct.
> +                */
> +               duration_ns = tick_nohz_get_sleep_length(&delta_tick);
> +               cpu_data->sleep_length_ns = duration_ns;

This is going to select the shallowest state anyway AFAICS, so is it
useful to check constraint_idx in this case?

> +       }
>
>         /*
>          * If there is a latency constraint, it may be necessary to select an
> --
diff mbox series

Patch

diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c
index 200a3598cbcf..c2d73507d23b 100644
--- a/drivers/cpuidle/governors/teo.c
+++ b/drivers/cpuidle/governors/teo.c
@@ -287,6 +287,7 @@  static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 	unsigned int hit_sum = 0;
 	int constraint_idx = 0;
 	int idx0 = 0, idx = -1;
+	int prev_intercept_idx;
 	s64 duration_ns;
 	int i;

@@ -364,6 +365,7 @@  static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 	 * all of the deeper states a shallower idle state is likely to be a
 	 * better choice.
 	 */
+	prev_intercept_idx = idx;
 	if (2 * idx_intercept_sum > cpu_data->total - idx_hit_sum) {
 		int first_suitable_idx = idx;

@@ -415,6 +417,14 @@  static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 			first_suitable_idx = i;
 		}
 	}
+	if (!idx && prev_intercept_idx) {
+		/*
+		 * We have to query the sleep length here otherwise we don't
+		 * know after wakeup if our guess was correct.
+		 */
+		duration_ns = tick_nohz_get_sleep_length(&delta_tick);
+		cpu_data->sleep_length_ns = duration_ns;
+	}

 	/*
 	 * If there is a latency constraint, it may be necessary to select an