Skip to content

Commit 07d79fc

Browse files
congwangdavem330
authored andcommitted
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: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ea3100a commit 07d79fc

11 files changed

Lines changed: 148 additions & 2 deletions

File tree

‎include/net/sch_generic.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ struct tcf_proto_ops {
217217
void **, bool);
218218
int (*delete)(struct tcf_proto*, void *, bool*);
219219
void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
220+
void (*bind_class)(void *, u32, unsigned long);
220221

221222
/* rtnetlink specific */
222223
int (*dump)(struct net*, struct tcf_proto*, void *,

‎net/sched/cls_basic.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg)
235235
}
236236
}
237237

238+
static void basic_bind_class(void *fh, u32 classid, unsigned long cl)
239+
{
240+
struct basic_filter *f = fh;
241+
242+
if (f && f->res.classid == classid)
243+
f->res.class = cl;
244+
}
245+
238246
static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh,
239247
struct sk_buff *skb, struct tcmsg *t)
240248
{
@@ -280,6 +288,7 @@ static struct tcf_proto_ops cls_basic_ops __read_mostly = {
280288
.delete = basic_delete,
281289
.walk = basic_walk,
282290
.dump = basic_dump,
291+
.bind_class = basic_bind_class,
283292
.owner = THIS_MODULE,
284293
};
285294

‎net/sched/cls_bpf.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,14 @@ static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, void *fh,
607607
return -1;
608608
}
609609

610+
static void cls_bpf_bind_class(void *fh, u32 classid, unsigned long cl)
611+
{
612+
struct cls_bpf_prog *prog = fh;
613+
614+
if (prog && prog->res.classid == classid)
615+
prog->res.class = cl;
616+
}
617+
610618
static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg)
611619
{
612620
struct cls_bpf_head *head = rtnl_dereference(tp->root);
@@ -635,6 +643,7 @@ static struct tcf_proto_ops cls_bpf_ops __read_mostly = {
635643
.delete = cls_bpf_delete,
636644
.walk = cls_bpf_walk,
637645
.dump = cls_bpf_dump,
646+
.bind_class = cls_bpf_bind_class,
638647
};
639648

640649
static int __init cls_bpf_init_mod(void)

‎net/sched/cls_flower.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,14 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
13511351
return -1;
13521352
}
13531353

