Received: by 10.213.65.68 with SMTP id h4csp24938imn; Thu, 15 Mar 2018 15:22:24 -0700 (PDT) X-Google-Smtp-Source: AG47ELvQ1Tq+JMBlTy+PTxFw+sVdAKMvxrD5mUhAG0WLzY+ju57hAeJ6TrCU7fV4DytALHOjswQA X-Received: by 10.101.82.195 with SMTP id z3mr8077722pgp.308.1521152544649; Thu, 15 Mar 2018 15:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521152544; cv=none; d=google.com; s=arc-20160816; b=g+GBLQws7ExVgzMwzvmE+q3ITju6x/71MRCA75BqdYS+sS+HcVRqtlD/FeVreYgl+t rAzciLM6Msg7u4GDp4ZR8g2l+z3Rs0ECWT5JWmKQ2tmq3IXAhVPmcvxmsVc8ufaRLzGU LU+TQdu21svyE9ISbIkLGOTuhq/45lp/15Kg0FIwMBaliPKlSu8SXUAoihKjWzw1+uq4 P7A0iFp2Eg9/pgzPEcFAi23lhES5bbtZQd50nuVRF4T72+fM1MaTZ7WWc8CMuGuW1FBn BNPfGeevGgvF540PCFoD6wDEK8bwfkI/iW2Zb642GRZzQgTrepln31GMdHxVMawUckXq ZRtA== 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=UjIDx274PaiklAV9I5u9KmGg3VT8BD8sNzB7GEvZlwA=; b=h1hyYsz0MXdf8ek6fnS271vi+ysP1pMyt1qpqPTLyLe2x6FYQnI9Zrq0Zp55OoH14r Dnt87aMYzTpursJWRQEIKeB4EIMUDoaJ0Yv/U5iPmpp1gGV/6sjtngdd3nwn5x5vKAkb iW+ODQnT2qnNIgPJNeq+Poyd+YKCsPJA84vWkadKelPX7KsHglIyOewO7aFj7oaH7QU2 6MUEg71YUFqu/1LwJhfbQ9yMN9fEMOAjFLx1vfG/BcKNgvycel8h4wG05D/Q7LW/ngqn SfX3bstzViLJBCZ3ch+8LhULQOqTX1AZsz1Eoftbknc3WclLgWdLQf6UY9/Y2Df8i/Ti l9Aw== 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 b10-v6si4706277plx.355.2018.03.15.15.22.04; Thu, 15 Mar 2018 15:22:24 -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 S932391AbeCOWU5 (ORCPT + 99 others); Thu, 15 Mar 2018 18:20:57 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:45817 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752565AbeCOWUz (ORCPT ); Thu, 15 Mar 2018 18:20:55 -0400 Received: from 79.184.254.228.ipv4.supernova.orange.pl (79.184.254.228) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id 3ba9670019dfc85f; Thu, 15 Mar 2018 23:20:53 +0100 From: "Rafael J. Wysocki" To: Peter Zijlstra , Linux PM , Frederic Weisbecker Cc: Thomas Gleixner , Paul McKenney , Thomas Ilsche , Doug Smythies , Rik van Riel , Aubrey Li , Mike Galbraith , LKML Subject: [RFT][PATCH v5 7/7] cpuidle: menu: Avoid selecting shallow states with stopped tick Date: Thu, 15 Mar 2018 23:19:37 +0100 Message-ID: <2148754.TY7qXgFyZy@aspire.rjw.lan> In-Reply-To: <2142751.3U6XgWyF8u@aspire.rjw.lan> References: <2142751.3U6XgWyF8u@aspire.rjw.lan> 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 From: Rafael J. Wysocki If the scheduler tick has been stopped already and the governor selects a shallow idle state, the CPU can spend a long time in that state if the selection is based on an inaccurate prediction of idle time. That effect turns out to be noticeable, so it needs to be mitigated. To that end, modify the menu governor to discard the result of the idle time prediction if the tick is stopped and the predicted idle time is less than the tick period length, unless the tick timer is going to expire soon. Signed-off-by: Rafael J. Wysocki --- v4 -> v5: * Rebase on top of the new [1-6/7]. * Never use the interactivity factor when the tick is stopped. --- drivers/cpuidle/governors/menu.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) Index: linux-pm/drivers/cpuidle/governors/menu.c =================================================================== --- linux-pm.orig/drivers/cpuidle/governors/menu.c +++ linux-pm/drivers/cpuidle/governors/menu.c @@ -353,13 +353,28 @@ static int menu_select(struct cpuidle_dr */ data->predicted_us = min(data->predicted_us, expected_interval); - /* - * Use the performance multiplier and the user-configurable - * latency_req to determine the maximum exit latency. - */ - interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load); - if (latency_req > interactivity_req) - latency_req = interactivity_req; + if (tick_nohz_tick_stopped()) { + /* + * If the tick is already stopped, the cost of possible short + * idle duration misprediction is much higher, because the CPU + * may be stuck in a shallow idle state for a long time as a + * result of it. In that case say we might mispredict and try + * to force the CPU into a state for which we would have stopped + * the tick, unless the tick timer is going to expire really + * soon anyway. + */ + if (data->predicted_us < TICK_USEC_HZ) + data->predicted_us = min_t(unsigned int, TICK_USEC_HZ, + ktime_to_us(tick_time)); + } else { + /* + * Use the performance multiplier and the user-configurable + * latency_req to determine the maximum exit latency. + */ + interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load); + if (latency_req > interactivity_req) + latency_req = interactivity_req; + } expected_interval = data->predicted_us; /*