drivers/cpuidle/governors/menu.c | 72 ++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 35 deletions(-)
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reduce the indentation level in the main loop of menu_select() by
rearranging some checks and assignments in it.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/cpuidle/governors/menu.c | 72 ++++++++++++++++++++-------------------
1 file changed, 37 insertions(+), 35 deletions(-)
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -314,45 +314,47 @@
if (s->exit_latency_ns > latency_req)
break;
- if (s->target_residency_ns > predicted_ns) {
- /*
- * Use a physical idle state, not busy polling, unless
- * a timer is going to trigger soon enough.
- */
- if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) &&
- s->target_residency_ns <= data->next_timer_ns) {
- predicted_ns = s->target_residency_ns;
- idx = i;
- break;
- }
- if (predicted_ns < TICK_NSEC)
- break;
-
- if (!tick_nohz_tick_stopped()) {
- /*
- * If the state selected so far is shallow,
- * waking up early won't hurt, so retain the
- * tick in that case and let the governor run
- * again in the next iteration of the loop.
- */
- predicted_ns = drv->states[idx].target_residency_ns;
- break;
- }
+ if (s->target_residency_ns <= predicted_ns) {
+ idx = i;
+ continue;
+ }
+
+ /*
+ * Use a physical idle state, not busy polling, unless a timer
+ * is going to trigger soon enough.
+ */
+ if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) &&
+ s->target_residency_ns <= data->next_timer_ns) {
+ predicted_ns = s->target_residency_ns;
+ idx = i;
+ break;
+ }
+ if (predicted_ns < TICK_NSEC)
+ break;
+
+ if (!tick_nohz_tick_stopped()) {
/*
- * If the state selected so far is shallow and this
- * state's target residency matches the time till the
- * closest timer event, select this one to avoid getting
- * stuck in the shallow one for too long.
+ * If the state selected so far is shallow, waking up
+ * early won't hurt, so retain the tick in that case and
+ * let the governor run again in the next iteration of
+ * the idle loop.
*/
- if (drv->states[idx].target_residency_ns < TICK_NSEC &&
- s->target_residency_ns <= delta_tick)
- idx = i;
-
- return idx;
+ predicted_ns = drv->states[idx].target_residency_ns;
+ break;
}
- idx = i;
+ /*
+ * If the state selected so far is shallow and this state's
+ * target residency matches the time till the closest timer
+ * event, select this one to avoid getting stuck in the shallow
+ * one for too long.
+ */
+ if (drv->states[idx].target_residency_ns < TICK_NSEC &&
+ s->target_residency_ns <= delta_tick)
+ idx = i;
+
+ return idx;
}
if (idx == -1)
Le Wed, Aug 13, 2025 at 12:26:35PM +0200, Rafael J. Wysocki a écrit : > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > Reduce the indentation level in the main loop of menu_select() by > rearranging some checks and assignments in it. > > No intentional functional impact. > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Frederic Weisbecker <frederic@kernel.org> -- Frederic Weisbecker SUSE Labs
On 8/13/25 11:26, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > Reduce the indentation level in the main loop of menu_select() by > rearranging some checks and assignments in it. > > No intentional functional impact. > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Christian Loehle <christian.loehle@arm.com> > --- > drivers/cpuidle/governors/menu.c | 72 ++++++++++++++++++++------------------- > 1 file changed, 37 insertions(+), 35 deletions(-) > > --- a/drivers/cpuidle/governors/menu.c > +++ b/drivers/cpuidle/governors/menu.c > @@ -314,45 +314,47 @@ > if (s->exit_latency_ns > latency_req) > break; > > - if (s->target_residency_ns > predicted_ns) { > - /* > - * Use a physical idle state, not busy polling, unless > - * a timer is going to trigger soon enough. > - */ > - if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && > - s->target_residency_ns <= data->next_timer_ns) { > - predicted_ns = s->target_residency_ns; > - idx = i; > - break; > - } > - if (predicted_ns < TICK_NSEC) > - break; > - > - if (!tick_nohz_tick_stopped()) { > - /* > - * If the state selected so far is shallow, > - * waking up early won't hurt, so retain the > - * tick in that case and let the governor run > - * again in the next iteration of the loop. > - */ > - predicted_ns = drv->states[idx].target_residency_ns; > - break; > - } > + if (s->target_residency_ns <= predicted_ns) { > + idx = i; > + continue; > + } > + > + /* > + * Use a physical idle state, not busy polling, unless a timer > + * is going to trigger soon enough. > + */ > + if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && > + s->target_residency_ns <= data->next_timer_ns) { > + predicted_ns = s->target_residency_ns; > + idx = i; > + break; > + } > > + if (predicted_ns < TICK_NSEC) > + break; > + > + if (!tick_nohz_tick_stopped()) { > /* > - * If the state selected so far is shallow and this > - * state's target residency matches the time till the > - * closest timer event, select this one to avoid getting > - * stuck in the shallow one for too long. > + * If the state selected so far is shallow, waking up > + * early won't hurt, so retain the tick in that case and > + * let the governor run again in the next iteration of > + * the idle loop. > */ > - if (drv->states[idx].target_residency_ns < TICK_NSEC && > - s->target_residency_ns <= delta_tick) > - idx = i; > - > - return idx; > + predicted_ns = drv->states[idx].target_residency_ns; > + break; > } > > - idx = i; > + /* > + * If the state selected so far is shallow and this state's > + * target residency matches the time till the closest timer > + * event, select this one to avoid getting stuck in the shallow > + * one for too long. > + */ > + if (drv->states[idx].target_residency_ns < TICK_NSEC && > + s->target_residency_ns <= delta_tick) > + idx = i; > + > + return idx; > } > > if (idx == -1) > > >
© 2016 - 2025 Red Hat, Inc.