日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發布時間:2025/6/17 65 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Linux 内核】CFS 调度器 ⑥ ( CFS 调度器就绪队列 cfs_rq | Linux 内核调度实体 sched_entity | “ 红黑树 “ 数据结构 rb_root_cached ) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 一、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 )的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。