mdev coldplugging

Natanael Copa natanael.copa at gmail.com
Mon Jul 17 14:47:08 PDT 2006


On Sat, 2006-07-15 at 15:42 -0400, Rob Landley wrote:
> > I spent half the day yesterday on reding sources to both udev and mdev
> > to try to find out how things really work.
> 
> I thought how mdev worked was in BusyBox.html.  (udev is very complicated.
> mdev isn't.)

I like mdev. It small and simple. Thats why I want to switch :)

With udev (provided from gentoo) everything just works. Almost all
hardware is detected on every box I try it on.

> > or:
> > while pidof mdev ; do
> >         echo -n .
> >         sleep 1
> > done
> 
> Much smaller, yes.
> 
> > But how do you limit maximum number of processes while doing this? You
> > might not want to fork 100 processes at the same time.
> 
> Did you look up what mdev -s is for?  One process scans for all new hardware.
> Creating a node that's already there is mostly a NOP (it calls chmod/chown on
> it again, I think).  I could even add a mode that says "if the device this
> would create is already there, skip it", if that would help.

It does not even look for NIC's. /sys/bus/*/devices*/

mdev currently does not create any link for cdrom -> hdX. udev does.

> > I want to auto detect all hardware and load the drivers and created
> > the /dev nodes (and do it fast).
> 
> That's what mdev -s does, although it does it with one process, single
> threaded.  When the mknod has a command line associated with it that's run
> synchronously instead of in the background, but the easy way to overlap that
> is to add the "skip devices that are already there" mode (which wasn't an
> issue before the shellout option went in).  That way you could run two
> mdev -s instances in parallel, and since the mknod is done before the
> shellout and filesystem operations are atomic, I could simply go "if the
> mknod failed because the device was already there, don't do the shellout" and
> then you can control how many processes are doing driver loading and such my
> controlling how many mdev -s instances you fire off.

mdev -s is cool. It creates lots more of /dev/ttyXX than udev. That does
not matter. I need to link a script to hd? devices that checks if its a
cdrom and create the necessary link(s).

I did a test here. I ran mdev -s. I trigged all uevents in /sys with
mdev in /proc/sys/kernel/hotplug. I scanned /sys for modalias and loaded
the module (worked thanks to Yann's patch)

with mdev + modaliases the system loaded 30 modules. thats the most of
it.

then I started the udev init scripts and the number of loaded modules
increased to 52. (soundcard related, i2c_piix4 and agp) I guess its pnp
related.

> And no it's not a daemon, it scans once then exits.  Register it as hotplug to
> get the ones after that.

I like that approach. Its perfect for embedded. I need to find out how
udev manage to find out the rest of the devices (like nic's) and maybe
create a patch for mdev that loads the modalias (links should be
possible to fix in mdev.conf). Then I need to make sure it works with
stuff like pcmcia.

The goal is, whatever hardware you have on your system, it should just
work. Whatever hardware you plug, it should just work. (as long as you
have the useland tools installed)

It was more work than I thought...

> Rob
> --
> Never bet against the cheap plastic solution.



More information about the busybox mailing list