From patchwork Fri Nov 10 17:42:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Smythies X-Patchwork-Id: 10053505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8BD24603FA for ; Fri, 10 Nov 2017 17:42:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 756162B3B7 for ; Fri, 10 Nov 2017 17:42:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69B872B3B9; Fri, 10 Nov 2017 17:42:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB0DD2B3B7 for ; Fri, 10 Nov 2017 17:42:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752685AbdKJRmV (ORCPT ); Fri, 10 Nov 2017 12:42:21 -0500 Received: from cmta17.telus.net ([209.171.16.90]:50649 "EHLO cmta17.telus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752625AbdKJRmU (ORCPT ); Fri, 10 Nov 2017 12:42:20 -0500 Received: from dougxps ([173.180.45.4]) by cmsmtp with SMTP id DDJoesU8dcUPyDDJpetA8A; Fri, 10 Nov 2017 10:42:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telus.net; s=neo; t=1510335739; bh=SGo21+ZfofMI9tKJQsQP3UBZ3TAWJlMb+1Q1Oewyomo=; h=From:To:Cc:References:In-Reply-To:Subject:Date; b=WZJDv2XrAgpSMBtDLtTqiU9dOdlMsNmDzM8e/MvRkLmoW3dfW8P6PTQZL+OCxhgTl uu5/Oey98dtfWxcCJPD7JI9EekbcxQ4UPCQHy5BfXZVPrb4zVuYOD8hK9GGrBkdxlk Nb8iGJsR4LacqusHVRZvqtHFFlwkFctxMZ2bfiCJuhhohEDiWxb6IXIyuFFZ9lfxFR 37au1jNdCrctkVWM0jpvok13BBhgZcH6xb2U31XtQMi2Omwh0G1unIodFZlVEggOpd CDIeUU4wpkJ2GfR5mdrKtMbEtDRrxevMXPtELubemiF3CieuLMidHSgS9IYpGDTH5m bI9G6kdGqqARw== X-Authority-Analysis: v=2.2 cv=CulQSjwD c=1 sm=1 tr=0 a=zJWegnE7BH9C0Gl4FFgQyA==:117 a=zJWegnE7BH9C0Gl4FFgQyA==:17 a=Pyq9K9CWowscuQLKlpiwfMBGOR0=:19 a=IkcTkHD0fZMA:10 a=NEAV23lmAAAA:8 a=aatUQebYAAAA:8 a=syalICBOW_0kl_wNtE8A:9 a=QEXdDO2ut3YA:10 a=7715FyvI7WU-l6oqrZBK:22 From: "Doug Smythies" To: "'Thomas Ilsche'" Cc: =?UTF-8?Q?'Marcus_H=C3=A4hnel'?= , "'Daniel Hackenberg'" , =?UTF-8?Q?'Robert_Sch=C3=B6ne'?= , , "'Rafael J. Wysocki'" , "'Alex Shi'" , "'Ingo Molnar'" , "'Rik van Riel'" , "'Daniel Lezcano'" , "'Nicholas Piggin'" , , "'Len Brown'" , "Doug Smythies" References: <000101d34938$da740870$8f5c1950$@net> <000801d34a78$cdd27890$697769b0$@net> CCuzeI4ZRt1L5CCv4eEEwJ In-Reply-To: CCuzeI4ZRt1L5CCv4eEEwJ Subject: RE: [PATCH] cpuidle: Allow menu governor to enter deeper sleep states after some time Date: Fri, 10 Nov 2017 09:42:14 -0800 Message-ID: <001901d35a4b$40d2f310$c278d930$@net> MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AdNYHMmw+kbu3/IETS61gZJ1wes8gwCKj56w Content-Language: en-ca X-CMAE-Envelope: MS4wfPP+8fu46Vm9tVg1n0WbsR2pKPFJv9flJOF80A6ZimsX1QDugcHas0yLAchTA6gIoN7tgC6WQ4TDqeq/FZN+IrodhDr9//yDMgy770llDRgg/w+F3osD SK0rGfynusUyzc2vXVGaCegGpBwjzcrME/wGAal7ceZEGXXQAQ9hHxFi0flR9RKaa9f6XEM3avgd3ZIy92GiKeMEFaVHtrt8dK2r2lJyjGHPKsCuEjf5eu/B IEJCxxSbj4m2TJojr7VfLnB0njM+TGK0KZhrhTC+zOAN6ScPn82dHjAO9TrjthCD1MNE6SamVCGBvwQtloQ//W6LyPfYyv7pXNTtteKg1nkCBbqTndx+K2/+ Jrp/rA2QYvYggASF+1juIdHn9JxjhDfnqpQIb2DVQYL+Tg6EGrkfcQnkai10+sutSd9+6lR78YSX7ncSmv3O4cl/ZH3Bc6lMPKDx3gEeoGSA771okl9wOEDN P1H1IfRgFHd0Y+Br5zQeGan7WJkpls8ToL1kJ1XtD7lHxwmMNCyItKDRpAGEkFfhuxJp9xHYuRyBSYdqfi7YoQofR64Qlo7fHqFJmgMEWMIsW9x7G2hgq9Bu 7BxosDsqkOxiwPh3zaMoloFfeeZBzZj5hCwMhPdwszbYeQ== Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Thomas, In addition to my previous reply: On 2017.11.7 15:04 Thomas Ilsche wrote: > I made a hack[1] to stop poll_idle after timer_expires which prevents the issue > in my tests. The idea is to make sure that poll_idle is really exited whenever a > timer happens. I was trying to use existing information, but I'm not entirely > sure if tick_sched.timer_expires actually has the right semantic. Your patch does not prevent the issue in my case. And actually I wouldn't expect it to. Why not? My (unproven) theory has always been that by the time it ends up in the loop in drivers/cpuidle/poll_state.c the timer has already expired, so you are looking at the next timer time, which is long. As previously mentioned, another old, but rebased, patch does work for my case, I'll paste it below. I'll just add a note that I find testing results hard to repeat here. Sometimes my tests will go for hours without an issue and other times they go for hours with constant issues. I will say that there does appear to be some repeatable pattern, where forcing minimum pstate makes the problem worse than when forcing the maximum pstate. (i.e. the time between reading the original call to tick_nohz_get_sleep_length and the loop inside drivers/cpuidle/poll_state.c is longer). [1]: https://github.com/tud-zih-energy/linux/commit/7529b167dc7c2afaacd4551fe01ec576df5097e3 ... Doug From 788fab5531625d7bc7f6db9622984c8e87fe7672 Mon Sep 17 00:00:00 2001 From: Doug Smythies Date: Sat, 28 Oct 2017 07:15:41 -0700 Subject: [PATCH] cpuidle: break out of idle polling loop after HLT threshold This was from Rik van Riel on 2016.03.18 Staying in the poll loop can be beneficial for workloads that wake back up very, very quickly, but staying in the poll loop for too long can waste a lot of power. Break out of the idle polling loop if the system has spent more time in the loop than the threshold for entering the next power saving mode. The poll loop uses full CPU power already, so this will not increase the power use of the poll loop. Signed-off-by: Doug Smythies --- drivers/cpuidle/poll_state.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c index 7416b16..3023d44 100644 --- a/drivers/cpuidle/poll_state.c +++ b/drivers/cpuidle/poll_state.c @@ -11,10 +11,29 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { + /* + * Polling is state 0; break out of the polling loop after the + * threshold for the next power state has passed. Doing this several + * times in a row should cause the menu governor to immediately + * select a deeper power state. + */ + u64 limit = drv->states[1].target_residency * NSEC_PER_USEC; + ktime_t start = ktime_get(); + int i = 0; + local_irq_enable(); if (!current_set_polling_and_test()) { - while (!need_resched()) + while (!need_resched()) { + ktime_t now; cpu_relax(); + + /* Occasionally check for a timeout. */ + if (!(i++ % 1000)) { + now = ktime_get(); + if (ktime_to_ns(ktime_sub(now, start)) > limit) + break; + } + } } current_clr_polling();