Module Stacking in Linux device drivers
Stacking just means that some module calls functions defined in another module. There is an example right on the page you cite. According to the figure, lp
is a driver for printers on parallel ports. It makes calls into the generic parallel port driver parport
. There are several different kinds of parallel ports, and each has its own low-level driver; the most common one is parport_pc
. On current kernels, it's actually parport_pc
that calls functions defined in parport
, and not the opposite as the figure suggests. Of course, all of them make calls to basic kernel features (which aren't in modules).
There are a lot of similar cases. For example most storage (disk) drivers communicate with (a variant of) the SCSI protocol, so they make calls into the generic scsi_mod
module. The usb_storage
module makes calls into both sci_mod
(for the storage aspects) and usbcore
(for the USB aspects).
You can see the dependencies for all the modules you have installed (i.e. what modules call functions from what other modules) in /lib/modules/*/modules.dep
(there'll be a lot of them). You can see the dependencies for modules that are currently loaded with lsmod
; for example the following output line shows that parport_pc
, ppdev
and lp
all depend on parport
:
parport 27954 3 parport_pc,ppdev,lp
Here's a small script that generates a dependency graph for the modules you have loaded. You need to have graphviz (available in most distributions).
lsmod | awk '
BEGIN {print "digraph modules {"}
END {print "}"}
NR != 1 {split($4, a, ","); for (i in a) print a[i], "->", $1;}
' | dot -Tpdf >lsmod.pdf
Related videos on Youtube
user6363
Updated on September 18, 2022Comments
-
user6363 over 1 year
I am trying my hand with Linux, just come across the concept of module stacking. It can be used to use symbol exported by other Modules. Means we can use something already made in some module so we do not have to do something that is already done. But still I am not getting where in real-time we see this type of concept with Linux.
I am following the same link from the o'reilly book - http://www.makelinux.net/ldd3/chp-2-sect-5.shtml
Stacking in the parallel port subsystem is shown in Figure 2-2:
I am not able to understand this figure.
Can you just give SOME REALTIME EXAMPLE APPLICATION where we can use concept of module stacking, which will increase my vision horizon?
-
user6363 about 13 yearsyou have metioned about an script, what scripting language is it ? please suggest.
-
Gilles 'SO- stop being evil' about 13 years@user6363 It's a shell script, most of it (the part between
'…'
) being obviously an awk script.