From patchwork Mon May 30 09:33:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 68834 Delivered-To: patches@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1308883qge; Mon, 30 May 2016 02:33:42 -0700 (PDT) X-Received: by 10.112.157.135 with SMTP id wm7mr7284105lbb.48.1464600811466; Mon, 30 May 2016 02:33:31 -0700 (PDT) Return-Path: Received: from mail-lf0-x22e.google.com (mail-lf0-x22e.google.com. [2a00:1450:4010:c07::22e]) by mx.google.com with ESMTPS id h80si18577022lfg.334.2016.05.30.02.33.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 02:33:31 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22e as permitted sender) client-ip=2a00:1450:4010:c07::22e; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22e as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x22e.google.com with SMTP id s64so45969306lfe.0 for ; Mon, 30 May 2016 02:33:31 -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=NnTD/u+5/3U1R3g8QuGriEbst4xXhUwI20Nz/83Ta8M=; b=h+D6wFmGqTErYjVdoz5VJtc4B2fnbgaGkuB1af2/2Rl1A71dtdELBptC5ZWUtAxtr1 29uFWukajvmj6Mjm186jeSynfVqVmzVGUBQ5ybl8DnQYIooofuM1ediEbxuyYeukT0AR flNxK76gsRVyNfPR6uDoepR+segGZ3BFldkgA= 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=NnTD/u+5/3U1R3g8QuGriEbst4xXhUwI20Nz/83Ta8M=; b=FJrWxP/p1IYcSRJUbL5SUyHK8vkbgetthsFE7C2BGn3PbY3f/b9r2rfhgyLjn5CQnM lqpvzZu+I4BtpXbyio/ef20MDMgsPkZM66YWnKmPJbQCnu/McdKWACUYnB2MraTnWXzo xATMRPuDd3bLnYnzdf0MJ0f2/e0ZaQVFVTqdyTxwknPinbWsakOKe2YZ3OZ93GzS4E+a vjKBe4GL7NIeqD1hd6IrtqZimus0prvBaH4JYPuokFLE4tw3sU/5IxaK2Rj8pkKUdggG UVb3yOUeVpNVPu14pFKXzplRCO91/PPa7u8blR7S8KI6XOe32bFNpJtSQFhqdbprBpOP uMBQ== X-Gm-Message-State: ALyK8tJcfblcrMxW0wd90aTyPFxh8L/rpM2hGZXiyIInPPSR1R19i4I+mcnGjpXDB3QOhHajTho= X-Received: by 10.25.133.10 with SMTP id h10mr338587lfd.28.1464600811111; Mon, 30 May 2016 02:33:31 -0700 (PDT) Return-Path: 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.29 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 30 May 2016 02:33:29 -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 5/5] PM / Runtime: Defer resuming of the device in pm_runtime_force_resume() Date: Mon, 30 May 2016 11:33:15 +0200 Message-Id: <1464600795-26307-6-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> When the pm_runtime_force_suspend|resume() helpers were invented, we still had CONFIG_PM_RUNTIME and CONFIG_PM_SLEEP as separate Kconfig options. To make sure these helpers worked for all combinations and without introducing too much of complexity, the device was always resumed in pm_runtime_force_resume(). More precisely, when CONFIG_PM_SLEEP was set and CONFIG_PM_RUNTIME was unset, we needed to resume the device as the subsystem/driver couldn't rely on using runtime PM to do it. As the CONFIG_PM_RUNTIME option was merged into CONFIG_PM a while ago, it removed this combination, of using CONFIG_PM_SLEEP without the earlier CONFIG_PM_RUNTIME. For this reason we can now rely on the subsystem/driver to use runtime PM to resume the device, instead of forcing that to be done in all cases. In other words, let's defer the runtime resume to a later point when it's actually needed. Signed-off-by: Ulf Hansson --- Changes in v2: - Updated changelog. - Updated comment in the code. --- drivers/base/power/runtime.c | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 1.9.1 diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 09e4eb1..81731a2 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1509,6 +1509,17 @@ int pm_runtime_force_resume(struct device *dev) if (!pm_runtime_status_suspended(dev)) goto out; + /* + * The PM core increases the runtime PM usage count in the system PM + * prepare phase. If the count is greater than 1 at this point, a real + * user (such as a subsystem, driver, userspace, etc.) has also + * increased it, indicating that the device was used when system suspend + * was invoked. In this case, the device is expected to be used on + * system resume as well, so invoke the ->runtime_resume() callback. + */ + if (atomic_read(&dev->power.usage_count) < 2) + goto out; + ret = pm_runtime_set_active(dev); if (ret) goto out;