2019-2020-1 20199309 "Linux kernel principle and Analysis" in the fourth week of work

Follow-up analysis of the Linux kernel boot process

First, the experiment

Tracking experiment content using gdb debugging kernel init process to start from start_kernel

1. In accordance with the process, open the shell in the laboratory building environment according to the experimental guidance:

cd LinuxKernel/  
qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img  


Enter the help command:

2. Use gdb trace debug kernel:

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


3. a shell open another window, enter commands gdb:

# 打开 GDB 调试器
$ gdb

# 在 GDB 中输入以下命令:

# 在gdb界面中targe remote之前加载符号表
(gdb)file linux-3.18.6/vmlinux 

# 建立gdb和gdbserver之间的连接,按c 让qemu上的Linux继续运行
(gdb)target remote:1234

# 断点的设置可以在target remote之前,也可以在之后
(gdb)break start_kernel 


Setting a breakpoint:


4. Enter command list:

Second, the analysis process execution function start_kernel

start_kernel () function to complete the initialization of the Linux kernel. Each core member is initialized with this function.

1. Call sched_init () function to initialize the scheduler

2. Call build_all_zonelists () function to initialize both memory management

3. Call page_alloc_init () function to initialize the buddy system allocator

4. Invoke trap_init () function and init_IRQ () function is to initialize the IDT

5. Call softing_init () function initializes TASKLET_SOFTIRQ and HI_SOFTIRQ (soft interrupt)

6. Call time_init () to initialize the system date and time

7. Call kmem_cache_init () function initializes the slab allocator (ordinary and cache)

8. call the calibrate_delay () function to determine the CPU clock (delay function)

9. calls kernel_thread () function to create a process within one thread, the kernel thread will create additional kernel threads and executes the / sbin / init program

10. start_kernel () will be displayed after the start of the implementation of linux version, in addition, the final phase will be the implementation of the init program and kernel threads show a lot of other information. Finally, there will be a familiar login prompt on the console, the Linux kernel has been launched to inform the user is running.

Third, the understanding of "Linux boot process".

1 1. The process, also known as the init process is the ancestor of all user processes called by the process 0 start_kernel rest_init create the init process PID 1, when the scheduler to select the init process, the init process started kernel_init () function init is a general the user mode process, which is initialized with the Unix kernel initialization junction user mode, it is the ancestor of all user processes. Init is running in kernel mode before initialization, the process (kernel initialization) The last action is to run the / sbin / init executable Overall, this is almost the birth of the various subsystems land.

2.idle process, such as the title says, the completion of an important subsystem initialization, you take a back seat. No. 1 from No. 0 process process fork out, then switch to the user mode, complete control of the state from the core to convert user mode, so users can start interacting.

Guess you like

Origin www.cnblogs.com/fungi/p/11617705.html