[Linux kernel] CFS scheduler ⑤ ( CFS scheduler class fair_sched_class source code | next assignment | enqueue_task assignment | dequeue_task assignment )





1. Introduction to the scheduler class sched_class



in previous blog

, introduces the source code of the scheduling class sched_class structure , important fields and function pointers;

The CFS scheduler class fair_sched_class is of sched_classstructure type;





2. CFS scheduler class source code



The source code of the CFS scheduler class fair_sched_class is in the Linux kernel source linux-5.6.18\kernel\sched\fair.ccode ,

/*
 * All the scheduling class methods:
 */
const struct sched_class fair_sched_class = {
    
    
	.next			= &idle_sched_class,
	.enqueue_task		= enqueue_task_fair,
	.dequeue_task		= dequeue_task_fair,
	.yield_task		= yield_task_fair,
	.yield_to_task		= yield_to_task_fair,

	.check_preempt_curr	= check_preempt_wakeup,

	.pick_next_task		= __pick_next_task_fair,
	.put_prev_task		= put_prev_task_fair,
	.set_next_task          = set_next_task_fair,
}

insert image description here





Three, next assignment



Fieldfair_sched_class assignment of the CFS scheduler class ,next

.next			= &idle_sched_class

idle_sched_classis the idle scheduling class;


Reference: [Linux kernel] Scheduler ③ ( sched_class scheduling class structure analysis | next field | enqueue_task function | dequeue_task function)

There are multiple "scheduling classes" in the whole Linux system, which are sorted by priority . These "scheduling classes" are placed in a "linked list" , and the "scheduling classes" with high priority are executed first, and those with lower priority are executed later;

sched_classThe nextfield points to the next "scheduling class" in the " scheduling class" linked list ; (the priority is lower than this scheduling class)

const struct sched_class *next;

Source path: linux-5.6.18\kernel\sched\sched.h#1709 ;





Four, enqueue_task assignment



Fieldfair_sched_class assignment of the CFS scheduler class , when the process task enters the "runnable state" , this function to store the scheduling entity, that is, the process , in the execution queue (red-black tree);enqueue_taskenqueue_task_fair

	.enqueue_task		= enqueue_task_fair,

Reference: [Linux kernel] Scheduler ③ ( sched_class scheduling class structure analysis | next field | enqueue_task function | dequeue_task function)

sched_classThe enqueue_taskfunction points to a function, and when the function is called, the "process" can be added to the "execution queue" , and it is nr_runningautomatically incremented by 1 11 ;

  • A process is a scheduling entity;
  • The execution queue is a red- black tree;
void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);

Source code path: linux-5.6.18\kernel\sched\sched.h#1715 ;





Five, dequeue_task assignment



fair_sched_classThe dequeue_taskfield assignment of the CFS scheduler class , when the process task exits the "runnable state" , the dequeue_task_fairfunction to delete the scheduling entity, that is, the process, from the execution queue (red-black tree) and perform the dequeue operation;

	.dequeue_task		= dequeue_task_fair,

Reference: [Linux kernel] Scheduler ③ ( sched_class scheduling class structure analysis | next field | enqueue_task function | dequeue_task function)

dequeue_taskThe dequeue_taskfunction points to a function, calling this function can delete the "process" from the "execution queue" and decrement it by 1 1nr_running1 ;

  • A process is a scheduling entity;
  • The execution queue is a red- black tree;
void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);

Source code path: linux-5.6.18\kernel\sched\sched.h#1716 ;

Guess you like

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