From patchwork Sun Sep 18 03:39:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 9337557 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 A23F2601C2 for ; Sun, 18 Sep 2016 03:41:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 974902932B for ; Sun, 18 Sep 2016 03:41:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C22D2937D; Sun, 18 Sep 2016 03:41:24 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 59C2929379 for ; Sun, 18 Sep 2016 03:41:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755880AbcIRDlW (ORCPT ); Sat, 17 Sep 2016 23:41:22 -0400 Received: from mailout2.hostsharing.net ([83.223.90.233]:54041 "EHLO mailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755486AbcIRDlV (ORCPT ); Sat, 17 Sep 2016 23:41:21 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout2.hostsharing.net (Postfix) with ESMTPS id 943871018C44C; Sun, 18 Sep 2016 05:41:19 +0200 (CEST) Received: from localhost (3-38-90-81.adsl.cmo.de [81.90.38.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id E8090603E217; Sun, 18 Sep 2016 05:41:17 +0200 (CEST) X-Mailbox-Line: From 760eb8c67a02e35938a4fbd3b31cbe9bb1414c5a Mon Sep 17 00:00:00 2001 Message-Id: <760eb8c67a02e35938a4fbd3b31cbe9bb1414c5a.1474130360.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Sun, 18 Sep 2016 05:39:20 +0200 Subject: [PATCH v2 5/5] PCI: Avoid unnecessary resume on shutdown To: linux-pci@vger.kernel.org Cc: linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Peter Wu , Andreas Noever Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We currently perform a mandatory runtime resume of all PCI devices on ->shutdown. However it is pointless to wake devices only to immediately power them down afterwards. (Or have the firmware reset them, in case of a reboot.) It seems there are only two cases when a runtime resume is actually necessary: If the driver has declared a ->shutdown callback or if kexec is in progress. Constrain resume of a device to these cases and let it slumber otherwise, thereby conserving energy and speeding up shutdown. To prevent the device from being runtime resumed during the remainder of the shutdown process, disable runtime PM for it. Cc: Rafael J. Wysocki Signed-off-by: Lukas Wunner --- Changes since v1: * Disable runtime PM on the device to prevent it from being runtime resumed during the remainder of the shutdown process. drivers/pci/pci-driver.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index fd4b9c4..f21c620 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -459,6 +459,15 @@ static void pci_device_shutdown(struct device *dev) struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_driver *drv = pci_dev->driver; + /* Fast path for suspended devices */ + if (pm_runtime_status_suspended(dev) && (!drv || !drv->shutdown) && + !kexec_in_progress) { + pm_runtime_disable(dev); + if (pm_runtime_status_suspended(dev)) + return; + pm_runtime_enable(dev); + } + pm_runtime_resume(dev); if (drv && drv->shutdown)