Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH v2] cpuidle: Add sanity check for exit latency and target residency
@ 2025-11-07 19:07 Rafael J. Wysocki
  2025-11-08  8:49 ` Artem Bityutskiy
  2025-11-10  7:58 ` Christian Loehle
  0 siblings, 2 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2025-11-07 19:07 UTC (permalink / raw)
  To: Linux PM, Artem Bityutskiy; +Cc: LKML, Daniel Lezcano

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

Make __cpuidle_driver_init() fail if the exit latency of one of the
driver's idle states is less than its exit latency which would break
cpuidle assumptions.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v1 -> v2: Make __cpuidle_driver_init() fail if the check is not passed (Artem).

---
 drivers/cpuidle/driver.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -152,7 +152,7 @@ static void cpuidle_setup_broadcast_time
  * __cpuidle_driver_init - initialize the driver's internal data
  * @drv: a valid pointer to a struct cpuidle_driver
  */
-static void __cpuidle_driver_init(struct cpuidle_driver *drv)
+static int __cpuidle_driver_init(struct cpuidle_driver *drv)
 {
 	int i;
 
@@ -193,7 +193,17 @@ static void __cpuidle_driver_init(struct
 			s->exit_latency_ns =  0;
 		else
 			s->exit_latency = div_u64(s->exit_latency_ns, NSEC_PER_USEC);
+
+		/*
+		 * Ensure that the exit latency of a CPU idle state does not
+		 * exceed its target residency which is assumed in cpuidle in
+		 * multiple places.
+		 */
+		if (s->exit_latency_ns > s->target_residency_ns)
+			return -EINVAL;
 	}
+
+	return 0;
 }
 
 /**
@@ -223,7 +233,9 @@ static int __cpuidle_register_driver(str
 	if (cpuidle_disabled())
 		return -ENODEV;
 
-	__cpuidle_driver_init(drv);
+	ret = __cpuidle_driver_init(drv);
+	if (ret)
+		return ret;
 
 	ret = __cpuidle_set_driver(drv);
 	if (ret)




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-10  7:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-07 19:07 [PATCH v2] cpuidle: Add sanity check for exit latency and target residency Rafael J. Wysocki
2025-11-08  8:49 ` Artem Bityutskiy
2025-11-08 11:02   ` Rafael J. Wysocki
2025-11-08 11:48     ` Rafael J. Wysocki
2025-11-08 14:07       ` Artem Bityutskiy
2025-11-10  7:58 ` Christian Loehle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox