LoGin 880720250e
doc: Add ai doc translate tool and add English doc. (#1168)
- add tools/doc_translator.py
- translated docs into English

Signed-off-by: longjin <longjin@DragonOS.org>
2025-05-20 10:44:28 +08:00

2.6 KiB
Raw Permalink Blame History

:::{note} AI Translation Notice

This document was automatically translated by Qwen/Qwen3-8B model, for reference only.

  • Source document: kernel/sched/cfs.md

  • Translation time: 2025-05-19 01:41:13

  • Translation model: Qwen/Qwen3-8B

Please report issues via Community Channel

:::

APIs Related to the Completely Fair Scheduler

CFS (Completely Fair Scheduler), as the name suggests, is a fully fair scheduler. CFS is one of the mainline schedulers and is also one of the most typical O(1) schedulers.

Structure Introduction

  • _translated_label__CompletelyFairScheduler&emsp;&emsp;CompletelyFairScheduler实现了Scheduler``trait他是完全调度算法逻辑的主要实施者。

  • FairSchedEntity

    • 重要字段
      • cfs_rq: 它指向了自己所在的完全公平调度队列。
      • my_cfs_rq: 为一个Option变量,当该实体作为一个单独进程时,这个值为None,但是若这个实体为一个组,那这个变量必需为这个组内的私有调度队列。这个cfs_rq还可以继续往下深入,就构成了上述的树型结构。
      • pcb: 它指向了当前实体对应的PCB,同样,若当前实体为一个组,则这个Weak指针不指向任何值。

FairSchedEntity是完全公平调度器中最重要的结构体他代表一个实体单位它不止表示一个进程它还可以是一个组或者一个用户但是它在cfs队列中所表示的就单单是一个调度实体。这样的设计可以为上层提供更多的思路比如上层可以把不同的进程归纳到一个调度实体从而实现组调度等功能而不需要改变调度算法。

在cfs中整体的结构是一棵树,每一个调度实体作为cfs_rq中的一个节点,若该调度实体不是单个进程(它可能是一个进程组),则在该调度实体中还需要维护一个自己的cfs_rq,这样的嵌套展开后,每一个叶子节点就是一个单独的进程。需要理解这样一棵树,在后续文档中会以这棵树为核心讲解

  该结构体具体的字段意义请查阅源代码。这里提及几个重要的字段:

  • CfsRunQueue CfsRunQueue完全公平调度算法中管理FairSchedEntity的队列,它可以挂在总的CpuRunQueue下,也可以作为子节点挂在FairSchedEntity上,详见上文FairSchedEntity

    • 重要字段
      • entities: 存储调度实体的红黑树
      • ``current_en: The entity currently running