Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp717134pxb; Thu, 21 Oct 2021 08:11:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXqhJQI9G5N5YdOd2gBuCWKNKcFhgTGjCm9GWbcG7DUe3m/n8fdg48/fz9NzlXVj3yfA4h X-Received: by 2002:a17:90a:d347:: with SMTP id i7mr7510718pjx.101.1634829060078; Thu, 21 Oct 2021 08:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634829060; cv=none; d=google.com; s=arc-20160816; b=e2khmSMIDjuxuRqxUDjgtClCeBA2biUlQeGd6mitOyTbcgsWUC9P5jUNVWqw/m9ZS4 NU3+XQkQQi1hxN7Jw7I8NUKpUz5Fis7UrX5KneXK9ZHx9EaMQFwNXeOK2Et0gpnzMf0A LMFEwUKkfqt3filounsUdj8yMg3TCAgVOnMNZoY+FmBcurzd0nBlhOhe/cPS4CloJieW HkaM6+kyMGpZlTARysIzzQMdU/+hpcWRFfZfnL+JaN5ze2KsuCoR66m8LzSeqOh31AoA oOVhhqkqEO1ohylp1U4CwpRzho3lIqOCyb1wi0bl8SgiRzey+NjMmgXaWYbWmCq5AhBH Df0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=RvOTN1WtkH5yz7qex2pCyDRZPmCtpaKD7ET9RQlXazU=; b=EsKnwc2OKKR0eFzY5xMjBWaamvYdVijktvZs20rXGsLKaSit3X4AzAys7/uyqaEJPN CmOJFpJDpJR+KzHWQX411FR5tEXY5gNg/Xxy9A074M/uWMVyCFGHsuAxcrc/pD/HC5CW 6/qf7v9fq9G4RX6UHKcLi4pnlHXYv0y7wpTgIib5wZjXUzIJl36zk2xd9T3B/tBCZNsq JdTpPeCgNX1DAVK9e+/jzPnjRXS7w+L/JjON+AybuR8IYgMuRrbHGypLhKZFIjd+X6Ju PiqE5O8rMcqnGBviRrPjXJtgYeZM4QKnFLhu4NCTpOXSNsjQABsw2NuAHMT72H07gMxF E4LQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si6794449plr.189.2021.10.21.08.10.47; Thu, 21 Oct 2021 08:11:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231683AbhJUPLk (ORCPT + 99 others); Thu, 21 Oct 2021 11:11:40 -0400 Received: from mail-oi1-f169.google.com ([209.85.167.169]:45886 "EHLO mail-oi1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231503AbhJUPLi (ORCPT ); Thu, 21 Oct 2021 11:11:38 -0400 Received: by mail-oi1-f169.google.com with SMTP id z126so1190902oiz.12; Thu, 21 Oct 2021 08:09:23 -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=RvOTN1WtkH5yz7qex2pCyDRZPmCtpaKD7ET9RQlXazU=; b=4N6J6z6e8FjIjWW2HSyJm3jCb0DStZ/NjZNtewptRpJo9zftRstsVcusFWtCl8dp+F 5egSqkPUxrJf69NzpP5KsloLErxSAlXqM3fBI6+pn4Wh/CqWdkYvgf+S8/BTJ7V2WeS/ nfRhn6J4U3GPBCX1GwxJpr8OTjQ/rthagIoMSfMomJKC2NuHBua5Lq0sx3mJ3LcY+sZ6 TqMAQ8T7ZI3NybgRr1XodvlnFLJI+5qwK7eyCW7dYDrwtUd31tMIj9ZFNhF7Fyo0Kfdb GJX5En9CAD4RLtlo8gTXUy09pHu0JeFj2ieAi2AkO5RtR3U5en2An/O2gzyCparJ5r8s wJnw== X-Gm-Message-State: AOAM53355lSR2NtnpzdFh9HvhENs/wmLhhJqTn+Hz2OujPsBlCwri19W E9dICo/ggoE97BW1xv1wN66MmlU+tREs5WuJyaU= X-Received: by 2002:aca:5c5:: with SMTP id 188mr4802252oif.154.1634828962563; Thu, 21 Oct 2021 08:09:22 -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 17:09:11 +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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > > > > > Is this really what we want? > > > > > > > > > > > The other guys who rely on the cpuidle pausing today could be switched > > > > over to this new mechanism later and it would be possible to get rid > > > > of the pausing from the system suspend path completely. > > > > > > Avoiding to pause cpuidle when it's not needed makes perfect sense. > > > Although, it looks to me that we could also implement that on top of > > > $subject patch. > > > > Yes, it could. > > > > > Unless you insist on the CPUIDLE_STATE_DISABLED_ way, I would probably > > > explore an option to let a cpuidle driver to set a global cpuidle flag > > > during ->probe(). Depending if this flag is set, we can simply skip > > > calling cpuidle_pause() during system suspend. > > > > > > What do you think? > > > > Well, which driver in particular is in question here? > > Honestly, I don't know. It has not been my goal to entirely prevent > calling cpuidle_pause(). > > In any case, it was introduced in the below commit, perhaps that can > give us a hint when this is still needed? > > commit 8651f97bd951d0bb1c10fa24e3fa3455193f3548 > Author: Preeti U Murthy > Date: Mon Jul 9 10:12:56 2012 +0200 > PM / cpuidle: System resume hang fix with cpuidle Yes, I remember that.