Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp821651imm; Fri, 17 Aug 2018 07:14:23 -0700 (PDT) X-Google-Smtp-Source: AA+uWPysubF6Uh5YQl2+kWMPGzLvGdAqtuaad4Z0C4WLrzxzn1jeLOmYudAnpXnPQKNO3dLvbLFP X-Received: by 2002:a65:6243:: with SMTP id q3-v6mr32412081pgv.273.1534515263751; Fri, 17 Aug 2018 07:14:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534515263; cv=none; d=google.com; s=arc-20160816; b=CbazkT8rwJ0WHpM4G3vaFE9zIqjAqHHDeJ5faqlbFr8aOQJuVXehY437mi4LDMzmu5 Aj1uWD1Soo9PCCYw89lG9u5ET0H4nIEHTqJIDpdRyypjb+hqzJ/k+DSW6yDZ7hzwu3qh 83SIbphePwZQDTPboqVR/Rf7a6DM89BBZEFrR1lX+em4YQfjihC0sDO045zLJ7wZPDsT CIGtRrR7KfXOQ7hOqTIJ96bSh4fGbVLmSvJsFMtWpVcfEgZBRyND1TrtrV3/iMXeVTjz mXZ0umTljBNlCNhmVaz0Xq4f5cpcKsm8l8VQTgA4F+OTuJmTgRBQeW1Y3eV3N4iNXw/w sn6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=aMCI6Fk0+qwROq7b79BFSr1JOFHrHJzB+karlJHmcH0=; b=HCvZUsxvYXYMrAtm582sVBMvFu8sTkWD1OtvCm6+gWmlKWEqYlHT8IU80isxZb8fCv yX6NoeLK95NBthzhuLScmEpziW3onms/UwzEEJJ+KfYrv0hkchqRTAXqevNkKFCSfvMK JMhUzLLpiiXkW+pdCOo25nedRkpfEMapOsC9k6vYsgQhQ8RGHfo16t1+98LMO1WnxH2y QSAYyXUNuihrKfVxKimgvZVBpJdxX0BKHpROOl94lswHDE2rgmvNVj7V13stWv0JAwSa aKkwf+Oig9z89Kn+IsBCHe0dJoObQ85R7o8tYS+wn5B4Wthr1qL3T0lA2xRVyWSlnIFA acrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GdCQVGgn; 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=pass (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 68-v6si2271418pff.55.2018.08.17.07.14.08; Fri, 17 Aug 2018 07:14:23 -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; dkim=pass header.i=@kernel.org header.s=default header.b=GdCQVGgn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727526AbeHQRQ3 (ORCPT + 99 others); Fri, 17 Aug 2018 13:16:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:37580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725879AbeHQRQ3 (ORCPT ); Fri, 17 Aug 2018 13:16:29 -0400 Received: from localhost (LFbn-NCY-1-241-207.w83-194.abo.wanadoo.fr [83.194.85.207]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 57A232185A; Fri, 17 Aug 2018 14:12:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1534515176; bh=HJmL29St/mHSM6P+CFgoRIekoTpw97xpECKpi+mpA8c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GdCQVGgn6rP4RCdGZw0/MTUaNW1EZVOe/pyZx4M1EZhtmbvFAbNG0+Sz1DFQVa+Yw T9puvJwQQYJiaQcdpcYGKQILYK6F1oo+1mIfsbADYYR65Kr74P5opr8vLFklWqaRax zV6Krhot5JzeIUmICgnXmwH/UImy3766H6jLmrrk= Date: Fri, 17 Aug 2018 16:12:54 +0200 From: Frederic Weisbecker To: "Rafael J. Wysocki" Cc: Peter Zijlstra , Linux PM , LKML , Ingo Molnar , Leo Yan Subject: Re: [PATCH] sched: idle: Avoid retaining the tick when it has been stopped Message-ID: <20180817141252.GA12426@lerouge> References: <2161372.IsD4PDzmmY@aspire.rjw.lan> <20180816132723.GA6010@lerouge> <10817203.8q7neLTJVD@aspire.rjw.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <10817203.8q7neLTJVD@aspire.rjw.lan> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 17, 2018 at 11:32:07AM +0200, Rafael J. Wysocki wrote: > On Thursday, August 16, 2018 3:27:24 PM CEST Frederic Weisbecker wrote: > > On Thu, Aug 09, 2018 at 07:08:34PM +0200, Rafael J. Wysocki wrote: > > > From: Rafael J. Wysocki > > > > > > If the tick has been stopped already, but the governor has not asked to > > > stop it (which it can do sometimes), the idle loop should invoke > > > tick_nohz_idle_stop_tick(), to let tick_nohz_stop_tick() take care > > > of this case properly. > > > > > > Fixes: 554c8aa8ecad (sched: idle: Select idle state before stopping the tick) > > > Signed-off-by: Rafael J. Wysocki > > > --- > > > kernel/sched/idle.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > Index: linux-pm/kernel/sched/idle.c > > > =================================================================== > > > --- linux-pm.orig/kernel/sched/idle.c > > > +++ linux-pm/kernel/sched/idle.c > > > @@ -190,7 +190,7 @@ static void cpuidle_idle_call(void) > > > */ > > > next_state = cpuidle_select(drv, dev, &stop_tick); > > > > > > - if (stop_tick) > > > + if (stop_tick || tick_nohz_tick_stopped()) > > > tick_nohz_idle_stop_tick(); > > > else > > > tick_nohz_idle_retain_tick(); > > > > So what if tick_nohz_idle_stop_tick() sees no timer to schedule and > > cancels it, we may remain idle in a shallow state for a long while? > > Yes, but the governor is expected to avoid using shallow states when the > tick is stopped already. So what kind of sleep do we enter to when an idle tick fires and we go back to idle? Is it always deep? I believe that ts->tick_stopped == 1 shouldn't be too relevant for the governor. We can definetly have scenarios where the idle tick is stopped for a long while, then it fires and schedules the next timer at NOW() + TICK_NSEC (as if the tick had been restarted). This can even repeat that way for some time, because ts->tick_stopped == 1 only implies that the tick has been stopped once since we entered the idle loop. After that we may well have a periodic tick behaviour. In that case we probably don't want deep idle state. Especially if we have: idle_loop() { tick_stop (scheduled several seconds forward) deep_idle_sleep() //several seconds later tick() tick_stop (scheduled TICK_NSEC forward) deep_idle_sleep() tick() { set_need_resched() } exit idle loop } Here the last deep idle state isn't necessary. > > > Otherwise we can have something like this: > > > > diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c > > index da9455a..408c985 100644 > > --- a/kernel/time/tick-sched.c > > +++ b/kernel/time/tick-sched.c > > @@ -806,6 +806,9 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) > > static void tick_nohz_retain_tick(struct tick_sched *ts) > > { > > ts->timer_expires_base = 0; > > + > > + if (ts->tick_stopped) > > + tick_nohz_restart(ts, ktime_get()); > > } > > > > #ifdef CONFIG_NO_HZ_FULL > > > > We could do that, but my concern with that approach is that we may end up > stopping and starting the tick back and forth without exiting the loop > in do_idle() just because somebody uses a periodic timer behind our > back and the governor gets confused. > > Besides, that would be a change in behavior, while the $subject patch > simply fixes a mistake in the original design. Ok, let's take the safe approach for now as this is a fix and it should even be routed to stable. But then in the longer term, perhaps cpuidle_select() should think that through. Thanks.