What is the difference between module_init
and subsys_initcall
while initializing the driver?
module_init is used to mark a function to be used as the entry-point of a Linux device-driver. It is called. during do_initcalls() (for a builtin driver) at module insertion time (for a *.ko module)
That is, the procedure declared as subsys_initcall is guaranteed to be executed before the procedure declared as module_init . This ordering ensures that subsystem and platform drivers are initialized before device drivers try to utilize the former's functionality (e.g. a device driver registers as a subsystem device).
a module is a "piece of software", of any kind. it is a part of the main kernel, not a "user program". a driver is a "piece of software" of one specific kind: it is needed to communicate with hardware components. a "driver" IS a kind of module.
If "module_init()" is used to wrap the initialization function, then by default initcall() puts the call in the "device" phase of initialization. Within that phase, the items are ordered by link order. This means that the table is created by the order of the functions as they are encountered by the linker.
The difference relates to timing, or more precisely, order of execution. That is, the procedure declared as subsys_initcall
is guaranteed to be executed before the procedure declared as module_init
. This ordering ensures that subsystem and platform drivers are initialized before device drivers try to utilize the former's functionality (e.g. a device driver registers as a subsystem device).
The actual macro definition for each depends on if the kernel is configured for (loadable) modules or not. The definition for these macros (and other init macros) can be found in include/linux/init.h
Note that subsys_initcall()
can only be used by a built-in (statically linked) module.module_init
can be used by either built-in or loadable modules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With