Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp540502pxb; Thu, 21 Oct 2021 04:50:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnbYwWqNHS5xvjoioLpZDwSVEpF9BrxXLYWYHYFUBLaWTL2ctfhPKFo3QvYOvWoT+YMnUl X-Received: by 2002:aa7:8b56:0:b0:44b:e510:a208 with SMTP id i22-20020aa78b56000000b0044be510a208mr5297722pfd.56.1634817037566; Thu, 21 Oct 2021 04:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634817037; cv=none; d=google.com; s=arc-20160816; b=PCs/5g7DMpWmEe4dcXfp8mrg3a5owOJfwPNypfVPcbr1AhnElOOCONwC2P//Fx1mYA MUkeHNr21A/PwFuEwIxzY0YT8ADwvZAuL5br1NawRMDzLtzqXSC9p+7NCY4oQbjluJlM z6wPWxP1JkuijdVXHlrJX0JPXB/dbvhQwk95Y8NovN3Eli75q3qIZEPEQiyxjLdYQA2A xpgoZnbX/IL9B7hJXzk6FAm3VaACAmJF2ZwG2/4B15LLCQHUogoL2BcgNskbYPQPY0fF YssOTmKv7+FJ6gsKVcK/EtRvdQb1TsssqPyXVKOJ2p9a8L+QDVKGcjb22s3M89RWISuy Z3+g== 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:dkim-signature; bh=EuH9sIJDNZs0UgxOGh411kkOSLBffoDt7vM8MC6DQHM=; b=AOP/iHd75TPngG8A3oyKilFbCZ6+qKGT5TpsdpVSI+UzDcJclvrsXHqVPA56HLS2Ap Itq84z2P7qTnFyHNgEZYCYozsvMqFvjZMnOcgsHfWq5ry+6IYiLFFBZyF7Ud913l2+Dc eSESMIJvnmWMOwtQUr+IhR5rlCrTlOKHaLk+gpuiWUPwnYV9L9OEM70x0mGCaVpOc9LB pwKr+2MN2xKaw2ytrOXzNpmvGYlfhUAQ258SbKNVYnN66SkiNFZfkEWEK/jnXHM/0dtr OqUTW7jX7z6cUjT29+9SRkD8qCKByyfiNKuuQCrdvrqYu+Mw+i2M8Zn477X4wrLrgnKR 23DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=khNjdgZS; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pc8si13547517pjb.118.2021.10.21.04.50.24; Thu, 21 Oct 2021 04:50:37 -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; dkim=pass header.i=@linaro.org header.s=google header.b=khNjdgZS; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230231AbhJULvd (ORCPT + 99 others); Thu, 21 Oct 2021 07:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbhJULvc (ORCPT ); Thu, 21 Oct 2021 07:51:32 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F91C061749 for ; Thu, 21 Oct 2021 04:49:16 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id i24so751866lfj.13 for ; Thu, 21 Oct 2021 04:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EuH9sIJDNZs0UgxOGh411kkOSLBffoDt7vM8MC6DQHM=; b=khNjdgZSZgYDOh0Umaa9AzdCVK8l/F6gc5xBy/Fns2BjZ3fwNTPYybpbibSbX63fzt FvdZGy17wja6fJX82el0+bQf1Q6B3wCme5hw18xz3UJ4AiDysMGXmQps5sLPHd/L/1p8 9bhGcRzF16wX17A14XQgA47Ei7ykkXavUwanOwLPexiZ9F6BoZGLhfci1SvQOri8MCtX 8I3erdt58i1MJbzTNhdMj0m9dv4wlbwxnmZckFcziWTy98bOeMKZHZB2pqzmSDS2Hx54 VBjKCAsIH4F2VBPR+4YuEevd/Z7r2GBrHNd0O2FQ+o8mAR95DLtL4hLV+DZFcU6dJ6PD Cc5A== 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=EuH9sIJDNZs0UgxOGh411kkOSLBffoDt7vM8MC6DQHM=; b=dV0ubtKGU7cBrp8oQY8hbYVXyUWkAweB+bGLG2GtNPUGW7i6UpQX9EEpA3bXG/ks0A 0uaaHEP+c17byfdfiGlhVymQqZdY2jaKv8i+LPJJddTu4CoLE8//o5v4GmV+8LIbtQbl RKvd1nN7EnY5JtInSP0WGgvkglu7+BFgdHVoSxKMeLYZg6Z3jpDfDXulkr4AGCDGPsvN MQz6Qy3d/IaujvA7zFpt7EwNYIKpyO6U7UoWMcArr4wiy0mignsXI14AVniz2J6Eq3yD oede3dIHvlKpUTBo/K6wM4sA2pxW9XpN159kv/cOasBrr4KE8/doARCDKm2Yuahdb49W IT5g== X-Gm-Message-State: AOAM530H77zmZ9VN1ZXMHVxRIg2GSzo6AvUs7ynVAD4XaR1x+dAdRNE5 GsVlKznF3AEbpLZykYgXqmD6rVhIfKqawMtC6gXusQ== X-Received: by 2002:a05:651c:907:: with SMTP id e7mr2082259ljq.300.1634816954458; Thu, 21 Oct 2021 04:49:14 -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: Ulf Hansson Date: Thu, 21 Oct 2021 13:48:37 +0200 Message-ID: Subject: Re: [PATCH 2/2] PM: sleep: Fix runtime PM based cpuidle support To: "Rafael J. Wysocki" Cc: 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 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. > > 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? 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? 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. 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? Kind regards Uffe