2022-2023-1 20222820 "Linux Kernel Principles and Analysis" Week 9 Assignment

1. Experimental steps

cd LinuxKernel
rm menu -rf
git clone https://github.com/mengning/menu.git 
cd menu
mv test_exec.c test.c
make rootfs

Update menu

 

 After suspending qemu preparation, open a shell for gdb debugging

 

gdb distribution debugging 

 2. Summary


The timing of process scheduling: directly call schedule() during the interrupt processing process, or call schedule() according to the need_resched mark when returning to user mode. The kernel thread is a special process. It only has kernel mode and no user mode. It can directly call schedule() to switch processes, or it can be scheduled during interrupt processing (kernel threads can directly access kernel functions, so no system calls will occur) . As a special type of process, kernel threads can be scheduled actively or passively.
User mode processes cannot implement active scheduling and can only be scheduled during interrupt processing (schedule is a kernel function, not a system call). Suspending a process that is executing on the CPU is different from saving the scene when interrupted. Before and after the interrupt, the process is in the same process context, but execution is transferred from user mode to kernel mode. The process context contains all the information needed for process execution: user address space: including program code, data, user stack and other control information: process descriptor, kernel stack, etc. Hardware context
The schedule() function selects a new process to run and calls context_switch to perform context switching. A key macro switch_to in context_switch is used to perform key context switching. Users from 0 to 3G can access, and above 3G only kernel mode can access. All processes above 3G are fully shared. For example, process X is switched to process Y, but the address space is still above 3G. It is just that the process descriptor and other process contexts are switched. It is different only when returning. Any process can "wave" into the kernel state. After walking for a while, it can return to the user state. When it is empty, it will enter the idle process.
 

Guess you like

Origin blog.csdn.net/weixin_44226607/article/details/127839182