* [PATCH v1] cpuidle: Add sanity check for exit latency and target residency
@ 2025-11-07 18:19 Rafael J. Wysocki
2025-11-07 18:47 ` Artem Bityutskiy
0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2025-11-07 18:19 UTC (permalink / raw)
To: Linux PM; +Cc: LKML, Daniel Lezcano, Artem Bityutskiy
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Make __cpuidle_driver_init() sanitize CPU idle states so that the exit
latency of a given state is not greater than its target residency which
would break cpuidle assumptions.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/cpuidle/driver.c | 11 +++++++++++
1 file changed, 11 insertions(+)
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -193,6 +193,16 @@ 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) {
+ s->target_residency_ns = s->exit_latency_ns;
+ s->target_residency = s->exit_latency;
+ }
}
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] cpuidle: Add sanity check for exit latency and target residency
2025-11-07 18:19 [PATCH v1] cpuidle: Add sanity check for exit latency and target residency Rafael J. Wysocki
@ 2025-11-07 18:47 ` Artem Bityutskiy
2025-11-07 18:58 ` Rafael J. Wysocki
0 siblings, 1 reply; 3+ messages in thread
From: Artem Bityutskiy @ 2025-11-07 18:47 UTC (permalink / raw)
To: Rafael J. Wysocki, Linux PM; +Cc: LKML, Daniel Lezcano
On Fri, 2025-11-07 at 19:19 +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Make __cpuidle_driver_init() sanitize CPU idle states so that the exit
> latency of a given state is not greater than its target residency which
> would break cpuidle assumptions.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/cpuidle/driver.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> --- a/drivers/cpuidle/driver.c
> +++ b/drivers/cpuidle/driver.c
> @@ -193,6 +193,16 @@ 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) {
> + s->target_residency_ns = s->exit_latency_ns;
> + s->target_residency = s->exit_latency;
> + }
I suggest to error out instead of capping it. Because as soon as you
cap it, you may end up with the target residency of the next C-state.
Just erroring out is very explicit, no surprises, and the table
provider will have to just fix the table.
Thanks, Artem.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] cpuidle: Add sanity check for exit latency and target residency
2025-11-07 18:47 ` Artem Bityutskiy
@ 2025-11-07 18:58 ` Rafael J. Wysocki
0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2025-11-07 18:58 UTC (permalink / raw)
To: Artem Bityutskiy; +Cc: Rafael J. Wysocki, Linux PM, LKML, Daniel Lezcano
On Fri, Nov 7, 2025 at 7:47 PM Artem Bityutskiy
<artem.bityutskiy@linux.intel.com> wrote:
>
> On Fri, 2025-11-07 at 19:19 +0100, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > Make __cpuidle_driver_init() sanitize CPU idle states so that the exit
> > latency of a given state is not greater than its target residency which
> > would break cpuidle assumptions.
> >
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> > drivers/cpuidle/driver.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > --- a/drivers/cpuidle/driver.c
> > +++ b/drivers/cpuidle/driver.c
> > @@ -193,6 +193,16 @@ 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) {
> > + s->target_residency_ns = s->exit_latency_ns;
> > + s->target_residency = s->exit_latency;
> > + }
>
> I suggest to error out instead of capping it. Because as soon as you
> cap it, you may end up with the target residency of the next C-state.
Good point.
> Just erroring out is very explicit, no surprises, and the table
> provider will have to just fix the table.
Alternatively, the state may just be dropped, but let's try with
failing to begin with.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-07 18:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-07 18:19 [PATCH v1] cpuidle: Add sanity check for exit latency and target residency Rafael J. Wysocki
2025-11-07 18:47 ` Artem Bityutskiy
2025-11-07 18:58 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox