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: 9917503 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 98F5F60327 for ; Wed, 23 Aug 2017 14:42:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A956285C2 for ; Wed, 23 Aug 2017 14:42:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DE99289AF; Wed, 23 Aug 2017 14:42:32 +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 CB467288A1 for ; Wed, 23 Aug 2017 14:42:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754133AbdHWOma (ORCPT ); Wed, 23 Aug 2017 10:42:30 -0400 Received: from mail-lf0-f53.google.com ([209.85.215.53]:34459 "EHLO mail-lf0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932130AbdHWOm2 (ORCPT ); Wed, 23 Aug 2017 10:42:28 -0400 Received: by mail-lf0-f53.google.com with SMTP id g77so1537467lfg.1 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=jTSnsrgoWc42NgK589avgSDJ6fq08fugaPGhC9I2TE4GnakJiVWCbmfuEkbZ5CtBBo 7uvoCnUz7gC+Z3+0lgNHZ9i8cz1hHPEtMLGIeZ/gMLIbwGQGZSwcrwGvg9Ws1JKwyxvW HAftqgIsGBFH9mxIyiTkRu9oMCb1EgVMMGmbBit/JT+dEos6GHClWJR3hFKJovwjzart i0+pzUoBce7TXzpdecrTmL6PvvJN/y7u9URBukMT1hTgiY+9nHRAelhgvN+acTLwvehk Gy7E3GwYA0AX4dSYbTKvSYt7BIwkIKF7F3vKgEUn9/4lkPUWx+VfH7XyQlJC02Z9I/lh 7WYg== X-Gm-Message-State: AHYfb5j6g2t7soWqinRpDiTWsybtbk28nPxsJheIzyrn8BoCSBwhfSXI ryp9jFVvTLuK+lhE X-Received: by 10.46.69.213 with SMTP id s204mr1196849lja.176.1503499346939; Wed, 23 Aug 2017 07:42:26 -0700 (PDT) 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> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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);