Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07d79fc7 authored by Cong Wang's avatar Cong Wang Committed by David S. Miller
Browse files

net_sched: add reverse binding for tc class



TC filters when used as classifiers are bound to TC classes.
However, there is a hidden difference when adding them in different
orders:

1. If we add tc classes before its filters, everything is fine.
   Logically, the classes exist before we specify their ID's in
   filters, it is easy to bind them together, just as in the current
   code base.

2. If we add tc filters before the tc classes they bind, we have to
   do dynamic lookup in fast path. What's worse, this happens all
   the time not just once, because on fast path tcf_result is passed
   on stack, there is no way to propagate back to the one in tc filters.

This hidden difference hurts performance silently if we have many tc
classes in hierarchy.

This patch intends to close this gap by doing the reverse binding when
we create a new class, in this case we can actually search all the
filters in its parent, match and fixup by classid. And because
tcf_result is specific to each type of tc filter, we have to introduce
a new ops for each filter to tell how to bind the class.

Note, we still can NOT totally get rid of those class lookup in
->enqueue() because cgroup and flow filters have no way to determine
the classid at setup time, they still have to go through dynamic lookup.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ea3100ab
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -217,6 +217,7 @@ struct tcf_proto_ops {
					void **, bool);
	int			(*delete)(struct tcf_proto*, void *, bool*);
	void			(*walk)(struct tcf_proto*, struct tcf_walker *arg);
	void			(*bind_class)(void *, u32, unsigned long);

	/* rtnetlink specific */
	int			(*dump)(struct net*, struct tcf_proto*, void *,
+9 −0
Original line number Diff line number Diff line
@@ -235,6 +235,14 @@ static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg)
	}
}

static void basic_bind_class(void *fh, u32 classid, unsigned long cl)
{
	struct basic_filter *f = fh;

	if (f && f->res.classid == classid)
		f->res.class = cl;
}

static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh,
		      struct sk_buff *skb, struct tcmsg *t)
{
@@ -280,6 +288,7 @@ static struct tcf_proto_ops cls_basic_ops __read_mostly = {
	.delete		=	basic_delete,
	.walk		=	basic_walk,
	.dump		=	basic_dump,
	.bind_class	=	basic_bind_class,
	.owner		=	THIS_MODULE,
};

+9 −0
Original line number Diff line number Diff line
@@ -607,6 +607,14 @@ static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, void *fh,
	return -1;
}

static void cls_bpf_bind_class(void *fh, u32 classid, unsigned long cl)
{
	struct cls_bpf_prog *prog = fh;

	if (prog && prog->res.classid == classid)
		prog->res.class = cl;
}

static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg)
{
	struct cls_bpf_head *head = rtnl_dereference(tp->root);
@@ -635,6 +643,7 @@ static struct tcf_proto_ops cls_bpf_ops __read_mostly = {
	.delete		=	cls_bpf_delete,
	.walk		=	cls_bpf_walk,
	.dump		=	cls_bpf_dump,
	.bind_class	=	cls_bpf_bind_class,
};

static int __init cls_bpf_init_mod(void)
+9 −0
Original line number Diff line number Diff line
@@ -1351,6 +1351,14 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
	return -1;
}

static void fl_bind_class(void *fh, u32 classid, unsigned long cl)
{
	struct cls_fl_filter *f = fh;

	if (f && f->res.classid == classid)
		f->res.class = cl;
}

static struct tcf_proto_ops cls_fl_ops __read_mostly = {
	.kind		= "flower",
	.classify	= fl_classify,
@@ -1361,6 +1369,7 @@ static struct tcf_proto_ops cls_fl_ops __read_mostly = {
	.delete		= fl_delete,
	.walk		= fl_walk,
	.dump		= fl_dump,
	.bind_class	= fl_bind_class,
	.owner		= THIS_MODULE,
};

+9 −0
Original line number Diff line number Diff line
@@ -412,6 +412,14 @@ static int fw_dump(struct net *net, struct tcf_proto *tp, void *fh,
	return -1;
}

static void fw_bind_class(void *fh, u32 classid, unsigned long cl)
{
	struct fw_filter *f = fh;

	if (f && f->res.classid == classid)
		f->res.class = cl;
}

static struct tcf_proto_ops cls_fw_ops __read_mostly = {
	.kind		=	"fw",
	.classify	=	fw_classify,
@@ -422,6 +430,7 @@ static struct tcf_proto_ops cls_fw_ops __read_mostly = {
	.delete		=	fw_delete,
	.walk		=	fw_walk,
	.dump		=	fw_dump,
	.bind_class	=	fw_bind_class,
	.owner		=	THIS_MODULE,
};

Loading