From patchwork Fri Apr 1 14:11:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 555762 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21688C433F5 for ; Fri, 1 Apr 2022 14:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346734AbiDAONh (ORCPT ); Fri, 1 Apr 2022 10:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346718AbiDAON3 (ORCPT ); Fri, 1 Apr 2022 10:13:29 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ED2C214072 for ; Fri, 1 Apr 2022 07:11:39 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id d5so5127704lfj.9 for ; Fri, 01 Apr 2022 07:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dc7bcPLHSzDeVD5ow88/lepa6mD08+FL5qt0hCCvM24=; b=Gs++QERUQ6VZTav+T8iX4NX+HP4paalYcpGZTaqYgcvKWD3gcJnCjsvRq74CalCDQD ZOZ3jfl0z6fqX3p2JCZN5YBH7DjJDvfmf7DYHZIAZfaENweW5oy/yBOAjRde0PJm+BiK +BNTFmNl9QnskE96uabMgEt8GQ4rq/UdCp1KFldhsjEBrjipJC3aBK/XcfUJ2+38jd9E vQdNrorAoW97tRvVl4/wKRr9TNlHynMSIUHXgaelkssAMco89uegyP468+KlYXFz2wgQ VK/ZjUasEbG6bqEm1sgTD7iDNsDhiFPjPO674O0E3k7da6H+a/VJhJaweshHL0bkC9Wc s+xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dc7bcPLHSzDeVD5ow88/lepa6mD08+FL5qt0hCCvM24=; b=mFmYalyyy3TNZ5YgEJJ93xrScOYcWLP24uHOzIkYFLrz33SnR42mDrS3LaN1bqmD/r XaxBqlrKIJCgp4FLLmXpf2EXxoyo/QKn5pKqTqPVAzSir887FPtI8tLtper+y334rJ8n nu/nNM3TVgG1IWBHAWEpaH3qJ/kDrlao5QgPLLbmWgK18jAvGNHiATVvSdFvxxpkmpDf CN3BMGrfBIwey7MjuXLBIP3AxgPNMIq0c91YnQ1P1ztUzXPsZ0xAbF/xglothWnfOG/7 JbQDAJNxg1tucy4/7yB6cKQmjsUihhySbHTZS6lcUE3ArjyT0wWcxj4vqrzhQnAUvVTE 3T5g== X-Gm-Message-State: AOAM531Szv1ooCWfV6CIa9QPmy36XeIsWh6pCAVMrecTt4/jSY1gCbte 9ks5yb4zWzITdLqvLpeX5WgJ9A== X-Google-Smtp-Source: ABdhPJxRtRhtqUT7n7uSs6oA1DmMyYSR5uMWLnIib8aSgqAuEV/CUQy3xIotPv+wra+vfJMp5vzoRw== X-Received: by 2002:a05:6512:c01:b0:448:6aec:65c5 with SMTP id z1-20020a0565120c0100b004486aec65c5mr14350038lfu.193.1648822297707; Fri, 01 Apr 2022 07:11:37 -0700 (PDT) Received: from localhost.localdomain (h-98-128-181-154.NA.cust.bahnhof.se. [98.128.181.154]) by smtp.gmail.com with ESMTPSA id 16-20020ac24d50000000b0044a255c8d3bsm251926lfp.116.2022.04.01.07.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 07:11:36 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: Maulik Shah , Daniel Lezcano , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Alexandre Torgue , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] PM: runtime: Allow to call __pm_runtime_set_status() from atomic context Date: Fri, 1 Apr 2022 16:11:23 +0200 Message-Id: <20220401141124.27272-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220401141124.27272-1-ulf.hansson@linaro.org> References: <20220401141124.27272-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The only two users of __pm_runtime_set_status() are pm_runtime_set_active() and pm_runtime_set_suspended(). These are widely used and should be called from non-atomic context to work as expected. However, it would be convenient to allow them be called from atomic context too, as shown from a subsequent change, so let's add support for this. Signed-off-by: Ulf Hansson --- drivers/base/power/runtime.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index d4059e6ffeae..91d757914686 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1210,12 +1210,13 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status) { struct device *parent = dev->parent; bool notify_parent = false; + unsigned long flags; int error = 0; if (status != RPM_ACTIVE && status != RPM_SUSPENDED) return -EINVAL; - spin_lock_irq(&dev->power.lock); + spin_lock_irqsave(&dev->power.lock, flags); /* * Prevent PM-runtime from being enabled for the device or return an @@ -1226,7 +1227,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status) else error = -EAGAIN; - spin_unlock_irq(&dev->power.lock); + spin_unlock_irqrestore(&dev->power.lock, flags); if (error) return error; @@ -1247,7 +1248,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status) device_links_read_unlock(idx); } - spin_lock_irq(&dev->power.lock); + spin_lock_irqsave(&dev->power.lock, flags); if (dev->power.runtime_status == status || !parent) goto out_set; @@ -1288,7 +1289,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status) dev->power.runtime_error = 0; out: - spin_unlock_irq(&dev->power.lock); + spin_unlock_irqrestore(&dev->power.lock, flags); if (notify_parent) pm_request_idle(parent); From patchwork Fri Apr 1 14:11:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 555864 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42A24C433FE for ; Fri, 1 Apr 2022 14:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346723AbiDAONi (ORCPT ); Fri, 1 Apr 2022 10:13:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346724AbiDAONb (ORCPT ); Fri, 1 Apr 2022 10:13:31 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B030D217973 for ; Fri, 1 Apr 2022 07:11:41 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id h11so4123149ljb.2 for ; Fri, 01 Apr 2022 07:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+mT7DozH0I+kyrJvkjL2P2dEm61K2NFLYH90tYVa51o=; b=P7c4fDPcdG/p6IDbn6XygyqieRQwUZhlzkE+5K1NmkEbE4nBBTsJDkJPg9D8E8pAu4 9ETDlnCnoW27jEd3/9JE2NVFZSCcFSaavPEe04CxJhnt6xl7IGYtRjcbYZ2uqxm4yc97 151x3IIqAzoJLcwfNBz0Dry5Lab0/okslV9lDKgLV3C5f2bEEJMrgVH4jOF80Ut9lPmB UuyClcUBsUdMxA2mztVPVxsjUWDwL6+HiNIVkbRQsAwMzmnYBqRi4s1wXkRBI1tmiuzo W7inJ9GMeM+3W8VdsmjmOGHz36wfnRBgB7QX7Y0o4M+XmSJfT6IHm4AIKtOyr9aupyEd wdsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+mT7DozH0I+kyrJvkjL2P2dEm61K2NFLYH90tYVa51o=; b=xoonHMgotXqgkHYdDn8U3c0pAHfNBZ3oHudYVjltuDa0lTgyAX7l/m2yGKKp+QRamr qTGU6J6N82bDkviy8gV9hIoL4fJfmqrv+mEN84MNZu8w6P08Clxtqc3TRdC8/9LuWaJI hw3AVgKuacZrV4OoeqjZtY0+4p1Z2tRvWpL2h8vLxG8zEMJmWMotm2QSttQoomGqL8bU PbOQppVj/P4imyA+hMaymM+9h426F+c3sOpSbl00JNcg5NvPkPRWCxdXUsm7iGr3hwl+ VCQEYqmMZulEFueDgqxsgtvGdQ3mLCJzY3gIBJqUMDmfQRfJDN5HOhlQ9wncTUHt5rET 8IFQ== X-Gm-Message-State: AOAM531/R855+x8lzm+Vy3HVY8Fd2vhXNzZLuw2qwAC/GTodyPwim98B FNT2VXUrsnQKn1al3xbInZWgFg== X-Google-Smtp-Source: ABdhPJzPNIzR8o/fTHBpIIc5TQRIQ6skrKM1Hx35yicn83dRV3rC2APQINhmpRQugY4tPM0ZnstwXg== X-Received: by 2002:a2e:9045:0:b0:249:78ba:fbf8 with SMTP id n5-20020a2e9045000000b0024978bafbf8mr13484220ljg.218.1648822299947; Fri, 01 Apr 2022 07:11:39 -0700 (PDT) Received: from localhost.localdomain (h-98-128-181-154.NA.cust.bahnhof.se. [98.128.181.154]) by smtp.gmail.com with ESMTPSA id 16-20020ac24d50000000b0044a255c8d3bsm251926lfp.116.2022.04.01.07.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 07:11:38 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: Maulik Shah , Daniel Lezcano , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Alexandre Torgue , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode Date: Fri, 1 Apr 2022 16:11:24 +0200 Message-Id: <20220401141124.27272-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220401141124.27272-1-ulf.hansson@linaro.org> References: <20220401141124.27272-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When PSCI OSI mode is supported the syscore flag is set for the CPU devices that becomes attached to their PM domains (genpds). In the suspend-to-idle case, we call dev_pm_genpd_suspend|resume() to allow genpd to properly manage the power-off/on operations (pick an idlestate and manage the on/off notifications). For suspend-to-ram, dev_pm_genpd_suspend|resume() is currently not being called, which causes a problem that the genpd on/off notifiers do not get sent as expected. This prevents the platform-specific operations from being executed, typically needed just before/after the boot CPU is being turned off/on. To deal with this problem, let's register a syscore ops for cpuidle-psci when PSCI OSI mode is being used and call dev_pm_genpd_suspend|resume() from them. In this way, genpd regains control of the PM domain topology and then sends the on/off notifications when it's appropriate. Reported-by: Maulik Shah Suggested-by: Maulik Shah Signed-off-by: Ulf Hansson Tested-by: Maulik Shah --- drivers/cpuidle/cpuidle-psci.c | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index b51b5df08450..540105ca0781 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -131,6 +132,49 @@ static int psci_idle_cpuhp_down(unsigned int cpu) return 0; } +static void psci_idle_syscore_switch(bool suspend) +{ + bool cleared = false; + struct device *dev; + int cpu; + + for_each_possible_cpu(cpu) { + dev = per_cpu_ptr(&psci_cpuidle_data, cpu)->dev; + + if (dev && suspend) { + dev_pm_genpd_suspend(dev); + } else if (dev) { + dev_pm_genpd_resume(dev); + + /* Account for userspace having offlined a CPU. */ + if (pm_runtime_status_suspended(dev)) + pm_runtime_set_active(dev); + + /* Clear domain state to re-start fresh. */ + if (!cleared) { + psci_set_domain_state(0); + cleared = true; + } + } + } +} + +static int psci_idle_syscore_suspend(void) +{ + psci_idle_syscore_switch(true); + return 0; +} + +static void psci_idle_syscore_resume(void) +{ + psci_idle_syscore_switch(false); +} + +static struct syscore_ops psci_idle_syscore_ops = { + .suspend = psci_idle_syscore_suspend, + .resume = psci_idle_syscore_resume, +}; + static void psci_idle_init_cpuhp(void) { int err; @@ -138,6 +182,8 @@ static void psci_idle_init_cpuhp(void) if (!psci_cpuidle_use_cpuhp) return; + register_syscore_ops(&psci_idle_syscore_ops); + err = cpuhp_setup_state_nocalls(CPUHP_AP_CPU_PM_STARTING, "cpuidle/psci:online", psci_idle_cpuhp_up,