Received: by 10.213.65.68 with SMTP id h4csp182539imn; Wed, 28 Mar 2018 01:15:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/mUB8hDR1QUq1gjOxlSs4qWYv+xoEulT5g0phFpWX3nPx36MU+Icg+XER6Ghhz0ninNHp7 X-Received: by 2002:a17:902:8f97:: with SMTP id z23-v6mr2797547plo.162.1522224906225; Wed, 28 Mar 2018 01:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522224906; cv=none; d=google.com; s=arc-20160816; b=i//aH/NHyyJhEDG4HIuGX7dMrFI9587+rilKjVoyh846GZAWQZM9FNAJrFmQKFLfks VGvgqIZOynvTuQ2F6dPQGIqFOv0AUZV+384QCJC1dRvySFZKOwiQP5nTnw7MoB8dag9V lHRWAppqMggbVpLXsaLu465nEC4kT+Nl4iUW2qvDsSQJW1+6pSrP3zv/izMe5C+cj2as cxEfc+8KeOeX0mxHj/l6IGYCy0ffGsTznTEu3oSONxRyq2ermE1j9k/S3b7+06MqE4yQ ehniiWnKu4OKZA5BxaD2xOzIY1aQBcrGYgIJsAB0G46HReQEGYCTb2KRmKOIsgwQxH7O owtg== 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=UtBcmvE4pQclE/b/YQV1S15OksjZUeY5FAYnNfQS4EM=; b=sNZNAfem0jpSDpAKGl41iszIP2En7D53PmYnrPP/z+fscvp2KTA18hLV8i+bVX5nlB +yJxFGiyARqYhFCyKdwNCS++FOaB8J3PZwP4Ix64YM1CcLmn6VsPBz6jH9nm2uKIhwtS jf61gxnNttMykJkoytTuJPpC25B0N2c6r1qHVKxiiAgV7fhjA3A8LHFIAvWb0aXXWT4R oLrNhU9hhPTF/DVSEli5cGmja8wxSZj/v4TBag6Mup2JPNf2G9WlQsRlWwiRPM83HZU7 FeB/dzR5ljq7Sxuop/xS4aPB/Fe79/pSyqa1s7gKDSLVKwbX+3LOBGnGlwmVJJP0aKM9 4Pfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=FE+/+k4a; 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 b8-v6si3283676pll.146.2018.03.28.01.14.52; Wed, 28 Mar 2018 01:15:06 -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=FE+/+k4a; 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 S1752454AbeC1INo (ORCPT + 99 others); Wed, 28 Mar 2018 04:13:44 -0400 Received: from mail-oi0-f48.google.com ([209.85.218.48]:43018 "EHLO mail-oi0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752077AbeC1INj (ORCPT ); Wed, 28 Mar 2018 04:13:39 -0400 Received: by mail-oi0-f48.google.com with SMTP id u84-v6so1385639oie.10; Wed, 28 Mar 2018 01:13:39 -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=UtBcmvE4pQclE/b/YQV1S15OksjZUeY5FAYnNfQS4EM=; b=FE+/+k4a42AMlb/QT0SU6rSY7TxG4xgE9AcKk/4Fyf4iq7uiFBR6eKOxRZC/2oCFzo xgr90jc2Ew3+hzQYVoyjOZrs2H0o8Dy4USWbt9kQqdQczF5xvFzmSOjURoXrJJIZNyAd vaHQBtufv0PXki+aTviuvJ7T8Fe55oqndFy3jPAvTF11EHWGFxeG2nyQJ7KSiX4XLHrw z8yEsMSGputRlHFyJWNlxvwpuEkmuKWoMxCVF21Z1zUxOjebSEXO/UI48xiZqHbzCa2q o+E7aYKb+NhU0zNnuvwT4/R9R6tDvSaRdAfap2b+0IBHAdGqFDypzPHeAkH8URwvA3oS rcJA== 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=UtBcmvE4pQclE/b/YQV1S15OksjZUeY5FAYnNfQS4EM=; b=msMXFMPVbl3FjW4js+4DV/R0RRA401gymLU25AznHERjVsq//QLn6DdmQ12u/bSJD3 tdYtuE3798jnxA5ajYkFS2dnvEtGetxblNFByEAp98pENVB0ZIKndnmQOy/B7LeU+KxT m5C5fzZ6YlLDstp3BC1IDqNbWhJIODFZoLtRkhezeT0+ADiM8W82/vR/FX9NVfANZbLA QnO50ow0W3Ml1kQw25zw0v6QQs6KH5n8o8X7FDU1eUp6w7q40v2Q3kiEvsbtcyHLL4w6 WTv8vgLqAW6ybyLrnt6OlHRbtUhdGyc3dP0eGKV2d9LkMFT8IQnoGUXRNu+lyCD54XCU WxVg== X-Gm-Message-State: ALQs6tCbfB3GH81YB7a1qRPp+2HAooLBiIZSXuqV2DDT4R9il7CqDk4q 5+mEiXfV3FvaRqvTLitTOF7AvjBAlaoS7l8esEI= X-Received: by 10.202.108.73 with SMTP id h70mr1383457oic.282.1522224818788; Wed, 28 Mar 2018 01:13:38 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:9f7:0:0:0:0:0 with HTTP; Wed, 28 Mar 2018 01:13:38 -0700 (PDT) In-Reply-To: <4198010.6ArFqS34NK@aspire.rjw.lan> References: <2390019.oHdSGtR3EE@aspire.rjw.lan> <2249320.0Z4q8AXauv@aspire.rjw.lan> <6462e44a-e207-6b97-22bf-ad4aed69afc2@tu-dresden.de> <4198010.6ArFqS34NK@aspire.rjw.lan> From: "Rafael J. Wysocki" Date: Wed, 28 Mar 2018 10:13:38 +0200 X-Google-Sender-Auth: QDGS3QbEp3QGbLWdT72aLij4NRs Message-ID: Subject: Re: [RFT][PATCH v7 6/8] sched: idle: Select idle state before stopping the tick To: Thomas Ilsche Cc: Peter Zijlstra , Linux PM , Frederic Weisbecker , Thomas Gleixner , Paul McKenney , Doug Smythies , 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 Wed, Mar 28, 2018 at 12:10 AM, Rafael J. Wysocki wrote: > On Tuesday, March 27, 2018 11:50:02 PM CEST Thomas Ilsche wrote: >> On 2018-03-20 16:45, Rafael J. Wysocki wrote: >> > From: Rafael J. Wysocki >> > >> > In order to address the issue with short idle duration predictions >> > by the idle governor after the tick has been stopped, reorder the >> > code in cpuidle_idle_call() so that the governor idle state selection >> > runs before tick_nohz_idle_go_idle() and use the "nohz" hint returned >> > by cpuidle_select() to decide whether or not to stop the tick. >> > >> > This isn't straightforward, because menu_select() invokes >> > tick_nohz_get_sleep_length() to get the time to the next timer >> > event and the number returned by the latter comes from >> > __tick_nohz_idle_enter(). Fortunately, however, it is possible >> > to compute that number without actually stopping the tick and with >> > the help of the existing code. >> >> I think something is wrong with the new tick_nohz_get_sleep_length. >> It seems to return a value that is too large, ignoring immanent >> non-sched timer. > > That's a very useful hint, let me have a look. > >> I tested idle-loop-v7.3. It looks very similar to my previous results >> on the first idle-loop-git-version [1]. Idle and traditional synthetic >> powernightmares are mostly good. > > OK > >> But it selects too deep C-states for short idle periods, which is bad >> for power consumption [2]. > > That still needs to be improved, then. > >> I tracked this down with additional tests using >> __attribute__((optimize("O0"))) menu_select >> and perf probe. With this the behavior seems slightly different, but it >> shows that data->next_timer_us is: >> v4.16-rc6: the expected ~500 us [3] >> idle-loop-v7.3: many milliseconds to minutes [4]. >> This leads to the governor to wrongly selecting C6. >> >> Checking with 372be9e and 6ea0577, I can confirm that the change is >> introduced by this patch. > > Yes, that's where the most intrusive reordering happens. Overall, this is an interesting conundrum, because the case in question is when the tick should never be stopped at all during the workload and the code's behavior in that case should not change, so the change was not intentional. Now, from walking through the code, as long as can_stop_idle_tick() returns 'true' all should be fine or at least I don't see why there is any difference in behavior in that case. However, if can_stop_idle_tick() returns 'false' (for example, because need_resched() returns 'true' when it is evaluated), the behavior *is* different in a couple of ways. I sort of know how that can be addressed, but I'd like to reproduce your results here. Are you still using the same workload as before to trigger this behavior?