There are many instances of __init
calls in kernel both in drivers module_init and other functions of kernel. My doubt is how exactly kernel determines the sequence of the __init
call. More importantly, How it also determine the sequence of driver module_init call?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Kernel oops Oops: 80000005 on arm embedded system
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
All the init magic are implemented in files:
Firstly, look at
include/asm-generic/vmlinux.lds.h
that contains the following:Where INIT_TEXT_SECTION and INIT_DATA_SECTION defined as follow:
Let's look at INIT_CALLS defines for example:
You can see the this defines the sections names that marked with
.initcall...
. And all the marked data gets into the__initcall_start .. __initcall_end
range.Now let's look at the
[include/linux/init.h
that contains the following:And further:
So you can see that
module_init
defined as__initcall
that defined asdevice_initcall
that defined as__define_initcall("6",fn,6)
. Six here means initcall level. See below...init/main.c
contains the following:As you can see
do_initcall
simply iterates over all the initcall levels and callsdo_initcall_level
for each one that calls do_one_initcall for each level's entry.Let's note also that kernel discards all the
__init
functions after execution. So they don't take place in memory after the kernel loads.That's all.