From patchwork Mon Jun 26 05:38:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 9808637 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.web.codeaurora.org (Postfix) with ESMTP id 25237603F2 for ; Mon, 26 Jun 2017 05:38:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FC9628161 for ; Mon, 26 Jun 2017 05:38:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 148F428408; Mon, 26 Jun 2017 05:38:45 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 9E5A828389 for ; Mon, 26 Jun 2017 05:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750914AbdFZFif (ORCPT ); Mon, 26 Jun 2017 01:38:35 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33725 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751335AbdFZFi1 (ORCPT ); Mon, 26 Jun 2017 01:38:27 -0400 Received: by mail-pf0-f194.google.com with SMTP id e199so6005080pfh.0; Sun, 25 Jun 2017 22:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=WjAnoyCNkqsWY74zsLfrX1t3HPm42kip7EU5+u0sugM=; b=NB+6NGaxOWIYfLoQRxIdDc3HtDBF8kdqAstMKswsTSE8YbUC6pd3e8/3htnw8azOWN w5XUr6K1JcLhJnDZLQjx6/mQD6fOujoYv68XBDjVYkAPpdDXnVMZaTaxDYq6XLK1Rou0 oudG+kOgvZRMiI7ejFjLe4W4g2s4PVA/zs/QhPxPHwbI1fByDtDLygtl8teIA2XVEIj7 PSOPlS07W9fwwOL6U/lSQ8dDpJ/tAWZEoQZyEGmcfEHPlBOX5GmK9w+LgtuLw+nSKR2y wdlTlEIHBJa5Cl+64DTEucLqP3zOSNxbyON+Qoxo6FZE3u/pP4WEkvGxLNShs3agN7kk 34EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WjAnoyCNkqsWY74zsLfrX1t3HPm42kip7EU5+u0sugM=; b=T/TSZTasd7ojawT29a0cdsdYmCUs5N0LxCK9JRCvoDOEYdBqVpjjsr6Wck8hCQYzN7 dmoOnArLzuG0Sh3qOqc3/oO8IFc8d/FAoJA83yUFFLpuBDmcPvh539TkMe+aditEw5yO nMK6MrQWd9ctEYAsxIVogqtYTXWOVxgZXcgXimje6qCKKJhQ/3bEr/OUi4Vtrb1tbPQD sPLOE7xKibBz9amF1y1seX0duZd41z9uBhPn4btnxz5KrDw6cVgjkvFljzclzQ6SsAub sUU9lcV9WPKTt8ZSR8imwX17ICcW8w2+onEpxdyLCoqihmmPGDQOuUDEo+WcoBpwilbK CujA== X-Gm-Message-State: AKS2vOzmgrxFxlQlJxPpiL+Z5KT+UO99yNHfPgGx0zyIAXJ+YM4EtHtR OGuMgYVQyeq7Cw== X-Received: by 10.98.152.25 with SMTP id q25mr19438920pfd.47.1498455507106; Sun, 25 Jun 2017 22:38:27 -0700 (PDT) Received: from roar.au.ibm.com (59-102-83-48.tpgi.com.au. [59.102.83.48]) by smtp.gmail.com with ESMTPSA id t67sm2270242pfj.98.2017.06.25.22.38.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Jun 2017 22:38:25 -0700 (PDT) From: Nicholas Piggin To: "Rafael J . Wysocki" Cc: Nicholas Piggin , linux-pm@vger.kernel.org, Vaidyanathan Srinivasan , "Gautham R . Shenoy" , Daniel Lezcano , linux-kernel@vger.kernel.org Subject: [PATCH] cpuidle: menu: allow state 0 to be disabled Date: Mon, 26 Jun 2017 15:38:15 +1000 Message-Id: <20170626053815.11845-1-npiggin@gmail.com> X-Mailer: git-send-email 2.11.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 The menu driver does not allow state0 to be disabled completely. If it is disabled but other enabled states don't meet latency requirements, it is still used. Fix this by starting with the first enabled idle state. Fall back to state 0 if no idle states are enabled (arguably this should be -EINVAL if it is attempted, but this is the minimal fix). Acked-by: Gautham R. Shenoy Signed-off-by: Nicholas Piggin --- Hi Rafael, This patch is helpful when measuring power draw of polling, latency cost of idle states, etc. Please consider merging if you agree. Thanks, Nick drivers/cpuidle/governors/menu.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index b2330fd69e34..61b64c2b2cb8 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -286,6 +286,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) struct device *device = get_cpu_device(dev->cpu); int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY); int i; + int first_idx; + int idx; unsigned int interactivity_req; unsigned int expected_interval; unsigned long nr_iowaiters, cpu_load; @@ -335,11 +337,11 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) if (data->next_timer_us > polling_threshold && latency_req > s->exit_latency && !s->disabled && !dev->states_usage[CPUIDLE_DRIVER_STATE_START].disable) - data->last_state_idx = CPUIDLE_DRIVER_STATE_START; + first_idx = CPUIDLE_DRIVER_STATE_START; else - data->last_state_idx = CPUIDLE_DRIVER_STATE_START - 1; + first_idx = CPUIDLE_DRIVER_STATE_START - 1; } else { - data->last_state_idx = CPUIDLE_DRIVER_STATE_START; + first_idx = 0; } /* @@ -359,20 +361,28 @@ 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 = data->last_state_idx + 1; i < drv->state_count; i++) { + idx = -1; + for (i = first_idx; 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 > data->predicted_us) break; if (s->exit_latency > latency_req) break; - data->last_state_idx = i; + idx = i; } + if (idx == -1) + idx = 0; /* No states enabled. Must use 0. */ + + data->last_state_idx = idx; + return data->last_state_idx; }