mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-10-30 20:25:50 +08:00
Add BPF qdisc feature background
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
# eBPF Tutorial by Example: Build an Egress Pacer with a BPF Qdisc
|
||||
|
||||
Want to throttle a virtual link in your test environment? Say, squeeze a veth down to 64 Kbit/s and watch how many packets queue up before they start dropping. Ordinary TC BPF handles inspection and actions, while the existing qdisc retains departure-time control.
|
||||
Want to throttle a virtual link in your test environment? Say, squeeze a veth down to 64 Kbit/s and watch how many packets queue up before they start dropping.
|
||||
|
||||
Linux 6.16 hands that layer to BPF as well. You write a set of `struct_ops` callbacks and the kernel treats them as a real root qdisc. This tutorial builds `egress_pacer`, a small FIFO pacer that runs on a veth, TAP, or IFB. Give it a rate and a queue limit. It holds packets, releases them on schedule, and reports enqueue, dequeue, and drop statistics at the end.
|
||||
This lesson is part of the eBPF Tutorial by Example series. eBPF lets user space load a verifier-checked program into the kernel and attach it to a subsystem. `struct_ops` goes further by letting BPF supply an operation table whose callbacks the subsystem invokes. Ordinary TC BPF classifies or acts on packets while the existing qdisc still owns queueing and departure time. Linux 6.16 added BPF implementations of the `Qdisc_ops` callbacks through `struct_ops`. Programs implement `enqueue`, `dequeue`, `init`, `reset`, and `destroy` and register dynamically as a qdisc.
|
||||
|
||||
This example uses one aggregate FIFO to demonstrate skb ownership, queue accounting, departure time, watchdog wakeups, and teardown cleanup. It is suitable for observing the full flow on controlled interfaces such as veth, TAP, or IFB. A fuller scheduler can build on this foundation with classes, fairness, ECN, and burst control.
|
||||
`egress_pacer` is a FIFO pacer built exactly this way. It becomes the root qdisc, owns `skb` queueing, computes release time from packet length, uses the `watchdog` to wake `dequeue`, and cleans up queued packets during `reset`. Give it a rate and a queue limit. It holds packets, releases them on schedule, and reports enqueue, dequeue, and drop statistics at the end. The example uses one aggregate FIFO to demonstrate `skb` ownership, pacing, and qdisc cleanup, suitable for observing the full flow on controlled interfaces such as `veth`, `TAP`, or `IFB`.
|
||||
|
||||
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/53-egress-pacer>
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# eBPF 教程:用 BPF Qdisc 实现出口限速
|
||||
|
||||
想给测试环境里的一条虚拟网线限个速?比方说,把 veth 压到 64 Kbit/s,看看丢包之前队列能塞多少报文。常见的 TC BPF 示例处理检查和动作,发送时间仍由原有的 qdisc 安排。
|
||||
想给测试环境里的一条虚拟网线限个速?比方说,把 veth 压到 64 Kbit/s,看看丢包之前队列能塞多少报文。
|
||||
|
||||
Linux 6.16 把这一层也交给了 BPF。你可以用 `struct_ops` 写一个真正的 qdisc,自己管 skb 队列,自己算发送时间。本课会用它构建 `egress_pacer`:一个运行在 veth、TAP 或 IFB 上的小型 FIFO 限速器。给出速率和队列上限,它就把报文存起来,到点再放,最后报告入队、发送和丢包统计。
|
||||
本课属于 eBPF Tutorial by Example 系列。eBPF 让用户态把经过 verifier 检查的程序加载到内核,再挂到某个子系统。`struct_ops` 进一步允许 BPF 提供一张操作表,子系统随后调用其中的回调。普通 TC BPF 程序可以检查和处理报文,排队和发送时间仍由原有的 qdisc 管理。Linux 6.16 通过 `struct_ops` 引入了 BPF 实现的 `Qdisc_ops` 回调。程序实现 `enqueue`、`dequeue`、`init`、`reset` 和 `destroy`,可以动态注册为一个 qdisc。
|
||||
|
||||
这个例子用一条聚合 FIFO 展示 skb 所有权、队列统计、发送时间、watchdog 唤醒和 reset 清理,适合在 veth、TAP 或 IFB 这类受控接口上观察完整流程。更完整的调度器可以在此基础上加入 class、公平调度、ECN 和 burst 控制。
|
||||
本课的 `egress_pacer` 正是用这种方式构建的 FIFO 限速器。它注册为 root qdisc,自己管理 `skb` 入队,按报文长度计算发送时间,使用 `watchdog` 唤醒 `dequeue`,并在移除时清理队列中的报文。给出速率和队列上限后,它把报文存起来,到点再放,最后报告入队、发送和丢包统计。这个例子用一条聚合 FIFO 展示 `skb` 所有权、发送时序和 qdisc 清理,适合在 `veth`、`TAP` 或 `IFB` 这类受控接口上观察完整流程。
|
||||
|
||||
> 完整源码:<https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/53-egress-pacer>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user