From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755327AbcFQG1W (ORCPT ); Fri, 17 Jun 2016 02:27:22 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:54478 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755169AbcFQG1P (ORCPT ); Fri, 17 Jun 2016 02:27:15 -0400 X-AuditID: cbfec7f4-f796c6d000001486-c3-576398413922 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 Cc: Marek Szyprowski , Joerg Roedel , Inki Dae , Kukjin Kim , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , "Rafael J. Wysocki" , Ulf Hansson , Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH v2 05/10] PM core: Optimize the use of device links for runtime PM Date: Fri, 17 Jun 2016 08:26:55 +0200 Message-id: <1466144820-6286-6-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+NgFrrGLMWRmVeSWpSXmKPExsVy+t/xa7qOM5LDDe79lrHYOGM9q8XUh0/Y LJoXr2ezmHR/AovFgv3WFp2zN7BbvH5haNH/+DWzxabH11gtLu+aw2bxufcIo8WM8/uYLNYe uctu8XjFW3aLM6cvsVocXxvuIODx5OA8Jo/Fe14yeWxa1cnmcefaHjaP/XPXsHtsXlLvMfnG ckaPLVfbWTz6tqxi9Pi8SS6AK4rLJiU1J7MstUjfLoEr4+Odc4wFB9Ur7pz4w9rA+Fuhi5GT Q0LARKJpwRNGCFtM4sK99WxdjFwcQgJLGSUa921lhnCamCT2zX3LDlLFJmAo0fW2C6xKRGAl o8S2PfvAqpgFrjJLzNmzk6WLkYNDWCBE4uQbJhCTRUBV4svzJJBeXgF3iU+Tu5ggtslJnDw2 mRXE5hTwkHhx6wcLiC0EVLPr8CnmCYy8CxgZVjGKppYmFxQnpeca6hUn5haX5qXrJefnbmKE hPaXHYyLj1kdYhTgYFTi4V0hmhwuxJpYVlyZe4hRgoNZSYRXczpQiDclsbIqtSg/vqg0J7X4 EKM0B4uSOO/cXe9DhATSE0tSs1NTC1KLYLJMHJxSDYzqiQkPu5QmNfotr6mPvXZxZc+BjbXC kVuWfCn9tzDKYruY39qeSQ3zT5/x2Ttd0G7FdQmHiOQf3/o3VldKZk89s+ZRxnOrb2vmbBMT ac8Nddl+rdNp9Ylwv6gWzoNz57Hoaz/8WLLMeaeEvdrdUO8Yhe9Vei02a+1n+X5Jiy6PPeit aHv8wAwlluKMREMt5qLiRACzj2YzaQIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Rafael J. Wysocki" If the device has no links to suppliers that should be used for runtime PM (links with DEVICE_LINK_PM_RUNTIME set), there is no reason to walk the list of suppliers for that device during runtime suspend and resume. Add a simple mechanism to detect that case and possibly avoid the extra unnecessary overhead. Signed-off-by: Rafael J. Wysocki Signed-off-by: Marek Szyprowski --- drivers/base/core.c | 6 ++++++ drivers/base/power/runtime.c | 23 ++++++++++++++++++++--- include/linux/pm.h | 1 + include/linux/pm_runtime.h | 4 ++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 1fe7cf232e1e..215cd44de761 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -119,6 +119,9 @@ struct devlink *device_link_add(struct device *consumer, get_device(consumer); link->consumer = consumer; INIT_LIST_HEAD(&link->c_node); + if (flags & DEVICE_LINK_PM_RUNTIME) + pm_runtime_new_link(consumer); + link->flags = flags; link->status = (flags & DEVICE_LINK_PROBE_TIME) ? DEVICE_LINK_CONSUMER_PROBE : DEVICE_LINK_DORMANT; @@ -161,6 +164,9 @@ static void devlink_del(struct devlink *link) dev_info(link->consumer, "Dropping the link to %s\n", dev_name(link->supplier)); + if (link->flags & DEVICE_LINK_PM_RUNTIME) + pm_runtime_drop_link(link->consumer); + list_del_rcu(&link->s_node); list_del_rcu(&link->c_node); call_srcu(&device_links_srcu, &link->rcu_head, __devlink_free_srcu); diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index ba21c123b16e..0ea00d442e0f 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -270,6 +270,7 @@ static int __rpm_callback(int (*cb)(struct device *), struct device *dev) { struct devlink *link; int retval, idx; + bool use_links = dev->power.links_count > 0; if (dev->power.irq_safe) { spin_unlock(&dev->power.lock); @@ -283,7 +284,7 @@ static int __rpm_callback(int (*cb)(struct device *), struct device *dev) * routine returns, so it is safe to read the status outside of * the lock. */ - if (dev->power.runtime_status == RPM_RESUMING) { + if (use_links && dev->power.runtime_status == RPM_RESUMING) { idx = device_links_read_lock(); list_for_each_entry_rcu(link, &dev->consumer_links, c_node) @@ -314,8 +315,9 @@ static int __rpm_callback(int (*cb)(struct device *), struct device *dev) * * Do that if resume fails too. */ - if ((dev->power.runtime_status == RPM_SUSPENDING && !retval) - || (dev->power.runtime_status == RPM_RESUMING && retval)) { + if (use_links + && ((dev->power.runtime_status == RPM_SUSPENDING && !retval) + || (dev->power.runtime_status == RPM_RESUMING && retval))) { idx = device_links_read_lock(); fail: @@ -1525,6 +1527,21 @@ void pm_runtime_clean_up_links(struct device *dev) device_links_read_unlock(idx); } +void pm_runtime_new_link(struct device *dev) +{ + spin_lock_irq(&dev->power.lock); + dev->power.links_count++; + spin_unlock_irq(&dev->power.lock); +} + +void pm_runtime_drop_link(struct device *dev) +{ + spin_lock_irq(&dev->power.lock); + WARN_ON(dev->power.links_count == 0); + dev->power.links_count--; + spin_unlock_irq(&dev->power.lock); +} + /** * pm_runtime_force_suspend - Force a device into suspend state if needed. * @dev: Device to suspend. diff --git a/include/linux/pm.h b/include/linux/pm.h index 06eb353182ab..49c811378110 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -596,6 +596,7 @@ struct dev_pm_info { unsigned int use_autosuspend:1; unsigned int timer_autosuspends:1; unsigned int memalloc_noio:1; + unsigned int links_count; enum rpm_request request; enum rpm_status runtime_status; int runtime_error; diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index c21a21c064e3..bef6203aaf14 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -56,6 +56,8 @@ extern void pm_runtime_update_max_time_suspended(struct device *dev, s64 delta_ns); extern void pm_runtime_set_memalloc_noio(struct device *dev, bool enable); extern void pm_runtime_clean_up_links(struct device *dev); +extern void pm_runtime_new_link(struct device *dev); +extern void pm_runtime_drop_link(struct device *dev); static inline void pm_suspend_ignore_children(struct device *dev, bool enable) { @@ -188,6 +190,8 @@ static inline unsigned long pm_runtime_autosuspend_expiration( static inline void pm_runtime_set_memalloc_noio(struct device *dev, bool enable){} static inline void pm_runtime_clean_up_links(struct device *dev) {} +static inline void pm_runtime_new_link(struct device *dev) {} +static inline void pm_runtime_drop_link(struct device *dev) {} #endif /* !CONFIG_PM */ -- 1.9.1