From patchwork Mon May 30 09:33:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 9140789 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B488B60759 for ; Mon, 30 May 2016 09:33:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A47A9281B4 for ; Mon, 30 May 2016 09:33:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9965628212; Mon, 30 May 2016 09:33:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D6E0281B4 for ; Mon, 30 May 2016 09:33:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932210AbcE3Jda (ORCPT ); Mon, 30 May 2016 05:33:30 -0400 Received: from mail-lf0-f51.google.com ([209.85.215.51]:34638 "EHLO mail-lf0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932141AbcE3Jd3 (ORCPT ); Mon, 30 May 2016 05:33:29 -0400 Received: by mail-lf0-f51.google.com with SMTP id k98so69927645lfi.1 for ; Mon, 30 May 2016 02:33:28 -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; bh=mAHrh26fBqyvP8DMTOMJG6uCJyYc73fQKEJ4MTqBSFo=; b=Y/d8Nb2KfJq622tpYKNsWzoJhtkqZpfVoT2sX5evqRgnBbS9oNBfR2jQnmCBmru8d0 QDxd7csPRUeh5BACa4fGuM9df9dR2jUSW4SS+oKGsm3pcYqipRqp7MTP5DcPnDyyb8ZI vUKUFUVRCjt23j4uNpOzyYT3xHzkNO4yRriq0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mAHrh26fBqyvP8DMTOMJG6uCJyYc73fQKEJ4MTqBSFo=; b=if7GPWykCpZ3J0AxCfdkFFl3XhylRvMDXyOnOCoruj4+raMD9F5XZvlt42u9QlQIRk t6hrTdCOn8U+xzsJd+V81mRoaok0aqSc/p3oTBPTdmbHbSYQzt5M3wZukYIJXwur/Jz5 eLHhCLg0ZhPSstTfxn4/odD4Jaif3uxPhnoINngK2jJ6MOrhyaRUCLoyq3HJMZBVykDB C31RCnPFk3yjUZZvaWvr5v/SNE6Fiv3SQ6ic+fbnmwUCSnHK/GI0MYKyaGo2bKf7WRix zcP2nasQwzkX9FpxIWIWQk68WwEsS6tc64HwWs9InqV+RT/t/D+PAnBF9ZEJrNsGFg97 wpiA== X-Gm-Message-State: ALyK8tJH9iKorScCCecEkLBwf+T7+VVTYcrvSG9ZSxNhYc5dfjqf9jgv+OmYxYqoPUe0JM2d X-Received: by 10.25.160.85 with SMTP id j82mr7989009lfe.52.1464600807780; Mon, 30 May 2016 02:33:27 -0700 (PDT) Received: from uffe-Latitude-E6430s.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id 75sm4596853lfw.25.2016.05.30.02.33.26 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 30 May 2016 02:33:26 -0700 (PDT) From: Ulf Hansson To: "Rafael J. Wysocki" , Kevin Hilman , Ulf Hansson , linux-pm@vger.kernel.org Cc: Len Brown , Pavel Machek , Geert Uytterhoeven , Lina Iyer , Axel Haslam , Marek Szyprowski , Jon Hunter , Andy Gross , Laurent Pinchart Subject: [PATCH v2 3/5] PM / Domains: Allow runtime PM during system PM phases Date: Mon, 30 May 2016 11:33:13 +0200 Message-Id: <1464600795-26307-4-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1464600795-26307-1-git-send-email-ulf.hansson@linaro.org> References: <1464600795-26307-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In cases when the PM domain isn't powered off when genpd's ->prepare() callback is invoked, genpd runtime resumes and disables runtime PM for the device. This behaviour was needed when genpd managed intermediate states during the power off sequence, as to maintain proper low power states of devices during system PM suspend/resume. The commit ba2bbfbf6307 ("PM / Domains: Remove intermediate states from the power off sequence"), enables genpd to improve its behaviour in this regards. The PM core disables runtime PM at __device_suspend_late() before it calls a system PM "late" callback for a device. When resuming a device, after a corresponding "early" callback has been invoked, the PM core re-enables runtime PM. By changing genpd to allow runtime PM according to the same system PM phases as the PM core, devices can be runtime resumed by its corresponding subsystem/driver when really needed. In this way, genpd no longer need to runtime resume the device from its ->prepare() callback. In most cases that avoids unnecessary and energy- wasting operations of runtime resuming devices that have nothing to do, only to runtime suspend them shortly after. Although, because of changing this behaviour in genpd and due to that genpd powers on the PM domain unconditionally in the system PM resume "noirq" phase, it could potentially cause a PM domain to stay powered on even if it's unused after the system has resumed. To avoid this, let's schedule a power off work when genpd's system PM ->complete() callback has been invoked for the last device in the PM domain. Another issue that arises due to this change in genpd, concerns those platforms/PM domains that makes use of genpd's device ->stop|start() callbacks. In these scenarios, the corresponding subsystem/driver needs to invoke pm_runtime_force_suspend() from a system PM suspend callback to allow genpd's ->runtime_suspend() to be invoked for an active device, else genpd won't "stop" a device that has been "started". The subsystem/driver also needs to invoke pm_runtime_force_resume() in a system PM resume callback, to restore the runtime PM state for the device and to re-enable runtime PM. Signed-off-by: Ulf Hansson Reviewed-by: Kevin Hilman --- Changes in v2: - Updated changelog. - Split patch into two pieces, to deal with stop/start issues from a separate change on top of this one. --- drivers/base/power/domain.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 60a9971..4cb57f3 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -739,21 +739,6 @@ static int pm_genpd_prepare(struct device *dev) mutex_unlock(&genpd->lock); - /* - * Even if the PM domain is powered off at this point, we can't expect - * it to remain in that state during the entire system PM suspend - * phase. Any subsystem/driver for a device in the PM domain, may still - * need to serve a request which may require the device to be runtime - * resumed and its PM domain to be powered. - * - * As we are disabling runtime PM at this point, we are preventing the - * subsystem/driver to decide themselves. For that reason, we need to - * make sure the device is operational as it may be required in some - * cases. - */ - pm_runtime_resume(dev); - __pm_runtime_disable(dev, false); - ret = pm_generic_prepare(dev); if (ret) { mutex_lock(&genpd->lock); @@ -761,7 +746,6 @@ static int pm_genpd_prepare(struct device *dev) genpd->prepared_count--; mutex_unlock(&genpd->lock); - pm_runtime_enable(dev); } return ret; @@ -787,8 +771,6 @@ static int pm_genpd_suspend_noirq(struct device *dev) if (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev)) return 0; - genpd_stop_dev(genpd, dev); - /* * Since all of the "noirq" callbacks are executed sequentially, it is * guaranteed that this function will never run twice in parallel for @@ -827,7 +809,7 @@ static int pm_genpd_resume_noirq(struct device *dev) pm_genpd_sync_poweron(genpd, true); genpd->suspended_count--; - return genpd_start_dev(genpd, dev); + return 0; } /** @@ -849,7 +831,7 @@ static int pm_genpd_freeze_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - return genpd_stop_dev(genpd, dev); + return 0; } /** @@ -869,7 +851,7 @@ static int pm_genpd_thaw_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - return genpd_start_dev(genpd, dev); + return 0; } /** @@ -907,7 +889,7 @@ static int pm_genpd_restore_noirq(struct device *dev) pm_genpd_sync_poweron(genpd, true); - return genpd_start_dev(genpd, dev); + return 0; } /** @@ -929,15 +911,15 @@ static void pm_genpd_complete(struct device *dev) if (IS_ERR(genpd)) return; + pm_generic_complete(dev); + mutex_lock(&genpd->lock); genpd->prepared_count--; + if (!genpd->prepared_count) + genpd_queue_power_off_work(genpd); mutex_unlock(&genpd->lock); - - pm_generic_complete(dev); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); } /**