Skip to content

Commit ee39e10

Browse files
kaberDavid S. Miller
authored andcommitted
[NET_SCHED]: sch_htb: use generic estimator
Use the generic estimator instead of reimplementing (parts of) it. For compatibility always create a default estimator for new classes. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4bdf399 commit ee39e10

1 file changed

Lines changed: 24 additions & 61 deletions

File tree

‎net/sched/sch_htb.c‎

Lines changed: 24 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@
6969
*/
7070

7171
#define HTB_HSIZE 16 /* classid hash size */
72-
#define HTB_EWMAC 2 /* rate average over HTB_EWMAC*HTB_HSIZE sec */
73-
#define HTB_RATECM 1 /* whether to use rate computer */
7472
#define HTB_HYSTERESIS 1 /* whether to use mode hysteresis for speedup */
7573
#define HTB_VER 0x30011 /* major must be matched with number suplied by TC as version */
7674

@@ -95,12 +93,6 @@ struct htb_class {
9593
struct tc_htb_xstats xstats; /* our special stats */
9694
int refcnt; /* usage count of this class */
9795

98-
#ifdef HTB_RATECM
99-
/* rate measurement counters */
100-
unsigned long rate_bytes, sum_bytes;
101-
unsigned long rate_packets, sum_packets;
102-
#endif
103-
10496
/* topology */
10597
int level; /* our level (see above) */
10698
struct htb_class *parent; /* parent class */
@@ -194,10 +186,6 @@ struct htb_sched {
194186
int rate2quantum; /* quant = rate / rate2quantum */
195187
psched_time_t now; /* cached dequeue time */
196188
struct qdisc_watchdog watchdog;
197-
#ifdef HTB_RATECM
198-
struct timer_list rttim; /* rate computer timer */
199-
int recmp_bucket; /* which hash bucket to recompute next */
200-
#endif
201189

202190
/* non shaped skbs; let them go directly thru */
203191
struct sk_buff_head direct_queue;
@@ -677,34 +665,6 @@ static int htb_requeue(struct sk_buff *skb, struct Qdisc *sch)
677665
return NET_XMIT_SUCCESS;
678666
}
679667

680-
#ifdef HTB_RATECM
681-
#define RT_GEN(D,R) R+=D-(R/HTB_EWMAC);D=0
682-
static void htb_rate_timer(unsigned long arg)
683-
{
684-
struct Qdisc *sch = (struct Qdisc *)arg;
685-
struct htb_sched *q = qdisc_priv(sch);
686-
struct hlist_node *p;
687-
struct htb_class *cl;
688-
689-
690-
/* lock queue so that we can muck with it */
691-
spin_lock_bh(&sch->dev->queue_lock);
692-
693-
q->rttim.expires = jiffies + HZ;
694-
add_timer(&q->rttim);
695-
696-
/* scan and recompute one bucket at time */
697-
if (++q->recmp_bucket >= HTB_HSIZE)
698-
q->recmp_bucket = 0;
699-
700-
hlist_for_each_entry(cl,p, q->hash + q->recmp_bucket, hlist) {
701-
RT_GEN(cl->sum_bytes, cl->rate_bytes);
702-
RT_GEN(cl->sum_packets, cl->rate_packets);
703-
}
704-
spin_unlock_bh(&sch->dev->queue_lock);
705-
}
706-
#endif
707-
708668
/**
709669
* htb_charge_class - charges amount "bytes" to leaf and ancestors
710670
*
@@ -750,11 +710,6 @@ static void htb_charge_class(struct htb_sched *q, struct htb_class *cl,
750710
if (cl->cmode != HTB_CAN_SEND)
751711
htb_add_to_wait_tree(q, cl, diff);
752712
}
753-
#ifdef HTB_RATECM
754-
/* update rate counters */
755-
cl->sum_bytes += bytes;
756-
cl->sum_packets++;
757-
#endif
758713

759714
/* update byte stats except for leaves which are already updated */
760715
if (cl->level) {
@@ -1095,13 +1050,6 @@ static int htb_init(struct Qdisc *sch, struct rtattr *opt)
10951050
if (q->direct_qlen < 2) /* some devices have zero tx_queue_len */
10961051
q->direct_qlen = 2;
10971052

1098-
#ifdef HTB_RATECM
1099-
init_timer(&q->rttim);
1100-
q->rttim.function = htb_rate_timer;
1101-
q->rttim.data = (unsigned long)sch;
1102-
q->rttim.expires = jiffies + HZ;
1103-
add_timer(&q->rttim);
1104-
#endif
11051053
if ((q->rate2quantum = gopt->rate2quantum) < 1)
11061054
q->rate2quantum = 1;
11071055
q->defcls = gopt->defcls;
@@ -1175,11 +1123,6 @@ htb_dump_class_stats(struct Qdisc *sch, unsigned long arg, struct gnet_dump *d)
11751123
{
11761124
struct htb_class *cl = (struct htb_class *)arg;
11771125

1178-
#ifdef HTB_RATECM
1179-
cl->rate_est.bps = cl->rate_bytes / (HTB_EWMAC * HTB_HSIZE);
1180-
cl->rate_est.pps = cl->rate_packets / (HTB_EWMAC * HTB_HSIZE);
1181-
#endif
1182-
11831126
if (!cl->level && cl->un.leaf.q)
11841127
cl->qstats.qlen = cl->un.leaf.q->q.qlen;
11851128
cl->xstats.tokens = cl->tokens;
@@ -1277,6 +1220,7 @@ static void htb_destroy_class(struct Qdisc *sch, struct htb_class *cl)
12771220
BUG_TRAP(cl->un.leaf.q);
12781221
qdisc_destroy(cl->un.leaf.q);
12791222
}
1223+
gen_kill_estimator(&cl->bstats, &cl->rate_est);
12801224
qdisc_put_rtab(cl->rate);
12811225
qdisc_put_rtab(cl->ceil);
12821226

@@ -1305,9 +1249,6 @@ static void htb_destroy(struct Qdisc *sch)
13051249
struct htb_sched *q = qdisc_priv(sch);
13061250

13071251
qdisc_watchdog_cancel(&q->watchdog);
1308-
#ifdef HTB_RATECM
1309-
del_timer_sync(&q->rttim);
1310-
#endif
13111252
/* This line used to be after htb_destroy_class call below
13121253
and surprisingly it worked in 2.4. But it must precede it
13131254
because filter need its target class alive to be able to call
@@ -1403,6 +1344,20 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
14031344
if (!cl) { /* new class */
14041345
struct Qdisc *new_q;
14051346
int prio;
1347+
struct {
1348+
struct rtattr rta;
1349+
struct gnet_estimator opt;
1350+
} est = {
1351+
.rta = {
1352+
.rta_len = RTA_LENGTH(sizeof(est.opt)),
1353+
.rta_type = TCA_RATE,
1354+
},
1355+
.opt = {
1356+
/* 4s interval, 16s averaging constant */
1357+
.interval = 2,
1358+
.ewma_log = 2,
1359+
},
1360+
};
14061361

14071362
/* check for valid classid */
14081363
if (!classid || TC_H_MAJ(classid ^ sch->handle)
@@ -1418,6 +1373,9 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
14181373
if ((cl = kzalloc(sizeof(*cl), GFP_KERNEL)) == NULL)
14191374
goto failure;
14201375

1376+
gen_new_estimator(&cl->bstats, &cl->rate_est,
1377+
&sch->dev->queue_lock,
1378+
tca[TCA_RATE-1] ? : &est.rta);
14211379
cl->refcnt = 1;
14221380
INIT_LIST_HEAD(&cl->sibling);
14231381
INIT_HLIST_NODE(&cl->hlist);
@@ -1469,8 +1427,13 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
14691427
hlist_add_head(&cl->hlist, q->hash + htb_hash(classid));
14701428
list_add_tail(&cl->sibling,
14711429
parent ? &parent->children : &q->root);
1472-
} else
1430+
} else {
1431+
if (tca[TCA_RATE-1])
1432+
gen_replace_estimator(&cl->bstats, &cl->rate_est,
1433+
&sch->dev->queue_lock,
1434+
tca[TCA_RATE-1]);
14731435
sch_tree_lock(sch);
1436+
}
14741437

14751438
/* it used to be a nasty bug here, we have to check that node
14761439
is really leaf before changing cl->un.leaf ! */

0 commit comments

Comments
 (0)