forked from torvalds/linux
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
net_sched: introduce eBPF based Qdisc
This *incomplete* patch introduces a programmable Qdisc with eBPF. The goal is to make this Qdisc as programmable as possible, that is, to replace as many existing Qdisc's as we can, no matter in tree or out of tree. And we want to make programmer's and researcher's life as easy as possible, so that they don't have to write a complete Qdisc kernel module just to experiment some queuing theory. The design was discussed during last LPC: https://linuxplumbersconf.org/event/7/contributions/679/attachments/520/1188/sch_bpf.pdf Here is a summary of design decisions I made: 1. Avoid eBPF struct_ops, as it would be really hard to program a Qdisc with this approach, literally all the struct Qdisc_ops and struct Qdisc_class_ops are needed to implement. This is almost as hard as programming a Qdisc kernel module. 2. Avoid exposing skb's to user-space, which means we don't introduce a map to store skb's. Instead, store them in kernel without exposure to user-space. There are three different reasons behind this: 2a) User-space does not need to read skb, there is no use case to let user-space make decisions, so far. 2b) Kernel would lose the visibility of the "queues", as maps are only shared between eBPF programs and user-space. These queues still have to interact with the kernel, for example, kernel wants to reset all queues when we reset the network interface, kernel wants to adjust number of queues if they are mapped to hardware queues. 2c) It is harder to interact with existing TC infra. See below. 3. Integrate with existing TC infra. For example, if the user doesn't want to implement her own filters (e.g. a flow dissector), she should be able to re-use the existing TC filters. And each queue can be easily mapped to a TC class and dump its stats easily via netlink. Users can use this Qdisc together with any other Qdisc's too, pretty much like a regular Qdisc. So I choose to use priority queues to store skb's inside a flow and to store flows inside a Qdisc, and let eBPF programs decide the *relative* position of the skb within the flow and the *relative* order of the flows too, upon each enqueue and dequeue. Each flow is also exposed to user as a TC class, like many other classful Qdisc's. Although the biggest limitation is obviously that users can not traverse the packets or flows inside the Qdisc, I think at least they could store those global information of interest inside their own hashmap. Any high-level feedbacks are welcome. Please do not review any coding details until RFC tag is removed. TODO: 1. actually test it 2. write a document for this Qdisc 3. add test cases and sample code Cc: Jamal Hadi Salim <jhs@mojatatu.com> Cc: Jiri Pirko <jiri@resnulli.us> Signed-off-by: Cong Wang <cong.wang@bytedance.com>
- Loading branch information
1 parent
13bb842
commit 11b7d639a3edc1182a3027ae62cc35dcf0924178
Showing
8 changed files
with
754 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // SPDX-License-Identifier: GPL-2.0 | ||
| /* | ||
| * A priority queue implementation based on rbtree | ||
| * | ||
| * Copyright (C) 2021, Bytedance, Cong Wang <cong.wang@bytedance.com> | ||
| */ | ||
|
|
||
| #ifndef _LINUX_PRIORITY_QUEUE_H | ||
| #define _LINUX_PRIORITY_QUEUE_H | ||
|
|
||
| #include <linux/rbtree.h> | ||
|
|
||
| struct pq_node { | ||
| struct rb_node rb_node; | ||
| }; | ||
|
|
||
| struct pq_root { | ||
| struct rb_root_cached rb_root; | ||
| bool (*cmp)(struct pq_node *l, struct pq_node *r); | ||
| }; | ||
|
|
||
| static inline void pq_root_init(struct pq_root *root, | ||
| bool (*cmp)(struct pq_node *l, struct pq_node *r)) | ||
| { | ||
| root->rb_root = RB_ROOT_CACHED; | ||
| root->cmp = cmp; | ||
| } | ||
|
|
||
| static inline void pq_push(struct pq_root *root, struct pq_node *node) | ||
| { | ||
| struct rb_node **link = &root->rb_root.rb_root.rb_node; | ||
| struct rb_node *parent = NULL; | ||
| struct pq_node *entry; | ||
| bool leftmost = true; | ||
|
|
||
| /* | ||
| * Find the right place in the rbtree: | ||
| */ | ||
| while (*link) { | ||
| parent = *link; | ||
| entry = rb_entry(parent, struct pq_node, rb_node); | ||
| /* | ||
| * We dont care about collisions. Nodes with | ||
| * the same key stay together. | ||
| */ | ||
| if (root->cmp(entry, node)) { | ||
| link = &parent->rb_left; | ||
| } else { | ||
| link = &parent->rb_right; | ||
| leftmost = false; | ||
| } | ||
| } | ||
|
|
||
| rb_link_node(&node->rb_node, parent, link); | ||
| rb_insert_color_cached(&node->rb_node, &root->rb_root, leftmost); | ||
| } | ||
|
|
||
| static inline struct pq_node *pq_top(struct pq_root *root) | ||
| { | ||
| struct rb_node *left = rb_first_cached(&root->rb_root); | ||
|
|
||
| if (!left) | ||
| return NULL; | ||
| return rb_entry(left, struct pq_node, rb_node); | ||
| } | ||
|
|
||
| static inline struct pq_node *pq_pop(struct pq_root *root) | ||
| { | ||
| struct pq_node *t = pq_top(root); | ||
|
|
||
| if (t) | ||
| rb_erase_cached(&t->rb_node, &root->rb_root); | ||
| return t; | ||
| } | ||
|
|
||
| static inline void pq_flush(struct pq_root *root, void (*destroy)(struct pq_node *)) | ||
| { | ||
| struct rb_node *node, *next; | ||
|
|
||
| for (node = rb_first(&root->rb_root.rb_root); | ||
| next = node ? rb_next(node) : NULL, node != NULL; | ||
| node = next) { | ||
| struct pq_node *pqe; | ||
|
|
||
| pqe = rb_entry(node, struct pq_node, rb_node); | ||
| if (destroy) | ||
| destroy(pqe); | ||
| } | ||
| } | ||
| #endif /* _LINUX_PRIORITY_QUEUE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.