Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1706400pxb; Fri, 22 Oct 2021 06:13:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFFH/4p5nsLaaNffSAlgpvIm4/qcRR4hDYcKksE3Oickh+RYYi8lnLiZAGVBCD9ZWie02x X-Received: by 2002:a17:907:62a5:: with SMTP id nd37mr15654176ejc.114.1634908393256; Fri, 22 Oct 2021 06:13:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634908393; cv=none; d=google.com; s=arc-20160816; b=Swb4pkg8VCjX8uEudyHea793WGdhc/gsrFAobnbT6wbi/Uz7QGHtiWtkbfoYxleCZl brFKPUGmFpSVN8fRbshO5zoDCI5tRf/iT+qlFE3EqCp4/tl+PAbsJar4hHNFf9qmUquI 9PLL3B9TdeACMmMnHwEsaTGLf1hpwJ7iITGN5eBY2+/V0bsxANAKFZ5yV9CrnxLAHWuu qlxj4MpjAAXbSDL5I8kUOPpqOAq8NoH/FYyPiocZ7CIpjzpGobl/Uv7K4ogi/WwtJR2r 2kqjb9AA2ygQDxRpW5QxHJlM95kKLDOCrmULbCXlmTldeeJCzQbBxcxAoKghUn9YX7nG eXjA== 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=ea+dffKzojjtHMbhrke+o7EPuvNXQWSumCl4dU8Qqig=; b=XAqbarSo4l9nkL/yvDD/Is73QFt7TPX8KwuQL1B4v7eOpNAjH/iBlxbskHPRWwYU5Q 3mgh9taLUThzsiKAakIClrqNS6d6z8KKm9E9DMLr//KhvJxTl9bWf8tkIMEOCK4fzDQl Kj1mN7rPIDoXy9Lh4Z8Mz0rFv6QnBk15nJp/giqJqumeDy8qcd1xUQtntIMiAD2anifg CiGQYvERx0Y3nPojg/1lk9+vRhU+W0AG2Sg5ip2I4FHia0knDkTt7ohhhgFZoOKg3Axo hQF5ZpiUQOwPfsGFDBl5SH44riEPXntkBHjRUY7xlglt+9RUT1nb1yIu3QG23CDKcLjG zRcQ== 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 q9si10710648ejn.647.2021.10.22.06.12.41; Fri, 22 Oct 2021 06:13:13 -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 S232263AbhJVNKh (ORCPT + 99 others); Fri, 22 Oct 2021 09:10:37 -0400 Received: from mail-ot1-f45.google.com ([209.85.210.45]:40745 "EHLO mail-ot1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231597AbhJVNKf (ORCPT ); Fri, 22 Oct 2021 09:10:35 -0400 Received: by mail-ot1-f45.google.com with SMTP id s18-20020a0568301e1200b0054e77a16651so4296601otr.7; Fri, 22 Oct 2021 06:08:18 -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=ea+dffKzojjtHMbhrke+o7EPuvNXQWSumCl4dU8Qqig=; b=4i6xGWRBoBlmCZATjMRmxLlwHHGMcX962FAND/yM7QCxVefn+BTJwdqcTZaJ9l8Z3l Tb4sGxfZIew5fSZbboID0/NAjZZrTceAO4IyIDOeDGVqTNIiTaDQpIihZeoC13lDHtvQ y/nJqR0R8FL0B0gk/I7wWxyQ3ZbvBqGW9PDmwx8AX8u475p9rUlf2/PstjTmQOQZSwTp CIIXbSf6QSfdzyWucrbdxzznw5MpvCTpniwtWtDZ20qfz/1Igi06fAu4BrqAr5vGy5Wk mZ7v4UrShNQiNdpZ88SbmWwSaBrHluUB3p2HzejRkgphjoGvRjj0E4QMweXjK7Q+/4Th CiqQ== X-Gm-Message-State: AOAM530OdtyhBc8653OC74+9jlUkAGlHEQTBgnFMcPDFnr0wEQ38QA8K VIx2k0/RMNI+9vSqdx+BF2vGoiRjJsRcx0thCewA3NADRSw= X-Received: by 2002:a05:6830:90b:: with SMTP id v11mr10046614ott.254.1634908097786; Fri, 22 Oct 2021 06:08:17 -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: Fri, 22 Oct 2021 15:08:06 +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 Fri, Oct 22, 2021 at 2:57 PM Ulf Hansson wrote: > > On Fri, 22 Oct 2021 at 14:02, Rafael J. Wysocki wrote: > > > > On Fri, Oct 22, 2021 at 12:18 PM Ulf Hansson wrote: > > > > > > On Thu, 21 Oct 2021 at 21:56, Ulf Hansson wrote: > > > > > > > > On Thu, 21 Oct 2021 at 21:02, Rafael J. Wysocki wrote: > > > > > > > > > > On Thu, Oct 21, 2021 at 8:12 PM Ulf Hansson wrote: > > > > > > > > > > > > On Thu, 21 Oct 2021 at 18:33, Rafael J. Wysocki wrote: > > > > > > > > > > > > > > On Thu, Oct 21, 2021 at 6:17 PM Ulf Hansson wrote: > > > > > > > > > > [cut] > > > > > > > > > > > > So in theory you could check the pm_runtime_put_sync_suspend() return > > > > > > > value and fall back to something like WFI if that's an error code. > > > > > > > > > > > > I have already tried that, but it simply got too complicated. The main > > > > > > issue was that runtime PM could become disabled for the device in the > > > > > > middle of executing the ->enter() callback. > > > > > > > > > > So IIUC the problem is that you cannot resume after suspending in that case. > > > > > > > > > > IOW, you need to guarantee that if the suspend is successful, the > > > > > resume also will take place, but if the suspend fails, you basically > > > > > don't care. > > > > > > > > Exactly. > > > > > > > > > > > > > > > For example, if pm_runtime_get_sync() fails, I still need to make sure > > > > > > the reference counting in genpd becomes correct - and I can't do that > > > > > > using dev_pm_genpd_resume(). That's because it's not designed to be > > > > > > called in this "unknown" suspend phase, but should be called after the > > > > > > noirq phase and be properly balanced with dev_pm_genpd_suspend(). > > > > > > > > > > > > In other words, the error path didn't work out for me. > > > > > > > > > > It should be sufficient to call wake_up_all_idle_cpus() in the suspend > > > > > path before dpm_suspend_late(), because system suspend acquires a > > > > > PM-runtime reference on every device. IOW, it won't let any devices > > > > > runtime-suspend, so if your power domain devices are resumed in that > > > > > path, they will never suspend again in it and the > > > > > pm_runtime_put_sync_suspend() in __psci_enter_domain_idle_state() > > > > > becomes a reference counter management call which works regardless of > > > > > whether or not PM runtime is disabled. > > > > > > > > That sounds like a great idea, this should work too! Then the question > > > > is, how to make that call to wake_up_all_idle_cpus() to become > > > > optional - or only invoked for the cpuidle drivers that need it. > > > > It need not be optional. > > > > For suspend-to-idle it doesn't matter, because all CPUs will be woken > > up from idle shortly anyway. > > > > For other suspend variants this doesn't matter, because all secondary > > CPUs will be taken offline shortly and the primary CPU will call into > > the platform "sleep" handler. > > > > > > > > > > In any case, I will try this out, thanks for the suggestion! > > > > > > I now recall that I have already tried this, but unfortunately it doesn't work. > > > > > > The problem is that the dev->power.syscore flag is set for the device, > > > which makes device_prepare() to bail out early and skip calling > > > pm_runtime_get_noresume(). > > > > This needs to be fixed, then. > > So bumping the usage count even if the dev->power.syscore is set, > should be fine? (And of course dropping it in the complete phase). Yes, please see https://patchwork.kernel.org/project/linux-pm/patch/5773062.lOV4Wx5bFT@kreacher/ It should have been done this way from the outset, but I messed up a merge (and said that it was "trivial" :-/). > I can work with that, let me try!