[2/2] PM: s2idle: Fully prevent the system from entering s2idle when cpuidle isn't supported
Message ID | 20230711-cpuidle-v1-2-f391224b3140@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp274451vqm; Mon, 10 Jul 2023 23:18:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlGcRxS+nxbkOllaWb4YmykgaxOrGQe+Li88A9epSvdKpOcOEo2LgvmUYAgbJwXjyOgo7Tay X-Received: by 2002:a2e:2405:0:b0:2b6:ce35:2e9e with SMTP id k5-20020a2e2405000000b002b6ce352e9emr11803329ljk.44.1689056327810; Mon, 10 Jul 2023 23:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689056327; cv=none; d=google.com; s=arc-20160816; b=0bR5+Er4QENMS+Kwx7K++k097GnbnDj6iGFu1yHXvXEfEvlK+SCJ4qL4uGkCFsuqgw F4K0U1f17AYyKEV7qT6FnZCURMibQPG1IXcuf2uQPya70ojYXTZkqclk6LaATadxK2w6 1Rs/7MwKbq2ONGpHb8LYXOhyTli3OOuujoCWOrmS6Un8zUYVGNo3jHnfUytaTXg6Kc05 U8sE1TdsmDj3WxsEW/zSJcyDzqO/X52Ie6VsiZYVPBRVYlkzWC5dFIfcenhyL5qZoPBj c0WCtfNzvsoYcyx8WZP1HNdZdlAFCpFZ/W9xK1q9jfTKJayOMbeqACLaHYmwa7LUiK+i ypww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=nk4niLNV6K0/PBl1ZDWCwqAEI3u1h+Q4tTNLOBHoMWM=; fh=IKlDn2abjmtvqJm9Uotgu9m7s6SHFoJLg0z2JSHIbx8=; b=Ij+HpBfITPGanAC6m9D75f0890OVlgB/XT5urLAairTh3aEgnPVcbvFxJsa6HtMObB 9EQTzYbPqWCfYyDuvgBKjtCxd7MZBfzMdbgZhGhPFg5LTvYSjhrGxWdzUo3yS+klYJUY VAZcot44S3Wc9uh990Cb4vfxcuk6X6wPW7Ep7UzXeyB7AS+7iUJDdKj2qCkkK3w8+E4S 7aff5nZxsi1eHjCwTYh10BgiI0r5/aT2rTbx1Mn4JoGllsdc9J/yDS3S+j9l6a26cae+ T5sSrsehSoGP8aKQ5oWOU5bpe7ZP2fBQgRQpwmhGBebe3ZSgrp5EnaSvCjghtDnMmhMI GVqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=kWPuKebr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a4-20020a17090680c400b00992fef5cff9si1122118ejx.497.2023.07.10.23.18.23; Mon, 10 Jul 2023 23:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=kWPuKebr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230455AbjGKFyj (ORCPT <rfc822;gnulinuxfreebsd@gmail.com> + 99 others); Tue, 11 Jul 2023 01:54:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbjGKFyf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 11 Jul 2023 01:54:35 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92104E40; Mon, 10 Jul 2023 22:54:32 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-666683eb028so2804971b3a.0; Mon, 10 Jul 2023 22:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689054872; x=1691646872; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nk4niLNV6K0/PBl1ZDWCwqAEI3u1h+Q4tTNLOBHoMWM=; b=kWPuKebr23fLuFvrI3MW4ogXI6dr/IRwsu/v40oN4sHO1B15ZKtejInkzcOS8BLsMS fhZIJ76/5TOOSuk+vi2y0XQIsK2m8hi7MDkVqr3jbkgYbBsmLRhJoC5X63gijFpNGFbN f01mVUks/HfHprmN16QR5elSbGKmQpGfpIjzzGSWHStCrRl7De6V8oOmqYXmvB2yLpuR i1ARofJ/hSDSj5BNou5oNgOAkTQMPze7ru4UQn1L62Eu6HpnI1sCqkW+bg73KgAhDCkZ 4aL9MaFAbhZ1YsUsIbSdsUlKFWLvPjAbE8h/FIc46Xx93onlyxoEVynaDyEIeugwUgMU pm3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689054872; x=1691646872; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nk4niLNV6K0/PBl1ZDWCwqAEI3u1h+Q4tTNLOBHoMWM=; b=FAWYkeRkLx6h3aNIYKuf1cPaU2ezNP5AuapUvpPM0g0Echoj1c9YmCXaVEdkQAB1Lx DitnRqqPPsPoLlVob9c6ljDMLFDdS0wu84nQglQnuL0aTRoAI5KBkeDj+FEQbxxEqZy5 iBRgtmo/NSfL1unfK0/48k6Ih2ItjLioKuIa+AUSfpERbs0iopL313uffRWPD+UjbCbO 3dreCLm/wZ6jHvyUKOd9RjR0d5XHCPaIcZVROrDXuY2t7sMWZFPZ4JrzpIkl1rlIKAmE krd90RdDoyBQZA6rgjQ9vLl85LW/8NU0hFhYkt4g0QWoQggxaVpC9LsBpOXf+dvaiBai xTfA== X-Gm-Message-State: ABy/qLYsS05a2+c/jWd++ovBRKzjSwCxV95fE5BsUiKgkGO+eYiqwtNy NEmAQJXAYcGTX4mza5b4bNDqr2quuCw= X-Received: by 2002:a05:6a21:6811:b0:131:1bbd:dc50 with SMTP id wr17-20020a056a21681100b001311bbddc50mr6236730pzb.6.1689054872037; Mon, 10 Jul 2023 22:54:32 -0700 (PDT) Received: from j293.lan ([2400:4051:ea3:5910:5676:1078:8b85:c18f]) by smtp.gmail.com with ESMTPSA id bd5-20020a170902830500b001b8761c739csm878053plb.271.2023.07.10.22.54.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 22:54:31 -0700 (PDT) From: Kazuki Hashimoto <kazukih0205@gmail.com> Date: Tue, 11 Jul 2023 14:54:22 +0900 Subject: [PATCH 2/2] PM: s2idle: Fully prevent the system from entering s2idle when cpuidle isn't supported MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230711-cpuidle-v1-2-f391224b3140@gmail.com> References: <20230711-cpuidle-v1-0-f391224b3140@gmail.com> In-Reply-To: <20230711-cpuidle-v1-0-f391224b3140@gmail.com> To: "Rafael J. Wysocki" <rafael@kernel.org>, Daniel Lezcano <daniel.lezcano@linaro.org>, Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz> Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>, Hector Martin <marcan@marcan.st>, Kazuki Hashimoto <kazukih0205@gmail.com> X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689054863; l=2849; i=kazukih0205@gmail.com; s=20230709; h=from:subject:message-id; bh=M0tNL3ccyxkfW5oli7KYKognuqR974/5Z/sS00RLTpY=; b=+vtnn6cnlTZTyDy/DLEZFml0G2vgNaqFHTs6ssNRATlNAiax2uJaMsh5C/xmGlJkeKHtBogaV dZBlmMupN8cAw3FQS8Ek1VDKZkTlEKdBC/p9vYQA1hluzM5WyJFYx2t X-Developer-Key: i=kazukih0205@gmail.com; a=ed25519; pk=r8m5wVK5lljix+hYnqXRT/GsxNkTADqXGmhdl7kykYY= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771103927895797396 X-GMAIL-MSGID: 1771103927895797396 |
Series |
s2idle fixes for systems without cpuidle
|
|
Commit Message
Kazuki Hashimoto
July 11, 2023, 5:54 a.m. UTC
In order for systems to properly enter s2idle, we need functions both in
the idle subsystem (such as call_cpuidle_s2idle()) and the suspend subsystem
to be executed.
s2idle got blocked in the idle subsystem on platforms without cpuidle after
commit ef2b22ac540c ("cpuidle / sleep: Use broadcast timer for states that stop
local timer"). However, the suspend subsystem doesn't have this, which can cause
the suspend subsystem to begin entering s2idle behind the idle subsystem's back,
which in turn can cause the system to enter s2idle even though all the functions
necessary for s2idle hasn't been executed, breaking the system
(e.g. ClOCK_MONOTONIC keeps ticking during suspend even though it's not supposed
to).
Prevent the system from entering s2idle when cpuidle isn't supported in the
suspend subsystem as well.
Fixes: ef2b22ac540c ("cpuidle / sleep: Use broadcast timer for states that stop local timer")
Signed-off-by: Kazuki Hashimoto <kazukih0205@gmail.com>
---
kernel/power/main.c | 12 +++++++++---
kernel/power/suspend.c | 5 +++++
2 files changed, 14 insertions(+), 3 deletions(-)
Comments
On Tue, Jul 11, 2023 at 7:54 AM Kazuki Hashimoto <kazukih0205@gmail.com> wrote: > > In order for systems to properly enter s2idle, we need functions both in > the idle subsystem (such as call_cpuidle_s2idle()) and the suspend subsystem > to be executed. > > s2idle got blocked in the idle subsystem on platforms without cpuidle after > commit ef2b22ac540c ("cpuidle / sleep: Use broadcast timer for states that stop > local timer"). What do you mean by "blocked in the idle subsystem"? > However, the suspend subsystem doesn't have this, which can cause > the suspend subsystem to begin entering s2idle behind the idle subsystem's back, What do you mean by this? > which in turn can cause the system to enter s2idle even though all the functions > necessary for s2idle hasn't been executed, breaking the system > (e.g. ClOCK_MONOTONIC keeps ticking during suspend even though it's not supposed > to). Why is this a problem? > Prevent the system from entering s2idle when cpuidle isn't supported in the > suspend subsystem as well. I'm sure that there's a real problem you're trying to address, but I cannot help you without understanding what the problem is. So please explain what exactly is going on, what is expected to happen and what happens instead and why this is problematic. Till then, the patches are not going anywhere. Thanks!
On Tue, Jul 11, 2023 at 07:55:46PM +0200, Rafael J. Wysocki wrote: > On Tue, Jul 11, 2023 at 7:54 AM Kazuki Hashimoto <kazukih0205@gmail.com> wrote: > > > > In order for systems to properly enter s2idle, we need functions both in > > the idle subsystem (such as call_cpuidle_s2idle()) and the suspend subsystem > > to be executed. > > > > s2idle got blocked in the idle subsystem on platforms without cpuidle after > > commit ef2b22ac540c ("cpuidle / sleep: Use broadcast timer for states that stop > > local timer"). > > What do you mean by "blocked in the idle subsystem"? There is a check in kernel/sched/idle.c which determines whether cpuidle is enabled. If that isn't the case, functions necessary for s2idle don't get executed. Here's a snippet of the code: if (cpuidle_not_available(drv, dev)) { tick_nohz_idle_stop_tick(); default_idle_call(); goto exit_idle; } /* * Suspend-to-idle ("s2idle") is a system state in which all user space * has been frozen, all I/O devices have been suspended and the only * activity happens here and in interrupts (if any). In that case bypass * the cpuidle governor and go straight for the deepest idle state * available. Possibly also suspend the local tick and the entire * timekeeping to prevent timer interrupts from kicking us out of idle * until a proper wakeup interrupt happens. */ if (idle_should_enter_s2idle() || dev->forced_idle_latency_limit_ns) { u64 max_latency_ns; if (idle_should_enter_s2idle()) { entered_state = call_cpuidle_s2idle(drv, dev); if (entered_state > 0) goto exit_idle; max_latency_ns = U64_MAX; } else { max_latency_ns = dev->forced_idle_latency_limit_ns; } tick_nohz_idle_stop_tick(); next_state = cpuidle_find_deepest_state(drv, dev, max_latency_ns); call_cpuidle(drv, dev, next_state); } else { bool stop_tick = true; /* * Ask the cpuidle framework to choose a convenient idle state. */ next_state = cpuidle_select(drv, dev, &stop_tick); if (stop_tick || tick_nohz_tick_stopped()) tick_nohz_idle_stop_tick(); else tick_nohz_idle_retain_tick(); entered_state = call_cpuidle(drv, dev, next_state); /* * Give the governor an opportunity to reflect on the outcome */ cpuidle_reflect(dev, entered_state); } exit_idle: __current_set_polling(); /* * It is up to the idle functions to reenable local interrupts */ if (WARN_ON_ONCE(irqs_disabled())) local_irq_enable(); > > > However, the suspend subsystem doesn't have this, which can cause > > the suspend subsystem to begin entering s2idle behind the idle subsystem's back, > > What do you mean by this? The suspend subsystem doesn't have the check which determines whether cpuidle is enabled or not. Therefore, the suspend subsystem can put the system into s2idle even though functions necessary for s2idle in the idle subsystem hasn't been executed. > > > which in turn can cause the system to enter s2idle even though all the functions > > necessary for s2idle hasn't been executed, breaking the system > > (e.g. ClOCK_MONOTONIC keeps ticking during suspend even though it's not supposed > > to). > > Why is this a problem? There are programs such as systemd, which depend on CLOCK_MONOTONIC being paused during suspend as outlined here: > > It increases by the slept time (1min + some seconds required to suspend/wakeup). > Well, it's really not supposed to. The monotonic clock (CLOCK_MONOTONIC) is supposed > to pause while the system is suspended. If it continues running then what you are > seeing is kinda expected, because nothing will be scheduled while the system is > suspended. > > The python test I gave you is entirely independent from systemd, this means this is > a bug within your kernel, and your kernel only. Please report this to your distro's > kernel packaging team, there's nothing we can do about this. CLOCK_MONOTONIC is > supposed to pause during suspend (and CLOCK_BOOTTIME is supposed to continue), and > if this doesn't work then this is something that has to be fixed in the kernel. > (Some pre-release kernels carried some patches that broke CLOCK_MONOTONIC and made > it work like CLOCK_BOOTTIME. They got reverted later on, and shouldn't have reached > anybody's systems. Otherwise what you are seeing does smell a lot like those patches.) > > Anyway, closing this here, as there's nothing we can do about this in systemd, and > the bug is in your kernel. https://github.com/systemd/systemd/issues/9538#issuecomment-405590102 > > > Prevent the system from entering s2idle when cpuidle isn't supported in the > > suspend subsystem as well. > > I'm sure that there's a real problem you're trying to address, but I > cannot help you without understanding what the problem is. > > So please explain what exactly is going on, what is expected to happen > and what happens instead and why this is problematic. > > Till then, the patches are not going anywhere. > > Thanks! Sorry for the confusion, I hope this cleared some things up. Thanks, Kazuki
diff --git a/kernel/power/main.c b/kernel/power/main.c index f6425ae3e8b0..82fedcf6032d 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -174,6 +174,8 @@ static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr, for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++) { if (i >= PM_SUSPEND_MEM && cxl_mem_active()) continue; + if (i == PM_SUSPEND_TO_IDLE && cpuidle_not_available()) + continue; if (mem_sleep_states[i]) { const char *label = mem_sleep_states[i]; @@ -226,11 +228,15 @@ static ssize_t mem_sleep_store(struct kobject *kobj, struct kobj_attribute *attr } state = decode_suspend_state(buf, n); - if (state < PM_SUSPEND_MAX && state > PM_SUSPEND_ON) + if (state == PM_SUSPEND_TO_IDLE && cpuidle_not_available()) + goto err; + if (state < PM_SUSPEND_MAX && state > PM_SUSPEND_ON) { mem_sleep_current = state; - else - error = -EINVAL; + goto out; + } + err: + error = -EINVAL; out: pm_autosleep_unlock(); return error ? error : n; diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index fa3bf161d13f..02cc76c9109e 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -556,6 +556,11 @@ static int enter_state(suspend_state_t state) trace_suspend_resume(TPS("suspend_enter"), state, true); if (state == PM_SUSPEND_TO_IDLE) { + if (cpuidle_not_available()) { + pr_warn("s2idle is unsupported when cpuidle is unavailable"); + return -EINVAL; + } + #ifdef CONFIG_PM_DEBUG if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) { pr_warn("Unsupported test mode for suspend to idle, please choose none/freezer/devices/platform.\n");