Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4843027imm; Tue, 21 Aug 2018 01:48:58 -0700 (PDT) X-Google-Smtp-Source: AA+uWPz7CKQXyU/9DxxM6h317v4BCASia5y8nDfG5b8ryF4NmgCiQG3Inkm+z0N9kpMK1dj5uq+2 X-Received: by 2002:a63:91:: with SMTP id 139-v6mr15480686pga.389.1534841337936; Tue, 21 Aug 2018 01:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534841337; cv=none; d=google.com; s=arc-20160816; b=GzuekYmis29yKZIxzcRIfQviPOWDBrepX8XPWqgqnbUH8v37DT72byN4CpidD+Xylj BrLicLOb+oOnHtpiAlp9rjZaq758nbUbpEl7udvcv7uAc4/qO1AVMJ6VNUE/yZJGyBSu edVSLSeDekllr7pgEkaYZvOmHjriw9EEpor8q0b8EN5oOo6oEOdZfhaNimgSs3sXjI0v 9glO2koWM9wwWKsi9dvtf95VtcEw6pECZXxT77+e+vOnz75daxZNIgQHpfMk6ADhTJW4 SQeTzEfQWWO29nl/cLd6eMmfUl0mqJvJk1HTsBfEIMN1jCL+EZrpPsIgB3AwlGdqn+gD r11A== 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 :message-id:date:subject:cc:to:from:arc-authentication-results; bh=7UhJqKZKb8p/qRmybciRMcO+kkprxUvKbNoDQgvwWQc=; b=Vpmp6y3Iw0RZ/0q+hzNm9z2Kb6oVhVRB+20Bq4f2PC1DRRSQMP9wygWAt3E540mA+h +gJQ37auDS7oY7jJl3CEN55J4JjL29TopI+1diSZvPCnmTBaQ7o3AV8a70UZ+c6RSV9D Z/PtO8DpnZPV1E6lpIclJoPB1nDR/MJPg41eEsOEK/ssOMd+o+goHQZcieSE5VQbGtqa SkDGpE6OLr3uUVV0AFoYSjxmY2zaGCKkI+QVKf5EnJQ490fcldwRMo0t6udpmjHLPPi0 eLhksx8CfXKkMj0pTVjIva1ijU8CSW2f/EI6zKmD/VgMzefOjr3POo5r2uz1AsCuQ1// Sf1g== 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 n11-v6si5344023pgl.133.2018.08.21.01.48.41; Tue, 21 Aug 2018 01:48:57 -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 S1726861AbeHUMFo (ORCPT + 99 others); Tue, 21 Aug 2018 08:05:44 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:50947 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726315AbeHUMFo (ORCPT ); Tue, 21 Aug 2018 08:05:44 -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 25013b0cdf134190; Tue, 21 Aug 2018 10:46:27 +0200 From: "Rafael J. Wysocki" To: Linux PM , Peter Zijlstra Cc: LKML , Leo Yan , Daniel Lezcano , Frederic Weisbecker Subject: [PATCH] cpuidle: menu: Retain tick when shallow state is selected Date: Tue, 21 Aug 2018 10:44:10 +0200 Message-ID: <34910476.pgRhNDWo5t@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 The case addressed by commit 5ef499cd571c (cpuidle: menu: Handle stopped tick more aggressively) in the stopped tick case is present when the tick has not been stopped yet too. Namely, if only two CPU idle states, shallow state A with target residency significantly below the tick boundary and deep state B with target residency significantly above it, are available and the predicted idle duration is above the tick boundary, but below the target residency of state B, state A will be selected and the CPU may spend indefinite amount of time in it, which is not quite energy-efficient. However, if the tick has not been stopped yet and the governor is about to select a shallow idle state for the CPU even though the idle duration predicted by it is above the tick boundary, it should be fine to wake up the CPU early, so the tick can be retained then and the governor will have a chance to select a deeper state when it runs next time. [Note that when this really happens, it will make the idle duration predictor believe that the CPU might be idle longer than predicted, which will make it more likely to predict longer idle durations going forward, but that will also cause deeper idle states to be selected going forward, on average, which is what's needed here.] Fixes: 87c9fe6ee495 (cpuidle: menu: Avoid selecting shallow states with stopped tick) Reported-by: Leo Yan Signed-off-by: Rafael J. Wysocki --- Commit 5ef499cd571c (cpuidle: menu: Handle stopped tick more aggressively) is in linux-next only at this point. --- drivers/cpuidle/governors/menu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) Index: linux-pm/drivers/cpuidle/governors/menu.c =================================================================== --- linux-pm.orig/drivers/cpuidle/governors/menu.c +++ linux-pm/drivers/cpuidle/governors/menu.c @@ -379,9 +379,20 @@ static int menu_select(struct cpuidle_dr if (idx == -1) idx = i; /* first enabled state */ if (s->target_residency > data->predicted_us) { - if (!tick_nohz_tick_stopped()) + if (data->predicted_us < TICK_USEC) break; + if (!tick_nohz_tick_stopped()) { + /* + * If the state selected so far is shallow, + * waking up early won't hurt, so retain the + * tick in that case and let the governor run + * again in the next iteration of the loop. + */ + expected_interval = drv->states[idx].target_residency; + break; + } + /* * If the state selected so far is shallow and this * state's target residency matches the time till the