From patchwork Fri Dec 14 13:57:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1878701 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 895B140E3A for ; Fri, 14 Dec 2012 13:58:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755226Ab2LNN6g (ORCPT ); Fri, 14 Dec 2012 08:58:36 -0500 Received: from mail-ee0-f46.google.com ([74.125.83.46]:36807 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756075Ab2LNN5p (ORCPT ); Fri, 14 Dec 2012 08:57:45 -0500 Received: by mail-ee0-f46.google.com with SMTP id e53so1950153eek.19 for ; Fri, 14 Dec 2012 05:57:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=K/l+skJ7+hYv3isMLyj5IeWuPXuPRYHhBqjYGB/pV04=; b=Mv2lPm4Tj29YBy0gmfD2qogIe2bmr/BRbPpPJVafS9uXdRB/xeINFva59nJ2PX8JPG 2S4O4VH/blGj6LeGt2Rmp4/q4YqSwGz9ZvWgSjyikOMkZbguWCHb2oHjD+jGW1poLgFt FHXEgBHUUESheECYSEvLTCscEaBCOha3Qv7L4nzb8ZXwiaUfD+rBL8e9xb0ZGFOy5KQ6 C2bl6B9+6F37neOgnQ4kDdVRPj5p04EpwwJI61AYMFJqBF4H7a6bUMFZ6ONoULusgfEQ +EFDSP+0O7+4/n7/ODvb4oDvzJtbqozwpxae1MN+NPfzJsqUZzzG3J8Li+ddT0w+2/v1 vVvg== Received: by 10.14.203.2 with SMTP id e2mr15387875eeo.20.1355493463786; Fri, 14 Dec 2012 05:57:43 -0800 (PST) Received: from localhost.localdomain (AToulouse-654-1-446-186.w83-205.abo.wanadoo.fr. [83.205.197.186]) by mx.google.com with ESMTPS id d3sm9599217eeo.13.2012.12.14.05.57.41 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Dec 2012 05:57:43 -0800 (PST) From: Daniel Lezcano To: rjw@sisk.pl Cc: jwerner@chromium.org, francescolavra.fl@gmail.com, linux-pm@vger.kernel.org, deepthi@linux.vnet.ibm.com, g.trinabh@gmail.com, linaro-dev@lists.linaro.org, len.brown@intel.com, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, snanda@chromium.org 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> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1355493455-30665-1-git-send-email-daniel.lezcano@linaro.org> References: <1355493455-30665-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQlx5DxbOrRbEXS4Sz5L8svE9Z5M1mrwtTGDCnBTHIcF+sd4yxyrm7k1RosXjHZtlnl8iw8C Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: 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) {