From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C687C433F5 for ; Thu, 21 Oct 2021 16:42:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F3496138D for ; Thu, 21 Oct 2021 16:42:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8F3496138D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uKvd9wdrWHg2WkfY1ZqnrXzIK4Vm6VpQi0ZEbFqSQ3U=; b=z8vB9U1zi1krIX vwT0Ibd5bunypy8y1sXeQxOOOL2XJPLynRTedLg3EOTzPzvVmbNVh4GVhZzhKDkVdTzaJMSyAFThF qvmyViY16TTwFKk9R/EPbbrBWZ+6Ap7zEP+sLXY9AZFx4pLdC8i60Lmgb2Yt2IqPEEgmWS2eic/Ut mX0NEJAZGOnAuG51F+gM/SOAiceGmS4o/MiFUGAvlZXmKa2uVmajSWcMWwTGkBg06tsElEo0Z+4AO d/49R6UEfuwN4Qq5HdgS97YO6osMWFR3GOc/4dqQbHcmAu4DhmHdu2lSwNwVI/Ahs/KqYnej18D9D fCesL+GdVQTHOimKRF3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdb8J-008P0I-Eb; Thu, 21 Oct 2021 16:41:35 +0000 Received: from mail-ot1-f42.google.com ([209.85.210.42]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdb8F-008Oyw-8X for linux-arm-kernel@lists.infradead.org; Thu, 21 Oct 2021 16:41:33 +0000 Received: by mail-ot1-f42.google.com with SMTP id l24-20020a9d1c98000000b00552a5c6b23cso1113215ota.9 for ; Thu, 21 Oct 2021 09:41:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5uPZ/FP8yzMTpzRShGtT6IgrdRGI+lDwuUXMfZ66cW0=; b=L3anBxre9SqQ19ESEvxrDBkayAFKxmOtp54E6Q2fIfbJFy0rbGF4JsHfFCfasWzUsP S+Ba3FUArS1BAX7/97KKTB2Mhq65oLM3ljBFDiBn4Vgg63d0Zere+IH5mT1+ayx5cVck 4WPh4FdaKYUr0unoIwJ2idO+aBmdA3dSOouK9LxrICDv9wK9hwKwSqNk6WXONhaufUlM ZTmKmxzspJQjEzsxBD1uCCd9LzG/hprrYCROKHheUxpaWymoRan6FjJ+LLzrieOJcgYi GMq9Wn9Zsk9hLPE3LbFDiQn8zCFBEZNPNR9qfQFo+ITzqiy02kjK1BPTK2pbdFqo61UQ 0/6w== X-Gm-Message-State: AOAM533Kz+ray6weWGYyMMnRxdKE8g3FE+7UL5x+P0Wkat3JEqY03iVo XC1XbfcxS3XeuBmKnYGEpPsG70lYvh2BQuRE1j8= X-Google-Smtp-Source: ABdhPJzQeQp+61HyPE7e+lfaJr37LqxOk9cWDZc5frl9KHPfief+DXPqkXwCsLUj+aT08M/An0nuMAfQ3OpeK4zo+b8= X-Received: by 2002:a9d:65c1:: with SMTP id z1mr5538112oth.198.1634834490288; Thu, 21 Oct 2021 09:41:30 -0700 (PDT) MIME-Version: 1.0 References: <20210929144451.113334-1-ulf.hansson@linaro.org> <20210929144451.113334-3-ulf.hansson@linaro.org> In-Reply-To: From: "Rafael J. Wysocki" Date: Thu, 21 Oct 2021 18:41:19 +0200 Message-ID: Subject: Re: [PATCH 2/2] PM: sleep: Fix runtime PM based cpuidle support To: Ulf Hansson Cc: "Rafael J. Wysocki" , Daniel Lezcano , Linux PM , Maulik Shah , Peter Zijlstra , Vincent Guittot , Len Brown , Bjorn Andersson , Linux ARM , Linux Kernel Mailing List X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211021_094131_330594_8B044F51 X-CRM114-Status: GOOD ( 57.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Oct 21, 2021 at 6:29 PM Ulf Hansson wrote: > > On Thu, 21 Oct 2021 at 17:46, Rafael J. Wysocki wrote: > > > > On Thu, Oct 21, 2021 at 5:09 PM Rafael J. Wysocki wrote: > > > > > > On Thu, Oct 21, 2021 at 4:05 PM Ulf Hansson wrote: > > > > > > > > On Thu, 21 Oct 2021 at 15:45, Rafael J. Wysocki wrote: > > > > > > > > > > On Thu, Oct 21, 2021 at 1:49 PM Ulf Hansson wrote: > > > > > > > > > > > > On Wed, 20 Oct 2021 at 20:18, Rafael J. Wysocki wrote: > > > > > > > > > > > > > > On Wed, Sep 29, 2021 at 4:44 PM Ulf Hansson wrote: > > > > > > > > > > > > > > > > In the cpuidle-psci case, runtime PM in combination with the generic PM > > > > > > > > domain (genpd), may be used when entering/exiting an idlestate. More > > > > > > > > precisely, genpd relies on runtime PM to be enabled for the attached device > > > > > > > > (in this case it belongs to a CPU), to properly manage the reference > > > > > > > > counting of its PM domain. > > > > > > > > > > > > > > > > This works fine most of the time, but during system suspend in the > > > > > > > > dpm_suspend_late() phase, the PM core disables runtime PM for all devices. > > > > > > > > Beyond this point and until runtime PM becomes re-enabled in the > > > > > > > > dpm_resume_early() phase, calls to pm_runtime_get|put*() will fail. > > > > > > > > > > > > > > > > To make sure the reference counting in genpd becomes correct, we need to > > > > > > > > prevent cpuidle-psci from using runtime PM when it has been disabled for > > > > > > > > the device. Therefore, let's move the call to cpuidle_pause() from > > > > > > > > dpm_suspend_noirq() to dpm_suspend_late() - and cpuidle_resume() from > > > > > > > > dpm_resume_noirq() into dpm_resume_early(). > > > > > > > > > > > > > > > > Diagnosed-by: Maulik Shah > > > > > > > > Suggested-by: Maulik Shah > > > > > > > > Signed-off-by: Ulf Hansson > > > > > > > > --- > > > > > > > > drivers/base/power/main.c | 6 ++---- > > > > > > > > 1 file changed, 2 insertions(+), 4 deletions(-) > > > > > > > > > > > > > > > > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c > > > > > > > > index cbea78e79f3d..1c753b651272 100644 > > > > > > > > --- a/drivers/base/power/main.c > > > > > > > > +++ b/drivers/base/power/main.c > > > > > > > > @@ -747,8 +747,6 @@ void dpm_resume_noirq(pm_message_t state) > > > > > > > > > > > > > > > > resume_device_irqs(); > > > > > > > > device_wakeup_disarm_wake_irqs(); > > > > > > > > - > > > > > > > > - cpuidle_resume(); > > > > > > > > } > > > > > > > > > > > > > > > > /** > > > > > > > > @@ -870,6 +868,7 @@ void dpm_resume_early(pm_message_t state) > > > > > > > > } > > > > > > > > mutex_unlock(&dpm_list_mtx); > > > > > > > > async_synchronize_full(); > > > > > > > > + cpuidle_resume(); > > > > > > > > dpm_show_time(starttime, state, 0, "early"); > > > > > > > > trace_suspend_resume(TPS("dpm_resume_early"), state.event, false); > > > > > > > > } > > > > > > > > @@ -1336,8 +1335,6 @@ int dpm_suspend_noirq(pm_message_t state) > > > > > > > > { > > > > > > > > int ret; > > > > > > > > > > > > > > > > - cpuidle_pause(); > > > > > > > > - > > > > > > > > device_wakeup_arm_wake_irqs(); > > > > > > > > suspend_device_irqs(); > > > > > > > > > > > > > > > > @@ -1467,6 +1464,7 @@ int dpm_suspend_late(pm_message_t state) > > > > > > > > int error = 0; > > > > > > > > > > > > > > > > trace_suspend_resume(TPS("dpm_suspend_late"), state.event, true); > > > > > > > > + cpuidle_pause(); > > > > > > > > mutex_lock(&dpm_list_mtx); > > > > > > > > pm_transition = state; > > > > > > > > async_error = 0; > > > > > > > > -- > > > > > > > > > > > > > > Well, this is somewhat heavy-handed and it affects even the systems > > > > > > > that don't really need to pause cpuidle at all in the suspend path. > > > > > > > > > > > > Yes, I agree. > > > > > > > > > > > > Although, I am not really changing the behaviour in regards to this. > > > > > > cpuidle_pause() is already being called in dpm_suspend_noirq(), for > > > > > > everybody today. > > > > > > > > > > Yes, it is, but pausing it earlier will cause more energy to be spent, > > > > > potentially. > > > > > > > > > > That said, there are not too many users of suspend_late callbacks in > > > > > the tree, so it may not matter too much. > > > > > > > > > > > > > > > > > > > Also, IIUC you don't need to pause cpuidle completely, but make it > > > > > > > temporarily avoid idle states potentially affected by this issue. An > > > > > > > additional CPUIDLE_STATE_DISABLED_ flag could be used for that I > > > > > > > suppose and it could be set via cpuidle_suspend() called from the core > > > > > > > next to cpufreq_suspend(). > > > > > > > > > > > > cpuidle_suspend() would then need to go and fetch the cpuidle driver > > > > > > instance, which in some cases is one driver per CPU. Doesn't that get > > > > > > rather messy? > > > > > > > > > > Per-CPU variables are used for that, so it is quite straightforward. > > > > > > > > > > > Additionally, since find_deepest_state() is being called for > > > > > > cpuidle_enter_s2idle() too, we would need to treat the new > > > > > > CPUIDLE_STATE_DISABLED_ flag in a special way, right? > > > > > > > > > > No, it already checks "disabled". > > > > > > > > Yes, but that would be wrong. > > > > > > Hmmm. > > > > > > > The use case I want to support, for cpuidle-psci, is to allow all idle > > > > states in suspend-to-idle, > > > > > > So does PM-runtime work in suspend-to-idle? How? > > > > > > > but prevent those that rely on runtime PM > > > > (after it has been disabled) for the regular idle path. > > > > > > Do you have a special suspend-to-idle handling of those states that > > > doesn't require PM-runtime? > > > > Regardless, pausing cpuidle in the suspend-to-idle path simply doesn't > > make sense at all, so this needs to be taken care of in the first > > place. > > Right, I do agree, don't get me wrong. But, do we really want to treat > s2-to-idle differently, compared to s2-to-ram in regards to this? > > Wouldn't it be a lot easier to let cpuidle drivers to opt-out for > cpuidle_pause|resume(), no matter whether it's for s2-to-idle or > s2-to-ram? I don't think so. Suspend-to-idle resume cpuidle after pausing it which is just plain confusing and waste of energy and the fact that the system-wide suspend flow interferes with using PM-runtime for implementing cpuidle callbacks at the low level really is an orthogonal problem. > > > > The problem with PM-runtime being unavailable after dpm_suspend() > > needs to be addressed in a different way IMO, because it only affects > > one specific use case. > > It's one specific case so far, but we have the riscv driver on its > way, which would suffer from the same problem. So perhaps they should be advised about this issue. > Anyway, an option is to figure out what platforms and cpuidle drivers, > that really needs cpuidle_pause|resume() at this point and make an > opt-in solution instead. None of them need to pause cpuidle for suspend-to-idle AFAICS. Some may want it in the non-s2idle suspend path, but I'm not sure about the exact point where cpuidle needs to be paused in this case. Possibly before offlining the nonboot CPUs. > This could then be used by runtime PM based > cpuidle drivers as well. Would that be a way forward? The PM-runtime case should be addressed directly IMO, we only need to figure out how to do that. I'm wondering how you are dealing with the case when user space prevents pd_dev from suspending via sysfs, for that matter. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel