Received: by 10.213.65.68 with SMTP id h4csp1450324imn; Mon, 19 Mar 2018 04:38:59 -0700 (PDT) X-Google-Smtp-Source: AG47ELsz/HTfPJNssbijGq4IMEsb6gDkFcwXwdCvujG/76S3wf8bcfot+H2CMquFbqu6XsIeq0Rn X-Received: by 2002:a17:902:b901:: with SMTP id bf1-v6mr11914537plb.175.1521459539639; Mon, 19 Mar 2018 04:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521459539; cv=none; d=google.com; s=arc-20160816; b=SOnOAuKq+ZEXFps8c/dQjdbjyZM6f4PZl3R02LPSdjXvHzYNWwixtHQx5pcDnQTH0v hVouf9uvJx2pLhKrzinckZNyycZv4DLztLxmq8v+qPdDjt395s4EP53yVJGITwH/Htd5 +RCnJeyAuREhDbGH7ggXDbgOD5+uQwgzlr5lHAlLE9EynQoK8/xOOEXwzAElhxPfSEiH RUVB4AM2GGXGll3rx+E26q6Cuc6iP8jFIl9vElFpe0OZ3RqtvbRO/J9AAEK03ru46Wp8 8oGC87W9BnXsSmVgX4oUqoziXT0Ub4w9gZnIivmKM8B4CloUHlcA+kaU2hD7yp9zRRPJ OEVw== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=25ZSyBianpLTZpn+eljSVbshFJ5ypeW0LOo4da8lvaE=; b=rF34xjgYcmMR6f4dGrykUvs4KIJAH/xpynRuTE9+Q8EorhM6DPXWzwE2grVD1o3HhI DeuGwpYGoVIKDnXYKfQp+5KHYkzvHf5dVGF423SqFcHdG8NzVK/Q9wVqSHP1sXVm8H+P pff05D+mAKwwaSDlAeMVqJZdTcSXFtvvRZMIofvE1Xx3BurwpXEArk36XvoYcWmPaE0W i5vWOyaxHBFXHNv7Vzr1yBw5dIKDUW1Qa7BkX7GRYvIQl32NImpBJ0pFyBOWYaWGqiBG FBSiOkuraVTFoaa1tFPeJeuzE9wD3HYsdkyqF+Eee4KyC/CBKDJ7Mg2hcYe4SSPDjvDr BMBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=OJeqTql1; 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 x14si9547838pgq.614.2018.03.19.04.38.45; Mon, 19 Mar 2018 04:38:59 -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=fail header.i=@gmail.com header.s=20161025 header.b=OJeqTql1; 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 S932672AbeCSLg7 (ORCPT + 99 others); Mon, 19 Mar 2018 07:36:59 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:40418 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932538AbeCSLgy (ORCPT ); Mon, 19 Mar 2018 07:36:54 -0400 Received: by mail-ot0-f193.google.com with SMTP id l12-v6so16975799otj.7; Mon, 19 Mar 2018 04:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=25ZSyBianpLTZpn+eljSVbshFJ5ypeW0LOo4da8lvaE=; b=OJeqTql1dED/V4YP3pP6qlypO0CZ7HWtxd898b7ZPRTtOQDNOOsiUAgnJ/ZLIb3+NE cygQUrPT3xnCHMbtwVCOM3QI93nB+x6DBzR5xdZBsgXcxMGfAu8/y7luLUnGLJIHG58r 42YTT/Z8u/LtgskAO0pNN6PW4KQZD40rnBV6eCy7ZiaI1dpLqj3I59iOj82ItmzXQRCW 1EtwACpYgvtPyQmdM5XkdJnerJn7itPAA7DVpL+tnfSJSWrBwdq5sG7ZoM82KPBX2ROD FfIxIWJ3gR2pKDaa3WEWhNMG/AR/fQnh1MF8IYEZOVYhteUSZDQFQkvvqCeQ9IsucVR4 do9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=25ZSyBianpLTZpn+eljSVbshFJ5ypeW0LOo4da8lvaE=; b=SUYp+oRXMDonFPWEqjpIVoX5YNuuzoMSEBB7f7R+5qGZ1oF8l1npEjiLpk/pFEz0Ul ovm+zce3U+mGOpy3nRLT9xmlwUJncXOzshzrpLIlxSSZBt/g19EMdyiq3trPWnaUp+m2 MnZGM5ZCaVyhsEsuJbhbQblNgBAdC+7u7xANSQ1ApEFRAvi76sYWNq4Jcdcp2pdTDULd boV/an2mVUoEMhFvC0sDbm+lgRs9sg99ntpRou4X0QNheG8Ev1rHEEHBrrGD1ccFdohI RccrIjDER4Z/0h1bhA7FgcQxQgkyJV0UbA2kG1C81PQrBDMvi7y09+izIc8kLMMHRTya X0/A== X-Gm-Message-State: AElRT7Gswa8Sl1x8dncp6gQw9jK/QPFG5b/FXKOWG1I8g9iR2JFWA0Dh Ph7uVsSdwiooLigzcVfNzEUsl9xEf25d6b7OxXI= X-Received: by 2002:a9d:5b44:: with SMTP id e4-v6mr6214394otj.305.1521459413360; Mon, 19 Mar 2018 04:36:53 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:9f7:0:0:0:0:0 with HTTP; Mon, 19 Mar 2018 04:36:52 -0700 (PDT) In-Reply-To: <20180319104900.GH4043@hirez.programming.kicks-ass.net> References: <2142751.3U6XgWyF8u@aspire.rjw.lan> <001a01d3be0a$ad3a0ed0$07ae2c70$@net> <2043615.lCdO10SMaB@aspire.rjw.lan> <20180319104900.GH4043@hirez.programming.kicks-ass.net> From: "Rafael J. Wysocki" Date: Mon, 19 Mar 2018 12:36:52 +0100 X-Google-Sender-Auth: r4O57rGYHX0XEhAgxtvupof8rMY Message-ID: Subject: Re: [RFT][PATCH v5 0/7] sched/cpuidle: Idle loop rework To: Peter Zijlstra Cc: "Rafael J. Wysocki" , Doug Smythies , Thomas Ilsche , Linux PM , Frederic Weisbecker , Thomas Gleixner , Paul McKenney , Rik van Riel , Aubrey Li , Mike Galbraith , LKML 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 Mon, Mar 19, 2018 at 11:49 AM, Peter Zijlstra wrote: > On Sun, Mar 18, 2018 at 05:15:22PM +0100, Rafael J. Wysocki wrote: >> On Sun, Mar 18, 2018 at 12:00 PM, Rafael J. Wysocki wrote: >> > @@ -354,6 +360,7 @@ static int menu_select(struct cpuidle_dr >> > if (latency_req > interactivity_req) >> > latency_req = interactivity_req; >> > >> > + expected_interval = TICK_USEC_HZ; >> > /* >> > * Find the idle state with the lowest power while satisfying >> > * our constraints. >> > @@ -367,17 +374,44 @@ static int menu_select(struct cpuidle_dr >> > continue; >> > if (idx == -1) >> > idx = i; /* first enabled state */ >> > - if (s->target_residency > data->predicted_us) >> > + if (s->target_residency > data->predicted_us) { >> > + /* >> > + * Retain the tick if the selected state is shallower >> > + * than the deepest available one with target residency >> > + * within the tick period range. >> > + * >> > + * This allows the tick to be stopped even if the >> > + * predicted idle duration is within the tick period >> > + * range to counter the effect by which the prediction >> > + * may be skewed towards lower values due to the tick >> > + * bias. >> > + */ >> > + expected_interval = s->target_residency; >> > break; >> >> BTW, I guess I need to explain the motivation here more thoroughly, so >> here it goes. >> >> The governor predicts idle duration under the assumption that the >> tick will be stopped, so if the result of the prediction is within the tick >> period range and it is not accurate, that needs to be taken into >> account in the governor's statistics. However, if the tick is allowed >> to run every time the governor predicts idle duration within the tick >> period range, the governor will always see that it was "almost >> right" and the correction factor applied by it to improve the >> prediction next time will not be sufficient. For this reason, it >> is better to stop the tick at least sometimes when the governor >> predicts idle duration within the tick period range and the idea >> here is to do that when the selected state is the deepest available >> one with the target residency within the tick period range. This >> allows the opportunity to save more energy to be seized which >> balances the extra overhead of stopping the tick. > > My brain is just not willing to understand how that work this morning. > Also it sounds really dodgy. Well, I guess I can't really explain it better. :-) The reason why this works better than the original v5 is because of how menu_update() works AFAICS. > Should we not look to something like this instead? > > --- > --- a/include/linux/tick.h > +++ b/include/linux/tick.h > @@ -119,6 +119,7 @@ extern void tick_nohz_idle_stop_tick(voi > extern void tick_nohz_idle_retain_tick(void); > extern void tick_nohz_idle_restart_tick(void); > extern void tick_nohz_idle_enter(void); > +extern bool tick_nohz_idle_got_tick(void); > extern void tick_nohz_idle_exit(void); > extern void tick_nohz_irq_exit(void); > extern ktime_t tick_nohz_get_sleep_length(void); > @@ -142,6 +143,7 @@ static inline void tick_nohz_idle_stop_t > static inline void tick_nohz_idle_retain_tick(void) { } > static inline void tick_nohz_idle_restart_tick(void) { } > static inline void tick_nohz_idle_enter(void) { } > +static inline bool tick_nohz_idle_got_tick(void) { return false; } > static inline void tick_nohz_idle_exit(void) { } > > static inline ktime_t tick_nohz_get_sleep_length(void) > --- a/kernel/sched/idle.c > +++ b/kernel/sched/idle.c > @@ -198,10 +198,13 @@ static void cpuidle_idle_call(void) > rcu_idle_enter(); > > entered_state = call_cpuidle(drv, dev, next_state); > - /* > - * Give the governor an opportunity to reflect on the outcome > - */ > - cpuidle_reflect(dev, entered_state); > + > + if (!tick_nohz_idle_got_tick()) { > + /* > + * Give the governor an opportunity to reflect on the outcome > + */ > + cpuidle_reflect(dev, entered_state); > + } So I guess the idea is to only invoke menu_update() if the CPU was not woken up by the tick, right? I would check that in menu_reflect() (as the problem is really with the menu governor and not general). Also, do we really want to always disregard wakeups from the tick? Say, if the governor predicted idle duration of a few microseconds and the CPU is woken up by the tick, we want it to realize that it was way off, don't we? > } > > exit_idle: > --- a/kernel/time/tick-sched.c > +++ b/kernel/time/tick-sched.c > @@ -996,6 +996,21 @@ void tick_nohz_idle_enter(void) > local_irq_enable(); > } > > +bool tick_nohz_idle_got_tick(void) > +{ > + struct tick_sched *ts; > + bool got_tick = false; > + > + ts = this_cpu_ptr(&tick_cpu_sched); > + > + if (ts->inidle == 2) { > + got_tick = true; > + ts->inidle = 1; > + } > + > + return got_tick; > +} Looks simple enough. :-) > + > /** > * tick_nohz_irq_exit - update next tick event from interrupt exit > * > @@ -1142,6 +1157,9 @@ static void tick_nohz_handler(struct clo > struct pt_regs *regs = get_irq_regs(); > ktime_t now = ktime_get(); > > + if (ts->inidle) > + ts->inidle = 2; > + > dev->next_event = KTIME_MAX; > > tick_sched_do_timer(now); > @@ -1239,6 +1257,9 @@ static enum hrtimer_restart tick_sched_t > struct pt_regs *regs = get_irq_regs(); > ktime_t now = ktime_get(); > > + if (ts->inidle) > + ts->inidle = 2; > + Why do we need to do it here? > tick_sched_do_timer(now); > > /*