Received: by 10.213.65.68 with SMTP id h4csp566879imn; Tue, 20 Mar 2018 09:47:34 -0700 (PDT) X-Google-Smtp-Source: AG47ELua9etZafUnpuVYzkf+wxRXLS+Q8zPZJJ95jas6dSGoHTVrfbArLL0rYmtxxsy3RTQJeGic X-Received: by 2002:a17:902:c1:: with SMTP id a59-v6mr17090310pla.284.1521564454575; Tue, 20 Mar 2018 09:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521564454; cv=none; d=google.com; s=arc-20160816; b=mxu/QQpnFFNZ0bVofWGn5pjbilDArgR77bKGFhf+tZg83g4K1PFXaZWvscDgGNyV5a 7QEm9wPBvL/oulnJbgiFxW9nwSXAaw7ln2KiQmh++N41jwhq64FMA7mO+CmHOBwfBt3x LMqlR8VKqyYE+SgIflQPZwwcDbXrW7TgYifRXT9vfse/WxOFyfoqZIvJaGT0bo7aEceR dmwWzk7YeJzD6vY4CEtrZJgvrhiqLQU4SKM03PssKmA0ZznOgrfm2mxLj8TKAh4gZ5tY Czb2/sD2IR2nLfig1zkVh9x3nLK4dKMedwxEaSBIqzXKAEdzsjx5Ks6UbwycCwT1qOEg mFOQ== 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=65u/aePPoCI5Jfu8Fy+ml4dUUbjdV3mJJb7NahqhM+o=; b=gAWOkZqyiTy9u9n+1wF3ZMDSAdIGD1RXLV+TcWk6bVTpbTiIyF+dCh2ZICyYkcpPTi vmMi5Bbjf9yQvY/DH8LonP0KZhSkqYaAMLCTThgIsJZ1Yo5ihhMz57fa5ZDXFE7fdDK6 rfNse8eeFAmMRkg+933HNLBWlvhRh0999Ya1yMMCdUt0TvRV3ZoJk/Oib58EAThD3lgJ 8aSmSP+UGCuAQ0TBeLTZdDwfEx+BMDBOgOZIrvbMhbD2DhHduGMwc52lgcZ8fEblgzT4 OjdMkdtgegn4dkZht4qsOdRf+JQuDs6inqLjDY0GlHvEOQgf2FojDFJxIedNdFprRgoz kudQ== 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 h10si1425464pgc.296.2018.03.20.09.47.20; Tue, 20 Mar 2018 09:47:34 -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 S1752138AbeCTQqB (ORCPT + 99 others); Tue, 20 Mar 2018 12:46:01 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:56882 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751449AbeCTQnn (ORCPT ); Tue, 20 Mar 2018 12:43:43 -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 824f8c56f3da591d; Tue, 20 Mar 2018 17:43:41 +0100 From: "Rafael J. Wysocki" To: Peter Zijlstra , Linux PM Cc: Frederic Weisbecker , Thomas Gleixner , Paul McKenney , Thomas Ilsche , Doug Smythies , Rik van Riel , Aubrey Li , Mike Galbraith , LKML Subject: [RFT][PATCH v7 8/8] cpuidle: menu: Avoid selecting shallow states with stopped tick Date: Tue, 20 Mar 2018 16:47:09 +0100 Message-ID: <2317533.DCFkBeZAbT@aspire.rjw.lan> In-Reply-To: <2390019.oHdSGtR3EE@aspire.rjw.lan> References: <2390019.oHdSGtR3EE@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 --- v5 -> v7: * Rebase on top of the new [5-7/8]. Note that the problem tackled here may be addressed in a couple of other ways in principle. --- 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; /*