Tag: The calculation process starts to determine that the CPU does not have nbsp resource Sch wait Queue
Three scheduling strategies for the Linux kernel:
- Sched_other time-sharing scheduling policy, (default)
- Sched_fifo Real-time scheduling strategy, first-come-first service
- SCHED_RR Real Time scheduling strategy, time slice rotation
Real-time process will get priority call, real-time process according to the real-time priority to determine the scheduling weights, timeshare process through nice and counter values determine the weights, nice smaller, counter larger, the probability of being dispatched is greater, that is, the process of using the least CPU will be prioritized scheduling.
The difference between SHCED_RR and Sched_fifo:
When the time slice of the process using the SHCED_RR policy is exhausted, the system will redistribute the time slices and place them at the end of the ready queue. Placing at the end of the queue ensures that all RR tasks with the same priority are scheduled fairly.
Sched_fifo is always running once the CPU is occupied. Run until a higher priority task arrives or abandons itself.
If a real-time process with the same priority (which is the same as the scheduling weights computed by the priority) is ready, the FIFO must wait for the process to be actively discarded before it can run the same priority task. The RR allows each task to execute for a period of time.
Same point:
- Both RR and FIFO are used for real-time tasks only.
- The priority at creation is greater than 0 (1-99).
- According to the preemptive priority scheduling algorithm.
- Real-time tasks of ready state immediately preempt non-real-time tasks.
When all tasks use the time-sharing scheduling policy (Sched_other):
1. Create a task specify a time-sharing scheduling policy and specify a priority nice value ( -20~19).
2. The execution time on the CPU will be determined based on the nice value of each task (counter).
3. If no resources are waiting, the task is added to the ready queue.
4. The scheduler traverses the tasks in the ready queue, by calculating the dynamic priority of each task (Counter+20-nice) results, select one of the most calculated results to run, when the time slice is exhausted (counter to 0) or the active abandonment of the CPU, The task will be placed at the end of the ready queue (the time slice runs out) or wait for the queue (the CPU is discarded as a result of waiting for the resource).
5. At this point the scheduler repeats the above calculation process and goes to step 4th.
6. Repeat the 2nd step when the scheduler finds that all the ready tasks calculate a weight of less than 0 o'clock.
When all tasks are using a FIFO scheduling policy (SCHED_FIFO):
1. The process is created by specifying a FIFO and setting real-time priority rt_priority (1-99).
2. If no resources are waiting, the task is added to the ready queue.
3. The scheduler traverses the ready queue, calculates the scheduling weights based on the real-time priority, selects the task with the highest weights to use the CPU, and the FIFO task will always occupy the CPU until a higher priority task is ready (even if the priority is the same) or the active discard (waiting for the Resource).
4. The scheduler discovers that a higher priority task arrives (a high-priority task may be interrupted or the timer task wakes up, or is awakened by the currently running task, and so on), and the scheduler immediately saves all data for the current CPU register in the current task stack. When you reload the register data from the stack of the high-priority task to the CPU, the high-priority task begins to run. Repeat the 3rd step.
5. If the current task is actively abandoning the CPU usage due to waiting for a resource, the task will be removed from the ready queue, and the wait queue is added, and the 3rd step is repeated.
When all tasks are using RR scheduling policy (SCHED_RR):
1. When creating a task, specify the schedule parameter as RR and set the task's real-time priority and nice value (the nice value will be converted to the length of the task's time slice).
2. If no resources are waiting, the task is added to the ready queue.
3. The scheduler traverses the ready queue, calculates the scheduling weights based on the real-time priority, and selects the task with the highest weights to use the CPU.
4. If the RR task time slice in the ready queue is 0, the task's time slice is set according to the Nice value, and the task is placed at the end of the ready queue. Repeat step 3.
5. The current task exits the CPU as it waits for a resource, and it joins the wait queue. Repeat step 3.
In the system, there are time-sharing scheduling and temporal-slice rotation scheduling and FIFO scheduling:
The process of 1.RR scheduling and FIFO scheduling belongs to real-time process, and the process of scheduling with ticks is non-real-time process.
2. When the real-time process is ready, the real-time process immediately grabs the non-real-time process if the current CPU is running a non-real-time process.
3. RR processes and FIFO processes use real-time prioritization as a weighted standard for scheduling, and RR is an extension of the FIFO. FIFO, if the two processes have the same priority, then the two priority-like processes are specifically executed by their unknown in the queue, which leads to some unfairness (the priority is the same, why do you keep running?), if you set the scheduling policy for the two priority tasks to RR, The two tasks are guaranteed to be executed in a loop, guaranteeing fairness.
Linux process/thread scheduling policy (SCHED_OTHER,SCHED_FIFO,SCHED_RR)