From patchwork Wed Aug 23 14:42:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 110853 Delivered-To: patches@linaro.org Received: by 10.37.128.210 with SMTP id c18csp7031558ybm; Wed, 23 Aug 2017 07:42:27 -0700 (PDT) X-Received: by 10.46.76.9 with SMTP id z9mr1189558lja.134.1503499347435; Wed, 23 Aug 2017 07:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503499347; cv=none; d=google.com; s=arc-20160816; b=gMeLyJomkjjJOdzvus/x4AVksQrXQ17sOy4+XRwJFAoKy1I5oMi4INjB84N2AfY7uk IVp4Yd+fZDxolh/AI2ce+R5jTOgJiii7/NrWF2t2nzZaDWht8wlSlnK2p2PYNbSNbKqk dDTVQJrP9/j2SQr5/0I5K9K4/voP+Wfc8Jd9QAPqpYt3sEM59loCXpATdHNlIwQdIkrf Uj7ozoVxS8ztjyQcjG7FlAPO4TG7EgJzAmR5wM7iqeG0iyo4ScenU+tVwGNY7LsFNRaT luVQKS7CMROullcmVx2Tvz03aDztopK08lozG3oyr1fFAyPXNx2kmZVSqIMW06yro8jN yDJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=cFtN7cmkVNQ4DEF3pHQhfXJjO7HTQgcgUFCs5qRmUEo=; b=0Qtss00DnFOxGk2HI8lzVaZqnQr4pqPDYao4iMzvK4e+dRkDGGfRWsRg0z5iUFuRdJ 5xRGizfmMw4R51F+jRILHAAfz7ES8tQfchiouhYymQrjQ4hD3iELXZmjbpH1qxjxfIIO 1uvOBRO2v9BFX7eDNB4JklFszdlWFaXyHck59mvuZd8f/2e4OUexV/MVsY9qFYtsClla 8Y14RSDJNacd+SzqaB7F+mqnM1WRuKC6pcK5j1W/k0+xc/LSam76RpNxosQEE3CfyQ+o rcnYqeQbgPE9O6HXuLE7fzqlMESnfDlyEwlTgwb0gttZLOyM4MEgBlMY6ZK/RhqkZrRC iQ7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lj9VfaJ+; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::232 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-lf0-x232.google.com (mail-lf0-x232.google.com. [2a00:1450:4010:c07::232]) by mx.google.com with ESMTPS id z2si756619lja.485.2017.08.23.07.42.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 07:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::232 as permitted sender) client-ip=2a00:1450:4010:c07::232; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lj9VfaJ+; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::232 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x232.google.com with SMTP id l137so1428341lfg.3 for ; Wed, 23 Aug 2017 07:42:27 -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=cFtN7cmkVNQ4DEF3pHQhfXJjO7HTQgcgUFCs5qRmUEo=; b=Lj9VfaJ+xVEZHBDO4liUKOc2w96M80xH+qe9KbFA9TK173dHh6lFbDZXHMRFLAwGl1 Je2I3HUOai/jfX3qOGa3TSk51y2oRMfOIYy62NlCDWTnogRpOukA0FSq81U0+tYXba35 F6/w/F1XyUp68VtYFVkweY+u4xtHZpLsziTwk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cFtN7cmkVNQ4DEF3pHQhfXJjO7HTQgcgUFCs5qRmUEo=; b=K+F6SJKA3yGgtcFivsuPd8NYNFCKf+7dedpp3eqMvgV92X6us0AzT5Ii8fucVYO2Hz xomMZz9r9xlg95uKoYgfrbO4uLjz7ntvVxRuuMIkbG+PKtIsHZv5eIpm8uTS+A1r4WUF qc3X8lJ5d5j6ViFlgXhnI9I14aEditJM9TpbeWtL8cSCiozIj3aON545b5O6JLdOtyVn EJAI+TJ0nUZvevDIjnbJ9tbhS7QHS0I3oAGFc4ZNf26USjrnnO0cIspXBkMJpvf89m0L +tN8v4GuiVBVcg82v9tD/lOJRnTpYEwt1KOm8pSJMaoeFkVTxp1H3v7Vrxnon1xfZb/E qaTg== X-Gm-Message-State: AHYfb5jPsBlk49cnk0OuW+MU7l29blWxNQfClycp41JjIDm067DKtqzn +Q4u1YcUWNq6UgxK2aY= X-Received: by 10.46.69.213 with SMTP id s204mr1196849lja.176.1503499346939; Wed, 23 Aug 2017 07:42:26 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-67.NA.cust.bahnhof.se. [158.174.22.67]) by smtp.gmail.com with ESMTPSA id c89sm287593lfb.78.2017.08.23.07.42.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Aug 2017 07:42:26 -0700 (PDT) From: Ulf Hansson To: Wolfram Sang , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org Cc: Kevin Hilman , Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jisheng Zhang , John Stultz , Guodong Xu , Sumit Semwal , Haojian Zhuang , linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, Ulf Hansson Subject: [PATCH v2 7/9] PM / ACPI: Avoid runtime resuming device in acpi_subsys_suspend|freeze() Date: Wed, 23 Aug 2017 16:42:07 +0200 Message-Id: <1503499329-28834-8-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503499329-28834-1-git-send-email-ulf.hansson@linaro.org> References: <1503499329-28834-1-git-send-email-ulf.hansson@linaro.org> In the case when the no_direct_complete flag is set for the ACPI device, we can under some conditions during system sleep, avoid runtime resuming the device in acpi_subsys_suspend|freeze(). This means we can decrease the time needed for the device to enter its system sleep state, but also that we can avoid to waste power. More precisely, calling acpi_dev_needs_resume() from the acpi_subsys_suspend|freeze() in cases when the no_direct_complete flag has been set for the device, tells us if a runtime resume of the device is needed. Thus it may allow us to avoid it. Signed-off-by: Ulf Hansson --- Changes in v2: - Clarified changelog. - Improved comments is code. - Rebased. - Improved change to avoid open-coding. --- drivers/acpi/device_pm.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index b595968..5dd23de 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1117,11 +1117,19 @@ EXPORT_SYMBOL_GPL(acpi_subsys_complete); * @dev: Device to handle. * * Follow PCI and resume devices suspended at run time before running their - * system suspend callbacks. + * system suspend callbacks. However, try to avoid it when no_direct_complete + * is set. */ int acpi_subsys_suspend(struct device *dev) { - pm_runtime_resume(dev); + struct acpi_device *adev = ACPI_COMPANION(dev); + + if (!adev) + return 0; + + if (!adev->power.no_direct_complete || acpi_dev_needs_resume(dev, adev)) + pm_runtime_resume(dev); + return pm_generic_suspend(dev); } EXPORT_SYMBOL_GPL(acpi_subsys_suspend); @@ -1178,13 +1186,20 @@ EXPORT_SYMBOL_GPL(acpi_subsys_resume_early); */ int acpi_subsys_freeze(struct device *dev) { + struct acpi_device *adev = ACPI_COMPANION(dev); + + if (!adev) + return 0; + /* * This used to be done in acpi_subsys_prepare() for all devices and * some drivers may depend on it, so do it here. Ideally, however, * runtime-suspended devices should not be touched during freeze/thaw - * transitions. + * transitions. In case the no_direct_complete is set, try to avoid it. */ - pm_runtime_resume(dev); + if (!adev->power.no_direct_complete || acpi_dev_needs_resume(dev, adev)) + pm_runtime_resume(dev); + return pm_generic_freeze(dev); } EXPORT_SYMBOL_GPL(acpi_subsys_freeze);