]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cpuidle: teo: Reorder candidate state index checks
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 13 Jan 2025 18:36:57 +0000 (19:36 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 20 Jan 2025 16:16:16 +0000 (17:16 +0100)
Since constraint_idx may be 0, the candidate state index may change to 0
after assigning constraint_idx to it, so first check if it is greater
than constraint_idx (and update it if so) and then check it against 0.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Christian Loehle <christian.loehle@arm.com>
Tested-by: Aboorva Devarajan <aboorvad@linux.ibm.com>
Tested-by: Christian Loehle <christian.loehle@arm.com>
Link: https://patch.msgid.link/1907276.tdWV9SEqCh@rjwysocki.net
drivers/cpuidle/governors/teo.c

index 68af712f706478c7bbe84ee561f40c9f89bd8cd5..30e444c9c40b0b6a5a60667822397b65bf0e1470 100644 (file)
@@ -428,6 +428,14 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
                                break;
                }
        }
+
+       /*
+        * If there is a latency constraint, it may be necessary to select an
+        * idle state shallower than the current candidate one.
+        */
+       if (idx > constraint_idx)
+               idx = constraint_idx;
+
        if (!idx && prev_intercept_idx) {
                /*
                 * We have to query the sleep length here otherwise we don't
@@ -438,13 +446,6 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
                goto out_tick;
        }
 
-       /*
-        * If there is a latency constraint, it may be necessary to select an
-        * idle state shallower than the current candidate one.
-        */
-       if (idx > constraint_idx)
-               idx = constraint_idx;
-
        /*
         * Skip the timers check if state 0 is the current candidate one,
         * because an immediate non-timer wakeup is expected in that case.