diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2011-01-19 14:26:56 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-01-20 02:31:12 -0500 |
commit | cc7ec456f82da7f89a5b376e613b3ac4311b3e9a (patch) | |
tree | 534729db08c10f40c090261cdc191dd2303dfc5c /net/sched/sch_htb.c | |
parent | 7180a03118cac7256fb04f929fe34d0aeee92c40 (diff) |
net_sched: cleanups
Cleanup net/sched code to current CodingStyle and practices.
Reduce inline abuse
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sched/sch_htb.c')
-rw-r--r-- | net/sched/sch_htb.c | 104 |
1 files changed, 61 insertions, 43 deletions
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 984c1b0c6836..3e86fd3a1b78 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c | |||
@@ -99,9 +99,10 @@ struct htb_class { | |||
99 | struct rb_root feed[TC_HTB_NUMPRIO]; /* feed trees */ | 99 | struct rb_root feed[TC_HTB_NUMPRIO]; /* feed trees */ |
100 | struct rb_node *ptr[TC_HTB_NUMPRIO]; /* current class ptr */ | 100 | struct rb_node *ptr[TC_HTB_NUMPRIO]; /* current class ptr */ |
101 | /* When class changes from state 1->2 and disconnects from | 101 | /* When class changes from state 1->2 and disconnects from |
102 | parent's feed then we lost ptr value and start from the | 102 | * parent's feed then we lost ptr value and start from the |
103 | first child again. Here we store classid of the | 103 | * first child again. Here we store classid of the |
104 | last valid ptr (used when ptr is NULL). */ | 104 | * last valid ptr (used when ptr is NULL). |
105 | */ | ||
105 | u32 last_ptr_id[TC_HTB_NUMPRIO]; | 106 | u32 last_ptr_id[TC_HTB_NUMPRIO]; |
106 | } inner; | 107 | } inner; |
107 | } un; | 108 | } un; |
@@ -185,7 +186,7 @@ static inline struct htb_class *htb_find(u32 handle, struct Qdisc *sch) | |||
185 | * have no valid leaf we try to use MAJOR:default leaf. It still unsuccessfull | 186 | * have no valid leaf we try to use MAJOR:default leaf. It still unsuccessfull |
186 | * then finish and return direct queue. | 187 | * then finish and return direct queue. |
187 | */ | 188 | */ |
188 | #define HTB_DIRECT (struct htb_class*)-1 | 189 | #define HTB_DIRECT ((struct htb_class *)-1L) |
189 | 190 | ||
190 | static struct htb_class *htb_classify(struct sk_buff *skb, struct Qdisc *sch, | 191 | static struct htb_class *htb_classify(struct sk_buff *skb, struct Qdisc *sch, |
191 | int *qerr) | 192 | int *qerr) |
@@ -197,11 +198,13 @@ static struct htb_class *htb_classify(struct sk_buff *skb, struct Qdisc *sch, | |||
197 | int result; | 198 | int result; |
198 | 199 | ||
199 | /* allow to select class by setting skb->priority to valid classid; | 200 | /* allow to select class by setting skb->priority to valid classid; |
200 | note that nfmark can be used too by attaching filter fw with no | 201 | * note that nfmark can be used too by attaching filter fw with no |
201 | rules in it */ | 202 | * rules in it |
203 | */ | ||
202 | if (skb->priority == sch->handle) | 204 | if (skb->priority == sch->handle) |
203 | return HTB_DIRECT; /* X:0 (direct flow) selected */ | 205 | return HTB_DIRECT; /* X:0 (direct flow) selected */ |
204 | if ((cl = htb_find(skb->priority, sch)) != NULL && cl->level == 0) | 206 | cl = htb_find(skb->priority, sch); |
207 | if (cl && cl->level == 0) | ||
205 | return cl; | 208 | return cl; |
206 | 209 | ||
207 | *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; | 210 | *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; |
@@ -216,10 +219,12 @@ static struct htb_class *htb_classify(struct sk_buff *skb, struct Qdisc *sch, | |||
216 | return NULL; | 219 | return NULL; |
217 | } | 220 | } |
218 | #endif | 221 | #endif |
219 | if ((cl = (void *)res.class) == NULL) { | 222 | cl = (void *)res.class; |
223 | if (!cl) { | ||
220 | if (res.classid == sch->handle) | 224 | if (res.classid == sch->handle) |
221 | return HTB_DIRECT; /* X:0 (direct flow) */ | 225 | return HTB_DIRECT; /* X:0 (direct flow) */ |
222 | if ((cl = htb_find(res.classid, sch)) == NULL) | 226 | cl = htb_find(res.classid, sch); |
227 | if (!cl) | ||
223 | break; /* filter selected invalid classid */ | 228 | break; /* filter selected invalid classid */ |
224 | } | 229 | } |
225 | if (!cl->level) | 230 | if (!cl->level) |
@@ -378,7 +383,8 @@ static void htb_activate_prios(struct htb_sched *q, struct htb_class *cl) | |||
378 | 383 | ||
379 | if (p->un.inner.feed[prio].rb_node) | 384 | if (p->un.inner.feed[prio].rb_node) |
380 | /* parent already has its feed in use so that | 385 | /* parent already has its feed in use so that |
381 | reset bit in mask as parent is already ok */ | 386 | * reset bit in mask as parent is already ok |
387 | */ | ||
382 | mask &= ~(1 << prio); | 388 | mask &= ~(1 << prio); |
383 | 389 | ||
384 | htb_add_to_id_tree(p->un.inner.feed + prio, cl, prio); | 390 | htb_add_to_id_tree(p->un.inner.feed + prio, cl, prio); |
@@ -413,8 +419,9 @@ static void htb_deactivate_prios(struct htb_sched *q, struct htb_class *cl) | |||
413 | 419 | ||
414 | if (p->un.inner.ptr[prio] == cl->node + prio) { | 420 | if (p->un.inner.ptr[prio] == cl->node + prio) { |
415 | /* we are removing child which is pointed to from | 421 | /* we are removing child which is pointed to from |
416 | parent feed - forget the pointer but remember | 422 | * parent feed - forget the pointer but remember |
417 | classid */ | 423 | * classid |
424 | */ | ||
418 | p->un.inner.last_ptr_id[prio] = cl->common.classid; | 425 | p->un.inner.last_ptr_id[prio] = cl->common.classid; |
419 | p->un.inner.ptr[prio] = NULL; | 426 | p->un.inner.ptr[prio] = NULL; |
420 | } | 427 | } |
@@ -664,8 +671,9 @@ static psched_time_t htb_do_events(struct htb_sched *q, int level, | |||
664 | unsigned long start) | 671 | unsigned long start) |
665 | { | 672 | { |
666 | /* don't run for longer than 2 jiffies; 2 is used instead of | 673 | /* don't run for longer than 2 jiffies; 2 is used instead of |
667 | 1 to simplify things when jiffy is going to be incremented | 674 | * 1 to simplify things when jiffy is going to be incremented |
668 | too soon */ | 675 | * too soon |
676 | */ | ||
669 | unsigned long stop_at = start + 2; | 677 | unsigned long stop_at = start + 2; |
670 | while (time_before(jiffies, stop_at)) { | 678 | while (time_before(jiffies, stop_at)) { |
671 | struct htb_class *cl; | 679 | struct htb_class *cl; |
@@ -688,7 +696,7 @@ static psched_time_t htb_do_events(struct htb_sched *q, int level, | |||
688 | 696 | ||
689 | /* too much load - let's continue after a break for scheduling */ | 697 | /* too much load - let's continue after a break for scheduling */ |
690 | if (!(q->warned & HTB_WARN_TOOMANYEVENTS)) { | 698 | if (!(q->warned & HTB_WARN_TOOMANYEVENTS)) { |
691 | printk(KERN_WARNING "htb: too many events!\n"); | 699 | pr_warning("htb: too many events!\n"); |
692 | q->warned |= HTB_WARN_TOOMANYEVENTS; | 700 | q->warned |= HTB_WARN_TOOMANYEVENTS; |
693 | } | 701 | } |
694 | 702 | ||
@@ -696,7 +704,8 @@ static psched_time_t htb_do_events(struct htb_sched *q, int level, | |||
696 | } | 704 | } |
697 | 705 | ||
698 | /* Returns class->node+prio from id-tree where classe's id is >= id. NULL | 706 | /* Returns class->node+prio from id-tree where classe's id is >= id. NULL |
699 | is no such one exists. */ | 707 | * is no such one exists. |
708 | */ | ||
700 | static struct rb_node *htb_id_find_next_upper(int prio, struct rb_node *n, | 709 | static struct rb_node *htb_id_find_next_upper(int prio, struct rb_node *n, |
701 | u32 id) | 710 | u32 id) |
702 | { | 711 | { |
@@ -740,12 +749,14 @@ static struct htb_class *htb_lookup_leaf(struct rb_root *tree, int prio, | |||
740 | for (i = 0; i < 65535; i++) { | 749 | for (i = 0; i < 65535; i++) { |
741 | if (!*sp->pptr && *sp->pid) { | 750 | if (!*sp->pptr && *sp->pid) { |
742 | /* ptr was invalidated but id is valid - try to recover | 751 | /* ptr was invalidated but id is valid - try to recover |
743 | the original or next ptr */ | 752 | * the original or next ptr |
753 | */ | ||
744 | *sp->pptr = | 754 | *sp->pptr = |
745 | htb_id_find_next_upper(prio, sp->root, *sp->pid); | 755 | htb_id_find_next_upper(prio, sp->root, *sp->pid); |
746 | } | 756 | } |
747 | *sp->pid = 0; /* ptr is valid now so that remove this hint as it | 757 | *sp->pid = 0; /* ptr is valid now so that remove this hint as it |
748 | can become out of date quickly */ | 758 | * can become out of date quickly |
759 | */ | ||
749 | if (!*sp->pptr) { /* we are at right end; rewind & go up */ | 760 | if (!*sp->pptr) { /* we are at right end; rewind & go up */ |
750 | *sp->pptr = sp->root; | 761 | *sp->pptr = sp->root; |
751 | while ((*sp->pptr)->rb_left) | 762 | while ((*sp->pptr)->rb_left) |
@@ -773,7 +784,8 @@ static struct htb_class *htb_lookup_leaf(struct rb_root *tree, int prio, | |||
773 | } | 784 | } |
774 | 785 | ||
775 | /* dequeues packet at given priority and level; call only if | 786 | /* dequeues packet at given priority and level; call only if |
776 | you are sure that there is active class at prio/level */ | 787 | * you are sure that there is active class at prio/level |
788 | */ | ||
777 | static struct sk_buff *htb_dequeue_tree(struct htb_sched *q, int prio, | 789 | static struct sk_buff *htb_dequeue_tree(struct htb_sched *q, int prio, |
778 | int level) | 790 | int level) |
779 | { | 791 | { |
@@ -790,9 +802,10 @@ next: | |||
790 | return NULL; | 802 | return NULL; |
791 | 803 | ||
792 | /* class can be empty - it is unlikely but can be true if leaf | 804 | /* class can be empty - it is unlikely but can be true if leaf |
793 | qdisc drops packets in enqueue routine or if someone used | 805 | * qdisc drops packets in enqueue routine or if someone used |
794 | graft operation on the leaf since last dequeue; | 806 | * graft operation on the leaf since last dequeue; |
795 | simply deactivate and skip such class */ | 807 | * simply deactivate and skip such class |
808 | */ | ||
796 | if (unlikely(cl->un.leaf.q->q.qlen == 0)) { | 809 | if (unlikely(cl->un.leaf.q->q.qlen == 0)) { |
797 | struct htb_class *next; | 810 | struct htb_class *next; |
798 | htb_deactivate(q, cl); | 811 | htb_deactivate(q, cl); |
@@ -832,7 +845,8 @@ next: | |||
832 | ptr[0]) + prio); | 845 | ptr[0]) + prio); |
833 | } | 846 | } |
834 | /* this used to be after charge_class but this constelation | 847 | /* this used to be after charge_class but this constelation |
835 | gives us slightly better performance */ | 848 | * gives us slightly better performance |
849 | */ | ||
836 | if (!cl->un.leaf.q->q.qlen) | 850 | if (!cl->un.leaf.q->q.qlen) |
837 | htb_deactivate(q, cl); | 851 | htb_deactivate(q, cl); |
838 | htb_charge_class(q, cl, level, skb); | 852 | htb_charge_class(q, cl, level, skb); |
@@ -882,6 +896,7 @@ static struct sk_buff *htb_dequeue(struct Qdisc *sch) | |||
882 | m = ~q->row_mask[level]; | 896 | m = ~q->row_mask[level]; |
883 | while (m != (int)(-1)) { | 897 | while (m != (int)(-1)) { |
884 | int prio = ffz(m); | 898 | int prio = ffz(m); |
899 | |||
885 | m |= 1 << prio; | 900 | m |= 1 << prio; |
886 | skb = htb_dequeue_tree(q, prio, level); | 901 | skb = htb_dequeue_tree(q, prio, level); |
887 | if (likely(skb != NULL)) { | 902 | if (likely(skb != NULL)) { |
@@ -989,13 +1004,12 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt) | |||
989 | return err; | 1004 | return err; |
990 | 1005 | ||
991 | if (tb[TCA_HTB_INIT] == NULL) { | 1006 | if (tb[TCA_HTB_INIT] == NULL) { |
992 | printk(KERN_ERR "HTB: hey probably you have bad tc tool ?\n"); | 1007 | pr_err("HTB: hey probably you have bad tc tool ?\n"); |
993 | return -EINVAL; | 1008 | return -EINVAL; |
994 | } | 1009 | } |
995 | gopt = nla_data(tb[TCA_HTB_INIT]); | 1010 | gopt = nla_data(tb[TCA_HTB_INIT]); |
996 | if (gopt->version != HTB_VER >> 16) { | 1011 | if (gopt->version != HTB_VER >> 16) { |
997 | printk(KERN_ERR | 1012 | pr_err("HTB: need tc/htb version %d (minor is %d), you have %d\n", |
998 | "HTB: need tc/htb version %d (minor is %d), you have %d\n", | ||
999 | HTB_VER >> 16, HTB_VER & 0xffff, gopt->version); | 1013 | HTB_VER >> 16, HTB_VER & 0xffff, gopt->version); |
1000 | return -EINVAL; | 1014 | return -EINVAL; |
1001 | } | 1015 | } |
@@ -1208,9 +1222,10 @@ static void htb_destroy(struct Qdisc *sch) | |||
1208 | cancel_work_sync(&q->work); | 1222 | cancel_work_sync(&q->work); |
1209 | qdisc_watchdog_cancel(&q->watchdog); | 1223 | qdisc_watchdog_cancel(&q->watchdog); |
1210 | /* This line used to be after htb_destroy_class call below | 1224 | /* This line used to be after htb_destroy_class call below |
1211 | and surprisingly it worked in 2.4. But it must precede it | 1225 | * and surprisingly it worked in 2.4. But it must precede it |
1212 | because filter need its target class alive to be able to call | 1226 | * because filter need its target class alive to be able to call |
1213 | unbind_filter on it (without Oops). */ | 1227 | * unbind_filter on it (without Oops). |
1228 | */ | ||
1214 | tcf_destroy_chain(&q->filter_list); | 1229 | tcf_destroy_chain(&q->filter_list); |
1215 | 1230 | ||
1216 | for (i = 0; i < q->clhash.hashsize; i++) { | 1231 | for (i = 0; i < q->clhash.hashsize; i++) { |
@@ -1344,11 +1359,12 @@ static int htb_change_class(struct Qdisc *sch, u32 classid, | |||
1344 | 1359 | ||
1345 | /* check maximal depth */ | 1360 | /* check maximal depth */ |
1346 | if (parent && parent->parent && parent->parent->level < 2) { | 1361 | if (parent && parent->parent && parent->parent->level < 2) { |
1347 | printk(KERN_ERR "htb: tree is too deep\n"); | 1362 | pr_err("htb: tree is too deep\n"); |
1348 | goto failure; | 1363 | goto failure; |
1349 | } | 1364 | } |
1350 | err = -ENOBUFS; | 1365 | err = -ENOBUFS; |
1351 | if ((cl = kzalloc(sizeof(*cl), GFP_KERNEL)) == NULL) | 1366 | cl = kzalloc(sizeof(*cl), GFP_KERNEL); |
1367 | if (!cl) | ||
1352 | goto failure; | 1368 | goto failure; |
1353 | 1369 | ||
1354 | err = gen_new_estimator(&cl->bstats, &cl->rate_est, | 1370 | err = gen_new_estimator(&cl->bstats, &cl->rate_est, |
@@ -1368,8 +1384,9 @@ static int htb_change_class(struct Qdisc *sch, u32 classid, | |||
1368 | RB_CLEAR_NODE(&cl->node[prio]); | 1384 | RB_CLEAR_NODE(&cl->node[prio]); |
1369 | 1385 | ||
1370 | /* create leaf qdisc early because it uses kmalloc(GFP_KERNEL) | 1386 | /* create leaf qdisc early because it uses kmalloc(GFP_KERNEL) |
1371 | so that can't be used inside of sch_tree_lock | 1387 | * so that can't be used inside of sch_tree_lock |
1372 | -- thanks to Karlis Peisenieks */ | 1388 | * -- thanks to Karlis Peisenieks |
1389 | */ | ||
1373 | new_q = qdisc_create_dflt(sch->dev_queue, | 1390 | new_q = qdisc_create_dflt(sch->dev_queue, |
1374 | &pfifo_qdisc_ops, classid); | 1391 | &pfifo_qdisc_ops, classid); |
1375 | sch_tree_lock(sch); | 1392 | sch_tree_lock(sch); |
@@ -1421,17 +1438,18 @@ static int htb_change_class(struct Qdisc *sch, u32 classid, | |||
1421 | } | 1438 | } |
1422 | 1439 | ||
1423 | /* it used to be a nasty bug here, we have to check that node | 1440 | /* it used to be a nasty bug here, we have to check that node |
1424 | is really leaf before changing cl->un.leaf ! */ | 1441 | * is really leaf before changing cl->un.leaf ! |
1442 | */ | ||
1425 | if (!cl->level) { | 1443 | if (!cl->level) { |
1426 | cl->quantum = rtab->rate.rate / q->rate2quantum; | 1444 | cl->quantum = rtab->rate.rate / q->rate2quantum; |
1427 | if (!hopt->quantum && cl->quantum < 1000) { | 1445 | if (!hopt->quantum && cl->quantum < 1000) { |
1428 | printk(KERN_WARNING | 1446 | pr_warning( |
1429 | "HTB: quantum of class %X is small. Consider r2q change.\n", | 1447 | "HTB: quantum of class %X is small. Consider r2q change.\n", |
1430 | cl->common.classid); | 1448 | cl->common.classid); |
1431 | cl->quantum = 1000; | 1449 | cl->quantum = 1000; |
1432 | } | 1450 | } |
1433 | if (!hopt->quantum && cl->quantum > 200000) { | 1451 | if (!hopt->quantum && cl->quantum > 200000) { |
1434 | printk(KERN_WARNING | 1452 | pr_warning( |
1435 | "HTB: quantum of class %X is big. Consider r2q change.\n", | 1453 | "HTB: quantum of class %X is big. Consider r2q change.\n", |
1436 | cl->common.classid); | 1454 | cl->common.classid); |
1437 | cl->quantum = 200000; | 1455 | cl->quantum = 200000; |
@@ -1480,13 +1498,13 @@ static unsigned long htb_bind_filter(struct Qdisc *sch, unsigned long parent, | |||
1480 | struct htb_class *cl = htb_find(classid, sch); | 1498 | struct htb_class *cl = htb_find(classid, sch); |
1481 | 1499 | ||
1482 | /*if (cl && !cl->level) return 0; | 1500 | /*if (cl && !cl->level) return 0; |
1483 | The line above used to be there to prevent attaching filters to | 1501 | * The line above used to be there to prevent attaching filters to |
1484 | leaves. But at least tc_index filter uses this just to get class | 1502 | * leaves. But at least tc_index filter uses this just to get class |
1485 | for other reasons so that we have to allow for it. | 1503 | * for other reasons so that we have to allow for it. |
1486 | ---- | 1504 | * ---- |
1487 | 19.6.2002 As Werner explained it is ok - bind filter is just | 1505 | * 19.6.2002 As Werner explained it is ok - bind filter is just |
1488 | another way to "lock" the class - unlike "get" this lock can | 1506 | * another way to "lock" the class - unlike "get" this lock can |
1489 | be broken by class during destroy IIUC. | 1507 | * be broken by class during destroy IIUC. |
1490 | */ | 1508 | */ |
1491 | if (cl) | 1509 | if (cl) |
1492 | cl->filter_cnt++; | 1510 | cl->filter_cnt++; |