Received: by 10.213.65.68 with SMTP id h4csp1492187imn; Mon, 19 Mar 2018 05:50:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELt3A7fDkHdR4VNnC6L/BuXzmKYaTVNo5s8iGAp08WFVfCkL/iT1BZstB5uIm5z0CKvR4SeP X-Received: by 10.99.0.200 with SMTP id 191mr3766023pga.33.1521463809101; Mon, 19 Mar 2018 05:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521463809; cv=none; d=google.com; s=arc-20160816; b=QgDiAw5qXVIqdActUJ8jQF8Nt1YBC+ofM9jrro9bHQvVvgaoDoox30xVG34//nK7Kr swlTxshFTDTrWuCoweqwqYY4HSLs2b4inZEl0LcSC+HmvyGn0Oz1D3Dgsi9xq05TcuF5 Td5qPezaE3ziDmerz8AjS5EjmSmjAN3eeQ2S+u0y/eXbWWtsjaA++XhqWdu2mH486w6b IpBLBuD/8CugwPKfaXDNNHitIXZrmq90T6lKQzJuEAnD59ktr8KGhW31YDjVCf3Hw75N 69hKAPNCb8i1s+sKo+DNimz1f0v+iO0Bu0iwQUNVyGx8Rt+RiLg9oJbEhIZj7GSFqo/N yg7w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=3xmccilKt9DjVv5NyLulKkbE48rxcNGms0QKymnAdBQ=; b=gKZtpByHNdGkzQ9RfT8YtA4f9pV0FCPIrlJ5897Crv4K0dBLh74ee/SrFZacVIvRes aKgcNmlGWt7MWAQtO6Y8/hT7RtDVdV4niOfHVd0On16RI9FhKm8Cup5gIrzPLDJk6TLg zJjB5FUA1E7yzRUkOn2xJb76/CssN/jnZ5Tucj5lx1vfYzzU27Scn8pCmuXOmYIXj1yD aLOYwrm/WhFAJR668edVICjXzo8nEwAF3qWz7rPaVFxEoWAn7OHRPRc/FVk07sV9AEB7 o1wVijOVNd3JG0H+MSKrfQACFKZ32tItFOc3vreft5zFGu/6ool8gjB+XrloXuBjIcv6 0aUQ== 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 ay10-v6si1156444plb.258.2018.03.19.05.49.55; Mon, 19 Mar 2018 05:50:09 -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 S932773AbeCSMse (ORCPT + 99 others); Mon, 19 Mar 2018 08:48:34 -0400 Received: from mailout6.zih.tu-dresden.de ([141.30.67.75]:48162 "EHLO mailout6.zih.tu-dresden.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932300AbeCSMs3 (ORCPT ); Mon, 19 Mar 2018 08:48:29 -0400 Received: from [172.26.34.104] (helo=msx.tu-dresden.de) by mailout6.zih.tu-dresden.de with esmtps (TLSv1.2:AES256-SHA:256) (Exim 4.84_2) (envelope-from ) id 1exuD4-0000TU-Be; Mon, 19 Mar 2018 13:48:18 +0100 Received: from [141.30.69.3] (141.30.69.3) by MSX-L104.msx.ad.zih.tu-dresden.de (172.26.34.104) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Mon, 19 Mar 2018 13:47:16 +0100 Subject: Re: [RFT][PATCH v5 7/7] cpuidle: menu: Avoid selecting shallow states with stopped tick To: "Rafael J. Wysocki" , Peter Zijlstra , Linux PM , "Frederic Weisbecker" CC: Thomas Gleixner , Paul McKenney , Doug Smythies , "Rik van Riel" , Aubrey Li , "Mike Galbraith" , LKML References: <2142751.3U6XgWyF8u@aspire.rjw.lan> <2148754.TY7qXgFyZy@aspire.rjw.lan> From: Thomas Ilsche Message-ID: Date: Mon, 19 Mar 2018 13:47:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <2148754.TY7qXgFyZy@aspire.rjw.lan> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MSX-L104.msx.ad.zih.tu-dresden.de (172.26.34.104) To MSX-L104.msx.ad.zih.tu-dresden.de (172.26.34.104) X-PMWin-Version: 4.0.3, Antivirus-Engine: 3.70.2, Antivirus-Data: 5.49 X-TUD-Virus-Scanned: mailout6.zih.tu-dresden.de Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-03-15 23:19, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > If the scheduler tick has been stopped already and the governor > selects a shallow idle state, the CPU can spend a long time in that > state if the selection is based on an inaccurate prediction of idle > time. That effect turns out to be noticeable, so it needs to be > mitigated. What are some common causes for that situation? How could I trigger this for testing? > To that end, modify the menu governor to discard the result of the > idle time prediction if the tick is stopped and the predicted idle > time is less than the tick period length, unless the tick timer is > going to expire soon. This seems dangerous. Using a C-state that is too deep could be problematic for soft latency, caches and overall energy. Would it be viable to re-enable the sched tick to act as a fallback? Generally, would it be feasible to modify the upcoming sched tick timer to be a better time for a fallback wakeup in certain situations? > > Signed-off-by: Rafael J. Wysocki > --- > > v4 -> v5: > * Rebase on top of the new [1-6/7]. > * Never use the interactivity factor when the tick is stopped. > > --- > drivers/cpuidle/governors/menu.c | 29 ++++++++++++++++++++++------- > 1 file changed, 22 insertions(+), 7 deletions(-) > > Index: linux-pm/drivers/cpuidle/governors/menu.c > =================================================================== > --- linux-pm.orig/drivers/cpuidle/governors/menu.c > +++ linux-pm/drivers/cpuidle/governors/menu.c > @@ -353,13 +353,28 @@ static int menu_select(struct cpuidle_dr > */ > data->predicted_us = min(data->predicted_us, expected_interval); > > - /* > - * Use the performance multiplier and the user-configurable > - * latency_req to determine the maximum exit latency. > - */ > - interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load); > - if (latency_req > interactivity_req) > - latency_req = interactivity_req; > + if (tick_nohz_tick_stopped()) { > + /* > + * If the tick is already stopped, the cost of possible short > + * idle duration misprediction is much higher, because the CPU > + * may be stuck in a shallow idle state for a long time as a > + * result of it. In that case say we might mispredict and try > + * to force the CPU into a state for which we would have stopped > + * the tick, unless the tick timer is going to expire really > + * soon anyway. > + */ > + if (data->predicted_us < TICK_USEC_HZ) > + data->predicted_us = min_t(unsigned int, TICK_USEC_HZ, > + ktime_to_us(tick_time)); This applies to the heuristic (expected_interval) and the (heuristically corrected) next timer. Should this modification be applied only to the expected_interval under the assumption that the next_timer_us * correction is never totally wrong. > + } else { > + /* > + * Use the performance multiplier and the user-configurable > + * latency_req to determine the maximum exit latency. > + */ > + interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load); > + if (latency_req > interactivity_req) > + latency_req = interactivity_req; > + } > > expected_interval = data->predicted_us; > /* >