Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp862576imm; Wed, 22 Aug 2018 14:02:45 -0700 (PDT) X-Google-Smtp-Source: AA+uWPx+ZBrpOg6EfifxiqCru9C0+VpbIQV6d26O6kvoCC7ECf/15zu8jMCn8oKGEG2LEG5EbPiK X-Received: by 2002:a17:902:261:: with SMTP id 88-v6mr55810289plc.331.1534971765347; Wed, 22 Aug 2018 14:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534971765; cv=none; d=google.com; s=arc-20160816; b=N5WGDDxLTZpcHsbJQs3qizpZ3mammzETSav3gTwxg10JBSMSC9GOBPUcvJ9i9tbVJK nUefR+MH/x0lXW/qlQutvbtDqcs2/75xXT9jh76BfrNr6I9rF6WdKSBzFNt7FPTMHN+y 9R1yV6ghsTDHAkALJxTifmALxy6cyD4MEh4bcX1jAUeH95WRzHM6yfXzOBnMd8rQc/Kl NmuHsnk66Te6VjYZwcNTmBdaAiqnzaoHUOw9SNK5+rzlSOTXnkngquQtO/Dx8ELxJc0t DnJc2Gm9ecQjkxCI4ev8JFSUeLwcY6fKl+9WoWu7HAuXO2cPTHB2CIH+jiAp53pn0v9o U4mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:arc-authentication-results; bh=0L5E7TaaOy4i6U+TsDbyuvuPp/fP6snswDj8ZGW4IXs=; b=o781z5496oCdQNR79JIjggAvxcfT9tWV3objIpyCgVOp+10nhBe9inAIzrGOzNhLDI AZGrEOdKaKICzInFawX/GdxK6b2/dclK6KbLdcSbdaUI1aVaVzkxLgGxVUoV+U7xGP6K updLurl3amiAs01wZ3dDCZOT0jokcrG2zm5biZ2qT7b3f03GsCEdWX51wEO9UK2EGI9/ CsGc3xV8IzsXhDp8s/d7z8fv3IscO69U0QcOSoWDmMrHlEeMCkYbnRrbE/Coz0n3uzlw v6sRXAfHBXrxey4oxVQoxlpJLlZANu6RkQAdl9kfqnopBytLY3HqZrCmiZ2mC4lqxzrz 1OFg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y123-v6si2773120pfc.302.2018.08.22.14.02.29; Wed, 22 Aug 2018 14:02:45 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727353AbeHWA1u (ORCPT + 99 others); Wed, 22 Aug 2018 20:27:50 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:39229 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726789AbeHWA1u (ORCPT ); Wed, 22 Aug 2018 20:27:50 -0400 Received: by mail-oi0-f68.google.com with SMTP id c190-v6so5585508oig.6; Wed, 22 Aug 2018 14:01:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0L5E7TaaOy4i6U+TsDbyuvuPp/fP6snswDj8ZGW4IXs=; b=G49c1aMFnc/oy1WVjnfzjGlwJaP38tKgV1ksyM+KxLubmNN9V4yrJjJ16UnXpJM5xC hUDvXPbFW42PibGl7qRFPqTYRqCsiYGrSNYP4X5bvxLhcKTw1pzda5a7p9Hha467la2Z f9k8cvzQ7XNjNCyZZ5Yr8zESjmiE1i9lJ15r4HOK71mcjBorlS2E+0PwHJuMc1vG4CeV Bb+GZgLaRXSJy58ArtvIRZE0huBBDWuiYcOZtg3D9pStJH3Au1Ckjs+IpsJG0CpZCb+R yn1WdW6vKQQRyR+f8o1UG7JyX+01Is6ykl61AcgQRWLSuDT4Qab34dlYomnc68l9icoV 4LdA== X-Gm-Message-State: APzg51DKSwQMgxwKIrATxfcWM+vJM1GH3DE05QxAl/uj0H19Bs/jrRKA g3qKIlVlgBhktiZwXp9KcjKka+OJUT6YSSM6TEM= X-Received: by 2002:aca:aa06:: with SMTP id t6-v6mr5874781oie.152.1534971680809; Wed, 22 Aug 2018 14:01:20 -0700 (PDT) MIME-Version: 1.0 References: <34910476.pgRhNDWo5t@aspire.rjw.lan> <20180822120200.GA8949@leoy-ThinkPad-X240s> In-Reply-To: <20180822120200.GA8949@leoy-ThinkPad-X240s> From: "Rafael J. Wysocki" Date: Wed, 22 Aug 2018 23:01:09 +0200 Message-ID: Subject: Re: [PATCH] cpuidle: menu: Retain tick when shallow state is selected To: Leo Yan Cc: "Rafael J. Wysocki" , Linux PM , Peter Zijlstra , Linux Kernel Mailing List , Daniel Lezcano , Frederic Weisbecker Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 22, 2018 at 2:02 PM wrote: > > On Tue, Aug 21, 2018 at 10:44:10AM +0200, Rafael J . Wysocki wrote: > > 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) > > With this change, for tick has been stopped, it might introduce > regression to select a shallow state and it's conflict with the effect > of patch "cpuidle: menu: Handle stopped tick more aggressively". How so? If the tick has been stopped already, predicted_us cannot be less than TICK_USEC unless it is equal to delta_next (in usec), but if it is equal to delta_next, s->target_residency cannot be less than or equal to the latter, because it is greater than predicted_us, so idx would not be updated even without this change. I don't see a change in behavior in the stopped tick case resulting from this patch. > > 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; > > + } > > + > > This is reliable, how we can rely on a shallow idle state target > residency to decide if need to stop a tick or not? If the target residency of this state is beyond the tick boundary, it obviously is necessary to stop the tick in order to use it. Conversely, if its target residency is within the tick boundary, there is no reason to stop the tick (the state is not the deepest one available and its target residency is short enough). This is analogous to the case in which the loop is terminated for latency reasons. > > /* > > * If the state selected so far is shallow and this > > * state's target residency matches the time till the > >