Quoting r. Roland Dreier <[EMAIL PROTECTED]>:
> I was thinking the same thing -- lazy initialization of libibverbs
> when it is first use.  So yes, such a patch would be useful.

OK. Here goes. Works fine for me. Gleb, can you please verify that it
helps in your setup?

---

Lazy initialization of libibverbs on ibv_get_devices.

Signed-off-by: Michael S. Tsirkin <[EMAIL PROTECTED]>

Index: libibverbs/src/device.c
===================================================================
--- libibverbs/src/device.c     (revision 2894)
+++ libibverbs/src/device.c     (working copy)
@@ -46,8 +46,12 @@
 
 #include "ibverbs.h"
 
+static struct dlist *device_list;
+
 struct dlist *ibv_get_devices(void)
 {
+       if (!device_list)
+               device_list = ibverbs_init();
        return device_list;
 }
 
Index: libibverbs/src/ibverbs.h
===================================================================
--- libibverbs/src/ibverbs.h    (revision 2894)
+++ libibverbs/src/ibverbs.h    (working copy)
@@ -50,11 +50,10 @@ struct ibv_driver {
        ibv_driver_init_func init_func;
 };
 
-extern Dlist *device_list;
-
 extern int ibv_init_mem_map(void);
 extern int ibv_lock_range(void *base, size_t size);
 extern int ibv_unlock_range(void *base, size_t size);
+extern struct dlist * ibverbs_init(void);
 
 #define IBV_INIT_CMD(cmd, size, opcode)                                \
        do {                                                    \
Index: libibverbs/src/init.c
===================================================================
--- libibverbs/src/init.c       (revision 2894)
+++ libibverbs/src/init.c       (working copy)
@@ -50,12 +50,10 @@
 #  define OPENIB_DRIVER_PATH_ENV "OPENIB_DRIVER_PATH"
 #endif
 
-Dlist *device_list;
-
 static char default_path[] = DRIVER_PATH;
 static const char *user_path;
 
-static Dlist *driver_list;
+static struct dlist *driver_list;
 
 static void load_driver(char *so_path)
 {
@@ -112,7 +110,7 @@ static void find_drivers(char *dir)
                load_driver(so_glob.gl_pathv[i]);
 }
 
-static void init_drivers(struct sysfs_class_device *verbs_dev)
+static void init_drivers(struct sysfs_class_device *verbs_dev, struct dlist 
*device_list)
 {
        struct sysfs_class_device *ib_dev; 
        struct sysfs_attribute *attr;
@@ -187,13 +185,15 @@ static int check_abi_version(void)
 }
 
 
-static void INIT ibverbs_init(void)
+struct dlist *ibverbs_init(void)
 {
        char *wr_path, *dir;
        struct sysfs_class *cls;
-       Dlist *verbs_dev_list;
+       struct dlist *verbs_dev_list;
+       struct dlist *device_list;
        struct sysfs_class_device *verbs_dev;
 
+
        driver_list = dlist_new(sizeof (struct ibv_driver));
        device_list = dlist_new(sizeof (struct ibv_device));
        if (!driver_list || !device_list) {
@@ -202,7 +202,7 @@ static void INIT ibverbs_init(void)
        }
 
        if (ibv_init_mem_map())
-               return;
+               return NULL;
 
        /*
         * Check if a driver is statically linked, and if so load it first.
@@ -227,18 +227,20 @@ static void INIT ibverbs_init(void)
        cls = sysfs_open_class("infiniband_verbs");
        if (!cls) {
                fprintf(stderr, PFX "Fatal: couldn't open sysfs class 
'infiniband_verbs'.\n");
-               return;
+               return NULL;
        }
 
        if (check_abi_version())
-               return;
+               return NULL;
 
        verbs_dev_list = sysfs_get_class_devices(cls);
        if (!verbs_dev_list) {
                fprintf(stderr, PFX "Fatal: no infiniband class devices 
found.\n");
-               return;
+               return NULL;
        }
 
        dlist_for_each_data(verbs_dev_list, verbs_dev, struct 
sysfs_class_device)
-               init_drivers(verbs_dev);
+               init_drivers(verbs_dev, device_list);
+
+       return device_list;
 }

-- 
MST
_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to