xx_initcall initialization label in Linux kernel
Tian Hai li @csdn 2011-07-02
There are a number of initialization indicators in the Linux kernel Postcore_initcall (), Arch_initcall (), Subsys_initcall (), Device_initcall (), etc. What's the effect? Review the source code (Android goldfish-2.6.29) and search for relevant articles on the Web. Initialization Label
First look at the definitions of these macros (defined in file include/linux/init.h)[CPP] View Plain copy #define pure_initcall (FN) __define_initcall ("0", fn,0) #define core_initcall (FN) __define_initcall ("1", fn,1) #define  CORE_INITCALL_SYNC (FN) __ Define_initcall ("1s", fn,1s) #define postcore_initcall (FN) __define_initcall ("2", fn,2) #define  POSTCORE_INITCALL_SYNC (FN) __define_initcall ("2s", fn,2s) #define arch_initcall (FN) __define_initcall ("3 ", fn,3) #define  ARCH_INITCALL_SYNC (FN) __define_initcAll ("3s", fn,3s) #define subsys_initcall (FN) __define_initcall ("4", fn,4) #define  SUBSYS_INITCALL_SYNC (FN) __define_initcall ("4s", fn,4s) #define fs_ Initcall (FN) __define_initcall ("5", fn,5) #define  FS_INITCALL_SYNC (FN) __define_initcall ("5s", fn,5s) #define rootfs_ Initcall (FN) __define_initcall (" Rootfs ", Fn,rootfs) #define device_initcall (FN) __define_initcall ("6", fn,6) #define  DEVICE_INITCALL_SYNC (FN) &Nbsp; __define_initcall ("6s", fn,6s) #define late_initcall (FN) __define_initcall ("7", fn,7) #define  LATE_INITCALL_SYNC (FN) __define_ Initcall ("7s", fn,7s)
__define_initcall
These macros all use __define_initcall (), and then look at its definition (also defined in file include/linux/init.h) [CPP] view plain copy #define __define_ Initcall (level,fn,id) \ static initcall_t __initcall_# #fn # #id __used \ __attribute__ (__section__ (". In Itcall "level". Init ")) = fn
Here initcall_t is the function pointer, the prototype is as follows, [CPP] view plain copy typedef int (*initcall_t) (void);
The attribute __attribute__ ((__section__ ()) means that the object is placed in a section of the name in parentheses.
So the meaning of __define_initcall is:
1) Declare a name called __initcall_# #fn的函数指针;
2 Initialize the function pointer to FN;
3 The function pointer variable needs to be placed in a section named ". Initcall" Level ". Init".
3. Place. Initcall.init Section
By clarifying the meaning of __define_initcall, we know that these initialization label-decorated function pointers are placed in their section.
Section '. Initcall ' level '. Init ' was put into initcalls (include/asm-generic/vmlinux.lds.h)[CPP] View Plain copy #define INITCALLS \ * (. Initcallearly.init) \ vmlinux_symbol (__ Early_initcall_end) = .; \ * (. Initcall0.init) \ * (. Initcall0s.init) \ * (. Initcall1.init) \ * (. Initcall1s.init) \ * (. Initcall2.init) \ * (. Initcall2s.init) \ * (. Initcall3.init) \ * (. Initcall3s.init) \ * (. Initcall4.init) \ * (. Initcall4s.init) \ * (. Initcall5.init) \ * (. Initcall5s.init) \ * (. Initcallrootfs.init) \ * (. Initcall6.init) \ * (. Initcall6s.init) \ * (. Initcall7.init) \ * (. Initcall7s.init)
The sections defined in __initcall_start and __initcall_end and Initcalls are placed in the. Init segment in ARCH/XXX/KERNEL/VMLINUX.LDS.S. [plain] view plain copy SECTIONS {. init: {__initcall_start =.; Initcalls __initcall_end =.; } }
4. Initialize the function in Initcallxx.init.
The functions in these section are executed sequentially during initialization (init kernel thread->do_basic_setup () [Main.c#778]->do_initcalls ()).
The program (INIT/MAIN.C file Do_initcalls () function) is as follows, Do_initcalls () performs the functions in the. Initcallxx.init sequentially. [CPP] view plain copy for (call = __early_initcall_end, call < __initcall_end call++) DO_ONE_INITCA ll (*call);
The end of this article *****************************