Linux kernel segment attribute mechanism "Go"

Source: Internet
Author: User

This article was reproduced from: HTTPS://GITHUB.COM/TONGXINV/ONEBOOK/ISSUES/9

Linux kernel segment attribute mechanism

Taking Subsys_initcall and Module_init as an example

Subsys_initcall is a macro that is defined in linux/init.h . After the macro is expanded, it is discovered that the function of the macro is to put its declared function into a specific segment:.initcall4.init

subsys_initcall    __define_initcall("4",fn,4)

The following files are in/include/linux/init.h:


Analyzing the Module_init macro, you can see that it puts the function into the .initcall6.init segment

module_init    __initcall        device_initcall            __define_initcall("6",fn,6)

Open the/arch/arm/kernel/vmlinux.lds file in the compiled kernel source tree (not compiled without this file):

sections{. = 0xC0000000 + 0x00008000;. Init: { /* Init Code and data*/_stext =.; _sinittext =* (. head.text) * (. init.text) * (. Cpuinit.text) * (. Meminit.text) ...  = ALIGN (+) .* (. Init.setup) __setup_end = .; __initcall_start = * (. initcallearly.init) __early_initcall_end = . * (. initcall0.init) * (. initcall0s.init) * (. initcall1.init) Span class= "Pl-k" >* (. initcall1s.init) * (. Initcall2.init) ... __initcall_end =              

The kernel needs to do a lot of things in sequence during the boot process, how the kernel implements a number of initialization operations in order of precedence. The kernel solution is to classify all functions to be called when the kernel is started, execute the kernel function and each class will be invoked in a certain order. These classification names are called. Initcallx.init. The value of x is from 1 to 8. Kernel developers when writing kernel code, as long as the function set the appropriate level, these functions will be linked to the time of the specific segment, the kernel starts with a sequence of steps to execute the individual segments (through a function, the link script only specifies the location of a program segment in memory).

Kernel Source code:

The following files are in/INIT/MAIN.C

initcall_t __initcall_start[], __initcall_end[], __early_initcall_end[];   do_initcalls (void) {initcall_t *fn;  for (fn = __early_initcall_end; fn < __initcall_end; fn++)Do_one_initcall (*FN);  */Flush_scheduled_work ();}      

Execution Do_initcalls will be executed in a set order, through the contents of the function can be guessed that the principle is the link script set up the order, and then do_initcalls execution will be in accordance with the link script set in the order of the traversal.

After analysis, it can be seen that the role of Subsys_initcall and Module_init is the same, but the former function is declared earlier than the latter in the kernel when the execution sequence of the boot

In addition: Do_initcalls How to be called, simply see the process of lowering

Start_kernel (), Rest_init ()->kernel_init () Do_basic_setup ()->do_initcalls ()

Linux kernel segment attribute mechanism "Go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.