Linux 内核CFS 调度器 ⑥ ( CFS 调度器就绪队列 cfs_rq | Linux 内核调度实体 sched_entity | “ 红黑树 “ 数据结构 rb_root_cached )

Posted 韩曙亮

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 内核CFS 调度器 ⑥ ( CFS 调度器就绪队列 cfs_rq | Linux 内核调度实体 sched_entity | “ 红黑树 “ 数据结构 rb_root_cached )相关的知识,希望对你有一定的参考价值。

文章目录





一、CFS 调度器就绪队列 cfs_rq



调度器主要职责 就是 对 " 进程 " 进行 " 调度管理 " , 调度时 进程 是放在 " 调度队列 " 中的 ,

CFS 调度器 的 调度队列 struct cfs_rq ;

通过 该 " CFS 调度器就绪队列 " cfs_rq , 可以 跟踪 " 就绪队列 " 信息 , 管理 " 就绪状态 " 调度实体 , 维护着一个 按照 虚拟时钟 排序的 " 红黑树 " 数据结构 ;


struct cfs_rq 结构体在 Linux 内核源码 linux-5.6.18\\kernel\\sched\\sched.h 头文件中定义 ;


/* CFS-related fields in a runqueue */
struct cfs_rq 
	struct load_weight	load;
	unsigned long		runnable_weight;
	unsigned int		nr_running;
	unsigned int		h_nr_running;      /* SCHED_NORMAL,BATCH,IDLE */
	unsigned int		idle_h_nr_running; /* SCHED_IDLE */

	u64			exec_clock;
	u64			min_vruntime;

	struct rb_root_cached	tasks_timeline;

	/*
	 * 'curr' points to currently running entity on this cfs_rq.
	 * It is set to NULL otherwise (i.e when none are currently running).
	 */
	struct sched_entity	*curr;
	struct sched_entity	*next;
	struct sched_entity	*last;
	struct sched_entity	*skip;





二、Linux 内核调度实体 sched_entity



sched_entity 结构体 就是可以 被 Linux 内核 调度实体 ;

可以将该 " 调度实体 " 插入到 红黑树 ( 执行队列 ) 节点 中 ;

	struct sched_entity	*curr;
	struct sched_entity	*next;
	struct sched_entity	*last;
	struct sched_entity	*skip;




三、" 红黑树 " 数据结构 rb_root_cached



" CFS 调度器就绪队列 " cfs_rq中定义的

struct rb_root_cached	tasks_timeline;

字段 , 就是 按照 " 虚拟时钟 " 排序的 " 红黑树 " 数据结构 ,

tasks_timeline 指针指向 rb_root_cached 类型的结构体 ,

rb_root 成员 是 这个 " 红黑树 " 数据结构根节点 ;

rb_leftmost 成员 指向 这个 " 红黑树 " 数据结构最左侧的 " 调度实体 " , 就是 " 虚拟时间 " 最小的调度实体 ;


该 " 红黑树 " 数据结构 如下 : 在 Linux 内核源码 linux-5.6.18\\include\\linux\\rbtree.h 路径对应的源码中定义 ;

/*
 * Leftmost-cached rbtrees.
 *
 * We do not cache the rightmost node based on footprint
 * size vs number of potential users that could benefit
 * from O(1) rb_last(). Just not worth it, users that want
 * this feature can always implement the logic explicitly.
 * Furthermore, users that want to cache both pointers may
 * find it a bit asymmetric, but that's ok.
 */
struct rb_root_cached 
	struct rb_root rb_root;
	struct rb_node *rb_leftmost;
;

以上是关于Linux 内核CFS 调度器 ⑥ ( CFS 调度器就绪队列 cfs_rq | Linux 内核调度实体 sched_entity | “ 红黑树 “ 数据结构 rb_root_cached )的主要内容,如果未能解决你的问题,请参考以下文章

Linux 内核CFS 调度器 ⑤ ( CFS 调度器类 fair_sched_class 源码 | next 赋值 | enqueue_task 赋值 | dequeue_task 赋值 )

Linux 内核CFS 调度器 ② ( CFS 调度器 “ 权重 “ 概念 | CFS 调度器调度实例 | 计算进程 “ 实际运行时间 “ )

Linux 内核CFS 调度器 ③ ( 计算进程 “ 虚拟运行时间 “ )

linux内核源码分析之CFS调度

Linux(内核剖析):08---进程调度之Linux调度算法(调度器类公平调度(CFS))

CFS Scheduler(CFS调度器)