Because many designs of Linux are similar to Unix, here are a few points I learned from "Linux Kernel Design and Implementation". I hope it will be a little helpful to your understanding.
Kernel mode (also called kernel state) means that the current code instructions are executed in the kernel space. Relatively speaking, it is user mode, that is, the programs we write run in user space.
If a user space process wants to access or operate hardware, it must let the kernel do it. The system call is actually the process requesting the kernel to do something. When a system call occurs, the process falls into the kernel state. At this time, the kernel is in the process context. The kernel knows the process that currently initiates the system call and its information, and then the kernel does things on behalf of the process.
System calls are implemented using soft interrupts, that is, the user space process initiates a system call, which actually generates a soft interrupt, allowing the CPU to enter the kernel's interrupt handler, thus entering the kernel state. When the system call ends, the kernel is responsible for switching back to user space, and the process continues to execute in user space (of course the kernel knows how to switch back to user space, because the data and processes in user space are managed by the kernel). System call parameters and return values are copied between user space and kernel space.
Each processor (each core) has a kernel thread (or process), and the soft interrupt of the system call is processed in this kernel thread.
Kernel threads are a mechanism that assists in interrupt handling.
I have also been looking at unix operating systems recently. When an interrupt occurs, the kernel schedules the process, and the process itself cannot sense the interrupt. The system call is equivalent to calling a piece of code that is not the process itself, but the system code, and then enters the core state.
Because many designs of Linux are similar to Unix, here are a few points I learned from "Linux Kernel Design and Implementation". I hope it will be a little helpful to your understanding.
Kernel mode (also called kernel state) means that the current code instructions are executed in the kernel space. Relatively speaking, it is user mode, that is, the programs we write run in user space.
If a user space process wants to access or operate hardware, it must let the kernel do it. The system call is actually the process requesting the kernel to do something. When a system call occurs, the process falls into the kernel state. At this time, the kernel is in the process context. The kernel knows the process that currently initiates the system call and its information, and then the kernel does things on behalf of the process.
System calls are implemented using soft interrupts, that is, the user space process initiates a system call, which actually generates a soft interrupt, allowing the CPU to enter the kernel's interrupt handler, thus entering the kernel state. When the system call ends, the kernel is responsible for switching back to user space, and the process continues to execute in user space (of course the kernel knows how to switch back to user space, because the data and processes in user space are managed by the kernel). System call parameters and return values are copied between user space and kernel space.
Each processor (each core) has a kernel thread (or process), and the soft interrupt of the system call is processed in this kernel thread.
Kernel threads are a mechanism that assists in interrupt handling.
I have also been looking at unix operating systems recently. When an interrupt occurs, the kernel schedules the process, and the process itself cannot sense the interrupt.
The system call is equivalent to calling a piece of code that is not the process itself, but the system code, and then enters the core state.