From patchwork Sun Aug 12 16:09:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 10563683 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 CF277139A for ; Sun, 12 Aug 2018 16:10:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF68829466 for ; Sun, 12 Aug 2018 16:10:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B31DE29469; Sun, 12 Aug 2018 16:10:10 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 44EAF29466 for ; Sun, 12 Aug 2018 16:10:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728307AbeHLSsf (ORCPT ); Sun, 12 Aug 2018 14:48:35 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43209 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727747AbeHLSsf (ORCPT ); Sun, 12 Aug 2018 14:48:35 -0400 Received: by mail-wr1-f67.google.com with SMTP id b15-v6so12210482wrv.10 for ; Sun, 12 Aug 2018 09:10:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v4mRTz9lovuOcDxlp6+85Pwdka+3yYASS/8Q6JA5+Fc=; b=WqWRK+EhooOB8zO22jSGNKLlVuQnJLQ/RdvK4jHkVx663qtYtx2pnnwr0ncjiKn4UT E8tsB8HHZY+h5E/9abCtSeoATObCAafU+7IGV8372NNjcD+zy+GnTZL0StXLKcEofsaQ mSgTXhXyW2pnU+NyrCaJL3n3vMei/pkXGIsmE= 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:in-reply-to :references; bh=v4mRTz9lovuOcDxlp6+85Pwdka+3yYASS/8Q6JA5+Fc=; b=A33tYSQmW2gfSTv/WidN5qOkDrQkvV3t3GjPnsyCBTU6P4oWHXVJoD2i2B5jGFkr9i O1/Br06Rx8liV5D+JmrCzxFYWS923b883euurnYAlXSeRI8N6blTVRX/HQHe6FqaVBxz 5moWsAFZP8dUES9Td1wGc8cEDFLXn1NOTmKpV115QT5/EoGrIRoMUHpZoPiBs85Ye8wI mdjLWt29DQ7Nj1VFNBOb+F/IbJNgGrPPpvZ++Hp3j87slFlC4RykTrCmRlMWgsRmLSMW Wil3Q2PX91zg9hGmuC49TcAlcDHiKPVzPNlc330Mqn9j9T+05jTXjSMjB3k3iCyiSOja Fxyg== X-Gm-Message-State: AOUpUlETWn7VfTSgwOxgG/pEExiz24nsLx+94eaeI8m+WX+y3tkO10Wf +XOxvNA8pbMerqeYWUN66n5IpqTj8LWh0g== X-Google-Smtp-Source: AA+uWPwWAsKnnJ1jdYBxN7Nmjypuk1Jn2ShEhyFcS1RABpYB+XM73Jn1OFvN2KU0+X9WaiJk2G5bnQ== X-Received: by 2002:adf:9261:: with SMTP id 88-v6mr8159181wrj.62.1534090203670; Sun, 12 Aug 2018 09:10:03 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id t6-v6sm7437369wmf.8.2018.08.12.09.10.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Aug 2018 09:10:02 -0700 (PDT) From: Leo Yan To: "Rafael J. Wysocki" , "Peter Zijlstra (Intel)" , Daniel Lezcano , Vincent Guittot , Ramesh Thomas , linux-kernel@vger.kernel.org, Linux PM Cc: Leo Yan Subject: [PATCH v1 3/5] cpuidle: menu: Provide menu_decide_stopping_tick() Date: Mon, 13 Aug 2018 00:09:29 +0800 Message-Id: <1534090171-14464-4-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534090171-14464-1-git-send-email-leo.yan@linaro.org> References: <1534090171-14464-1-git-send-email-leo.yan@linaro.org> 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 This patch is only for code refactoring and without functional change. It introduces a new function menu_decide_stopping_tick(); we can use this function to focus on making stopping tick decision. With moving out stopping tick decision code, it lets the below piece code is simplized only for the idle state calibration and thus save one indent level in the loop. Signed-off-by: Leo Yan --- drivers/cpuidle/governors/menu.c | 76 ++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 83618ab..4f02207 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -276,6 +276,37 @@ static unsigned int get_typical_interval(struct menu_device *data) } /** + * menu_decide_stopping_tick - decides if need to stopping tick + * @drv: cpuidle driver containing state data + * @data: menu_device structure pointer + * @idx: the candidate idle state index + */ +static bool menu_decide_stopping_tick(struct cpuidle_driver *drv, + struct menu_device *data, int idx) +{ + /* + * If the tick has been stopped yet, force to stop it afterwards and + * don't give chance to set *stop_tick to false. + */ + if (tick_nohz_tick_stopped()) + return true; + + /* Don't stop the tick if the selected state is a polling one */ + if (drv->states[idx].flags & CPUIDLE_FLAG_POLLING) + return false; + + /* + * Don't stop the tick if the prediction is shorter than the + * tick period length. + */ + if (data->predicted_us < TICK_USEC) + return false; + + /* Otherwise, let's stop the tick at this time. */ + return true; +} + +/** * menu_select - selects the next idle state to enter * @drv: cpuidle driver containing state data * @dev: the CPU @@ -396,33 +427,26 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, if (idx == -1) idx = 0; /* No states enabled. Must use 0. */ - /* - * Don't stop the tick if the selected state is a polling one or if the - * expected idle duration is shorter than the tick period length. - */ - if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || - data->predicted_us < TICK_USEC) && !tick_nohz_tick_stopped()) { - - *stop_tick = false; + *stop_tick = menu_decide_stopping_tick(drv, data, idx); - if (idx > 0 && - drv->states[idx].target_residency > data->tick_delta_us) { - /* - * The tick is not going to be stopped and the target - * residency of the state to be returned is not within - * the time until the next timer event including the - * tick, so try to correct that. - */ - for (i = idx - 1; i >= 0; i--) { - if (drv->states[i].disabled || - dev->states_usage[i].disable) - continue; - - idx = i; - if (drv->states[i].target_residency <= - data->tick_delta_us) - break; - } + /* Calibrate the idle state according to the tick event. */ + if (!*stop_tick && idx > 0 && + drv->states[idx].target_residency > data->tick_delta_us) { + /* + * The tick is not going to be stopped and the target + * residency of the state to be returned is not within + * the time until the next timer event including the + * tick, so try to correct that. + */ + for (i = idx - 1; i >= 0; i--) { + if (drv->states[i].disabled || + dev->states_usage[i].disable) + continue; + + idx = i; + if (drv->states[i].target_residency <= + data->tick_delta_us) + break; } }