Received: by 10.213.65.68 with SMTP id h4csp487828imn; Wed, 4 Apr 2018 01:54:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Pgz+X6ej4ZdWowDJUmr94yaHqUBZ9eAdGybix8eRtYyz4miJueyOhsRTgcntUnQoZftMx X-Received: by 10.98.141.78 with SMTP id z75mr13295987pfd.174.1522832068327; Wed, 04 Apr 2018 01:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522832068; cv=none; d=google.com; s=arc-20160816; b=oLjM1chwkIGeDMTqh1BQx6Fjtj/lDhbGa4BLO7ZRAyGphtd/HO8to3GjJ/wtuFXs0R JhE8fPCbwrVbnjYPIPPM16Aqcq/DedCteAiScgJ7zyyrCy90VHfPiIYR3JouulJxYAHq zbhrco/R2rgy5ZRBNQivxXIkxMAr79eZzvZyTqexOAmo5DmeFK8jNToyItKtku2g/geE qdSn95yjZHbj/pvHpMqZ3AN98OZ7Ldw5GkR9Yl+uNeGoS+5tTPUEkiqvOsOOGRPiG58Y 8Yix87UgOzBGxqYB3L9yZ2ZGNeftksKYg7S76d9WCvC6gw7194ofVt4yh1BesgZUZwwk D82A== 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=RfwPCM2M2UT8rCpopalE4xDDbZePx+Oji1vWk7Zzjwc=; b=K5WUTDc9yz9NNxr5mBsdBgDEVF7kyOV+hNhteOXKvmprdCOs4FEhU2yU40Q2mSVWjG Ho5ZYspy1BImDA6UIs3Gz1qZUSCV7Rgab0pT9iPPsTYkje697zXuH+nD7U7XMQCjvIdl YmKP+PyoihZEKwyLeocX+gjsjlqq7tLx3A2es1GuLPD+HUIR98shGhBVIFlq6Qrz8K0i 3P2+5MWKNx4RAcIrY5CBm//oGZrx4nBMh+sA2e6j3OkaGFPwrydi6QhwfU4jYxpnIJv2 2r5RhZblPn4CbfjqxyLsxS2b009rwNm8hBpNTYAG7M/mrdcx75x90zCPU+OVsoQ1pYn8 +j4A== 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 l23si3306857pgn.696.2018.04.04.01.54.14; Wed, 04 Apr 2018 01:54:28 -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 S1751461AbeDDIxF (ORCPT + 99 others); Wed, 4 Apr 2018 04:53:05 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:50662 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751017AbeDDIxD (ORCPT ); Wed, 4 Apr 2018 04:53:03 -0400 Received: from 79.184.255.92.ipv4.supernova.orange.pl (79.184.255.92) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id 0ec94f8795eda1ab; Wed, 4 Apr 2018 10:53:01 +0200 From: "Rafael J. Wysocki" To: Linux PM Cc: Peter Zijlstra , Frederic Weisbecker , Thomas Gleixner , Paul McKenney , Thomas Ilsche , Doug Smythies , Rik van Riel , Aubrey Li , Mike Galbraith , LKML , Len Brown Subject: [PATCH v9 10/10] cpuidle: menu: Avoid selecting shallow states with stopped tick Date: Wed, 04 Apr 2018 10:50:36 +0200 Message-ID: <6542020.eHGLEK9V0J@aspire.rjw.lan> In-Reply-To: <1736751.LdhZHb50jq@aspire.rjw.lan> References: <1736751.LdhZHb50jq@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 relevant, 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 --- v8 -> v9: No changes. --- 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 @@ -352,13 +352,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) + data->predicted_us = min_t(unsigned int, TICK_USEC, + ktime_to_us(delta_next)); + } 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; /*