Skip to content

Commit

Permalink
net_sched: introduce eBPF based Qdisc
Browse files Browse the repository at this point in the history
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
  • Loading branch information
congwang authored and Cong Wang committed Sep 11, 2021
1 parent 90df3fc commit 4705634
Show file tree
Hide file tree
Showing 7 changed files with 683 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/linux/bpf_types.h
Expand Up @@ -8,6 +8,8 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_SCHED_CLS, tc_cls_act,
struct __sk_buff, struct sk_buff)
BPF_PROG_TYPE(BPF_PROG_TYPE_SCHED_ACT, tc_cls_act,
struct __sk_buff, struct sk_buff)
//BPF_PROG_TYPE(BPF_PROG_TYPE_SCHED_QDISC, tc_cls_act,
// struct __sk_buff, struct sk_buff)
BPF_PROG_TYPE(BPF_PROG_TYPE_XDP, xdp,
struct xdp_md, struct xdp_buff)
#ifdef CONFIG_CGROUP_BPF
Expand Down
2 changes: 2 additions & 0 deletions include/linux/skbuff.h
Expand Up @@ -36,6 +36,7 @@
#include <linux/splice.h>
#include <linux/in6.h>
#include <linux/if_packet.h>
#include <linux/priority_queue.h>
#include <net/flow.h>
#include <net/page_pool.h>
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
Expand Down Expand Up @@ -735,6 +736,7 @@ struct sk_buff {
};
};
struct rb_node rbnode; /* used in netem, ip4 defrag, and tcp stack */
struct pq_node pqnode; /* used in ebpf qdisc */
struct list_head list;
};

Expand Down
20 changes: 20 additions & 0 deletions include/uapi/linux/bpf.h
Expand Up @@ -949,6 +949,7 @@ enum bpf_prog_type {
BPF_PROG_TYPE_LSM,
BPF_PROG_TYPE_SK_LOOKUP,
BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
BPF_PROG_TYPE_SCHED_QDISC,
};

enum bpf_attach_type {
Expand Down Expand Up @@ -6260,4 +6261,23 @@ enum {
BTF_F_ZERO = (1ULL << 3),
};

struct sch_bpf_ctx {
/* Input */
struct __sk_buff *skb;
__u32 nr_flows;
__u32 handle;

/* Output */
__u64 rank;
__u64 delay;
__u32 classid;
};

enum {
SCH_BPF_OK,
SCH_BPF_REQUEUE,
SCH_BPF_DROP,
SCH_BPF_THROTTLE,
};

#endif /* _UAPI__LINUX_BPF_H__ */
21 changes: 21 additions & 0 deletions include/uapi/linux/pkt_sched.h
Expand Up @@ -1263,4 +1263,25 @@ enum {

#define TCA_ETS_MAX (__TCA_ETS_MAX - 1)

enum {
TCA_SCH_BPF_UNSPEC,
TCA_SCH_BPF_MODE, /* u32 */
TCA_SCH_BPF_ENQUEUE_PROG_NAME, /* string */
TCA_SCH_BPF_ENQUEUE_PROG_FD, /* u32 */
TCA_SCH_BPF_ENQUEUE_PROG_ID, /* u32 */
TCA_SCH_BPF_ENQUEUE_PROG_TAG, /* data */
TCA_SCH_BPF_DEQUEUE_PROG_NAME, /* string */
TCA_SCH_BPF_DEQUEUE_PROG_FD, /* u32 */
TCA_SCH_BPF_DEQUEUE_PROG_ID, /* u32 */
TCA_SCH_BPF_DEQUEUE_PROG_TAG, /* data */
__TCA_SCH_BPF_MAX,
};

#define TCA_SCH_BPF_MAX (__TCA_SCH_BPF_MAX - 1)

enum {
TCA_SCH_BPF_MODE_DEFAULT,
__TCA_SCH_BPF_MODE_MAX,
};

#endif
15 changes: 15 additions & 0 deletions net/sched/Kconfig
Expand Up @@ -439,6 +439,21 @@ config NET_SCH_ETS

If unsure, say N.

config NET_SCH_BPF
tristate "eBPF based programmable queue discipline"
help
This eBPF based queue discipline offers a way to program your
own packet scheduling algorithm. This is a classful qdisc which
also allows you to decide the hierarchy.

Say Y here if you want to use the eBPF based programmable queue
discipline.

To compile this driver as a module, choose M here: the module
will be called sch_bpf.

If unsure, say N.

menuconfig NET_SCH_DEFAULT
bool "Allow override default queue discipline"
help
Expand Down
1 change: 1 addition & 0 deletions net/sched/Makefile
Expand Up @@ -65,6 +65,7 @@ obj-$(CONFIG_NET_SCH_FQ_PIE) += sch_fq_pie.o
obj-$(CONFIG_NET_SCH_CBS) += sch_cbs.o
obj-$(CONFIG_NET_SCH_ETF) += sch_etf.o
obj-$(CONFIG_NET_SCH_TAPRIO) += sch_taprio.o
obj-$(CONFIG_NET_SCH_BPF) += sch_bpf.o

obj-$(CONFIG_NET_CLS_U32) += cls_u32.o
obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.o
Expand Down

0 comments on commit 4705634

Please sign in to comment.