summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Duyck <alexander.h.duyck@linux.intel.com>2019-01-22 13:39:21 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-01-31 08:20:53 -0500
commitef0ff68351be4fd83bec2d797f0efdc0174a55a4 (patch)
tree55368b22a14e108f416a7f846560065f92fbc4e1
parented88747c6c4a2fc2f961a36d4c50cb0868c30229 (diff)
driver core: Probe devices asynchronously instead of the driver
Probe devices asynchronously instead of the driver. This results in us seeing the same behavior if the device is registered before the driver or after. This way we can avoid serializing the initialization should the driver not be loaded until after the devices have already been added. The motivation behind this is that if we have a set of devices that take a significant amount of time to load we can greatly reduce the time to load by processing them in parallel instead of one at a time. In addition, each device can exist on a different node so placing a single thread on one CPU to initialize all of the devices for a given driver can result in poor performance on a system with multiple nodes. This approach can reduce the time needed to scan SCSI LUNs significantly. The only way to realize that speedup is by enabling more concurrency which is what is achieved with this patch. To achieve this it was necessary to add a new member "async_driver" to the device_private structure to store the driver pointer while we wait on the deferred probe call. Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Alexander Duyck <alexander.h.duyck@linux.intel.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/base/base.h2
-rw-r--r--drivers/base/bus.c23
-rw-r--r--drivers/base/dd.c43
3 files changed, 48 insertions, 20 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h
index b6966511b0ca..b405436ee28e 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -65,6 +65,7 @@ struct driver_private {
65 * binding of drivers which were unable to get all the resources needed by 65 * binding of drivers which were unable to get all the resources needed by
66 * the device; typically because it depends on another driver getting 66 * the device; typically because it depends on another driver getting
67 * probed first. 67 * probed first.
68 * @async_driver - pointer to device driver awaiting probe via async_probe
68 * @device - pointer back to the struct device that this structure is 69 * @device - pointer back to the struct device that this structure is
69 * associated with. 70 * associated with.
70 * @dead - This device is currently either in the process of or has been 71 * @dead - This device is currently either in the process of or has been
@@ -80,6 +81,7 @@ struct device_private {
80 struct klist_node knode_bus; 81 struct klist_node knode_bus;
81 struct klist_node knode_class; 82 struct klist_node knode_class;
82 struct list_head deferred_probe; 83 struct list_head deferred_probe;
84 struct device_driver *async_driver;
83 struct device *device; 85 struct device *device;
84 u8 dead:1; 86 u8 dead:1;
85}; 87};
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index cfa5b63b5582..0a58e969f8b7 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -610,17 +610,6 @@ static ssize_t uevent_store(struct device_driver *drv, const char *buf,
610} 610}
611static DRIVER_ATTR_WO(uevent); 611static DRIVER_ATTR_WO(uevent);
612 612
613static void driver_attach_async(void *_drv, async_cookie_t cookie)
614{
615 struct device_driver *drv = _drv;
616 int ret;
617
618 ret = driver_attach(drv);
619
620 pr_debug("bus: '%s': driver %s async attach completed: %d\n",
621 drv->bus->name, drv->name, ret);
622}
623
624/** 613/**
625 * bus_add_driver - Add a driver to the bus. 614 * bus_add_driver - Add a driver to the bus.
626 * @drv: driver. 615 * @drv: driver.
@@ -653,15 +642,9 @@ int bus_add_driver(struct device_driver *drv)
653 642
654 klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); 643 klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers);
655 if (drv->bus->p->drivers_autoprobe) { 644 if (drv->bus->p->drivers_autoprobe) {
656 if (driver_allows_async_probing(drv)) { 645 error = driver_attach(drv);
657 pr_debug("bus: '%s': probing driver %s asynchronously\n", 646 if (error)
658 drv->bus->name, drv->name); 647 goto out_unregister;
659 async_schedule(driver_attach_async, drv);
660 } else {
661 error = driver_attach(drv);
662 if (error)
663 goto out_unregister;
664 }
665 } 648 }
666 module_add_driver(drv->owner, drv); 649 module_add_driver(drv->owner, drv);
667 650
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 34556359c7da..627ad05064e0 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -925,6 +925,30 @@ int device_driver_attach(struct device_driver *drv, struct device *dev)
925 return ret; 925 return ret;
926} 926}
927 927
928static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie)
929{
930 struct device *dev = _dev;
931 struct device_driver *drv;
932 int ret = 0;
933
934 __device_driver_lock(dev, dev->parent);
935
936 drv = dev->p->async_driver;
937
938 /*
939 * If device has been removed or someone has already successfully
940 * bound a driver before us just skip the driver probe call.
941 */
942 if (!dev->p->dead && !dev->driver)
943 ret = driver_probe_device(drv, dev);
944
945 __device_driver_unlock(dev, dev->parent);
946
947 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret);
948
949 put_device(dev);
950}
951
928static int __driver_attach(struct device *dev, void *data) 952static int __driver_attach(struct device *dev, void *data)
929{ 953{
930 struct device_driver *drv = data; 954 struct device_driver *drv = data;
@@ -952,6 +976,25 @@ static int __driver_attach(struct device *dev, void *data)
952 return ret; 976 return ret;
953 } /* ret > 0 means positive match */ 977 } /* ret > 0 means positive match */
954 978
979 if (driver_allows_async_probing(drv)) {
980 /*
981 * Instead of probing the device synchronously we will
982 * probe it asynchronously to allow for more parallelism.
983 *
984 * We only take the device lock here in order to guarantee
985 * that the dev->driver and async_driver fields are protected
986 */
987 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name);
988 device_lock(dev);
989 if (!dev->driver) {
990 get_device(dev);
991 dev->p->async_driver = drv;
992 async_schedule(__driver_attach_async_helper, dev);
993 }
994 device_unlock(dev);
995 return 0;
996 }
997
955 device_driver_attach(drv, dev); 998 device_driver_attach(drv, dev);
956 999
957 return 0; 1000 return 0;