[Linux Kernel] CFS Scheduler ① (CFS Completely Fair Scheduler Concept | CFS Scheduler Virtual Clock Virtual Runtime Concept | Four Process Priorities | Five Scheduling Classes)





1. Concept of CFS scheduler (completely fair scheduler)



CFS scheduler ( Completely Fair Scheduler ) is "completely fair scheduler" , "completely fair scheduling algorithm" is fair to each process,

"Completely Fair Scheduling Algorithm" is a scheduling algorithm based on time slice round robin ,

Each process gets a CPU time slice of the same size to run;


The CFS scheduler has no concept of time slices, and the scheduler will fairly distribute the CPU usage time;


Example: If there are 4 44 processes with the same priority running on the same CPU, each process will be fairly allocated to 25% 25\%2 5 % runtime;





Second, CFS scheduler virtual clock concept (Virtual Runtime)



In the CFS scheduler, a "scheduling model" is defined , which sets a virtual clock Virtual Runtime for each CFS execution queue ; cfs_rq

Processes with virtual clocks set, execute nnAfter n duration,its virtual clock will increase bynnFor n duration, the virtual clock value of other processes that are notremains unchanged;





3. Process priority (scheduling priority | static priority | normal priority | real-time priority)



Refer to [Linux Kernel] Process Management - Process Priority ② (prio scheduling priority | static_prio static priority | normal_prio normal priority | rt_priority real-time priority) blog,

The process priority field is defined in the "process descriptor" structure in the linux-5.6.18\include\linux\sched.hheader file as follows:task_struct

	int				prio; 				 // 调度优先级
	int				static_prio; 		 // 静态优先级
	int				normal_prio; 		 // 正常优先级
	unsigned int			rt_priority; // 实时优先级

insert image description here

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




4. Scheduling class (stop scheduling class | deadline scheduling class | real-time scheduling class | fair scheduling class | idle scheduling class)



Fields defined in the "Process Descriptor" structure in the linux-5.6.18\include\linux\sched.hheader file,task_struct sched_class

Indicates the scheduling class to which the process belongs;

const struct sched_class	*sched_class;

Source address: linux-5.6.18\include\linux\sched.h#680


The above-mentioned scheduling classes that can be set refer to [Linux Kernel] Scheduler ⑦ (Scheduler Type | Stop Scheduling Class stop_sched_class | Deadline Scheduling Class dl_sched_class | Real Time Scheduling Class | Fair Scheduling Class | Idle Scheduling Class) Blog, In the Linux kernel, the sched_classscheduler Divided into the following 5 55 types:

  • stop_sched_class : stop scheduling class;
  • dl_sched_class : Deadline scheduling class;
  • rt_sched_class : real-time scheduling class;
  • fair_sched_class : fair scheduling class;
  • idle_sched_class : idle scheduling class;

The priorities of scheduling classes are arranged in descending order: shutdown scheduling class > deadline scheduling class > real-time scheduling class > fair scheduling class > idle scheduling class

Guess you like

Origin blog.csdn.net/han1202012/article/details/123835605
Recommended