24. Aug 2005

A more generic approach to solve the coldplug problem

udevsynthesize

Today a lot of solutions, workarounds or hacks exist to solve the problem of system configuration during bootup while events for hardware can not be catched before the real userspace is up and ready to listen to these events.

The kernel 2.6 exposes most of its internal state in the sysfs mounted at /sys. The device nodes are managed by udev and we already need to scan trough sysfs during bootup to get the devices we need to create nodes for. All later device nodes will be created by udev, which listens directly to kernel uevents.

I took a similar approach now and scan the whole sysfs for all devices and sythesize the events so that they have a similar format as the original kernel event. udevsynthesize passes these events, on my laptop around 700, to the udev daemon, which will do the device node creation and the hotplug handling including module loading. The whole process including populating the /dev directory takes less than a second of CPU time. Looks promising so far...

  pim:~ # udevmonitor --env
  udevmonitor prints the received event from the kernel [UEVENT]
  and the event which udev sends out after rule processing [UDEV]

  ...

  UDEV  [1124837525] add@/class/mem/kmsg
  UDEV_LOG=3
  DEVPATH=/class/mem/kmsg
  SUBSYSTEM=mem
  ACTION=add
  UDEV_COLDPLUG=1
  MAJOR=1
  MINOR=11
  UDEVD_EVENT=1
  DEVNAME=/dev/kmsg

  ...

  UDEV  [1124837527] add@/devices/pci0000:00/0000:00:1d.7/usb4/4-0:1.0
  UDEV_LOG=3
  DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb4/4-0:1.0
  SUBSYSTEM=usb
  ACTION=add
  UDEV_SYNTHESIZE=1
  PHYSDEVDRIVER=hub
  PHYSDEVBUS=usb
  MODALIAS=usb:v0000p0000d0206dc09dsc00dp01ic*isc*ip*
  INTERFACE=9/0/0
  PRODUCT=0/0/206
  TYPE=9/0/1
  UDEVD_EVENT=1

  ...

  UDEV  [1124837527] add@/devices/pci0000:00/0000:00:1d.1
  UDEV_LOG=3
  DEVPATH=/devices/pci0000:00/0000:00:1d.1
  SUBSYSTEM=pci
  ACTION=add
  UDEV_SYNTHESIZE=1
  PHYSDEVDRIVER=uhci_hcd
  PHYSDEVBUS=pci
  MODALIAS=pci:v00008086d000024C4sv00001014sd0000052Dbc0Csc03i00
  PCI_SLOT_NAME=0000:00:1d.1
  PCI_CLASS=0c0300
  PCI_ID=8086:24c4
  PCI_SUBSYS_ID=1014:052d
  UDEVD_EVENT=1

  ...