PM / Runtime: Rework runtime PM handling during driver removal
The driver core tries to prevent race conditions between runtime PM and driver removal from happening by incrementing the runtime PM usage counter of the device and executing pm_runtime_barrier() before running the bus notifier and the ->remove() callbacks provided by the device's subsystem or driver. This guarantees that, if a future runtime suspend of the device has been scheduled or a runtime resume or idle request has been queued up right before the driver removal, it will be canceled or waited for to complete and no other asynchronous runtime suspend or idle requests for the device will be put into the PM workqueue until the ->remove() callback returns. However, it doesn't prevent resume requests from being queued up after pm_runtime_barrier() has been called and it doesn't prevent pm_runtime_resume() from executing the device subsystem's runtime resume callback. Morever, it prevents the device's subsystem or driver from putting the device into the suspended state by calling pm_runtime_suspend() from its ->remove() routine. This turns out to be a major inconvenience for some subsystems and drivers that want to leave the devices they handle in the suspended state. To really prevent runtime PM callbacks from racing with the bus notifier callback in __device_release_driver(), which is necessary, because the notifier is used by some subsystems to carry out operations affecting the runtime PM functionality, use pm_runtime_get_sync() instead of the combination of pm_runtime_get_noresume() and pm_runtime_barrier(). This will resume the device if it's in the suspended state and will prevent it from being suspended again until pm_runtime_put_*() is called. To allow subsystems and drivers to put devices into the suspended state by calling pm_runtime_suspend() from their ->remove() routines, execute pm_runtime_put_sync() after running the bus notifier in __device_release_driver(). This will require subsystems and drivers to make their ->remove() callbacks avoid races with runtime PM directly, but it will allow of more flexibility in the handling of devices during the removal of their drivers. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
This commit is contained in:
parent
ee940d8dcc
commit
e1866b33b1
|
@ -316,8 +316,7 @@ static void __device_release_driver(struct device *dev)
|
||||||
|
|
||||||
drv = dev->driver;
|
drv = dev->driver;
|
||||||
if (drv) {
|
if (drv) {
|
||||||
pm_runtime_get_noresume(dev);
|
pm_runtime_get_sync(dev);
|
||||||
pm_runtime_barrier(dev);
|
|
||||||
|
|
||||||
driver_sysfs_remove(dev);
|
driver_sysfs_remove(dev);
|
||||||
|
|
||||||
|
@ -326,6 +325,8 @@ static void __device_release_driver(struct device *dev)
|
||||||
BUS_NOTIFY_UNBIND_DRIVER,
|
BUS_NOTIFY_UNBIND_DRIVER,
|
||||||
dev);
|
dev);
|
||||||
|
|
||||||
|
pm_runtime_put_sync(dev);
|
||||||
|
|
||||||
if (dev->bus && dev->bus->remove)
|
if (dev->bus && dev->bus->remove)
|
||||||
dev->bus->remove(dev);
|
dev->bus->remove(dev);
|
||||||
else if (drv->remove)
|
else if (drv->remove)
|
||||||
|
@ -338,7 +339,6 @@ static void __device_release_driver(struct device *dev)
|
||||||
BUS_NOTIFY_UNBOUND_DRIVER,
|
BUS_NOTIFY_UNBOUND_DRIVER,
|
||||||
dev);
|
dev);
|
||||||
|
|
||||||
pm_runtime_put_sync(dev);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue