All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: linux-pci@vger.kernel.org
Cc: linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Peter Wu <peter@lekensteyn.nl>,
	Andreas Noever <andreas.noever@gmail.com>
Subject: [PATCH v2 4/5] PCI: Avoid unnecessary resume after direct-complete
Date: Sun, 18 Sep 2016 05:39:20 +0200	[thread overview]
Message-ID: <4e8b490a18cc349318f0b71482d5dc7a7e9ca364.1474130360.git.lukas@wunner.de> (raw)
In-Reply-To: <cover.1474130360.git.lukas@wunner.de>

Commit 58a1fbbb2ee8 ("PM / PCI / ACPI: Kick devices that might have been
reset by firmware") added a runtime resume for devices that were runtime
suspended when the system entered sleep.

The motivation was that devices might be in a reset-power-on state after
waking from system sleep, so their power state as perceived by Linux
(stored in pci_dev->current_state) would no longer reflect reality.
By resuming such devices, we allow them to return to a low-power state
via autosuspend and also bring their current_state in sync with reality.

However for devices that are *not* in a reset-power-on state, doing an
unconditional resume wastes energy.  A more refined approach is called
for which issues a runtime resume only if the power state after
direct-complete is shallower than it was before. To achieve this, update
the device's current_state and compare it to its pre-sleep value.

Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
---
 drivers/pci/pci-driver.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index e39a67c..fd4b9c4 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -684,8 +684,19 @@ static int pci_pm_prepare(struct device *dev)
 
 static void pci_pm_complete(struct device *dev)
 {
-	pci_dev_complete_resume(to_pci_dev(dev));
-	pm_complete_with_resume_check(dev);
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+
+	pci_dev_complete_resume(pci_dev);
+	pm_generic_complete(dev);
+
+	/* Resume device if platform firmware has put it in reset-power-on */
+	if (dev->power.direct_complete && pm_resume_via_firmware()) {
+		pci_power_t pre_sleep_state = pci_dev->current_state;
+
+		pci_update_current_state(pci_dev, pci_dev->current_state);
+		if (pci_dev->current_state < pre_sleep_state)
+			pm_request_resume(dev);
+	}
 }
 
 #else /* !CONFIG_PM_SLEEP */
-- 
2.9.3

  parent reply	other threads:[~2016-09-18  3:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-18  3:39 [PATCH v2 0/5] PCI PM refinements Lukas Wunner
2016-09-18  3:39 ` [PATCH v2 1/5] PCI: Afford direct-complete to devices with nonstandard PM Lukas Wunner
2016-09-18  3:39 ` [PATCH v2 5/5] PCI: Avoid unnecessary resume on shutdown Lukas Wunner
2016-09-19  9:12   ` Oliver Neukum
2016-09-19 10:14     ` Lukas Wunner
2016-09-24  0:50       ` Rafael J. Wysocki
2016-10-05 12:32         ` Lukas Wunner
2016-09-18  3:39 ` Lukas Wunner [this message]
2016-09-24  0:47   ` [PATCH v2 4/5] PCI: Avoid unnecessary resume after direct-complete Rafael J. Wysocki
2016-09-18  3:39 ` [PATCH v2 3/5] PCI: Recognize D3cold in pci_update_current_state() Lukas Wunner
2016-09-24  0:46   ` Rafael J. Wysocki
2016-09-18  3:39 ` [PATCH v2 2/5] PCI: Query platform firmware for device power state Lukas Wunner
2016-09-24  0:46   ` Rafael J. Wysocki
2016-09-28 16:54 ` [PATCH v2 0/5] PCI PM refinements Bjorn Helgaas
2016-09-29 12:11   ` Lukas Wunner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e8b490a18cc349318f0b71482d5dc7a7e9ca364.1474130360.git.lukas@wunner.de \
    --to=lukas@wunner.de \
    --cc=andreas.noever@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=peter@lekensteyn.nl \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.