Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4834117imm; Tue, 21 Aug 2018 01:36:37 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxKidkCMye9fWmm1EMy/WgB6J5utG7vXd1Gk1/4d+Qk6CDnrEV2y8LcldIpKkUUwvnTmH05 X-Received: by 2002:a62:4ece:: with SMTP id c197-v6mr35484715pfb.240.1534840597743; Tue, 21 Aug 2018 01:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534840597; cv=none; d=google.com; s=arc-20160816; b=WE5aWq06DHzU0EKXYxR5nlVdx1RsFIuvgeSC4A2ZgzzwIv1TFX5T0wtnyflghe4gCG R7JfESa+MakFyfmxrUpRpgTiQBzl1zhRnMiLAMWKFO1davrR85dzQ53vfc8bYJnzrYhx SY+G0cnG1JQ4F768ZCqVbSUhjzUAoPdpFnGqjgIUgcujC3y8vAWdk5KoddNzWURzSI+J QHguSY7snA9cce6llZI1k4EiZJO6u9vuyFxIhdV7Kp4vBEbsz2vDxpDxAN9hyn06FbbZ Z5cy45wsla0zHDgh4J2plL4+PApuWZ+fYnrlmZh6LVwu777VBictFjCT/9iG06F77OAw rLfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=RJ7YOFjy4ZpoSfqYXrqa0XtC82DyqPGPNdAIoavOC6w=; b=X2OBGQd6stSVQ1sV/Q1nsIV8VIezmvMjmVoMHd5m8l9GHWDzz/BUR1zNa1M272ovbj cOnhcUt6tGBYCiQ4oXbACLSaF/3fQXrN6Mk6n2FU0sjTkvWrHnhx7BfS+XYspouAvUx6 Rn0qfTEjxHfKrQFBces/2V+ZKKG7D45zn5pHNVUs75brmxnF2nst6HSQoVmd1a2UQzfW BdkhW6sKR0iK9XiXC+jm0EXrJYehLG6pSgWI9NvRRumHwQONLMuD3HcZcXkaCnHpwfx8 notLFV4XowSKG8NiOdQl6vOWgPVPKQFQJrEi49lz+PKzhzrlcJdX5huvQrqrT9x8pvuL xPMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1-v6si11896125pld.184.2018.08.21.01.36.22; Tue, 21 Aug 2018 01:36:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726778AbeHULxq (ORCPT + 99 others); Tue, 21 Aug 2018 07:53:46 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:43455 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726315AbeHULxq (ORCPT ); Tue, 21 Aug 2018 07:53:46 -0400 Received: from 79.184.253.33.ipv4.supernova.orange.pl (79.184.253.33) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id 90be5fd06e6eea36; Tue, 21 Aug 2018 10:34:30 +0200 From: "Rafael J. Wysocki" To: Leo Yan Cc: "Rafael J. Wysocki" , "Peter Zijlstra (Intel)" , Daniel Lezcano , Vincent Guittot , Ramesh Thomas , linux-kernel@vger.kernel.org, Linux PM Subject: Re: [PATCH v1 1/5] cpuidle: menu: Clean up variables usage in menu_select() Date: Tue, 21 Aug 2018 10:32:14 +0200 Message-ID: <2838787.qSB1WlRZH1@aspire.rjw.lan> In-Reply-To: <1534090171-14464-2-git-send-email-leo.yan@linaro.org> References: <1534090171-14464-1-git-send-email-leo.yan@linaro.org> <1534090171-14464-2-git-send-email-leo.yan@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sunday, August 12, 2018 6:09:27 PM CEST Leo Yan wrote: > The usage for two variables 'data->predicted_us' and 'expected_interval' > in menu_select() are confused, especially these two variables are > assigned with each other: firstly 'data->predicted_us' is assigned to > the minimum value between 'data->predicted_us' and 'expected_interval', > so it presents the prediction period for taking account different > factors and include consideration for expected interval; but later > 'data->predicted_us' is assigned back to 'expected_interval' and from > then on the function uses 'expected_interval' to select idle state; this > results in 'expected_interval' has two different semantics between the > top half and the bottom half of the same function. > > This patch is to clean up the usage of these two variables, we always > use 'data->predicted_us' to present the idle duration predictions and > it can be used to compare with idle state target residency or tick > boundary for choosing idle state; we purely use 'expected_interval' to > record the expected interval value, which is mainly for interval > interrupt estimation. > > Signed-off-by: Leo Yan > --- > drivers/cpuidle/governors/menu.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c > index 5eb7d6f..b972db1 100644 > --- a/drivers/cpuidle/governors/menu.c > +++ b/drivers/cpuidle/governors/menu.c > @@ -363,7 +363,6 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, > latency_req = interactivity_req; > > select: > - expected_interval = data->predicted_us; > /* > * Find the idle state with the lowest power while satisfying > * our constraints. > @@ -386,7 +385,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, > * expected idle duration so that the tick is retained > * as long as that target residency is low enough. > */ > - expected_interval = drv->states[idx].target_residency; > + data->predicted_us = drv->states[idx].target_residency; This is not what is predicted though, so the name of the field isn't quite adequate for this use IMO. Besides, I'm not sure in what way using a structure field is simpler than using a local variable. > break; > } > idx = i; > @@ -400,7 +399,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, > * expected idle duration is shorter than the tick period length. > */ > if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || > - expected_interval < TICK_USEC) && !tick_nohz_tick_stopped()) { > + data->predicted_us < TICK_USEC) && !tick_nohz_tick_stopped()) { > unsigned int delta_next_us = ktime_to_us(delta_next); > > *stop_tick = false; > Yes, it can be simplified along these lines, but then please note that data->predicted_us is only used in menu_select(), so it doesn't even need to be there in struct menu_device. And if you make it a local variable and call it something like duration_us, then yes, it will be fine to use it like in this patch in my view. Thanks, Rafael