日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

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

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

文章目錄

  • 一、CFS 調(diào)度器就緒隊(duì)列 cfs_rq
  • 二、Linux 內(nèi)核調(diào)度實(shí)體 sched_entity
  • 三、" 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) rb_root_cached





一、CFS 調(diào)度器就緒隊(duì)列 cfs_rq



調(diào)度器主要職責(zé) 就是 對(duì) " 進(jìn)程 " 進(jìn)行 " 調(diào)度管理 " , 調(diào)度時(shí) 進(jìn)程 是放在 " 調(diào)度隊(duì)列 " 中的 ,

CFS 調(diào)度器 的 調(diào)度隊(duì)列 是 struct cfs_rq ;

通過 該 " CFS 調(diào)度器就緒隊(duì)列 " cfs_rq , 可以 跟蹤 " 就緒隊(duì)列 " 信息 , 管理 " 就緒狀態(tài) " 調(diào)度實(shí)體 , 維護(hù)著一個(gè) 按照 虛擬時(shí)鐘 排序的 " 紅黑樹 " 數(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)度實(shí)體 sched_entity



sched_entity 結(jié)構(gòu)體 就是可以 被 Linux 內(nèi)核 調(diào)度實(shí)體 ;

可以將該 " 調(diào)度實(shí)體 " 插入到 紅黑樹 ( 執(zhí)行隊(duì)列 ) 節(jié)點(diǎn) 中 ;

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)度器就緒隊(duì)列 " cfs_rq中定義的

struct rb_root_cached tasks_timeline;

字段 , 就是 按照 " 虛擬時(shí)鐘 " 排序的 " 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) ,

tasks_timeline 指針指向 rb_root_cached 類型的結(jié)構(gòu)體 ,

rb_root 成員 是 這個(gè) " 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu)根節(jié)點(diǎn) ;

rb_leftmost 成員 指向 這個(gè) " 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu)最左側(cè)的 " 調(diào)度實(shí)體 " , 就是 " 虛擬時(shí)間 " 最小的調(diào)度實(shí)體 ;


該 " 紅黑樹 " 數(shù)據(jù)結(jié)構(gòu) 如下 : 在 Linux 內(nèi)核源碼 linux-5.6.18\include\linux\rbtree.h 路徑對(duì)應(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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。