Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp577357imm; Fri, 17 Aug 2018 03:06:55 -0700 (PDT) X-Google-Smtp-Source: AA+uWPy4Crk4MaJ5U09wSxazMEH/lu+L6Jc2jOrQWqja2ySwwk7/1NaVOD9eCzHTjFTBXmXzZFPS X-Received: by 2002:a17:902:b28:: with SMTP id 37-v6mr32788791plq.337.1534500415782; Fri, 17 Aug 2018 03:06:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534500415; cv=none; d=google.com; s=arc-20160816; b=EfVb5qxuQXv3gwDQdSwsHaCFEGhvkazXup5/1JmCUtow18sL3o1XMHA0XgiSNJ3HBq Ayr/H2NKIPNNIsJRBb0GfBynTbCQskR4CLT52zcKUHaJyVSZRequPO/lS47tUNXqcCkI xvqzjg9nLQUK9tpserJcb1saGL94rB4tAektNF3MZHjSgsYbyBcDUb39J4XTh/EJ8Fj+ kVYHG5DaNdUelpIeB1DDvin/DGyOEuACp1wKvJAeVZKAOgT1yuJKUuRP7yEOLiEbGdn2 dHat9agRTnbcKcabAes+6qPeoegiG/KLDXDa1s8mgt3vcE7n80bTQ2xd8l2CTJAaoz5O jHXQ== 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=pPePN0ohmipkH5CoJdE8tix8JvpZf7xQYsOCJA9FMgU=; b=CO3fID0rZLye8MFac3uHaggVxmcwEwmZOgHzQ6gaKhm5sRGERnXEbcUkLGtNnZg7YE REhSugjFDKR3foDpj6vwo1FWnNF2BPrBwXx8HHLGHPE7eJ5X/1IwsvR5AWEtw3XcBCGB 8WnBFFE/3xoEygtY/TOq4R3OInLzRu1r2wwwkdw4Fg6nx0fqcr613jy28NAWqN70gPMt bcnvqofPwww+O2ny8HlUe6IooMWeC1gosVcihd2z2QR2Jxvdhb0TQMqbF4YpThcvDrus xp/xbK3noacmM0PDnhm4CuFLesLAW5dyIY3q3BruSJJVGCqpODQ1PoTiXseYFpKwUNCT 8IUw== 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 u20-v6si1853520pgj.443.2018.08.17.03.06.40; Fri, 17 Aug 2018 03:06:55 -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 S1726832AbeHQNIX (ORCPT + 99 others); Fri, 17 Aug 2018 09:08:23 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:34786 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbeHQNIX (ORCPT ); Fri, 17 Aug 2018 09:08:23 -0400 Received: by mail-oi0-f67.google.com with SMTP id 13-v6so13097971ois.1; Fri, 17 Aug 2018 03:05:34 -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=pPePN0ohmipkH5CoJdE8tix8JvpZf7xQYsOCJA9FMgU=; b=o0Czhw+9V9a6YbeLXMkVuMCQ7k9y5LtUEXbi8ByU5w07grGwPyjN7oxb+fxmRHhZbM /TR6jBOvN3daRMs0k4fGBGwTGON4lj5bkNj8E4VFqgl7Y4wKps1gboNsKOEuF5G2iVjF 5+08iguu6/eq6o3hPqIGwmE4mgmie6dnUnTw6Og7aTnbWoRQjvL5zwFGRz1irHMEJCJx zSMrG85xxejRXu6TcKREERq0ykqvTtPVzbxObdG0Z43+Gb2J/w7Ra7EHPst1kyQ27SdU yJ9lxJWdhH5859jkAXlXIMUYfzFff4vkS0KcQdWlFd/Eo5UFc+4YR2uXeHWi4gN9vch7 Oa/w== X-Gm-Message-State: AOUpUlF6xCXDMErgGdUcyiDHCONSKMhZRxxyD+Yx0pOrsPC02a1PujwA j7ySenp8RtjZwwEAuUoJUT3TbB16AI5gudGYoWQ= X-Received: by 2002:aca:37c2:: with SMTP id e185-v6mr1879632oia.326.1534500334376; Fri, 17 Aug 2018 03:05:34 -0700 (PDT) MIME-Version: 1.0 References: <2161372.IsD4PDzmmY@aspire.rjw.lan> <20180816132723.GA6010@lerouge> <10817203.8q7neLTJVD@aspire.rjw.lan> In-Reply-To: <10817203.8q7neLTJVD@aspire.rjw.lan> From: "Rafael J. Wysocki" Date: Fri, 17 Aug 2018 12:05:22 +0200 Message-ID: Subject: Re: [PATCH] sched: idle: Avoid retaining the tick when it has been stopped To: Frederic Weisbecker Cc: Peter Zijlstra , Linux PM , Linux Kernel Mailing List , Ingo Molnar , Leo Yan 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 Fri, Aug 17, 2018 at 11:34 AM 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. > > > 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. Anyway, I'm sort of divided here. We need to do something, this way or another, because the current code is not strictly correct. If there are no concerns about the possible extra overhead related to restarting the tick, I'd just add a tick_nohz_idle_restart_tick() to the tick_nohz_idle_retain_tick() branch in cpuidle_idle_call() (it would do what's needed in there without affecting any other places). Then, of course, governors would not need to worry about leaving the tick stopped, so menu could be simplified somewhat, which may be a good thing after all. Cheers, Rafael