KERNEL: Support asynchronously-discovered boot devices, v4
Subsystems (2)
PATCH 1/5 KERNEL: Support asynchronously-discovered boot devices, v4
This patch adds synchronization infrastructure between asynchronous device discovery and code that uses possibly asynchronous discovered devices at boot time. It provides the framework to fix race conditions, such as for the console, that have arisen as a result of quite successful work that has been done to reduce boot times.
History
v4 Update documentation and move to its own file. Change names of
functions to remove leading "bus_". Move functions into drivers/base/bootdev.c. Fix NETCONSOLE handling. Add function to be called from subsystems to wakeup waiters.
v3 Modify bus_bootdev_type_found to avoid superfluous wakeups.
v2 Remove global wait_queue for buses in favor of using the per-boot
device type wait_queues. Correct wait condition in bus_wait_for_bootdev so that the done function will be called even if devices are still being discovered. Added bus_bootdev_type_found.
v1 Original release
--- Documentation/driver-model/bootdev.txt | 115 +++++++++++++++++++ drivers/base/Makefile | 3 +- drivers/base/base.h | 1 + drivers/base/bootdev.c | 189 ++++++++++++++++++++++++++++++++ drivers/base/init.c | 1 + include/linux/device.h | 31 +++++ 6 files changed, 339 insertions(+), 1 deletions(-)
Documentation/driver-model/bootdev.txt new file +115 -0
@@ -0,0 +1,115 @@ +Boot Device Discovery Synchronization +===================================== +Boot devices are those devices that must be used or configured during the +boot process. They may be explicitly specified as kernel command line +parameters, such as console=ttyUSB0,115200, or implicitly specified, such as +ip=dhcp. + +Earlier versions of the Linux kernel used a single-threaded approach to +boot initialization. This took a number of seconds, which meant that +devices were generally set up before being used or configured. Modern +kernels use a multithreaded approach, which requires synchronization between +code that probes and initializes boot devices, and code that uses and +configures them. Support of fine-grained boot concurrency requires +distinguishing between types of boot devices, so that devices can be used as +soon as they are initialized. + +There are several types of boot devices: +- consoles +- network devices +- block devices + +There is a distinction between the hardware type and the boot device type. +From the hardware view, most any serial device can be used as a console, +but console support is generally configured separately. For example, USB +serial devices should be considered console boot devices only if the +kernel is configured to support this usage. This is done by enabling the +CONFIG_USB_SERIAL_CONSOLE option. If this option is disabled, the USB bus +driver should not report that it has found any console devices. + +The sequence for buses with asynchronously-discoverable boot devices is: +1. As each possible boot devices is discovered, call bootdev_found. +2. Optionally, if the device type wasn't known at the time + bootdev_found was called but is determined later, call + bootdev_type_found when the type is found. +3. As initialization is complete for each device, call + bootdev_probe_done. + +Per-Device Functions +-------------------- +Functions used to indicate the status of asynchronous device discovery on +a device-by-device basis are: + +bootdev_found(int bootdev_mask) + This function must be called each time a possible boot device device + is found. It is passed a bit mask created by ORing any of the + following flags that apply to the device found: + BOOTDEV_CONSOLE_MASK + BOOTDEV_NETDEV_MASK + BOOTDEV_BLOCK_MASK + There is no need to call this function for a given device if it is + known that it cannot be used as a boot device. If it is not + possible to determine whether a device is usable as a boot device, + or the specific type of a boot device, the argument BOOTDEV_ANY_MASK + should be passed. This should be used only when necessary, as it + reduces the level of boot-time concurrency. + +bootdev_type_found(int bootdev_mask, enum bootdev_type type) + If the type of a boot device could not be found, but was determined + later, this function can be used to indicate the device type. It + is passed the mask that was originally passed to bootdev_found. + Note that, if a device for which bootdev_found is called is + subsequently determine not to be a possible boot device, this function + should not be called. Instead, bootdev_probe_done should be + called. + +bootdev_probe_done(int bootdev_mask) + This function indicates that initialization is complete for a device + which may be one of the boot device types indicated by bootdev_mask. + Note that calling this function does not imply that device + initialization has been successful; if bootdev_found is called for a + device, bootdev_probe_done must be called even if an error occurred. + +Some rules about correct usage: +o Each call to bootdev_found *must* be matched by a call to + bootdev_probe_done. +o The function bootdev_type_found may be used only once for a given + device and must be called between the calls to bootdev_found and + bootdev_probe_done for that device. +o If bootdev_type_found is called: + - The value of bootdev_mask must be the same as that passed to + bootdev_found. + - The bit corresponding to the type argument must have been set + in the bootdev_mask argument of bootdev_found. + - The value of bootdev_mask in the call to bootdev_probe_done + must consist only of the bit corresponding to the argument + type passed to bootdev_type_found. +o If bootdev_type_found is not called, the value of bootdev_mask + passed to bootdev_found and bootdev_probe_done for a given + device must be identical. + +Subsystem Functions +------------------- +Boot devices are registered with the appropriate subsystem as they are found +Each subsystem determines when the boot devices is manages are ready for use. + +bootdev_wait(enum bootdev_type type, bool (*done)(void)) + Wait until one of two conditions is met: + o All possible boot devices of the given type have been probed + o The "done" function returns true + + The type is one of: + BOOTDEV_CONSOLE + BOOTDEV_NETDEV + BOOTDEV_BLOCK + The "done" function is subsystem-dependent and returns true if all + boot devices required for that subsystem to continue booting have + been registered. Registration is indicated through use of the + bootdev_registered function. If done always returns false, + bootdev_wait will not return until all possible boot devices of the + given type have been probed. + +bootdev_registered(enum bootdev_type type) + Called by each software subsystem that handles boot devices of a given + type. For example, register_console would call this function with + a type of BOOTDEV_CONSOLE.
drivers/base/Makefile +2 -1
@@ -3,7 +3,8 @@ obj-y := core.o sys.o bus.o dd.o \ driver.o class.o platform.o \ cpu.o firmware.o init.o map.o devres.o \ - attribute_container.o transport_class.o + attribute_container.o transport_class.o \ + bootdev.o obj-y += power/ obj-$(CONFIG_HAS_DMA) += dma-mapping.o obj-$(CONFIG_ISA) += isa.o
drivers/base/base.h +1 -0
@@ -90,6 +90,7 @@ struct device_private { container_of(obj, struct device_private, knode_bus) /* initialisation functions */ +extern int bootdevs_init (void );extern int devices_init (void );extern int buses_init (void );extern int classes_init (void );
drivers/base/bootdev.c new file +189 -0
189 lines not on this page · raw message
drivers/base/init.c +1 -0
@@ -21,6 +21,7 @@ void __init driver_init(void) {/* These are the core pieces */ devices_init (); +bootdevs_init ();buses_init ();classes_init ();firmware_init ();
include/linux/device.h +31 -0
@@ -94,6 +94,37 @@ int __must_check bus_for_each_drv(struct bus_type *bus,void bus_sort_breadthfirst (struct bus_type *bus,int (*compare)(const struct device *a,const struct device *b)); + +/* +* Definitions for synchronizing discovery of asynchronously-discoverable +* devices with their use as boot devices. +*/ +/* +* Define boot device types. These are not the same as the device classes +* supported by various buses, but are tied to support of specific Linux kernel +* devices. For example, USB knows about serial devices, but a serial device +* is only a BOOTDEV_CONSOLE if CONFIG_USB_SERIAL_CONSOLE is defined. +*/ +#define BOOTDEV_CONSOLE_MASK (1 << BOOTDEV_CONSOLE) +#define BOOTDEV_NETDEV_MASK (1 << BOOTDEV_NETDEV) +#define BOOTDEV_BLOCK_MASK (1 << BOOTDEV_BLOCK) +#define BOOTDEV_ANY_MASK ((1 << BOOTDEV_NUM) - 1) + +enum bootdev_type { +BOOTDEV_CONSOLE ,/* Device usable as a console */ +BOOTDEV_NETDEV ,/* Autoconfigurable network device */ +BOOTDEV_BLOCK ,/* Block device for boot filesystem */ +BOOTDEV_NUM /* Number of boot devices */ +}; + +extern void bootdev_start_search (void ); +extern void bootdev_found_all (void ); +extern void bootdev_found (int bootdev_mask); +extern void bootdev_type_found (int bootdev_mask,enum bootdev_type ); +extern void bootdev_probe_done (int bootdev_mask); +extern void bootdev_registered (enum bootdev_type type); +extern void bootdev_wait (enum bootdev_type type,bool (*done)(void )); +/* * Bus notifiers: Get notified of addition/removal of devices * and binding/unbinding of drivers to devices.