【Linux 内核】CFS 调度器 ⑥ ( CFS 调度器就绪队列 cfs_rq | Linux 内核调度实体 sched_entity | “ 红黑树 “ 数据结构 rb_root_cached )
文章目錄
- 一、CFS 調(diào)度器就緒隊列 cfs_rq
- 二、Linux 內(nèi)核調(diào)度實體 sched_entity
- 三、" 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) rb_root_cached
一、CFS 調(diào)度器就緒隊列 cfs_rq
調(diào)度器 的 主要職責(zé) 就是 對 " 進程 " 進行 " 調(diào)度管理 " , 調(diào)度時 進程 是放在 " 調(diào)度隊列 " 中的 ,
CFS 調(diào)度器 的 調(diào)度隊列 是 struct cfs_rq ;
通過 該 " CFS 調(diào)度器就緒隊列 " cfs_rq , 可以 跟蹤 " 就緒隊列 " 信息 , 管理 " 就緒狀態(tài) " 調(diào)度實體 , 維護著一個 按照 虛擬時鐘 排序的 " 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) ;
該 struct cfs_rq 結(jié)構(gòu)體在 Linux 內(nèi)核源碼 的 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 內(nèi)核調(diào)度實體 sched_entity
sched_entity 結(jié)構(gòu)體 就是可以 被 Linux 內(nèi)核 調(diào)度 的 實體 ;
可以將該 " 調(diào)度實體 " 插入到 紅黑樹 ( 執(zhí)行隊列 ) 節(jié)點 中 ;
struct sched_entity *curr;struct sched_entity *next;struct sched_entity *last;struct sched_entity *skip;三、" 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) rb_root_cached
在 " CFS 調(diào)度器就緒隊列 " cfs_rq中定義的
struct rb_root_cached tasks_timeline;字段 , 就是 按照 " 虛擬時鐘 " 排序的 " 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) ,
tasks_timeline 指針指向 rb_root_cached 類型的結(jié)構(gòu)體 ,
rb_root 成員 是 這個 " 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) 的 根節(jié)點 ;
rb_leftmost 成員 指向 這個 " 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) 的 最左側(cè)的 " 調(diào)度實體 " , 就是 " 虛擬時間 " 最小的調(diào)度實體 ;
該 " 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) 如下 : 在 Linux 內(nèi)核源碼 linux-5.6.18\include\linux\rbtree.h 路徑對應(yīng)的源碼中定義 ;
/** 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; };總結(jié)
以上是生活随笔為你收集整理的【Linux 内核】CFS 调度器 ⑥ ( CFS 调度器就绪队列 cfs_rq | Linux 内核调度实体 sched_entity | “ 红黑树 “ 数据结构 rb_root_cached )的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Linux 内核】CFS 调度器 ⑤
- 下一篇: 【Linux 内核】实时调度类 ① (