From patchwork Fri Jun 17 06:26:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9182657 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 AC7296075F for ; Fri, 17 Jun 2016 06:32:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AB7528386 for ; Fri, 17 Jun 2016 06:32:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F713283A1; Fri, 17 Jun 2016 06:32:00 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0F26728386 for ; Fri, 17 Jun 2016 06:32:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bDnHV-0004PQ-OG; Fri, 17 Jun 2016 06:29:29 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bDnFi-0002aD-S4 for linux-arm-kernel@lists.infradead.org; Fri, 17 Jun 2016 06:27:41 +0000 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8W00FO7KLC6010@mailout2.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Fri, 17 Jun 2016 07:27:12 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-bd-5763983f9556 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 4B.83.05254.04893675; Fri, 17 Jun 2016 07:27:12 +0100 (BST) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O8W00HUZKL21910@eusync4.samsung.com>; Fri, 17 Jun 2016 07:27:11 +0100 (BST) From: Marek Szyprowski To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 03/10] PM core: Make async suspend/resume of devices use device links Date: Fri, 17 Jun 2016 08:26:53 +0200 Message-id: <1466144820-6286-4-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1466144820-6286-1-git-send-email-m.szyprowski@samsung.com> References: <1466144820-6286-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRmVeSWpSXmKPExsVy+t/xa7oOM5LDDdoPMlpsnLGe1WLqwyds Fs2L17NZTLo/gcViwX5ri87ZG9gtXr8wtOh//JrZYtPja6wWl3fNYbP43HuE0WLG+X1MFmuP 3GW3eLziLbvFmdOXWC2Orw13EPB4cnAek8fiPS+ZPDat6mTzuHNtD5vH/rlr2D02L6n3mHxj OaPHlqvtLB59W1YxenzeJBfAFcVlk5Kak1mWWqRvl8CV0fOvl6VgjW5F95l7zA2M+1S7GDk5 JARMJJa3LGWCsMUkLtxbzwZiCwksZZTYd8yri5ELyG5ikth/ehMrSIJNwFCi620XG0hCRGAl o8S2PfuYQRxmgavMEnP27GQBqRIWiJJY3L0DbCyLgKrEx41vmEFsXgF3iZNfJjBCrJOTOHls MthUTgEPiRe3frBArHaX2HX4FPMERt4FjAyrGEVTS5MLipPScw31ihNzi0vz0vWS83M3MUKC +8sOxsXHrA4xCnAwKvHwrhBNDhdiTSwrrsw9xCjBwawkwqs5HSjEm5JYWZValB9fVJqTWnyI UZqDRUmcd+6u9yFCAumJJanZqakFqUUwWSYOTqkGxqAdVeeZH9eqOmxX+fIm4diiX/wXbE65 n1ksKMo3XWV5xixvpdVNfMlP5z/32vTkslL0BSm/V+xTxGoWez95FDM3VoH71U+xHtuNujOs jmRcfSwr0qFrpnjmQ1/gvIkhCs9EMlVfvlD6tHuq7Ha2hofn/ijOrT1i7NLg5FJxbqXDfZt8 pzPLKpRYijMSDbWYi4oTAY++ZwJqAgAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160616_232739_233186_3C238A96 X-CRM114-Status: GOOD ( 22.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Greg Kroah-Hartman , Joerg Roedel , "Rafael J. Wysocki" , "Rafael J. Wysocki" , Ulf Hansson , Inki Dae , Kukjin Kim , Mark Brown , Marek Szyprowski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Rafael J. Wysocki" Make the device suspend/resume part of the core system suspend/resume code use device links to ensure that supplier and consumer devices will be suspended and resumed in the right order in case of async suspend/resume. The idea, roughly, is to use dpm_wait() to wait for all consumers before a supplier device suspend and to wait for all suppliers before a consumer device resume. Signed-off-by: Rafael J. Wysocki Signed-off-by: Marek Szyprowski --- drivers/base/base.h | 2 ++ drivers/base/core.c | 4 +-- drivers/base/power/main.c | 68 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index cccb1d211541..123b986eb061 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -163,3 +163,5 @@ extern void device_links_driver_gone(struct device *dev); extern void device_links_no_driver(struct device *dev); extern bool device_links_busy(struct device *dev); extern void device_links_unbind_consumers(struct device *dev); +extern int device_links_read_lock(void); +extern void device_links_read_unlock(int idx); diff --git a/drivers/base/core.c b/drivers/base/core.c index 416341df3268..51a479ed68b5 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -163,12 +163,12 @@ void device_link_del(struct devlink *link) } EXPORT_SYMBOL_GPL(device_link_del); -static int device_links_read_lock(void) +int device_links_read_lock(void) { return srcu_read_lock(&device_links_srcu); } -static void device_links_read_unlock(int idx) +void device_links_read_unlock(int idx) { return srcu_read_unlock(&device_links_srcu, idx); } diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index e44944f4be77..9470ccd87f11 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -244,6 +244,62 @@ static void dpm_wait_for_children(struct device *dev, bool async) device_for_each_child(dev, &async, dpm_wait_fn); } +static void dpm_wait_for_suppliers(struct device *dev, bool async) +{ + struct devlink *link; + int idx; + + idx = device_links_read_lock(); + + /* + * If the supplier goes away right after we've checked the link to it, + * we'll wait for its completion to change the state, but that's fine, + * because the only things that will block as a result are the SRCU + * callbacks freeing the link objects for the links in the list we're + * walking. + */ + list_for_each_entry_rcu(link, &dev->consumer_links, c_node) + if (link->status != DEVICE_LINK_DORMANT) + dpm_wait(link->supplier, async); + + device_links_read_unlock(idx); +} + +static void dpm_wait_for_superior(struct device *dev, bool async) +{ + dpm_wait(dev->parent, async); + dpm_wait_for_suppliers(dev, async); +} + +static void dpm_wait_for_consumers(struct device *dev, bool async) +{ + struct devlink *link; + int idx; + + idx = device_links_read_lock(); + + /* + * The status of a device link can only be changed from "dormant" by a + * probe, but that cannot happen during system suspend/resume. In + * theory it can change to "dormant" at that time, but then it is + * reasonable to wait for the target device anyway (eg. if it goes + * away, it's better to wait for it to go away completely and then + * continue instead of trying to continue in parallel with its + * unregistration). + */ + list_for_each_entry_rcu(link, &dev->supplier_links, s_node) + if (link->status != DEVICE_LINK_DORMANT) + dpm_wait(link->consumer, async); + + device_links_read_unlock(idx); +} + +static void dpm_wait_for_subordinate(struct device *dev, bool async) +{ + dpm_wait_for_children(dev, async); + dpm_wait_for_consumers(dev, async); +} + /** * pm_op - Return the PM operation appropriate for given PM event. * @ops: PM operations to choose from. @@ -488,7 +544,7 @@ static int device_resume_noirq(struct device *dev, pm_message_t state, bool asyn if (!dev->power.is_noirq_suspended) goto Out; - dpm_wait(dev->parent, async); + dpm_wait_for_superior(dev, async); if (dev->pm_domain) { info = "noirq power domain "; @@ -618,7 +674,7 @@ static int device_resume_early(struct device *dev, pm_message_t state, bool asyn if (!dev->power.is_late_suspended) goto Out; - dpm_wait(dev->parent, async); + dpm_wait_for_superior(dev, async); if (dev->pm_domain) { info = "early power domain "; @@ -750,7 +806,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) goto Complete; } - dpm_wait(dev->parent, async); + dpm_wait_for_superior(dev, async); dpm_watchdog_set(&wd, dev); device_lock(dev); @@ -1038,7 +1094,7 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a if (dev->power.syscore || dev->power.direct_complete) goto Complete; - dpm_wait_for_children(dev, async); + dpm_wait_for_subordinate(dev, async); if (dev->pm_domain) { info = "noirq power domain "; @@ -1185,7 +1241,7 @@ static int __device_suspend_late(struct device *dev, pm_message_t state, bool as if (dev->power.syscore || dev->power.direct_complete) goto Complete; - dpm_wait_for_children(dev, async); + dpm_wait_for_subordinate(dev, async); if (dev->pm_domain) { info = "late power domain "; @@ -1358,7 +1414,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) TRACE_DEVICE(dev); TRACE_SUSPEND(0); - dpm_wait_for_children(dev, async); + dpm_wait_for_subordinate(dev, async); if (async_error) goto Complete;