Trace analysis of the boot process of the Linux kernel

Source: Internet
Author: User

Trace Analysis The boot process of the Linux kernel uses GDB to trace the debug kernel
    • Using QEMU

      qemu -kernel linux-3.18.6 /arch/x86/boot/bzImage -initrd rootfs.img -s -S

      Parameters:

      • -S: Freezes the CPU at initialization
      • -S: assigning 1234 ports to GDB

    • GDB debugging

      Open the shell.

      gdb(gdb) file linux-3.18.6/vmlinux  #在 gdb 界面中 target remote之前加载符号表(gdb) target remote :1234   #建立连接(gdb) break start_kernel    #设置断点

Starting from Start_kernel to Init process
  • Set_task_stack_end_magic ()

    To detect Stack Overflow

  • SMP_SETUP_PROCESSOR_ID ()

    Setting up a symmetric multi-processor

  • Cgroup_init_early ()

    Initialize Control Groups

    *control Groups provide a mechanism for aggregating/partitioning sets of
    Tasks, and all their The future children, to hierarchical groups with
    Specialized behaviour.*

  • Page_address_init ()

    Page address initialization (part of memory management)

  • Setup_arch ()

    Setup_arch-architecture-specific boot-time initializations

  • Build_all_zonelists ()

    Called with Zonelists_mutex held always unless system_state = = system_booting.

  • Page_alloc_init ()

  • Setup_log_buf ()

    Initialize the log buffer (KERNEL/PRINTK/PRINTK.C)

  • Pidhash_init ()

    Initializing a PID hash table

    The PID hash table is scaled according to the amount of memory in the machine. From a minimum of slots up to 4096 slots at one gigabyte or more.

  • Vfs_caches_init_early ()

  • Sort_main_extable ()

    Sort the kernel ' s built-in exception table

  • Trap_init ()

    Initializing interrupt vectors

  • Mm_init ()

    Memory Management Initialization

  • Sched_init ()

    Scheduling Service Initialization

  • ......

  • Rest_init ()

    Remaining initialization

    • Kernel_init:init process
    • Kthreadd: Kernel thread
    • Cpu_idle process: The code keeps looping, and if there are no executable processes in the system, the idle process is executed
Summarize
    • When Start_kernel executes to the last part, a new kernel_init process is created in Rest_init, the kernel_thread(kernel_init, NULL, CLONE_FS); init process is the number 1th process in the system, the ancestor of all subsequent user-state processes, and the new Kthreadd process, pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES); Kthreadd as the number 2nd process, is the ancestor of all kernel threads, in cpu_startup_entry(CPUHP_ONLINE) , is a while(1) loop that always has an idle process executing, and if the system does not always have any processes that can be executed, the idle process executes.

Last quote from the Monensin teacher's passage:

Daosh One: (Start_kernel)

Life Two: (Kernel_init and Kthreadd)

Two students three: (that is, the 0,1,2 process)

Sansheng: (Process 1th is all user-state process ancestor, process 2nd is all kernel thread ancestor)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Trace analysis of the boot process of the Linux kernel

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.