1354+
static void fl_bind_class(void *fh, u32 classid, unsigned long cl)
1355+
{
1356+
struct cls_fl_filter *f = fh;
1357+
1358+
if (f && f->res.classid == classid)
1359+
f->res.class = cl;
1360+
}
1361+
13541362
static struct tcf_proto_ops cls_fl_ops __read_mostly = {
13551363
.kind = "flower",
13561364
.classify = fl_classify,
@@ -1361,6 +1369,7 @@ static struct tcf_proto_ops cls_fl_ops __read_mostly = {
13611369
.delete = fl_delete,
13621370
.walk = fl_walk,
13631371
.dump = fl_dump,
1372+
.bind_class = fl_bind_class,
13641373
.owner = THIS_MODULE,
13651374
};
13661375

‎net/sched/cls_fw.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,14 @@ static int fw_dump(struct net *net, struct tcf_proto *tp, void *fh,
412412
return -1;
413413
}
414414

415+
static void fw_bind_class(void *fh, u32 classid, unsigned long cl)
416+
{
417+
struct fw_filter *f = fh;
418+
419+
if (f && f->res.classid == classid)
420+
f->res.class = cl;
421+
}
422+
415423
static struct tcf_proto_ops cls_fw_ops __read_mostly = {
416424
.kind = "fw",
417425
.classify = fw_classify,
@@ -422,6 +430,7 @@ static struct tcf_proto_ops cls_fw_ops __read_mostly = {
422430
.delete = fw_delete,
423431
.walk = fw_walk,
424432
.dump = fw_dump,
433+
.bind_class = fw_bind_class,
425434
.owner = THIS_MODULE,
426435
};
427436

‎net/sched/cls_matchall.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh,
251251
return -1;
252252
}
253253

254+
static void mall_bind_class(void *fh, u32 classid, unsigned long cl)
255+
{
256+
struct cls_mall_head *head = fh;
257+
258+
if (head && head->res.classid == classid)
259+
head->res.class = cl;
260+
}
261+
254262
static struct tcf_proto_ops cls_mall_ops __read_mostly = {
255263
.kind = "matchall",
256264
.classify = mall_classify,
@@ -261,6 +269,7 @@ static struct tcf_proto_ops cls_mall_ops __read_mostly = {
261269
.delete = mall_delete,
262270
.walk = mall_walk,
263271
.dump = mall_dump,
272+
.bind_class = mall_bind_class,
264273
.owner = THIS_MODULE,
265274
};
266275

‎net/sched/cls_route.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,14 @@ static int route4_dump(struct net *net, struct tcf_proto *tp, void *fh,
624624
return -1;
625625
}
626626

627+
static void route4_bind_class(void *fh, u32 classid, unsigned long cl)
628+
{
629+
struct route4_filter *f = fh;
630+
631+
if (f && f->res.classid == classid)
632+
f->res.class = cl;
633+
}
634+
627635
static struct tcf_proto_ops cls_route4_ops __read_mostly = {
628636
.kind = "route",
629637
.classify = route4_classify,
@@ -634,6 +642,7 @@ static struct tcf_proto_ops cls_route4_ops __read_mostly = {
634642
.delete = route4_delete,
635643
.walk = route4_walk,
636644
.dump = route4_dump,
645+
.bind_class = route4_bind_class,
637646
.owner = THIS_MODULE,
638647
};
639648

‎net/sched/cls_rsvp.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,14 @@ static int rsvp_dump(struct net *net, struct tcf_proto *tp, void *fh,
723723
return -1;
724724
}
725725

726+
static void rsvp_bind_class(void *fh, u32 classid, unsigned long cl)
727+
{
728+
struct rsvp_filter *f = fh;
729+
730+
if (f && f->res.classid == classid)
731+
f->res.class = cl;
732+
}
733+
726734
static struct tcf_proto_ops RSVP_OPS __read_mostly = {
727735
.kind = RSVP_ID,
728736
.classify = rsvp_classify,
@@ -733,6 +741,7 @@ static struct tcf_proto_ops RSVP_OPS __read_mostly = {
733741
.delete = rsvp_delete,
734742
.walk = rsvp_walk,
735743
.dump = rsvp_dump,
744+
.bind_class = rsvp_bind_class,
736745
.owner = THIS_MODULE,
737746
};
738747

‎net/sched/cls_tcindex.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,14 @@ static int tcindex_dump(struct net *net, struct tcf_proto *tp, void *fh,
606606
return -1;
607607
}
608608

609+
static void tcindex_bind_class(void *fh, u32 classid, unsigned long cl)
610+
{
611+
struct tcindex_filter_result *r = fh;
612+
613+
if (r && r->res.classid == classid)
614+
r->res.class = cl;
615+
}
616+
609617
static struct tcf_proto_ops cls_tcindex_ops __read_mostly = {
610618
.kind = "tcindex",
611619
.classify = tcindex_classify,
@@ -616,6 +624,7 @@ static struct tcf_proto_ops cls_tcindex_ops __read_mostly = {
616624
.delete = tcindex_delete,
617625
.walk = tcindex_walk,
618626
.dump = tcindex_dump,
627+
.bind_class = tcindex_bind_class,
619628
.owner = THIS_MODULE,
620629
};
621630

‎net/sched/cls_u32.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,14 @@ static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg)
11121112
}
11131113
}
11141114

1115+
static void u32_bind_class(void *fh, u32 classid, unsigned long cl)
1116+
{
1117+
struct tc_u_knode *n = fh;
1118+
1119+
if (n && n->res.classid == classid)
1120+
n->res.class = cl;
1121+
}
1122+
11151123
static int u32_dump(struct net *net, struct tcf_proto *tp, void *fh,
11161124
struct sk_buff *skb, struct tcmsg *t)
11171125
{
@@ -1242,6 +1250,7 @@ static struct tcf_proto_ops cls_u32_ops __read_mostly = {
12421250
.delete = u32_delete,
12431251
.walk = u32_walk,
12441252
.dump = u32_dump,
1253+
.bind_class = u32_bind_class,
12451254
.owner = THIS_MODULE,
12461255
};
12471256

0 commit comments

Comments
 (0)