Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINUX: order of statically linked module loading

If I have two modules which are being statically linked in. One modules' module_init function depends on another module's module_init function having already run. Is there a way to force one module to load before the other?

Also, is the first module's init function guaranteed to finish before the second one is invoked?

Lastly, if the answer to the above is NO, what is the recommended way of synchronizing the two module init calls to make sure I don't run into issues?

like image 520
John Ulvr Avatar asked Apr 14 '11 21:04

John Ulvr


People also ask

How will you insert a module statically in to Linux kernel?

Linux provides a utility known as “insmod”. This is the utility which can be used to load the kernel module at the running kernel. To load the kernel module, just execute the command as insmod followed by the module file name.

How do I know if a driver is loaded Linux?

Run the command lsmod to see if driver is loaded. (look for the driver name that was listed in the output of lshw, "configuration" line). If you did not see the driver module in the list then use the modprobe command to load it.

What are the two important characteristics of Linux loadable modules?

The Linux loadable modules have two important characteristics: Dynamic linking: A kernel module can be loaded and linked into the kernel while the kernel is already in memory and executing. A module can also be un- linked and removed from memory at any time. Stackable modules: The modules are arranged in a hierarchy.

Which command loads a kernel module into memory?

To load a kernel module, use the /sbin/modprobe command followed by the kernel module name.


1 Answers

Is there a way to force one module to load before the other?

Answer is surprisingly simple, make sure first module is first in Makefile:

obj-y += mod1.o
obj-y += mod2.o

is the first module's init function guaranteed to finish before the second one is invoked?

Yes, initcalls (module_init hook) in your case are called one-by-one. See init/main.c, do_one_initcall() callers.

like image 127
adobriyan Avatar answered Nov 30 '22 22:11

adobriyan