From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Lezcano Subject: [PATCH 2/2][V2] cpuidle - optimize the select function for the 'menu' governor Date: Fri, 14 Dec 2012 14:57:35 +0100 Message-ID: <1355493455-30665-3-git-send-email-daniel.lezcano@linaro.org> References: <1355493455-30665-1-git-send-email-daniel.lezcano@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1355493455-30665-1-git-send-email-daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linaro-dev-bounces-cunTk1MwBs8s++Sfvej+rw@public.gmane.org Errors-To: linaro-dev-bounces-cunTk1MwBs8s++Sfvej+rw@public.gmane.org To: rjw-KKrjLPT3xs0@public.gmane.org Cc: deepthi-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org, g.trinabh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, linaro-dev-cunTk1MwBs8s++Sfvej+rw@public.gmane.org, len.brown-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org, linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, jwerner-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org, akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org, snanda-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org List-Id: linux-pm@vger.kernel.org As the power is backward sorted in the states array and we are looking for the state consuming the little power as possible, instead of looking from the beginning of the array, we look from the end. That should save us some iterations in the loop each time we select a state at idle time. Signed-off-by: Daniel Lezcano --- drivers/cpuidle/governors/menu.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index fe343a0..05b8998 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -367,24 +367,24 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) * Find the idle state with the lowest power while satisfying * our constraints. */ - for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) { + for (i = drv->state_count - 1; i >= CPUIDLE_DRIVER_STATE_START; i--) { struct cpuidle_state *s = &drv->states[i]; struct cpuidle_state_usage *su = &dev->states_usage[i]; if (s->disabled || su->disable) continue; - if (s->target_residency > data->predicted_us) { - low_predicted = 1; - continue; - } if (s->exit_latency > latency_req) continue; + if (s->target_residency > data->predicted_us) + continue; if (s->exit_latency * multiplier > data->predicted_us) continue; + low_predicted = i - CPUIDLE_DRIVER_STATE_START; data->last_state_idx = i; data->exit_us = s->exit_latency; - } + break; + } /* not deepest C-state chosen for low predicted residency */ if (low_predicted) { -- 1.7.5.4