cpuidle/governors: Fix logic in selection of idle states
PATCH v3 1/1 cpuidle/governors: Fix logic in selection of idle states
The cpuidle governors today are not handling scenarios where no idle state can be chosen. Such scenarios coud arise if the user has disabled all the idle states at runtime or the latency requirement from the cpus is very strict.
The menu governor returns 0th index of the idle state table when no other idle state is suitable. This is even when the idle state corresponding to this index is disabled or the latency requirement is strict and the exit_latency of the lowest idle state is also not acceptable. Hence this patch fixes this logic in the menu governor by defaulting to an idle state index of -1 unless any other state is suitable.
The ladder governor needs a few more fixes in addition to that required in the menu governor. When the ladder governor decides to demote the idle state of a CPU, it does not check if the lower idle states are enabled. Add this logic in addition to the logic where it chooses an index of -1 if it can neither promote or demote the idle state of a cpu nor can it choose the current idle state.
The cpuidle_idle_call() will return back if the governor decides upon not entering any idle state. However it cannot return an error code because all archs have the logic today that if the call to cpuidle_idle_call() fails, it means that the cpuidle driver failed to *function*; for instance due to errors during registration. As a result they end up deciding upon a default idle state on their own, which could very well be a deep idle state. This is incorrect in cases where no idle state is suitable.
Besides for the scenario that this patch is addressing, the call actually succeeds. Its just that no idle state is thought to be suitable by the governors. Under such a circumstance return success code without entering any idle state.
The consequence of this patch, on the menu governor is that as long as a valid idle state cannot be chosen, the cpuidle statistics that this governor uses to predict the next idle state remain untouched from the last valid idle state. This is because an idle state is not even being predicted in this path, hence there is no point correcting the prediction either.
Changes from V1:https://lkml.org/lkml/2014/1/14/26
1. Change the return code to success from -EINVAL due to the reason mentioned in the changelog.
2. Add logic that the patch is addressing in the ladder governor as well.
3. Added relevant comments and removed redundant logic as suggested in the above thread.
Changes from V2:lkml.org/lkml/2014/1/16/617
1. Enable interrupts when exiting from cpuidle_idle_call() in the case when no idle state was deemed suitable by the governor.
---
drivers/cpuidle/cpuidle.c | 2 - drivers/cpuidle/governors/ladder.c | 101 ++++++++++++++++++++++++++---------- drivers/cpuidle/governors/menu.c | 7 +- 3 files changed, 78 insertions(+), 32 deletions(-)
drivers/cpuidle/cpuidle.c +1 -1
@@ -131,7 +131,7 @@ int cpuidle_idle_call(void)/* ask the governor for the next state */ next_state = cpuidle_curr_governor->select (drv, dev); -if (need_resched ()) { +if (need_resched () || (next_state <0 )) { dev->last_residency =0 ;/* give the governor an opportunity to reflect on the outcome */ if (cpuidle_curr_governor->reflect)
drivers/cpuidle/governors/ladder.c +73 -28
141 lines not on this page · raw message
drivers/cpuidle/governors/menu.c +4 -3
@@ -297,12 +297,12 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) data->needs_update =0 ; } - data->last_state_idx =0 ; + data->last_state_idx =-1 ; data->exit_us =0 ;/* Special case when user has set very strict latency requirement */ if (unlikely (latency_req ==0 )) -return 0 ; +return data->last_state_idx;/* determine the expected residency time, round up */ t =ktime_to_timespec (tick_nohz_get_sleep_length ());
@@ -368,7 +368,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)/** * menu_reflect - records that data structures need update * @dev: the CPU -* @index: the index of actual entered state +* @index: the index of actual entered state or -1 if no idle state is +* suitable. * * NOTE: it's important to be fast here because this operation will add to * the overall exit latency.
Quoted 10 lines · Preeti U Murthy
The cpuidle governors today are not handling scenarios where no idle state can be chosen. Such scenarios coud arise if the user has disabled all the idle states at runtime or the latency requirement from the cpus is very strict.
The menu governor returns 0th index of the idle state table when no other idle state is suitable. This is even when the idle state corresponding to this index is disabled or the latency requirement is strict and the
exit_latencyof the lowest idle state is also not acceptable. Hence this patch fixes this logic in the menu governor by defaulting to an idle state index
of -1 unless any other state is suitable.
state 0 is defined as polling, and polling ALWAYS should be ok
Hi Arjan,
Quoted 17 lines · Arjan van de Ven
Quoted 6 lines · Preeti U Murthy
The cpuidle governors today are not handling scenarios where no idle state
can be chosen. Such scenarios coud arise if the user has disabled all the idle states at runtime or the latency requirement from the cpus is very strict.Quoted 9 lines
The menu governor returns 0th index of the idle state table when no other idle state is suitable. This is even when the idle state corresponding to this
index is disabled or the latency requirement is strict and theexit_latency
of the lowest idle state is also not acceptable. Hence this patch fixes this logic in the menu governor by defaulting to an idle state index
of -1 unless any other state is suitable.
Quoted 1 line
state 0 is defined as polling, and polling ALWAYS should be ok
Hmm.. you are right. This is convincing. There is no need for this patch.
Thanks
Regards
Preeti U Murthy