Documentation/translations/zh_CN/scheduler/schedutil.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/scheduler/schedutil.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/scheduler/schedutil.rst- Extension
.rst- Size
- 6594 bytes
- Lines
- 165
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/scheduler/schedutil.rst
:翻译:
唐艺舟 Tang Yizhou <tangyeechou@gmail.com>
=========
Schedutil
=========
.. note::
本文所有内容都假设频率和工作算力之间存在线性关系。我们知道这是有瑕疵的,
但这是最可行的近似处理。
PELT(实体负载跟踪,Per Entity Load Tracking)
==============================================
通过PELT,我们跟踪了各种调度器实体的一些指标,从单个任务到任务组分片到CPU
运行队列。我们使用指数加权移动平均数(Exponentially Weighted Moving Average,
EWMA)作为其基础,每个周期(1024us)都会衰减,衰减速率满足y^32 = 0.5。
也就是说,最近的32ms贡献负载的一半,而历史上的其它时间则贡献另一半。
具体而言:
ewma_sum(u) := u_0 + u_1*y + u_2*y^2 + ...
ewma(u) = ewma_sum(u) / ewma_sum(1)
由于这本质上是一个无限几何级数的累加,结果是可组合的,即ewma(A) + ewma(B) = ewma(A+B)。
这个属性是关键,因为它提供了在任务迁移时重新组合平均数的能力。
请注意,阻塞态的任务仍然对累加值(任务组分片和CPU运行队列)有贡献,这反映了
它们在恢复运行后的预期贡献。
利用这一点,我们跟踪2个关键指标:“运行”和“可运行”。“运行”反映了一个调度实体
在CPU上花费的时间,而“可运行”反映了一个调度实体在运行队列中花费的时间。当只有
一个任务时,这两个指标是相同的,但一旦出现对CPU的争用,“运行”将减少以反映每个
任务在CPU上花费的时间,而“可运行”将增加以反映争用的激烈程度。
更多细节见:kernel/sched/pelt.c
频率 / CPU不变性
================
因为CPU频率在1GHz时利用率为50%和CPU频率在2GHz时利用率为50%是不一样的,同样
在小核上运行时利用率为50%和在大核上运行时利用率为50%是不一样的,我们允许架构
以两个比率来伸缩时间差,其中一个是动态电压频率升降(Dynamic Voltage and
Frequency Scaling,DVFS)比率,另一个是微架构比率。
对于简单的DVFS架构(软件有完全控制能力),我们可以很容易地计算该比率为::
f_cur
r_dvfs := -----
f_max
对于由硬件控制DVFS的更多动态系统,我们使用硬件计数器(Intel APERF/MPERF,
ARMv8.4-AMU)来计算这一比率。具体到Intel,我们使用::
APERF
f_cur := ----- * P0
MPERF
4C-turbo; 如果可用并且使能了turbo
f_max := { 1C-turbo; 如果使能了turbo
P0; 其它情况
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.