[Linux Kernel] Process Priority and Scheduling Policy ① ( SCHED_FIFO Scheduling Policy | SCHED_RR Scheduling Policy | Process Priority )





1. Linux Kernel Scheduling Policy



Linux kernel scheduling policy:

  • SCHED_OTHER : Time- sharing scheduling strategy;
  • SCHED_FIFO: real-time scheduling strategy , first come first serve ; once occupies the CPU , it will keep running until a higher priority process arrives before giving up the CPU, or the process itself gives up the CPU;
  • SCHED_RR: real-time scheduling strategy , time slice rotation ; the process is allocated to the CPU time slice for execution, after the time slice is used up, the process is placed at the end of the priority queue, waiting for the system to reallocate the time slice for execution;

To sum up, if there are multiple "real-time processes" of the same priority,

  • The SCHED_FIFO strategy needs to wait for the process to give up voluntarily before it can execute other tasks with the same priority.
  • SCHED_RR strategy Each process with the same priority can execute a time slice;

Special attention: The scheduling can be modified and determined by the developer;


Refer to [Linux Kernel] Scheduler⑨ (Linux Kernel Scheduling Policy | SCHED_NORMAL Policy | SCHED_FIFO Policy | SCHED_NORMAL Policy | SCHED_BATCH Policy) blog, which introduces the Linux kernel-related scheduling policy;


1. SCHED_FIFO scheduling policy


SCHED_FIFOis a "real-time process scheduling strategy" , which is a First In First Out (First In First Out) scheduling strategy ;

This strategy does not involve the CPU time slice mechanism (time-sharing multiplexing mechanism) , and in the absence of high-priority processes, it can only wait for other processes to actively release CPU resources;

SCHED_FIFOIn the scheduling strategy, the process that is scheduled to run by the scheduler has an unlimited running time and can run for any length of time;


2. SCHED_RR scheduling strategy


SCHED_RRIt is a "real-time process scheduling strategy" , which uses the time slice rotation mechanism, and the corresponding time value will decrease during runtime ;

After the process uses the CPU time slice , it will be added to the end of the execution queue corresponding to the process priority ;

At the same time, the CPU resources are released, and the CPU time slice will be rotated to other processes of the same process priority;





Second, the process priority



Priority value range of real-time process 1 1 1 ~ 99 99 9 9 ,the larger the value, thehigher the priority;

Real-time tasks in the ready state can immediately preempt non-real-time tasks;

If all processes use the Linux time-sharing scheduling strategy, when creating the process, you must specifynice value of the priority calculation parameter , the value range is − 20 -2020 ~ 19 19 1 9 , the execution time of the process on the CPU is determined by the priority weight calculated in combination with the nicevalue


in previous blog

, briefly introduced the concept of process priority , this blog begins to introduce the priority-related source code in the Linux kernel;


Process priority Deadline process real-time process normal process
prio scheduling priority equal to the normal_prio field equal to the normal_prio field equal to the normal_prio field
static_prio scheduling priority Field value is always 0 00 , meaningless Field value is always 0 00 , meaningless 120 + n i c e \rm 120 + nice120+n ic e , the smaller the value, the higher the priority
normal_prio normal priority − 1 -11 99 − r t _ p r i o r i t y 99 - \rm rt\_priority99rt_priority 120 + n i c e \rm 120 + nice120+n ic e , the smaller the value, the higher the priority
rt_priority real-time priority Field value is always 0 00 , meaningless Field value is 1 11 ~ 99 99 9 9 , the larger the value, the higher the priority Field value is always 0 00 , meaningless

Guess you like

Origin blog.csdn.net/han1202012/article/details/123917205