linux: Cache the entire descriptors at device-init
commitaf9997c4085ed0c26b022070ce9f5e19cd8cfec4
authorHans de Goede <hdegoede@redhat.com>
Wed, 22 May 2013 10:57:32 +0000 (22 12:57 +0200)
committerHans de Goede <hdegoede@redhat.com>
Thu, 23 May 2013 10:57:26 +0000 (23 12:57 +0200)
tree2830f9c6b84e60cc25341fbece33ca095362f47b
parent7201f72f2b21ce90436cae6cf021dc65123a1de6
linux: Cache the entire descriptors at device-init

Now that the core caches device-descriptors, we end up opening each
usbfs-node or sysfs-descriptors file once on libusb_init anyways.

So we might as well do this on device-init, rather then waiting for the
core to call op_get_device_descriptor. This allows us to simplify the
code in various places.

While we've it open, read the entire file rather then only reading the
device-descriptor. This is practically free, since most of the cost is in
the opening of the file, not in reading it.

Running the stress test, which does 10000 libusb_init calls, takes 21.8 seconds
on avarage on my idle system with 17 usb devices both before and after this
patch, showing that the cost of also reading the config descriptors while
we've the file open is truely neglible.

Note that this patch does not yet use the cached config descriptors, this is
done by a later patch in this series.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
libusb/os/linux_usbfs.c
libusb/version_nano.h