From patchwork Sun Aug 12 16:09:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 143994 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2183691ljj; Sun, 12 Aug 2018 09:10:00 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzb2tf4Hkg2BqHT1EQhZ+Cr+RFVlD5418SiOwXO05AuBMZ3YCo668uVOgBJxak2Z3Peunto X-Received: by 2002:a62:a05:: with SMTP id s5-v6mr15351521pfi.147.1534090200134; Sun, 12 Aug 2018 09:10:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534090200; cv=none; d=google.com; s=arc-20160816; b=Ex9GtDXQZ9FvzPXUCogaYP1V6EfJ6ASveVC/ugppoKUiTju0rHDaE81WmJf+khKinx CUkq5qMnuhWxuobERJMKYTmj0Ofv1z8mh2uxSqrNm7FpeeVuj7Hvvpm3WRpgF93gJEBP cZ1QcP2IXtureNepcXtjG50z342jJymD2muPMd+AcvtBMC6DKKEoNCqpZ3pxwoWUV/B/ iQ4Q4xaPiVc4nm1jmwYaC0IGxGUHiIzNCCn2cZwxVgEicr/NswHm2Sq93iwM0VKFfJgL 5ZNWOV3iUIWvPkJXl5bO+KiYsuoVzjZW0oA8+xgs/ajI/lhX4Ane2EDH9LyskjFXAfgm u9SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=7syOievGKU1gnJa8oh05y8DUlQgWF5NjJ3xt3wLMcp0=; b=ml6vBh2ORJ3CEuXJWBgwk/BMdJgN92kdqgXMgFegOJC8y6ahCbQLNu2fWXzryj5RWq OEh1qSYqdfL4fcgF/NaByhwmIBDj09dD+kgwCOYElTRx7Pk/9Pk3hXHIZ0l27bSZ1Nf7 s9iNAEPM1He5k/OHvVT5C/kSZhYQIIIJkKCbcVHgQRy06wGrWiYVL8ZpgIogCOn4TK59 dFx5RTfUxOvfKk2uF5AWXhfd0xe/19prcOumYMJAEaBsirq04VyjRrmdrZYt/8u23S5y tMR0VCB0Q1b4m+tQRT6/j7X3SfIDUj7tNdeyN4ij4im/1LcgypV4B7Zx09gEKQPMzF+q IrHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Aqw4vA0x; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i186-v6si17576957pfb.362.2018.08.12.09.09.59; Sun, 12 Aug 2018 09:10:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Aqw4vA0x; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727699AbeHLSs2 (ORCPT + 10 others); Sun, 12 Aug 2018 14:48:28 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:53850 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728180AbeHLSs1 (ORCPT ); Sun, 12 Aug 2018 14:48:27 -0400 Received: by mail-wm0-f68.google.com with SMTP id s9-v6so6473899wmh.3 for ; Sun, 12 Aug 2018 09:09:56 -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=7syOievGKU1gnJa8oh05y8DUlQgWF5NjJ3xt3wLMcp0=; b=Aqw4vA0xT3WxMfTUxnd2mwPWd8CNO/XKIvCXki9jTDnHbOsEpUGb8lNr5DxnTeREod RtqC2bdKn0+llD37F45FFVZkE3+SCLiR5wyX/knNX9M8hLOei8vErZgtXqz8CuzNhE1W OtoVDdXcF8fJUARQ4SjmDJL1uS57JPBz+gdfk= 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=7syOievGKU1gnJa8oh05y8DUlQgWF5NjJ3xt3wLMcp0=; b=e/odI49FNjEI3P0KulXdZXbVAy90exRzVZ2CjPsRSwMXk4YK9NVC0zVG6aXj2QOrM0 cGUms0jypV1l03YfOwnc4ux8+piUNpWKNlhuId+guRayRvLk/lVWdf96AVZNIDMcjXeA tr8u1AZOpw4Spb66HpjcEO9oU7nrxLisIKrJFNhepBMWfiicu4uQy6CRrqFSVGSLpUYE ZbsNvYCg9F/yZm0IJR3Xtscjs1UKIjYL4FteTo3U8Auc17xzZXUcXyUCmde53HdVUsUa Hxa4J1B8Tn2XtCIpXP1gdxojTztVxdhRE8VrDL3VW4j9y3ME5/r7VHq91HiVXnCKU5WP /m6A== X-Gm-Message-State: AOUpUlGzHPPXPdedY6z6k0N3kB70HIepSxiTuTmJwjPo14W/MhNKrNIt jEe6yypwVqX39s/2/E9ed0ygLw== X-Received: by 2002:a1c:28c2:: with SMTP id o185-v6mr6159731wmo.40.1534090195777; Sun, 12 Aug 2018 09:09:55 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id t6-v6sm7437369wmf.8.2018.08.12.09.09.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Aug 2018 09:09:55 -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 1/5] cpuidle: menu: Clean up variables usage in menu_select() Date: Mon, 13 Aug 2018 00:09:27 +0800 Message-Id: <1534090171-14464-2-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 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(-) -- 2.7.4 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; 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; From patchwork Sun Aug 12 16:09:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 143998 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2183902ljj; Sun, 12 Aug 2018 09:10:15 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwEuzpiVjRunnrvwV9YMmCOx4RGMjIusvGNPi6gLK5c98PayNVTLIu+/io82jPfysMpPY3s X-Received: by 2002:a63:d645:: with SMTP id d5-v6mr14263318pgj.450.1534090215012; Sun, 12 Aug 2018 09:10:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534090215; cv=none; d=google.com; s=arc-20160816; b=yXy6GQdyU+W88S+ff6Rrlmxvv5KTY4WqMV893SWLh2hqS/tvAyl8QB/fXlElp6fAIR xrzNSkzmVsNqFvhnV1KMAgafnaygyVvs4C0YjVuJjr1TM+LOBM6RnPksjWQziIKzjIv1 Y4B4FKRaqK3ZR5pevQ2ZmO7p6WZSeltMEW06ZkDYqs8O8TY/XVpKAlshMykioxtVh0Jm NNjaXrEKiw5wyLbpgS/P+JsN9t3OY0wQuDyfhDLyPdm9jFyDmFATtTDJ+KjRNZcavNjd luAPskw3q+nXAZjyOIz9oPy4OayCmapB0nu9SDIS6RZGBDlOfjTIqDd+/dgyvOo9iiI8 6ZHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=SX0m3tGLxDNEaSJcRwiLoR6t4RrqbIncbJJxqLoIX9o=; b=DaPzWCs/UHOcMgUcpFVpswAJmAqGMw+a5Y2D8ovafY/W6OOd+OjBgVCXe93AoyEIGE hqchP4DgoElCfxu1qY4i/jsQodU6io4A6tyOGjPFVP+muHyZKhFcCYUZ3mJm3NPi5QuT BF6FXMn3NQMxFByT3Djxieu8D68wLEuE8AU+/42z2BZGLHeBGneFCdv/6ovkJwY1unlJ CU2WnDA1yElDLq8hC5N0uCysuXbel+P9XDtQC5Sw1WxSthrzLkLK8GWNu4w0UjuBcd7/ ClKBSVplfoUekVysk7ccFwPLEgr+yMg9uVohfGrNOqg940t+jTKxuT4WRGzWYFSnqvUy NxJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HdnB8Nat; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6-v6si14317808pfh.266.2018.08.12.09.10.14; Sun, 12 Aug 2018 09:10:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HdnB8Nat; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728363AbeHLSsn (ORCPT + 10 others); Sun, 12 Aug 2018 14:48:43 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:54893 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbeHLSsn (ORCPT ); Sun, 12 Aug 2018 14:48:43 -0400 Received: by mail-wm0-f65.google.com with SMTP id c14-v6so6464092wmb.4 for ; Sun, 12 Aug 2018 09:10:12 -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=SX0m3tGLxDNEaSJcRwiLoR6t4RrqbIncbJJxqLoIX9o=; b=HdnB8NatpocGEL93w0XRHehbE84HUhV/wb/KWqRlt4/m3a3yrGKkZEratVTpaarNKQ EjqDQIshLQT01QbrZqGG/CJX39qrxEfXaJ9Wk132TKDlcchpBqygOcrQwHp1UquQXCKL 0nIGiLHmbhTbfoy3tE8GrerVdc1/PNgi1XnPw= 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=SX0m3tGLxDNEaSJcRwiLoR6t4RrqbIncbJJxqLoIX9o=; b=PJrNxjysKDR+nEdpKQHxupV3PPz9sNGrtSvGJr4K5bXmCaMV7vOrnNskarKlx6T0Dj bIQynOhcm5UNeKkNe/d5bzk3c5HmokZdQmVU3r3AU3duzx+phF15ymP8s82NLobdM9kY IYtCpB8wAYd8/to6o1d1C01sBBa5s6kaYg2e1+tch5mlhHNaRMJ+3slQa0xrOGSAB4T8 JDLQNFpoYZN9oWUsqHrqODhQUSPdG/tp4n7CT32pFin0EzK57X4MPPTcwRvUN0VQbtwq 7u+NK2lf3oO/mP9TdX0fU3mZG6Du2/QOLoEtFw1WTmKgrCKl6irH2jH8QwJdMxUbJa+L VZFQ== X-Gm-Message-State: AOUpUlFa4Gwoe1IBX38DktXF0qS0nHgiitSVhabRM1gtlvlNmyt60uYh 5tXT+QwdaB5e0gaDTDNHGx0mbA== X-Received: by 2002:a1c:1188:: with SMTP id 130-v6mr5942158wmr.138.1534090211534; Sun, 12 Aug 2018 09:10:11 -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.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Aug 2018 09:10:10 -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 5/5] cpuidle: menu: Change to compare prediction with tick delta Date: Mon, 13 Aug 2018 00:09:31 +0800 Message-Id: <1534090171-14464-6-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 The tick stopping decision is made by comparing the prediction with TICK_USEC, if the prediction is shorter than TICK_USEC then this means the CPU is likely waken up before the tick event so it's pointless to stop tick. In reality when make the decision, though the tick period is fixed to TICK_USEC, but the CPU is randomly entering/exiting idle states so the next tick delta is float and should be in the range [0, TICK_USEC]. This can result in wrong decision for stopping tick, e.g. if the prediction is 3ms idle duration and we compare with TICK_USEC=4000 (HZ=250), this can lead to a wrong conclusion is the tick event will be later than the prediction duration so the governor doesn't stop the tick; but in fact the tick is expired for 1ms, so the tick wakes up the CPU ahead and the CPU cannot stay in idle for 3ms as expected. Alternatively, 'data->tick_delta_us' is for the tick delta value and it's a accurate estimation for tick event coming. This patch changes to compare prediction with tick delta rather than comparing with the static tick interval. Signed-off-by: Leo Yan --- drivers/cpuidle/governors/menu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 566c65c..06d5942 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -300,10 +300,11 @@ static bool menu_decide_stopping_tick(struct cpuidle_driver *drv, return false; /* - * Don't stop the tick if the prediction is shorter than the - * tick period length. + * If the prediction is shorter than the next tick event, means + * the CPU will be waken up before the tick event; don't stop + * the tick. */ - if (data->predicted_us < TICK_USEC) + if (data->predicted_us < data->tick_delta_us) return false; /*