Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp552496imm; Fri, 17 Aug 2018 02:36:11 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzZNAmRsLejkGRx7eva6nRuWdmKUlYC2U9z9w5YUXGtXD5d+eOe4fWcCPkvjkv6BeuM1j4S X-Received: by 2002:a63:6ecf:: with SMTP id j198-v6mr32710536pgc.213.1534498571243; Fri, 17 Aug 2018 02:36:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534498571; cv=none; d=google.com; s=arc-20160816; b=jp+pOf80kvLo/YO7CcODcGnvkoGYfN+EoDqbHt2YCpJsTTJktkiAgPLLZPLMddUZmM SrN+6Av4Tdq4ANPfUIxK+8AsnoBkLr3gKgI6RxN1DcgMEGGOxLDHtvJpVzXvehlZF+Jk x8jBUb7naLQN46fdp+9I8GMvIJa5Aezf2RgaHJCU1XEzynbKg+XuPZZ9hmOk1upzC0Tw sSnaYa9DGA5MWVin6VFLG4IL6iD8yQYg2jjt/HsHYFVxm23f7Ia7p0zx57DVEi3kgI3z 4zxBwdihjmvsBliymGdynXpjQ/Js6fI4A77BH0DZQoH3b6twL2lph6Mod+KDynb2lKpL CVQA== 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=DHwguWE5kwmtsTDwuIWfnS0tQkwkPQhk2E03AgOfKWc=; b=lIX9Koo+SYJPjpV7o4VxfibSL0Hn7IkEclRhmNBiR2vxXkk3yJLsdT8SH8GphSVVu9 tKsSw32kH2Je8vToo5SordgfjyL02QDTFEoKnuZFxa+KRfExOfw1wACnlByZqMr0x/HA 1ve8dIVitPj+oN/o5004lFz0wspqWk1Vfy2hNFYLDSfhL5tn9A+ojnTASpFYQQ1QeQm5 efFL8THIoy5LANlg7q0NC1IdLN3/I6Uyim6AF6f2m7m4qKFQHvdisPoka/Vk6k0FvJQF PP+0ngMxnouBmG9VAlEdmOkxtVQ0lU5Eq25WO6hw/QK92qevJL131pJxcMPRAV5Fw08r PkSA== 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 x12-v6si1691337pgj.175.2018.08.17.02.35.56; Fri, 17 Aug 2018 02:36:11 -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 S1726717AbeHQMhB (ORCPT + 99 others); Fri, 17 Aug 2018 08:37:01 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:65266 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726376AbeHQMhB (ORCPT ); Fri, 17 Aug 2018 08:37:01 -0400 Received: from 79.184.254.66.ipv4.supernova.orange.pl (79.184.254.66) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id f83553e21db57294; Fri, 17 Aug 2018 11:34:18 +0200 From: "Rafael J. Wysocki" To: Frederic Weisbecker Cc: Peter Zijlstra , Linux PM , LKML , Ingo Molnar , Leo Yan Subject: Re: [PATCH] sched: idle: Avoid retaining the tick when it has been stopped Date: Fri, 17 Aug 2018 11:32:07 +0200 Message-ID: <10817203.8q7neLTJVD@aspire.rjw.lan> In-Reply-To: <20180816132723.GA6010@lerouge> References: <2161372.IsD4PDzmmY@aspire.rjw.lan> <20180816132723.GA6010@lerouge> 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 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. Cheers, Rafael