Received: by 10.213.65.68 with SMTP id h4csp1421646imn; Mon, 19 Mar 2018 03:51:39 -0700 (PDT) X-Google-Smtp-Source: AG47ELsEDrpfzCULUo78uzSXH9scGf9u0/0Q+Re2BcjjlOhIHqVpMfis7vlgLyh/cCYfkugPrWnN X-Received: by 2002:a17:902:28e3:: with SMTP id f90-v6mr3720867plb.250.1521456699411; Mon, 19 Mar 2018 03:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521456699; cv=none; d=google.com; s=arc-20160816; b=B6d5WXShD6dNYnKT+e1OTDkFzrsnifFdi1JeSr+D62ePPQFpUdNnPybQelOuEf33lt 7Ogv9xXAY/x7Xj/3Wo5lYjsoqk8SEpL8WOK/rErAhus/5/L8IxJ4OL11gLEaxLkM7tKj 9qyxdiG8/ORvifSy6lgUz7EtMBPplvXNI7NokCUNreXv+Y4l58ApDkVUycOAIL9zcZc8 yQTpLGGY65yZ/QtmlPPSmwj3VCkEO0DMjxMz/fk32MAIBhtjcyXnuLcPZ8nkAwmtwOnx LpCK6E8hJpyrho6OuJcXS6QQDNSnmSFsxvPo4a1r5crNcIsnexjKcHosJx4LM8ZASV2N i1pw== 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=EyuO9N1vHwJ+OdTAZOPV4+iyTF2zv+vKzpOWed2zVfs=; b=pRa83Z3jXBHiZR6SOjVqeyx1q5NehnSStfBNJKKSlq3liNtAZPp8J+EV1X7oFJZeOk 3X8V8TSXhXGw6qee+aNU9YtWMDMXddJS+vjRDNs9UyX0Pa+KMqAMN52oJJm4MmtJQBGK 9JmrjeFNoR34k9LNXksbLAezpCg9783MAdDPEueCcGzmBDuhQA4kJgFfpwgos9idYKec SpcH8xcVzyZqUwvPE2Ywwm3ohotSUVVyyzmQNwWcSZYUqZUli2+Bh/LNW++yU6cOUqw1 6XSB+aZFLpRtQmy30tg3+OxkQXGcMrCL/JhRXGWYGy4NUaasiHSYiVBl43xHOaeei38F D0qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=UXYWQLlh; 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 l5-v6si9452041pli.168.2018.03.19.03.51.25; Mon, 19 Mar 2018 03:51:39 -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=@infradead.org header.s=bombadil.20170209 header.b=UXYWQLlh; 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 S1755451AbeCSKtW (ORCPT + 99 others); Mon, 19 Mar 2018 06:49:22 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59892 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754894AbeCSKtP (ORCPT ); Mon, 19 Mar 2018 06:49:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=EyuO9N1vHwJ+OdTAZOPV4+iyTF2zv+vKzpOWed2zVfs=; b=UXYWQLlhDPyxZRKALsktJQ6m7 +jgY5DJmBIe84GQcWzt+NvmGseTKv6RsjOJUczO3pYGNKYoZ6sxZxHNDHXXwdjua2ogbTkSnMBPD1 XTh+y0QFGcNOXFkRSRA//r6U+35jjy0PsU0M33xqfGhFf68B5vaF/Q/7NTQBZb5IujgQEfk95+aeS J/1ww4XeicNekyjslKcWLTcsDrdU5E9qVsv3OSwr8bP+PSE7aaDj9i1GY2Pbp2bFhhhfUXM+Hiz1y XZKYs1RIv3gjQWaMJwZ7bulddttMmVG887OmfL19R2C6JWeWosY13dpjKuH2lTVzzoOHeMesiyT0u U6kv240QA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1exsLd-0001sH-Js; Mon, 19 Mar 2018 10:49:01 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1EB372029F860; Mon, 19 Mar 2018 11:49:00 +0100 (CET) Date: Mon, 19 Mar 2018 11:49:00 +0100 From: Peter Zijlstra To: "Rafael J. Wysocki" Cc: Doug Smythies , Thomas Ilsche , Linux PM , Frederic Weisbecker , Thomas Gleixner , Paul McKenney , Rik van Riel , Aubrey Li , Mike Galbraith , LKML Subject: Re: [RFT][PATCH v5 0/7] sched/cpuidle: Idle loop rework Message-ID: <20180319104900.GH4043@hirez.programming.kicks-ass.net> References: <2142751.3U6XgWyF8u@aspire.rjw.lan> <001a01d3be0a$ad3a0ed0$07ae2c70$@net> <2043615.lCdO10SMaB@aspire.rjw.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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); + } } 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; +} + /** * 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; + tick_sched_do_timer(now); /*