From patchwork Sun Aug 12 16:09:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 143997 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2183871ljj; Sun, 12 Aug 2018 09:10:12 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxBqk0KIUcerSTdQgwUV5mhCJ6zlh8fyC9zoIGxIs6MljcppnVJpeJs3HipX8Sp1NJ3U2KW X-Received: by 2002:a17:902:4124:: with SMTP id e33-v6mr13501944pld.48.1534090212170; Sun, 12 Aug 2018 09:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534090212; cv=none; d=google.com; s=arc-20160816; b=ULzOFdzMMHST5koD1Db14z8gLpGJXAVbdzze/3n865bMUj8q1bK0r259p2Hmf5M1hT 4sYTGaYF9yqCY1scRbUavNtIZIf8BIktM6k9pw4RKfzaqGthK7DIeYotYRemwqpPAYNm Zo2qjTNAwPkzHlzoC/96jfIJXY6F2jH+YXmLiZf1O5AQt1gWrTH7IxqIToUBUZhWRk39 w3KQpjhRTWuP6ClU5gbWyApWyfJN17n/penQckVETA2KDUBd8SoED0A06gYwLRP6Owxc tYQMkzRgp6KiL/bB7reSrV5LPgGIb0n6uVlax3OFffDAF8De3MukHFYm5yZ2qB1Z9f4b nfGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=V/KD4PZAGRjRkYZ8ZQmu8anS2A7JIpWJS7JiZdKweu4=; b=fLbbDgmS1NfAy6bEnXcrqR09KGq1Gh61RKkXZ5eqK3+CpwluYj4UWJhWbh1E/Ov+bU zXCjzLfBHQvIVZzcTONvd90To0Bkxyz3e7JDVuKvfmWhXCQUvXPKtDtihuw7DJAPqju4 +hU6FwhDFehGKUMAiYr1WXwyeIDmmQOz/ZjEzUjL4XQIj50KPMCVloE3VyHn6+GzVwNV MzjfeI1QsBWDBZa75r3zohSFddtTokKrcNIqM/gfdE08GSkcGWQRtzgeb/Jj6nXpgzq0 p/qmFAOfJTJvCOFRCCq2xKmVoWoOnlF9Dk6iYFzPT6vRKr28G+uttver6SVPzZnIlsNP m3lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aAes6E+f; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6-v6si14317808pfh.266.2018.08.12.09.10.11; Sun, 12 Aug 2018 09:10:12 -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=pass header.i=@linaro.org header.s=google header.b=aAes6E+f; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728358AbeHLSsk (ORCPT + 31 others); Sun, 12 Aug 2018 14:48:40 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37636 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbeHLSsj (ORCPT ); Sun, 12 Aug 2018 14:48:39 -0400 Received: by mail-wm0-f65.google.com with SMTP id n11-v6so6448455wmc.2 for ; Sun, 12 Aug 2018 09:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V/KD4PZAGRjRkYZ8ZQmu8anS2A7JIpWJS7JiZdKweu4=; b=aAes6E+f295M09g4lYl2w+zmOWFBPesp3HWKkqOQ5wPP5kvZPb7W5oWINgh1HcevCw oqkiFY51eG1PKuRYLMhZ+6B5AcRNNzTuCtfUB5xloqeK9tSAkUa15MIGFDbIYy9AmU8N AYXGe4AeVpuXtaiZrDMTZjIay1m0kZOJIQcQY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=V/KD4PZAGRjRkYZ8ZQmu8anS2A7JIpWJS7JiZdKweu4=; b=L1najRhW8bTOVt9ytHbj5fv9RDbv55qIvZ15fkaXdgX5uJSCkfQN5TVyNWc+nDhRxV rftW/XSAH1CajoKyaxLZA16fENKs2Gl/i0FS2X1gHgveNjVgk//eWYJRC/39UrmP5tBa gVD6+bihaqNwDQnJeeycFKMWspBRrSkoh3+cDIzcs3uaqnSfsaeRZ7I8W/ClcEbtHQI+ WSLr22BJ1UK0aqn62Mw1/gI+XO69Ku314RgtiRjr0WQLcQQwFrWHTgKnQhQt96/kdQco l5Bk6B5Um3HXqyJrwW0VNk/Ej5chzTbl3rwmS4B5j6NRoEcMD+4S7NlrtJwgu2uwbKh6 DijQ== X-Gm-Message-State: AOUpUlEDXu1XJXvafHg/Wiig2zlwvyftDH6xdEUqA8YanwLLETHsczle pocWxOY0F7RjSB5a3TfmfrDnvg== X-Received: by 2002:a1c:4885:: with SMTP id v127-v6mr5928679wma.161.1534090207747; Sun, 12 Aug 2018 09:10:07 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id t6-v6sm7437369wmf.8.2018.08.12.09.10.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Aug 2018 09:10:06 -0700 (PDT) From: Leo Yan To: "Rafael J. Wysocki" , "Peter Zijlstra (Intel)" , Daniel Lezcano , Vincent Guittot , Ramesh Thomas , linux-kernel@vger.kernel.org, Linux PM Cc: Leo Yan Subject: [PATCH v1 4/5] cpuidle: menu: Don't stay in shallow state for a long time Date: Mon, 13 Aug 2018 00:09:30 +0800 Message-Id: <1534090171-14464-5-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534090171-14464-1-git-send-email-leo.yan@linaro.org> References: <1534090171-14464-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To avoid staying in a shallow state for a long time, the menu governor relies on not stopping tick when detects the prediction is shorter than the tick event. This is just luckily to cover most cases but cannot say it is completely safe. For example, if the prediction is 2000us and the TICK_USEC=1000 so it's impossible to meet the condition 'data->predicted_us < TICK_USEC' and this lead to stop the tick for a shallow state; finally the CPU is possible to stay in this shallow state for very long time. This patch checks the candidate idle state isn't deepest one and find if the timer will come after more than 2 times of the maximum target residency, though the governor selects a shallow state according to prediction, due the timer is most reliable waken up source but it will come very late, so the CPU has chance to stay in the shallow state for a long time; the patch doesn't stop the tick for this case so can avoid powernightmares issue. Signed-off-by: Leo Yan --- drivers/cpuidle/governors/menu.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) -- 2.7.4 diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 4f02207..566c65c 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -284,6 +284,10 @@ static unsigned int get_typical_interval(struct menu_device *data) static bool menu_decide_stopping_tick(struct cpuidle_driver *drv, struct menu_device *data, int idx) { + int max_target_residency; + + max_target_residency = drv->states[drv->state_count-1].target_residency; + /* * If the tick has been stopped yet, force to stop it afterwards and * don't give chance to set *stop_tick to false. @@ -302,6 +306,23 @@ static bool menu_decide_stopping_tick(struct cpuidle_driver *drv, if (data->predicted_us < TICK_USEC) return false; + /* + * The candidate idle state isn't deepest one, on the other hand + * the most reliable wakeup source is timer (compare against to + * interrupts) says it will come after more than 2 times of maximum + * target residency, this means the CPU has risk to stay in shallow + * state for more than 2 times of maximum target residency. + * + * It's acceptable to stay in the shallow state at this time but we + * need to ensure to wake up the CPU by tick to check if has better + * choice. Finally it can have choice to select deeper state and + * avoid the CPU staying in shallow state for very long time and + * without any wake up event. + */ + if (idx < drv->state_count - 1 && + data->next_timer_us > max_target_residency * 2) + return false; + /* Otherwise, let's stop the tick at this time. */ return true; }