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: 805032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Lj9VfaJ+"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xcqsD6gsBz9s78 for ; Thu, 24 Aug 2017 00:42:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932129AbdHWOmi (ORCPT ); Wed, 23 Aug 2017 10:42:38 -0400 Received: from mail-lf0-f50.google.com ([209.85.215.50]:34859 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932131AbdHWOm2 (ORCPT ); Wed, 23 Aug 2017 10:42:28 -0400 Received: by mail-lf0-f50.google.com with SMTP id k186so1476765lfe.2 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=QjUjphzGi0sxr3l/qzYOHV4OAWBCPGP4HtK4LGsH+q5+iHLH/SI82DYBUWb+vSbDVM H739J7E8W0bUBrvWKcflIC7Fun0ToNVfERp2fdOiDdVVTV7txO8s71bqAIi+PhgBifJB GLpHXAPFkPirSkgz3KxEz9+huddtBqxiGosZ1PID7eMQiAGHK3NMtcOrsCuIWsF90xJy jANrdvokPAu4eGium8uUEddP2Edm0jTpqLm4p+xkyW41Z0Fd4jXDw6FCBDWC1K/p+pUX yRN3xeMFTzgKtiPoIq1PY1oTVEpPv7WccoSR+3tY8sJQFmghgj4ocy44iv4TJhqJ0Pts eJqw== X-Gm-Message-State: AHYfb5gvrkq/ZXmh4vApGItW2dFcraD7HnE8wqDP2XzazIRposd2N4Ue 7lblIyskQBCcKoaM 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-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.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(-) 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);