driver core: shut down devices asynchronously
PATCH v4 1/1 driver core: shut down devices asynchronously
Shut down devices asynchronously, ensuring that each device is shut down before its parents.
This can dramatically reduce system shutdown/reboot time on systems that have devices that take many seconds to shut down, such as some NVMe drives. On one system tested, the shutdown time went from 11 minutes without this patch to 55 seconds with the patch.
---v1->v2: rewritten using kernel async code (suggested by Lukas Wunner) v2->v3: removed recursive functions to schedule children to be shutdown
before parents, since existing device_shutdown loop will already do thisv3->v4: bug fix (used "parent" not "dev->parent", in device_shutdown)
--- drivers/base/base.h | 3 ++ drivers/base/core.c | 104 ++++++++++++++++++++++++++---------------- include/linux/async.h | 6 +++ 3 files changed, 74 insertions(+), 39 deletions(-)
drivers/base/base.h +3 -0
@@ -11,6 +11,7 @@* */ #include <linux/notifier.h> +#include <linux/async.h> /** * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure.
@@ -97,6 +98,7 @@ struct driver_private {* the device; typically because it depends on another driver getting * probed first. * @async_driver - pointer to device driver awaiting probe via async_probe +* @child_domain - domain for async shutdown work of children * @device - pointer back to the struct device that this structure is * associated with. * @dead - This device is currently either in the process of or has been
@@ -114,6 +116,7 @@ struct device_private {struct list_head deferred_probe;struct device_driver *async_driver;char *deferred_probe_reason; +struct async_domain child_domain;struct device *device; u8 dead:1; };
drivers/base/core.c +65 -39
149 lines not on this page · raw message
include/linux/async.h +6 -0
@@ -35,6 +35,12 @@ struct async_domain {struct async_domain _name = { .pending =LIST_HEAD_INIT (_name.pending), \ .registered = 0 } +static inline void INIT_ASYNC_DOMAIN_EXCLUSIVE (struct async_domain *domain) +{ +INIT_LIST_HEAD (&domain->pending); + domain->registered =0 ; +} +async_cookie_t async_schedule_node (async_func_t func,void *data,int node); async_cookie_t async_schedule_node_domain(async_func_t func, void *data,
Signature · 1 line
2.39.3
Greg Kroah-Hartman
maintainerQuoted 7 lines · Stuart Hayes
Shut down devices asynchronously, ensuring that each device is shut down before its parents.
This can dramatically reduce system shutdown/reboot time on systems that have devices that take many seconds to shut down, such as some NVMe drives. On one system tested, the shutdown time went from 11 minutes without this patch to 55 seconds with the patch.
That's a nice improvement, but I think we need a lot more testing on a wide range of systems before we can take a patch like this.
Also, what about busses that don't want this type of shutdown? We allow busses to opt-in for async probing, shouldn't that be also done for shutting them down to resolve issues for busses that can not handle this?
thanks,
greg k-h
Quoted 12 lines · Greg Kroah-Hartman
Quoted 7 lines · Stuart Hayes
Shut down devices asynchronously, ensuring that each device is shut down before its parents.
This can dramatically reduce system shutdown/reboot time on systems that have devices that take many seconds to shut down, such as some NVMe drives. On one system tested, the shutdown time went from 11 minutes without this patch to 55 seconds with the patch.
That's a nice improvement, but I think we need a lot more testing on a wide range of systems before we can take a patch like this.
Quoted 8 lines
Also, what about busses that don't want this type of shutdown? We allow busses to opt-in for async probing, shouldn't that be also done for shutting them down to resolve issues for busses that can not handle this?
thanks,
greg k-h
Yes, I could add something like what is done for async probing, so drivers have to opt in to async shutdown of their devices.
But I'm not sure how to get it tested on a wide range of systems, other than than having the patch in the kernel. What if it defaults to synchronous shutdown for now, but the option is there so people are able to test async shutdown by changing an attribute in sysfs? Then drivers could be patched later to opt in to async shutdown of their devices by default...?
Thanks for the feedback!
Greg Kroah-Hartman
maintainerQuoted 22 lines · stuart hayes
Quoted 19 lines · Greg Kroah-Hartman
Quoted 7 lines · Stuart Hayes
Shut down devices asynchronously, ensuring that each device is shut down before its parents.
This can dramatically reduce system shutdown/reboot time on systems that have devices that take many seconds to shut down, such as some NVMe drives. On one system tested, the shutdown time went from 11 minutes without this patch to 55 seconds with the patch.
That's a nice improvement, but I think we need a lot more testing on a wide range of systems before we can take a patch like this.
Also, what about busses that don't want this type of shutdown? We allow busses to opt-in for async probing, shouldn't that be also done for shutting them down to resolve issues for busses that can not handle this?
thanks,
Quoted 7 lines
Quoted 1 line
greg k-h
Yes, I could add something like what is done for async probing, so drivers have to opt in to async shutdown of their devices.
But I'm not sure how to get it tested on a wide range of systems, other than than having the patch in the kernel.
Yes, breaking things is the only way you will know :)
Quoted 4 lines
What if it defaults to synchronous
shutdown for now, but the option is there so people are able to test async shutdown by changing an attribute in sysfs? Then drivers could be patched later to opt in to async shutdown of their devices by default...?
Yes, that will be the proper way forward, default to what you know works today, and then busses can opt-in for the async option if they work properly. That's what we did with probing, so it can mirror that.
thanks,
greg k-h