Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between module_init and subsys_initcall while initializing the driver?

What is the difference between module_init and subsys_initcall while initializing the driver?

like image 347
kzs Avatar asked Mar 21 '13 07:03

kzs


People also ask

What is module_init?

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)

What is Subsys_initcall?

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).

What is the difference between module and driver?

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.

How module INIT is called?

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.


1 Answers

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.

like image 99
sawdust Avatar answered Oct 16 '22 01:10

sawdust