Linux Kernel development-process scheduling and Linux kernel Process Scheduling
This section briefly introduces the knowledge about process scheduling in kernel development.
What is process scheduling?
Process Scheduling is to select the most appropriate process execution process from a ready process.
Process Scheduling Policy
Real-time Class Scheduling Policy
Non-real-time Class Scheduling Policy
Process Scheduling time
The current process voluntarily waives the execution permission because it needs to wait for resources and other reasons, and requests to switch to the next process for execution.
Example of voluntarily giving up CPU:
Current-> state = TASK_INTERRUPTIBLE;
Schedule ();
The current process is forced to grant the CPU execution permission for reasons such as priority and process attributes.
1) User Preemption
When the system call is completed and the user space is returned
When the user space is returned after the interrupt processing is completed
2) kernel preemption
· In a system that does not support kernel preemption, once a process/thread runs in the kernel space, it is not allowed to be preemptible, the CPU will be released only after the kernel thread execution is completed, the CPU is automatically abandoned, or the time slice is exhausted.
· In systems that support kernel preemption, high-priority processes/Threads can seize low-priority processes/threads running in the kernel space.
· However, kernel preemption is not allowed in the following four cases:
- The kernel is processing the interrupt.
- The kernel is in the interrupt context.
- The kernel is executing scheduling.
- When a process holds resources such as a spin lock, readlock, or writelock
· To ensure that the above four conditions are not preemptible, The preempt_count variable is provided in Linux to record the above States. When the kernel enters the preceding four states, the preempt_count variable will add 1. When the kernel exits from the preceding states, the preempt_count variable will be reduced by 1, and the preempt_count variable will be placed in the thread_info structure.
Process Scheduling steps
Clear processes currently running
Select the next program (pick_next_task)
Set the running environment of the new process
Process context switch
Error Message
Linux Kernel Process Scheduling
The Linux kernel executes the corresponding Interrupt Processing Program through hardware interruptions. the Linux kernel uses the interrupt program to analyze and process the task linked list. This naturally includes allocating CPU time slices to Linux systems, the interruption system is a core task. To a large extent, it can affect the entire kernel, because the interruption signal may occur at any time, no matter what the CPU is doing, it will certainly be processed (unless the interruption has not been initialized yet or the interruption is still blocked)