From patchwork Tue Oct 2 21:44:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 10624097 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A635112B for ; Tue, 2 Oct 2018 21:51:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BAE020CCF for ; Tue, 2 Oct 2018 21:51:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E8EB2846D; Tue, 2 Oct 2018 21:51:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0714620CCF for ; Tue, 2 Oct 2018 21:51:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728324AbeJCEgm (ORCPT ); Wed, 3 Oct 2018 00:36:42 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:55625 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728099AbeJCEgk (ORCPT ); Wed, 3 Oct 2018 00:36:40 -0400 Received: from 79.184.253.194.ipv4.supernova.orange.pl (79.184.253.194) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.148) id 14404f7a6bc23072; Tue, 2 Oct 2018 23:51:12 +0200 From: "Rafael J. Wysocki" To: Linux PM Cc: Peter Zijlstra , LKML , Daniel Lezcano Subject: [PATCH 3/6] cpuidle: menu: Get rid of first_idx from menu_select() Date: Tue, 02 Oct 2018 23:44:06 +0200 Message-ID: <4130376.2FFt7p4687@aspire.rjw.lan> In-Reply-To: <3510260.hvypppS8Bs@aspire.rjw.lan> References: <3510260.hvypppS8Bs@aspire.rjw.lan> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafael J. Wysocki Rearrange the code in menu_select() so that the loop over idle states always starts from 0 and get rid of the first_idx variable. While at it, add two empty lines to separate conditional statements one another. No intentional behavior changes. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/cpuidle/governors/menu.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) Index: linux-pm/drivers/cpuidle/governors/menu.c =================================================================== --- linux-pm.orig/drivers/cpuidle/governors/menu.c +++ linux-pm/drivers/cpuidle/governors/menu.c @@ -285,7 +285,6 @@ static int menu_select(struct cpuidle_dr struct menu_device *data = this_cpu_ptr(&menu_devices); int latency_req = cpuidle_governor_latency_req(dev->cpu); int i; - int first_idx; int idx; unsigned int interactivity_req; unsigned int expected_interval; @@ -348,36 +347,33 @@ static int menu_select(struct cpuidle_dr latency_req = interactivity_req; } - first_idx = 0; - if (drv->states[0].flags & CPUIDLE_FLAG_POLLING) { - struct cpuidle_state *s = &drv->states[1]; - unsigned int polling_threshold; - - /* - * Default to a physical idle state, not to busy polling, unless - * a timer is going to trigger really really soon. - */ - polling_threshold = max_t(unsigned int, 20, s->target_residency); - if (data->next_timer_us > polling_threshold && - latency_req > s->exit_latency && !s->disabled && - !dev->states_usage[1].disable) - first_idx = 1; - } - /* * Find the idle state with the lowest power while satisfying * our constraints. */ idx = -1; - for (i = first_idx; i < drv->state_count; i++) { + for (i = 0; i < drv->state_count; i++) { struct cpuidle_state *s = &drv->states[i]; struct cpuidle_state_usage *su = &dev->states_usage[i]; if (s->disabled || su->disable) continue; + if (idx == -1) idx = i; /* first enabled state */ + if (s->target_residency > predicted_us) { + /* + * Use a physical idle state, not busy polling, unless + * a timer is going to trigger really really soon. + */ + if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && + i == idx + 1 && latency_req > s->exit_latency && + data->next_timer_us > max_t(unsigned int, 20, + s->target_residency)) { + idx = i; + break; + } if (predicted_us < TICK_USEC) break;