This section provides a brief introduction to the relevant knowledge points for process scheduling in kernel development.
What is process scheduling
Process scheduling is the process of selecting the most appropriate process to execute in a process that is already ready.
Process scheduling Policy
Real-time class scheduling strategy
Scheduling strategies for non-real-time classes
Timing of process scheduling
The current process proactively discards execution permissions because of the need to wait for resources, and proactively switches to the next process execution.
Examples of active abandonment of CPUs:
current->state = task_interruptible;
Schedule ();
The current process is forced to give up CPU execution permissions due to priority, process properties, and so on.
1) User preemption
When the system call is finished returning user space
When the user space is returned after the interrupt processing has completed
2) Kernel preemption
• In a system that does not support kernel preemption, the process/thread is not allowed to be preempted once it is running in kernel space, it must wait until the kernel thread finishes executing, the CPU is actively discarded, or the time slice is exhausted before the CPU is freed.
• In systems that support kernel preemption, high-priority processes/threads can preempt low-priority processes/threads that are running in kernel space.
• However, in the supported kernel preemption system, the following four scenarios are not allowed for kernel preemption:
- The kernel is processing interrupts
- The kernel is in the interrupt context
- The kernel is executing the dispatch
- When a process holds resources such as spin locks or readlock/writelock
· To ensure that the above four scenarios are not preempted, the preemptive kernel provides a variable (preempt_count) to record the above state. When the kernel enters the above four states, the Preempt_count variable will be added 1, and when exiting the above states Preempt_count the 1,preempt_count variable is placed in the THREAD_INFO structure.
Process scheduling steps
Clean up the current running process
Select the next program to run (Pick_next_task)
Set the run environment for a new process
Process Context Switch
Linux kernel development-process scheduling