2020-10-22 06:39:27

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH 3/3] PM: runtime: Resume the device earlier in __device_release_driver()

From: Rafael J. Wysocki <[email protected]>

Since the device is resumed from runtime-suspend in
__device_release_driver() anyway, it is better to do that before
looking for busy managed device links from it to consumers, because
if there are any, device_links_unbind_consumers() will be called
and it will cause the consumer devices' drivers to unbind, so the
consumer devices will be runtime-resumed. In turn, resuming each
consumer device will cause the supplier to be resumed and when the
runtime PM references from the given consumer to it are dropped, it
may be suspended. Then, the runtime-resume of the next consumer
will cause the supplier to resume again and so on.

Update the code accordingly.

Signed-off-by: Rafael J. Wysocki <[email protected]>
Fixes: 9ed9895370ae ("driver core: Functional dependencies tracking support")
Cc: All applicable <[email protected]> # All applicable
---
drivers/base/dd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux-pm/drivers/base/dd.c
===================================================================
--- linux-pm.orig/drivers/base/dd.c
+++ linux-pm/drivers/base/dd.c
@@ -1117,6 +1117,8 @@ static void __device_release_driver(stru

drv = dev->driver;
if (drv) {
+ pm_runtime_get_sync(dev);
+
while (device_links_busy(dev)) {
__device_driver_unlock(dev, parent);

@@ -1132,8 +1134,6 @@ static void __device_release_driver(stru
return;
}

- pm_runtime_get_sync(dev);
-
driver_sysfs_remove(dev);

if (dev->bus)




2020-10-22 18:02:54

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH update 3/3] PM: runtime: Resume the device earlier in __device_release_driver()

From: Rafael J. Wysocki <[email protected]>

Since the device is resumed from runtime-suspend in
__device_release_driver() anyway, it is better to do that before
looking for busy managed device links from it to consumers, because
if there are any, device_links_unbind_consumers() will be called
and it will cause the consumer devices' drivers to unbind, so the
consumer devices will be runtime-resumed. In turn, resuming each
consumer device will cause the supplier to be resumed and when the
runtime PM references from the given consumer to it are dropped, it
may be suspended. Then, the runtime-resume of the next consumer
will cause the supplier to resume again and so on.

Update the code accordingly.

Signed-off-by: Rafael J. Wysocki <[email protected]>
Fixes: 9ed9895370ae ("driver core: Functional dependencies tracking support")
Cc: All applicable <[email protected]> # All applicable
---

This update adds a missing pm_runtime_put() before a return statement.

Thanks!

---
drivers/base/dd.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

Index: linux-pm/drivers/base/dd.c
===================================================================
--- linux-pm.orig/drivers/base/dd.c
+++ linux-pm/drivers/base/dd.c
@@ -1117,6 +1117,8 @@ static void __device_release_driver(stru

drv = dev->driver;
if (drv) {
+ pm_runtime_get_sync(dev);
+
while (device_links_busy(dev)) {
__device_driver_unlock(dev, parent);

@@ -1128,12 +1130,12 @@ static void __device_release_driver(stru
* have released the driver successfully while this one
* was waiting, so check for that.
*/
- if (dev->driver != drv)
+ if (dev->driver != drv) {
+ pm_runtime_put(dev);
return;
+ }
}

- pm_runtime_get_sync(dev);
-
driver_sysfs_remove(dev);

if (dev->bus)



2020-10-22 20:23:47

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3/3] PM: runtime: Resume the device earlier in __device_release_driver()

On Thu, Oct 22, 2020 at 3:40 PM chenxiang (M) <[email protected]> wrote:
>
> Hi Rafael,
>
> 在 2020/10/22 3:14, Rafael J. Wysocki 写道:
> > From: Rafael J. Wysocki <[email protected]>
> >
> > Since the device is resumed from runtime-suspend in
> > __device_release_driver() anyway, it is better to do that before
> > looking for busy managed device links from it to consumers, because
> > if there are any, device_links_unbind_consumers() will be called
> > and it will cause the consumer devices' drivers to unbind, so the
> > consumer devices will be runtime-resumed. In turn, resuming each
> > consumer device will cause the supplier to be resumed and when the
> > runtime PM references from the given consumer to it are dropped, it
> > may be suspended. Then, the runtime-resume of the next consumer
> > will cause the supplier to resume again and so on.
> >
> > Update the code accordingly.
> >
> > Signed-off-by: Rafael J. Wysocki <[email protected]>
> > Fixes: 9ed9895370ae ("driver core: Functional dependencies tracking support")
> > Cc: All applicable <[email protected]> # All applicable
> > ---
> > drivers/base/dd.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > Index: linux-pm/drivers/base/dd.c
> > ===================================================================
> > --- linux-pm.orig/drivers/base/dd.c
> > +++ linux-pm/drivers/base/dd.c
> > @@ -1117,6 +1117,8 @@ static void __device_release_driver(stru
> >
> > drv = dev->driver;
> > if (drv) {
> > + pm_runtime_get_sync(dev);
> > +
> > while (device_links_busy(dev)) {
> > __device_driver_unlock(dev, parent);
> >
> > @@ -1132,8 +1134,6 @@ static void __device_release_driver(stru
>
> pm_runtime_put_sync() is required to be called if existed from here.
>
> > return;

Right, I overlooked this, thanks!

> > }
> >
> > - pm_runtime_get_sync(dev);
> > -
> > driver_sysfs_remove(dev);
> >
> > if (dev->bus)

2020-10-22 22:28:06

by chenxiang (M)

[permalink] [raw]
Subject: Re: [PATCH 3/3] PM: runtime: Resume the device earlier in __device_release_driver()

Hi Rafael,

在 2020/10/22 3:14, Rafael J. Wysocki 写道:
> From: Rafael J. Wysocki <[email protected]>
>
> Since the device is resumed from runtime-suspend in
> __device_release_driver() anyway, it is better to do that before
> looking for busy managed device links from it to consumers, because
> if there are any, device_links_unbind_consumers() will be called
> and it will cause the consumer devices' drivers to unbind, so the
> consumer devices will be runtime-resumed. In turn, resuming each
> consumer device will cause the supplier to be resumed and when the
> runtime PM references from the given consumer to it are dropped, it
> may be suspended. Then, the runtime-resume of the next consumer
> will cause the supplier to resume again and so on.
>
> Update the code accordingly.
>
> Signed-off-by: Rafael J. Wysocki <[email protected]>
> Fixes: 9ed9895370ae ("driver core: Functional dependencies tracking support")
> Cc: All applicable <[email protected]> # All applicable
> ---
> drivers/base/dd.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Index: linux-pm/drivers/base/dd.c
> ===================================================================
> --- linux-pm.orig/drivers/base/dd.c
> +++ linux-pm/drivers/base/dd.c
> @@ -1117,6 +1117,8 @@ static void __device_release_driver(stru
>
> drv = dev->driver;
> if (drv) {
> + pm_runtime_get_sync(dev);
> +
> while (device_links_busy(dev)) {
> __device_driver_unlock(dev, parent);
>
> @@ -1132,8 +1134,6 @@ static void __device_release_driver(stru

pm_runtime_put_sync() is required to be called if existed from here.

> return;
> }
>
> - pm_runtime_get_sync(dev);
> -
> driver_sysfs_remove(dev);
>
> if (dev->bus)
>
>
>
>
> .
>