]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
cpuidle: teo: Skip sleep length computation for low latency constraints
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 20 Jan 2025 16:08:50 +0000 (17:08 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 20 Jan 2025 16:19:53 +0000 (17:19 +0100)
If the idle state exit latency constraint is sufficiently low, it
is better to avoid the additional latency related to calling
tick_nohz_get_sleep_length().  It is also not necessary to compute
the sleep length in that case because shallow idle state selection
will be forced then regardless of the recent wakeup history.

Accordingly, skip the sleep length computation and subsequent
checks of the exit latency constraint is low enough.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Christian Loehle <christian.loehle@arm.com>
Link: https://patch.msgid.link/6122398.lOV4Wx5bFT@rjwysocki.net
drivers/cpuidle/governors/teo.c

index c232c95ca7faa695885720854bcbdc822f2b3920..8fe5e1b47ef9082d69584edea1b479023c822009 100644 (file)
 
 #include "gov.h"
 
+/*
+ * Idle state exit latency threshold used for deciding whether or not to check
+ * the time till the closest expected timer event.
+ */
+#define LATENCY_THRESHOLD_NS   (RESIDENCY_THRESHOLD_NS / 2)
+
 /*
  * The PULSE value is added to metrics when they grow and the DECAY_SHIFT value
  * is used for decreasing metrics on a regular basis.
@@ -432,9 +438,14 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
         * duration falls into that range in the majority of cases, assume
         * non-timer wakeups to be dominant and skip updating the sleep length
         * to reduce latency.
+        *
+        * Also, if the latency constraint is sufficiently low, it will force
+        * shallow idle states regardless of the wakeup type, so the sleep
+        * length need not be known in that case.
         */
        if ((!idx || drv->states[idx].target_residency_ns < RESIDENCY_THRESHOLD_NS) &&
-           2 * cpu_data->short_idles >= cpu_data->total)
+           (2 * cpu_data->short_idles >= cpu_data->total ||
+            latency_req < LATENCY_THRESHOLD_NS))
                goto out_tick;
 
        duration_ns = tick_nohz_get_sleep_length(&delta_tick);