# 2.6.4 带宽控制

系统引入任务组的基本目的之一，就是实现资源的分配与控制，对CPU时间的限制通过带宽控制来实现，本节我们就来一探究竟。实时任务和普通任务都有带宽控制的逻辑，我们这里只讨论CFS的带宽控制。

带宽控制的总体思路如下：系统为任务组设置带宽额度，任务组中的各个cfs\_rq首先需要向任务组（task\_group）申请时间，如果申请成功，则cfs\_rq中的任务可以被CFS调度运行，如果申请失败（例如当前周期内任务组的时间配额已经用完），则调度器会将cfs\_rq挂起（throttle）；系统通过定时器周期性地为任务组重新分配时间额度，并将挂起的cfs\_rq解挂（unthrottle）。

下面我们深入代码，从各个方面详细分析带宽控制的实现方式。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://s3.shizhz.me/linux-sched/cfs-sched/bandwidth.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
