1 --- linux-2.4.21/net/sched/sch_htb.c Thu Jun 19 09:33:50 2003
2 +++ linux-2.4/net/sched/sch_htb.c Wed Jun 18 21:57:07 2003
4 * Authors: Martin Devera, <devik@cdi.cz>
6 * Credits (in time order) for older HTB versions:
7 + * Stef Coene <stef.coene@docum.org>
8 + * HTB support at LARTC mailing list
9 * Ondrej Kraus, <krauso@barr.cz>
10 * found missing INIT_QDISC(htb)
11 * Vladimir Smelhaus, Aamer Akhter, Bert Hubert
13 * created test case so that I was able to fix nasty bug
14 * and many others. thanks.
19 #include <linux/config.h>
20 #include <linux/module.h>
22 #define HTB_HYSTERESIS 1/* whether to use mode hysteresis for speedup */
23 #define HTB_QLOCK(S) spin_lock_bh(&(S)->dev->queue_lock)
24 #define HTB_QUNLOCK(S) spin_unlock_bh(&(S)->dev->queue_lock)
25 -#define HTB_VER 0x3000a /* major must be matched with number suplied by TC as version */
26 +#define HTB_VER 0x3000c /* major must be matched with number suplied by TC as version */
28 #if HTB_VER >> 16 != TC_HTB_PROTOVER
29 #error "Mismatched sch_htb.c and pkt_sch.h"
31 /* time of nearest event per level (row) */
32 unsigned long near_ev_cache[TC_HTB_MAXDEPTH];
34 + /* cached value of jiffies in dequeue */
35 + unsigned long jiffies;
37 /* whether we hit non-work conserving class during this dequeue; we use */
38 int nwc_hit; /* this to disable mindelay complaint in dequeue */
41 static void htb_debug_dump (struct htb_sched *q)
44 - printk(KERN_DEBUG "htb*g j=%lu\n",jiffies);
45 + printk(KERN_DEBUG "htb*g j=%lu lj=%lu\n",jiffies,q->jiffies);
47 for (i=TC_HTB_MAXDEPTH-1;i>=0;i--) {
48 printk(KERN_DEBUG "htb*r%d m=%x",i,q->row_mask[i]);
50 if ((delay <= 0 || delay > cl->mbuffer) && net_ratelimit())
51 printk(KERN_ERR "HTB: suspicious delay in wait_tree d=%ld cl=%X h=%d\n",delay,cl->classid,debug_hint);
53 - cl->pq_key = jiffies + PSCHED_US2JIFFIE(delay);
54 - if (cl->pq_key == jiffies)
55 + cl->pq_key = q->jiffies + PSCHED_US2JIFFIE(delay);
56 + if (cl->pq_key == q->jiffies)
59 /* update the nearest event cache */
63 if ((toks = (cl->ctokens + *diff)) < (
64 -#ifdef HTB_HYSTERESIS
66 cl->cmode != HTB_CANT_SEND ? -cl->cbuffer :
72 if ((toks = (cl->tokens + *diff)) >= (
73 -#ifdef HTB_HYSTERESIS
75 cl->cmode == HTB_CAN_SEND ? -cl->buffer :
80 (unsigned long long) q->now,
81 (unsigned long long) cl->t_c,
89 * Scans event queue for pending events and applies them. Returns jiffies to
90 * next pending event (0 for no event in pq).
91 + * Note: Aplied are events whose have cl->pq_key <= jiffies.
93 static long htb_do_events(struct htb_sched *q,int level)
96 while (p->rb_left) p = p->rb_left;
98 cl = rb_entry(p, struct htb_class, pq_node);
99 - if (cl->pq_key - (jiffies+1) < 0x80000000) {
100 - HTB_DBG(8,3,"htb_do_ev_ret delay=%ld\n",cl->pq_key - jiffies);
101 - return cl->pq_key - jiffies;
102 + if (cl->pq_key - (q->jiffies+1) < 0x80000000) {
103 + HTB_DBG(8,3,"htb_do_ev_ret delay=%ld\n",cl->pq_key - q->jiffies);
104 + return cl->pq_key - q->jiffies;
106 htb_safe_rb_erase(p,q->wait_pq+level);
107 diff = PSCHED_TDIFF_SAFE(q->now, cl->t_c, (u32)cl->mbuffer, 0);
110 (unsigned long long) q->now,
111 (unsigned long long) cl->t_c,
120 del_timer(&q->timer);
121 - q->timer.expires = jiffies + delay;
122 + /* why don't use jiffies here ? because expires can be in past */
123 + q->timer.expires = q->jiffies + delay;
124 add_timer(&q->timer);
125 sch->flags |= TCQ_F_THROTTLED;
126 sch->stats.overlimits++;
127 @@ -1004,6 +1011,7 @@
131 + q->jiffies = jiffies;
132 HTB_DBG(3,1,"htb_deq dircnt=%d qlen=%d\n",skb_queue_len(&q->direct_queue),
135 @@ -1023,14 +1031,14 @@
136 /* common case optimization - skip event handler quickly */
139 - if (jiffies - q->near_ev_cache[level] < 0x80000000 || 0) {
140 + if (q->jiffies - q->near_ev_cache[level] < 0x80000000 || 0) {
141 delay = htb_do_events(q,level);
142 - q->near_ev_cache[level] += delay ? delay : HZ;
143 + q->near_ev_cache[level] = q->jiffies + (delay ? delay : HZ);
148 - delay = q->near_ev_cache[level] - jiffies;
149 + delay = q->near_ev_cache[level] - q->jiffies;
151 if (delay && min_delay > delay)
153 @@ -1049,8 +1057,8 @@
155 if (!q->nwc_hit && min_delay >= 10*HZ && net_ratelimit()) {
156 if (min_delay == LONG_MAX) {
157 - printk(KERN_ERR "HTB: dequeue bug (%d), report it please !\n",
159 + printk(KERN_ERR "HTB: dequeue bug (%d,%lu,%lu), report it please !\n",
160 + evs_used,q->jiffies,jiffies);
163 printk(KERN_WARNING "HTB: mindelay=%ld, some class has "
164 @@ -1059,7 +1067,7 @@
166 htb_delay_by (sch,min_delay > 5*HZ ? 5*HZ : min_delay);
168 - HTB_DBG(3,1,"htb_deq_end %s j=%lu skb=%p\n",sch->dev->name,jiffies,skb);
169 + HTB_DBG(3,1,"htb_deq_end %s j=%lu skb=%p\n",sch->dev->name,q->jiffies,skb);
173 @@ -1424,7 +1432,7 @@
174 parent = parentid == TC_H_ROOT ? NULL : htb_find (parentid,sch);
176 hopt = RTA_DATA(tb[TCA_HTB_PARMS-1]);
177 - HTB_DBG(0,1,"htb_chg cl=%p, clid=%X, opt/prio=%d, rate=%u, buff=%d, quant=%d\n", cl,cl?cl->classid:0,(int)hopt->prio,hopt->rate.rate,hopt->buffer,hopt->quantum);
178 + HTB_DBG(0,1,"htb_chg cl=%p(%X), clid=%X, parid=%X, opt/prio=%d, rate=%u, buff=%d, quant=%d\n", cl,cl?cl->classid:0,classid,parentid,(int)hopt->prio,hopt->rate.rate,hopt->buffer,hopt->quantum);
179 rtab = qdisc_get_rtab(&hopt->rate, tb[TCA_HTB_RTAB-1]);
180 ctab = qdisc_get_rtab(&hopt->ceil, tb[TCA_HTB_CTAB-1]);
181 if (!rtab || !ctab) goto failure;