终极免费方案:3步解锁QQ音乐加密格式,让您的音乐收藏重获自由
2026/7/27 12:26:19
接前一篇文章:Linux CFS(完全公平调度器)原理与实现细节全解析(1)
CFS的调度基本单位不是传统的task_struct,而是更通用的抽象 ——调度实体struct sched_entity。
设计原因很简单:
或cgroup;
因此:
CFS的核心调度逻辑只围绕sched_entity展开。
其关键字段如下(节选):
// include/linux/sched.h struct sched_entity { /* For load-balancing: */ struct load_weight load; struct rb_node run_node; struct list_head group_node; unsigned int on_rq; u64 exec_start; u64 sum_exec_runtime; u64 vruntime; u64 prev_sum_exec_runtime; u64 nr_migrations; #ifdef CONFIG_FAIR_GROUP_SCHED struct sched_entity *parent; /* rq on which this entity is (to be) queued: */ struct cfs_rq *cfs_rq; /* rq "owned" by this entity/group: */ struct cfs_rq *my_q; #endif };其中:
任务权重及其倒数等信息,由nice值通过sched_prio_to_weight映射而来。
虚拟运行时间,是CFS调度排序的核心字段。
作为红黑树节点,使得该实体可插入CFS运行队列的rb-tree中。
/my_q/parent:在启用组调度时构建层次化调度树:
该实体所属运行队列。
如果该实体本身代表一个任务组,则它拥有自己的子运行队列my_q。
父级调度实体,实现自上而下的嵌套调度。
这种设计将“调度逻辑”与“被调度对象”解耦,使CFS可以自然支持从单进程到多级cgroup的复杂层次结构。
更多内容请看下回。