Skip to contentSkip to conversation

driver core: shut down devices asynchronously

PATCH Superseded Stuart Hayes 2 participants 3 messages Sep 13, 2023 – Sep 16, 2023 Driver core

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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)
---

 drivers/base/base.h   |   2 +
 drivers/base/core.c   | 135 ++++++++++++++++++++++++------------------
 include/linux/async.h |   6 ++
 3 files changed, 87 insertions(+), 56 deletions(-)
drivers/base/base.h +2 -0
index eb4c0ace9242..e193d48d9acc 100644
@@ -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.
@@ -114,6 +115,7 @@ struct device_private {
 	struct list_head deferred_probe;
 	struct device_driver *async_driver;
 	char *deferred_probe_reason;
+	struct async_domain children_shutdown;
 	struct device *device;
 	u8 dead:1;
 };
drivers/base/core.c +79 -56

161 lines not on this page · raw message

include/linux/async.h +6 -0
index cce4ad31e8fc..ab62402452f8 100644
@@ -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
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Stuart,

kernel test robot noticed the following build warnings:

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on driver-core/driver-core-next driver-core/driver-core-linus linus/master v6.6-rc1 next-20230913] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Stuart-Hayes/driver-core-shut-down-devices-asynchronously/20230914-050611
base:   driver-core/driver-core-testing
patch link:    https://lore.kernel.org/r/20230913210516.3545-1-stuart.w.hayes%40gmail.com
patch subject: [PATCH v2] driver core: shut down devices asynchronously
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230914/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230914/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/base/core.c:68: warning: Function parameter or member 'flags' not described in '__fwnode_link_add'

>> drivers/base/core.c:4771: warning: Function parameter or member 'dev' not described in 'shutdown_device_and_children'
>> drivers/base/core.c:4771: warning: Function parameter or member 'data' not described in 'shutdown_device_and_children'
>> drivers/base/core.c:4771: warning: expecting prototype for device_shutdown_async(). Prototype was for shutdown_device_and_children() instead

vim +4771 drivers/base/core.c

4764
4765 /**
4766 * device_shutdown_async - schedule ->shutdown() on each device to shutdown
4767 * asynchronously, ensuring each device's children are shut down before
4768 * shutting down the device
4769 */
4770 static int shutdown_device_and_children(struct device *dev, void *data)

> 4771	{

4772 struct async_domain *domain = data;
4773 struct device_private *p = dev->p;
4774
4775 INIT_ASYNC_DOMAIN_EXCLUSIVE(&p->children_shutdown);
4776
4777 /* make sure device doesn't go away before it is shut down */
4778 get_device(dev);
4779
4780 /* schedule shutdown of children */
4781 device_for_each_child(dev, &p->children_shutdown,
4782 shutdown_device_and_children);
4783
4784 /* schedule shutdown of this device */
4785 async_schedule_domain(shutdown_device, dev, domain);
4786
4787 return 0;
4788 }
4789

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Stuart Hayes
Quoted 9 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.

Quoted 9 lines

---
v1->v2: rewritten using kernel async code (suggested by Lukas Wunner)
---

  drivers/base/base.h   |   2 +
  drivers/base/core.c   | 135 ++++++++++++++++++++++++------------------
  include/linux/async.h |   6 ++
  3 files changed, 87 insertions(+), 56 deletions(-)

Please disregard this patch... I realized this could be done in a simpler way. I'll send a V3 this week.