Diff markup
1 /* 1 /*
2 * net/sched/sch_cbq.c Class-Based Queueing d 2 * net/sched/sch_cbq.c Class-Based Queueing discipline.
3 * 3 *
4 * This program is free software; 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of t 5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Softw 6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your 7 * 2 of the License, or (at your option) any later version.
8 * 8 *
9 * Authors: Alexey Kuznetsov, <kuznet@ms2. 9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 * 10 *
11 */ 11 */
12 12
>> 13 #include <linux/config.h>
13 #include <linux/module.h> 14 #include <linux/module.h>
>> 15 #include <asm/uaccess.h>
>> 16 #include <asm/system.h>
>> 17 #include <linux/bitops.h>
14 #include <linux/types.h> 18 #include <linux/types.h>
15 #include <linux/kernel.h> 19 #include <linux/kernel.h>
>> 20 #include <linux/sched.h>
16 #include <linux/string.h> 21 #include <linux/string.h>
>> 22 #include <linux/mm.h>
>> 23 #include <linux/socket.h>
>> 24 #include <linux/sockios.h>
>> 25 #include <linux/in.h>
17 #include <linux/errno.h> 26 #include <linux/errno.h>
>> 27 #include <linux/interrupt.h>
>> 28 #include <linux/if_ether.h>
>> 29 #include <linux/inet.h>
>> 30 #include <linux/netdevice.h>
>> 31 #include <linux/etherdevice.h>
>> 32 #include <linux/notifier.h>
>> 33 #include <net/ip.h>
>> 34 #include <net/route.h>
18 #include <linux/skbuff.h> 35 #include <linux/skbuff.h>
19 #include <net/netlink.h> !! 36 #include <net/sock.h>
20 #include <net/pkt_sched.h> 37 #include <net/pkt_sched.h>
21 38
22 39
23 /* Class-Based Queueing (CBQ) algorithm. 40 /* Class-Based Queueing (CBQ) algorithm.
24 ====================================== 41 =======================================
25 42
26 Sources: [1] Sally Floyd and Van Jacob 43 Sources: [1] Sally Floyd and Van Jacobson, "Link-sharing and Resource
27 Management Models for Packet !! 44 Management Models for Packet Networks",
28 IEEE/ACM Transactions on Netw 45 IEEE/ACM Transactions on Networking, Vol.3, No.4, 1995
29 46
30 [2] Sally Floyd, "Notes on CB !! 47 [2] Sally Floyd, "Notes on CBQ and Guaranteed Service", 1995
31 48
32 [3] Sally Floyd, "Notes on Cl !! 49 [3] Sally Floyd, "Notes on Class-Based Queueing: Setting
33 Parameters", 1996 50 Parameters", 1996
34 51
35 [4] Sally Floyd and Michael S 52 [4] Sally Floyd and Michael Speer, "Experimental Results
36 for Class-Based Queueing", 19 53 for Class-Based Queueing", 1998, not published.
37 54
38 -------------------------------------- 55 -----------------------------------------------------------------------
39 56
40 Algorithm skeleton was taken from NS s 57 Algorithm skeleton was taken from NS simulator cbq.cc.
41 If someone wants to check this code ag 58 If someone wants to check this code against the LBL version,
42 he should take into account that ONLY 59 he should take into account that ONLY the skeleton was borrowed,
43 the implementation is different. Parti 60 the implementation is different. Particularly:
44 61
45 --- The WRR algorithm is different. Ou 62 --- The WRR algorithm is different. Our version looks more
46 reasonable (I hope) and works when qua !! 63 reasonable (I hope) and works when quanta are allowed to be
47 less than MTU, which is always the cas !! 64 less than MTU, which is always the case when real time classes
48 have small rates. Note, that the state !! 65 have small rates. Note, that the statement of [3] is
49 incomplete, delay may actually be esti !! 66 incomplete, delay may actually be estimated even if class
50 per-round allotment is less than MTU. !! 67 per-round allotment is less than MTU. Namely, if per-round
51 allotment is W*r_i, and r_1+...+r_k = !! 68 allotment is W*r_i, and r_1+...+r_k = r < 1
52 69
53 delay_i <= ([MTU/(W*r_i)]*W*r + W*r + 70 delay_i <= ([MTU/(W*r_i)]*W*r + W*r + k*MTU)/B
54 71
55 In the worst case we have IntServ esti 72 In the worst case we have IntServ estimate with D = W*r+k*MTU
56 and C = MTU*r. The proof (if correct a 73 and C = MTU*r. The proof (if correct at all) is trivial.
57 74
58 75
59 --- It seems that cbq-2.0 is not very 76 --- It seems that cbq-2.0 is not very accurate. At least, I cannot
60 interpret some places, which look like 77 interpret some places, which look like wrong translations
61 from NS. Anyone is advised to find the 78 from NS. Anyone is advised to find these differences
62 and explain to me, why I am wrong 8). 79 and explain to me, why I am wrong 8).
63 80
64 --- Linux has no EOI event, so that we 81 --- Linux has no EOI event, so that we cannot estimate true class
65 idle time. Workaround is to consider t 82 idle time. Workaround is to consider the next dequeue event
66 as sign that previous packet is finish 83 as sign that previous packet is finished. This is wrong because of
67 internal device queueing, but on a per 84 internal device queueing, but on a permanently loaded link it is true.
68 Moreover, combined with clock integrat 85 Moreover, combined with clock integrator, this scheme looks
69 very close to an ideal solution. */ 86 very close to an ideal solution. */
70 87
71 struct cbq_sched_data; 88 struct cbq_sched_data;
72 89
73 90
74 struct cbq_class 91 struct cbq_class
75 { 92 {
76 struct cbq_class *next; 93 struct cbq_class *next; /* hash table link */
77 struct cbq_class *next_alive; 94 struct cbq_class *next_alive; /* next class with backlog in this priority band */
78 95
79 /* Parameters */ 96 /* Parameters */
80 u32 classid; 97 u32 classid;
81 unsigned char priority; 98 unsigned char priority; /* class priority */
82 unsigned char priority2; 99 unsigned char priority2; /* priority to be used after overlimit */
83 unsigned char ewma_log; 100 unsigned char ewma_log; /* time constant for idle time calculation */
84 unsigned char ovl_strategy; 101 unsigned char ovl_strategy;
85 #ifdef CONFIG_NET_CLS_ACT !! 102 #ifdef CONFIG_NET_CLS_POLICE
86 unsigned char police; 103 unsigned char police;
87 #endif 104 #endif
88 105
89 u32 defmap; 106 u32 defmap;
90 107
91 /* Link-sharing scheduler parameters * 108 /* Link-sharing scheduler parameters */
92 long maxidle; 109 long maxidle; /* Class parameters: see below. */
93 long offtime; 110 long offtime;
94 long minidle; 111 long minidle;
95 u32 avpkt; 112 u32 avpkt;
96 struct qdisc_rate_table *R_tab; 113 struct qdisc_rate_table *R_tab;
97 114
98 /* Overlimit strategy parameters */ 115 /* Overlimit strategy parameters */
99 void (*overlimit)(s 116 void (*overlimit)(struct cbq_class *cl);
100 psched_tdiff_t penalty; !! 117 long penalty;
101 118
102 /* General scheduler (WRR) parameters 119 /* General scheduler (WRR) parameters */
103 long allot; 120 long allot;
104 long quantum; 121 long quantum; /* Allotment per WRR round */
105 long weight; 122 long weight; /* Relative allotment: see below */
106 123
107 struct Qdisc *qdisc; 124 struct Qdisc *qdisc; /* Ptr to CBQ discipline */
108 struct cbq_class *split; 125 struct cbq_class *split; /* Ptr to split node */
109 struct cbq_class *share; 126 struct cbq_class *share; /* Ptr to LS parent in the class tree */
110 struct cbq_class *tparent; 127 struct cbq_class *tparent; /* Ptr to tree parent in the class tree */
111 struct cbq_class *borrow; 128 struct cbq_class *borrow; /* NULL if class is bandwidth limited;
112 129 parent otherwise */
113 struct cbq_class *sibling; 130 struct cbq_class *sibling; /* Sibling chain */
114 struct cbq_class *children; 131 struct cbq_class *children; /* Pointer to children chain */
115 132
116 struct Qdisc *q; 133 struct Qdisc *q; /* Elementary queueing discipline */
117 134
118 135
119 /* Variables */ 136 /* Variables */
120 unsigned char cpriority; 137 unsigned char cpriority; /* Effective priority */
121 unsigned char delayed; 138 unsigned char delayed;
122 unsigned char level; 139 unsigned char level; /* level of the class in hierarchy:
123 140 0 for leaf classes, and maximal
124 141 level of children + 1 for nodes.
125 142 */
126 143
127 psched_time_t last; 144 psched_time_t last; /* Last end of service */
128 psched_time_t undertime; 145 psched_time_t undertime;
129 long avgidle; 146 long avgidle;
130 long deficit; 147 long deficit; /* Saved deficit for WRR */
131 psched_time_t penalized; !! 148 unsigned long penalized;
132 struct gnet_stats_basic bstats; 149 struct gnet_stats_basic bstats;
133 struct gnet_stats_queue qstats; 150 struct gnet_stats_queue qstats;
134 struct gnet_stats_rate_est rate_est; 151 struct gnet_stats_rate_est rate_est;
>> 152 spinlock_t *stats_lock;
135 struct tc_cbq_xstats xstats; 153 struct tc_cbq_xstats xstats;
136 154
137 struct tcf_proto *filter_list; 155 struct tcf_proto *filter_list;
138 156
139 int refcnt; 157 int refcnt;
140 int filters; 158 int filters;
141 159
142 struct cbq_class *defaults[TC_P 160 struct cbq_class *defaults[TC_PRIO_MAX+1];
143 }; 161 };
144 162
145 struct cbq_sched_data 163 struct cbq_sched_data
146 { 164 {
147 struct cbq_class *classes[16]; 165 struct cbq_class *classes[16]; /* Hash table of all classes */
148 int nclasses[TC_CB 166 int nclasses[TC_CBQ_MAXPRIO+1];
149 unsigned quanta[TC_CBQ_ 167 unsigned quanta[TC_CBQ_MAXPRIO+1];
150 168
151 struct cbq_class link; 169 struct cbq_class link;
152 170
153 unsigned activemask; 171 unsigned activemask;
154 struct cbq_class *active[TC_CBQ 172 struct cbq_class *active[TC_CBQ_MAXPRIO+1]; /* List of all classes
155 173 with backlog */
156 174
157 #ifdef CONFIG_NET_CLS_ACT !! 175 #ifdef CONFIG_NET_CLS_POLICE
158 struct cbq_class *rx_class; 176 struct cbq_class *rx_class;
159 #endif 177 #endif
160 struct cbq_class *tx_class; 178 struct cbq_class *tx_class;
161 struct cbq_class *tx_borrowed; 179 struct cbq_class *tx_borrowed;
162 int tx_len; 180 int tx_len;
163 psched_time_t now; 181 psched_time_t now; /* Cached timestamp */
164 psched_time_t now_rt; 182 psched_time_t now_rt; /* Cached real time */
165 unsigned pmask; 183 unsigned pmask;
166 184
167 struct hrtimer delay_timer; !! 185 struct timer_list delay_timer;
168 struct qdisc_watchdog watchdog; !! 186 struct timer_list wd_timer; /* Watchdog timer,
169 187 started when CBQ has
170 188 backlog, but cannot
171 189 transmit just now */
172 psched_tdiff_t wd_expires; !! 190 long wd_expires;
173 int toplevel; 191 int toplevel;
174 u32 hgenerator; 192 u32 hgenerator;
175 }; 193 };
176 194
177 195
178 #define L2T(cl,len) qdisc_l2t((cl)->R_tab, !! 196 #define L2T(cl,len) ((cl)->R_tab->data[(len)>>(cl)->R_tab->rate.cell_log])
179 197
180 198
181 static __inline__ unsigned cbq_hash(u32 h) 199 static __inline__ unsigned cbq_hash(u32 h)
182 { 200 {
183 h ^= h>>8; 201 h ^= h>>8;
184 h ^= h>>4; 202 h ^= h>>4;
185 return h&0xF; 203 return h&0xF;
186 } 204 }
187 205
188 static __inline__ struct cbq_class * 206 static __inline__ struct cbq_class *
189 cbq_class_lookup(struct cbq_sched_data *q, u32 207 cbq_class_lookup(struct cbq_sched_data *q, u32 classid)
190 { 208 {
191 struct cbq_class *cl; 209 struct cbq_class *cl;
192 210
193 for (cl = q->classes[cbq_hash(classid) 211 for (cl = q->classes[cbq_hash(classid)]; cl; cl = cl->next)
194 if (cl->classid == classid) 212 if (cl->classid == classid)
195 return cl; 213 return cl;
196 return NULL; 214 return NULL;
197 } 215 }
198 216
199 #ifdef CONFIG_NET_CLS_ACT !! 217 #ifdef CONFIG_NET_CLS_POLICE
200 218
201 static struct cbq_class * 219 static struct cbq_class *
202 cbq_reclassify(struct sk_buff *skb, struct cbq 220 cbq_reclassify(struct sk_buff *skb, struct cbq_class *this)
203 { 221 {
204 struct cbq_class *cl, *new; 222 struct cbq_class *cl, *new;
205 223
206 for (cl = this->tparent; cl; cl = cl-> 224 for (cl = this->tparent; cl; cl = cl->tparent)
207 if ((new = cl->defaults[TC_PRI 225 if ((new = cl->defaults[TC_PRIO_BESTEFFORT]) != NULL && new != this)
208 return new; 226 return new;
209 227
210 return NULL; 228 return NULL;
211 } 229 }
212 230
213 #endif 231 #endif
214 232
215 /* Classify packet. The procedure is pretty co 233 /* Classify packet. The procedure is pretty complicated, but
216 it allows us to combine link sharing and pr 234 it allows us to combine link sharing and priority scheduling
217 transparently. 235 transparently.
218 236
219 Namely, you can put link sharing rules (f.e 237 Namely, you can put link sharing rules (f.e. route based) at root of CBQ,
220 so that it resolves to split nodes. Then pa 238 so that it resolves to split nodes. Then packets are classified
221 by logical priority, or a more specific cla 239 by logical priority, or a more specific classifier may be attached
222 to the split node. 240 to the split node.
223 */ 241 */
224 242
225 static struct cbq_class * 243 static struct cbq_class *
226 cbq_classify(struct sk_buff *skb, struct Qdisc 244 cbq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
227 { 245 {
228 struct cbq_sched_data *q = qdisc_priv( 246 struct cbq_sched_data *q = qdisc_priv(sch);
229 struct cbq_class *head = &q->link; 247 struct cbq_class *head = &q->link;
230 struct cbq_class **defmap; 248 struct cbq_class **defmap;
231 struct cbq_class *cl = NULL; 249 struct cbq_class *cl = NULL;
232 u32 prio = skb->priority; 250 u32 prio = skb->priority;
233 struct tcf_result res; 251 struct tcf_result res;
234 252
235 /* 253 /*
236 * Step 1. If skb->priority points to 254 * Step 1. If skb->priority points to one of our classes, use it.
237 */ 255 */
238 if (TC_H_MAJ(prio^sch->handle) == 0 && 256 if (TC_H_MAJ(prio^sch->handle) == 0 &&
239 (cl = cbq_class_lookup(q, prio)) ! 257 (cl = cbq_class_lookup(q, prio)) != NULL)
240 return cl; 258 return cl;
241 259
242 *qerr = NET_XMIT_BYPASS; !! 260 *qerr = NET_XMIT_DROP;
243 for (;;) { 261 for (;;) {
244 int result = 0; 262 int result = 0;
245 defmap = head->defaults; 263 defmap = head->defaults;
246 264
247 /* 265 /*
248 * Step 2+n. Apply classifier. 266 * Step 2+n. Apply classifier.
249 */ 267 */
250 if (!head->filter_list || !! 268 if (!head->filter_list || (result = tc_classify(skb, head->filter_list, &res)) < 0)
251 (result = tc_classify_comp <<
252 goto fallback; 269 goto fallback;
253 270
254 if ((cl = (void*)res.class) == 271 if ((cl = (void*)res.class) == NULL) {
255 if (TC_H_MAJ(res.class 272 if (TC_H_MAJ(res.classid))
256 cl = cbq_class 273 cl = cbq_class_lookup(q, res.classid);
257 else if ((cl = defmap[ 274 else if ((cl = defmap[res.classid&TC_PRIO_MAX]) == NULL)
258 cl = defmap[TC 275 cl = defmap[TC_PRIO_BESTEFFORT];
259 276
260 if (cl == NULL || cl-> 277 if (cl == NULL || cl->level >= head->level)
261 goto fallback; 278 goto fallback;
262 } 279 }
263 280
264 #ifdef CONFIG_NET_CLS_ACT 281 #ifdef CONFIG_NET_CLS_ACT
265 switch (result) { 282 switch (result) {
266 case TC_ACT_QUEUED: 283 case TC_ACT_QUEUED:
267 case TC_ACT_STOLEN: !! 284 case TC_ACT_STOLEN:
268 *qerr = NET_XMIT_SUCCE 285 *qerr = NET_XMIT_SUCCESS;
269 case TC_ACT_SHOT: 286 case TC_ACT_SHOT:
270 return NULL; 287 return NULL;
271 case TC_ACT_RECLASSIFY: !! 288 }
>> 289 #elif defined(CONFIG_NET_CLS_POLICE)
>> 290 switch (result) {
>> 291 case TC_POLICE_RECLASSIFY:
272 return cbq_reclassify( 292 return cbq_reclassify(skb, cl);
>> 293 case TC_POLICE_SHOT:
>> 294 return NULL;
>> 295 default:
>> 296 break;
273 } 297 }
274 #endif 298 #endif
275 if (cl->level == 0) 299 if (cl->level == 0)
276 return cl; 300 return cl;
277 301
278 /* 302 /*
279 * Step 3+n. If classifier sel 303 * Step 3+n. If classifier selected a link sharing class,
280 * apply agency specif 304 * apply agency specific classifier.
281 * Repeat this procdur 305 * Repeat this procdure until we hit a leaf node.
282 */ 306 */
283 head = cl; 307 head = cl;
284 } 308 }
285 309
286 fallback: 310 fallback:
287 cl = head; 311 cl = head;
288 312
289 /* 313 /*
290 * Step 4. No success... 314 * Step 4. No success...
291 */ 315 */
292 if (TC_H_MAJ(prio) == 0 && 316 if (TC_H_MAJ(prio) == 0 &&
293 !(cl = head->defaults[prio&TC_PRIO 317 !(cl = head->defaults[prio&TC_PRIO_MAX]) &&
294 !(cl = head->defaults[TC_PRIO_BEST 318 !(cl = head->defaults[TC_PRIO_BESTEFFORT]))
295 return head; 319 return head;
296 320
297 return cl; 321 return cl;
298 } 322 }
299 323
300 /* 324 /*
301 A packet has just been enqueued on the empt 325 A packet has just been enqueued on the empty class.
302 cbq_activate_class adds it to the tail of a 326 cbq_activate_class adds it to the tail of active class list
303 of its priority band. 327 of its priority band.
304 */ 328 */
305 329
306 static __inline__ void cbq_activate_class(stru 330 static __inline__ void cbq_activate_class(struct cbq_class *cl)
307 { 331 {
308 struct cbq_sched_data *q = qdisc_priv( 332 struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
309 int prio = cl->cpriority; 333 int prio = cl->cpriority;
310 struct cbq_class *cl_tail; 334 struct cbq_class *cl_tail;
311 335
312 cl_tail = q->active[prio]; 336 cl_tail = q->active[prio];
313 q->active[prio] = cl; 337 q->active[prio] = cl;
314 338
315 if (cl_tail != NULL) { 339 if (cl_tail != NULL) {
316 cl->next_alive = cl_tail->next 340 cl->next_alive = cl_tail->next_alive;
317 cl_tail->next_alive = cl; 341 cl_tail->next_alive = cl;
318 } else { 342 } else {
319 cl->next_alive = cl; 343 cl->next_alive = cl;
320 q->activemask |= (1<<prio); 344 q->activemask |= (1<<prio);
321 } 345 }
322 } 346 }
323 347
324 /* 348 /*
325 Unlink class from active chain. 349 Unlink class from active chain.
326 Note that this same procedure is done direc 350 Note that this same procedure is done directly in cbq_dequeue*
327 during round-robin procedure. 351 during round-robin procedure.
328 */ 352 */
329 353
330 static void cbq_deactivate_class(struct cbq_cl 354 static void cbq_deactivate_class(struct cbq_class *this)
331 { 355 {
332 struct cbq_sched_data *q = qdisc_priv( 356 struct cbq_sched_data *q = qdisc_priv(this->qdisc);
333 int prio = this->cpriority; 357 int prio = this->cpriority;
334 struct cbq_class *cl; 358 struct cbq_class *cl;
335 struct cbq_class *cl_prev = q->active[ 359 struct cbq_class *cl_prev = q->active[prio];
336 360
337 do { 361 do {
338 cl = cl_prev->next_alive; 362 cl = cl_prev->next_alive;
339 if (cl == this) { 363 if (cl == this) {
340 cl_prev->next_alive = 364 cl_prev->next_alive = cl->next_alive;
341 cl->next_alive = NULL; 365 cl->next_alive = NULL;
342 366
343 if (cl == q->active[pr 367 if (cl == q->active[prio]) {
344 q->active[prio 368 q->active[prio] = cl_prev;
345 if (cl == q->a 369 if (cl == q->active[prio]) {
346 q->act 370 q->active[prio] = NULL;
347 q->act 371 q->activemask &= ~(1<<prio);
348 return 372 return;
349 } 373 }
350 } 374 }
>> 375
>> 376 cl = cl_prev->next_alive;
351 return; 377 return;
352 } 378 }
353 } while ((cl_prev = cl) != q->active[p 379 } while ((cl_prev = cl) != q->active[prio]);
354 } 380 }
355 381
356 static void 382 static void
357 cbq_mark_toplevel(struct cbq_sched_data *q, st 383 cbq_mark_toplevel(struct cbq_sched_data *q, struct cbq_class *cl)
358 { 384 {
359 int toplevel = q->toplevel; 385 int toplevel = q->toplevel;
360 386
361 if (toplevel > cl->level && !(cl->q->f 387 if (toplevel > cl->level && !(cl->q->flags&TCQ_F_THROTTLED)) {
362 psched_time_t now; 388 psched_time_t now;
363 psched_tdiff_t incr; 389 psched_tdiff_t incr;
364 390
365 now = psched_get_time(); !! 391 PSCHED_GET_TIME(now);
366 incr = now - q->now_rt; !! 392 incr = PSCHED_TDIFF(now, q->now_rt);
367 now = q->now + incr; !! 393 PSCHED_TADD2(q->now, incr, now);
368 394
369 do { 395 do {
370 if (cl->undertime < no !! 396 if (PSCHED_TLESS(cl->undertime, now)) {
371 q->toplevel = 397 q->toplevel = cl->level;
372 return; 398 return;
373 } 399 }
374 } while ((cl=cl->borrow) != NU 400 } while ((cl=cl->borrow) != NULL && toplevel > cl->level);
375 } 401 }
376 } 402 }
377 403
378 static int 404 static int
379 cbq_enqueue(struct sk_buff *skb, struct Qdisc 405 cbq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
380 { 406 {
381 struct cbq_sched_data *q = qdisc_priv( 407 struct cbq_sched_data *q = qdisc_priv(sch);
382 int len = skb->len; 408 int len = skb->len;
383 int uninitialized_var(ret); !! 409 int ret;
384 struct cbq_class *cl = cbq_classify(sk 410 struct cbq_class *cl = cbq_classify(skb, sch, &ret);
385 411
386 #ifdef CONFIG_NET_CLS_ACT !! 412 #ifdef CONFIG_NET_CLS_POLICE
387 q->rx_class = cl; 413 q->rx_class = cl;
388 #endif 414 #endif
389 if (cl == NULL) { 415 if (cl == NULL) {
390 if (ret == NET_XMIT_BYPASS) !! 416 if (ret == NET_XMIT_DROP)
391 sch->qstats.drops++; 417 sch->qstats.drops++;
392 kfree_skb(skb); 418 kfree_skb(skb);
393 return ret; 419 return ret;
394 } 420 }
395 421
396 #ifdef CONFIG_NET_CLS_ACT !! 422 #ifdef CONFIG_NET_CLS_POLICE
397 cl->q->__parent = sch; 423 cl->q->__parent = sch;
398 #endif 424 #endif
399 if ((ret = cl->q->enqueue(skb, cl->q)) 425 if ((ret = cl->q->enqueue(skb, cl->q)) == NET_XMIT_SUCCESS) {
400 sch->q.qlen++; 426 sch->q.qlen++;
401 sch->bstats.packets++; 427 sch->bstats.packets++;
402 sch->bstats.bytes+=len; 428 sch->bstats.bytes+=len;
403 cbq_mark_toplevel(q, cl); 429 cbq_mark_toplevel(q, cl);
404 if (!cl->next_alive) 430 if (!cl->next_alive)
405 cbq_activate_class(cl) 431 cbq_activate_class(cl);
406 return ret; 432 return ret;
407 } 433 }
408 434
409 sch->qstats.drops++; 435 sch->qstats.drops++;
410 cbq_mark_toplevel(q, cl); 436 cbq_mark_toplevel(q, cl);
411 cl->qstats.drops++; 437 cl->qstats.drops++;
412 return ret; 438 return ret;
413 } 439 }
414 440
415 static int 441 static int
416 cbq_requeue(struct sk_buff *skb, struct Qdisc 442 cbq_requeue(struct sk_buff *skb, struct Qdisc *sch)
417 { 443 {
418 struct cbq_sched_data *q = qdisc_priv( 444 struct cbq_sched_data *q = qdisc_priv(sch);
419 struct cbq_class *cl; 445 struct cbq_class *cl;
420 int ret; 446 int ret;
421 447
422 if ((cl = q->tx_class) == NULL) { 448 if ((cl = q->tx_class) == NULL) {
423 kfree_skb(skb); 449 kfree_skb(skb);
424 sch->qstats.drops++; 450 sch->qstats.drops++;
425 return NET_XMIT_CN; 451 return NET_XMIT_CN;
426 } 452 }
427 q->tx_class = NULL; 453 q->tx_class = NULL;
428 454
429 cbq_mark_toplevel(q, cl); 455 cbq_mark_toplevel(q, cl);
430 456
431 #ifdef CONFIG_NET_CLS_ACT !! 457 #ifdef CONFIG_NET_CLS_POLICE
432 q->rx_class = cl; 458 q->rx_class = cl;
433 cl->q->__parent = sch; 459 cl->q->__parent = sch;
434 #endif 460 #endif
435 if ((ret = cl->q->ops->requeue(skb, cl 461 if ((ret = cl->q->ops->requeue(skb, cl->q)) == 0) {
436 sch->q.qlen++; 462 sch->q.qlen++;
437 sch->qstats.requeues++; 463 sch->qstats.requeues++;
438 if (!cl->next_alive) 464 if (!cl->next_alive)
439 cbq_activate_class(cl) 465 cbq_activate_class(cl);
440 return 0; 466 return 0;
441 } 467 }
442 sch->qstats.drops++; 468 sch->qstats.drops++;
443 cl->qstats.drops++; 469 cl->qstats.drops++;
444 return ret; 470 return ret;
445 } 471 }
446 472
447 /* Overlimit actions */ 473 /* Overlimit actions */
448 474
449 /* TC_CBQ_OVL_CLASSIC: (default) penalize leaf 475 /* TC_CBQ_OVL_CLASSIC: (default) penalize leaf class by adding offtime */
450 476
451 static void cbq_ovl_classic(struct cbq_class * 477 static void cbq_ovl_classic(struct cbq_class *cl)
452 { 478 {
453 struct cbq_sched_data *q = qdisc_priv( 479 struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
454 psched_tdiff_t delay = cl->undertime - !! 480 psched_tdiff_t delay = PSCHED_TDIFF(cl->undertime, q->now);
455 481
456 if (!cl->delayed) { 482 if (!cl->delayed) {
457 delay += cl->offtime; 483 delay += cl->offtime;
458 484
459 /* !! 485 /*
460 Class goes to sleep, so tha 486 Class goes to sleep, so that it will have no
461 chance to work avgidle. Let 487 chance to work avgidle. Let's forgive it 8)
462 488
463 BTW cbq-2.0 has a crap in t 489 BTW cbq-2.0 has a crap in this
464 place, apparently they forg 490 place, apparently they forgot to shift it by cl->ewma_log.
465 */ 491 */
466 if (cl->avgidle < 0) 492 if (cl->avgidle < 0)
467 delay -= (-cl->avgidle 493 delay -= (-cl->avgidle) - ((-cl->avgidle) >> cl->ewma_log);
468 if (cl->avgidle < cl->minidle) 494 if (cl->avgidle < cl->minidle)
469 cl->avgidle = cl->mini 495 cl->avgidle = cl->minidle;
470 if (delay <= 0) 496 if (delay <= 0)
471 delay = 1; 497 delay = 1;
472 cl->undertime = q->now + delay !! 498 PSCHED_TADD2(q->now, delay, cl->undertime);
473 499
474 cl->xstats.overactions++; 500 cl->xstats.overactions++;
475 cl->delayed = 1; 501 cl->delayed = 1;
476 } 502 }
477 if (q->wd_expires == 0 || q->wd_expire 503 if (q->wd_expires == 0 || q->wd_expires > delay)
478 q->wd_expires = delay; 504 q->wd_expires = delay;
479 505
480 /* Dirty work! We must schedule wakeup 506 /* Dirty work! We must schedule wakeups based on
481 real available rate, rather than le 507 real available rate, rather than leaf rate,
482 which may be tiny (even zero). 508 which may be tiny (even zero).
483 */ 509 */
484 if (q->toplevel == TC_CBQ_MAXLEVEL) { 510 if (q->toplevel == TC_CBQ_MAXLEVEL) {
485 struct cbq_class *b; 511 struct cbq_class *b;
486 psched_tdiff_t base_delay = q- 512 psched_tdiff_t base_delay = q->wd_expires;
487 513
488 for (b = cl->borrow; b; b = b- 514 for (b = cl->borrow; b; b = b->borrow) {
489 delay = b->undertime - !! 515 delay = PSCHED_TDIFF(b->undertime, q->now);
490 if (delay < base_delay 516 if (delay < base_delay) {
491 if (delay <= 0 517 if (delay <= 0)
492 delay 518 delay = 1;
493 base_delay = d 519 base_delay = delay;
494 } 520 }
495 } 521 }
496 522
497 q->wd_expires = base_delay; 523 q->wd_expires = base_delay;
498 } 524 }
499 } 525 }
500 526
501 /* TC_CBQ_OVL_RCLASSIC: penalize by offtime cl 527 /* TC_CBQ_OVL_RCLASSIC: penalize by offtime classes in hierarchy, when
502 they go overlimit 528 they go overlimit
503 */ 529 */
504 530
505 static void cbq_ovl_rclassic(struct cbq_class 531 static void cbq_ovl_rclassic(struct cbq_class *cl)
506 { 532 {
507 struct cbq_sched_data *q = qdisc_priv( 533 struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
508 struct cbq_class *this = cl; 534 struct cbq_class *this = cl;
509 535
510 do { 536 do {
511 if (cl->level > q->toplevel) { 537 if (cl->level > q->toplevel) {
512 cl = NULL; 538 cl = NULL;
513 break; 539 break;
514 } 540 }
515 } while ((cl = cl->borrow) != NULL); 541 } while ((cl = cl->borrow) != NULL);
516 542
517 if (cl == NULL) 543 if (cl == NULL)
518 cl = this; 544 cl = this;
519 cbq_ovl_classic(cl); 545 cbq_ovl_classic(cl);
520 } 546 }
521 547
522 /* TC_CBQ_OVL_DELAY: delay until it will go to 548 /* TC_CBQ_OVL_DELAY: delay until it will go to underlimit */
523 549
524 static void cbq_ovl_delay(struct cbq_class *cl 550 static void cbq_ovl_delay(struct cbq_class *cl)
525 { 551 {
526 struct cbq_sched_data *q = qdisc_priv( 552 struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
527 psched_tdiff_t delay = cl->undertime - !! 553 psched_tdiff_t delay = PSCHED_TDIFF(cl->undertime, q->now);
528 554
529 if (!cl->delayed) { 555 if (!cl->delayed) {
530 psched_time_t sched = q->now; !! 556 unsigned long sched = jiffies;
531 ktime_t expires; <<
532 557
533 delay += cl->offtime; 558 delay += cl->offtime;
534 if (cl->avgidle < 0) 559 if (cl->avgidle < 0)
535 delay -= (-cl->avgidle 560 delay -= (-cl->avgidle) - ((-cl->avgidle) >> cl->ewma_log);
536 if (cl->avgidle < cl->minidle) 561 if (cl->avgidle < cl->minidle)
537 cl->avgidle = cl->mini 562 cl->avgidle = cl->minidle;
538 cl->undertime = q->now + delay !! 563 PSCHED_TADD2(q->now, delay, cl->undertime);
539 564
540 if (delay > 0) { 565 if (delay > 0) {
541 sched += delay + cl->p !! 566 sched += PSCHED_US2JIFFIE(delay) + cl->penalty;
542 cl->penalized = sched; 567 cl->penalized = sched;
543 cl->cpriority = TC_CBQ 568 cl->cpriority = TC_CBQ_MAXPRIO;
544 q->pmask |= (1<<TC_CBQ 569 q->pmask |= (1<<TC_CBQ_MAXPRIO);
545 !! 570 if (del_timer(&q->delay_timer) &&
546 expires = ktime_set(0, !! 571 (long)(q->delay_timer.expires - sched) > 0)
547 expires = ktime_add_ns !! 572 q->delay_timer.expires = sched;
548 if (hrtimer_try_to_can !! 573 add_timer(&q->delay_timer);
549 ktime_to_ns(ktime_ <<
550 <<
551 q->delay_timer <<
552 hrtimer_restart(&q->de <<
553 cl->delayed = 1; 574 cl->delayed = 1;
554 cl->xstats.overactions 575 cl->xstats.overactions++;
555 return; 576 return;
556 } 577 }
557 delay = 1; 578 delay = 1;
558 } 579 }
559 if (q->wd_expires == 0 || q->wd_expire 580 if (q->wd_expires == 0 || q->wd_expires > delay)
560 q->wd_expires = delay; 581 q->wd_expires = delay;
561 } 582 }
562 583
563 /* TC_CBQ_OVL_LOWPRIO: penalize class by lower 584 /* TC_CBQ_OVL_LOWPRIO: penalize class by lowering its priority band */
564 585
565 static void cbq_ovl_lowprio(struct cbq_class * 586 static void cbq_ovl_lowprio(struct cbq_class *cl)
566 { 587 {
567 struct cbq_sched_data *q = qdisc_priv( 588 struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
568 589
569 cl->penalized = q->now + cl->penalty; !! 590 cl->penalized = jiffies + cl->penalty;
570 591
571 if (cl->cpriority != cl->priority2) { 592 if (cl->cpriority != cl->priority2) {
572 cl->cpriority = cl->priority2; 593 cl->cpriority = cl->priority2;
573 q->pmask |= (1<<cl->cpriority) 594 q->pmask |= (1<<cl->cpriority);
574 cl->xstats.overactions++; 595 cl->xstats.overactions++;
575 } 596 }
576 cbq_ovl_classic(cl); 597 cbq_ovl_classic(cl);
577 } 598 }
578 599
579 /* TC_CBQ_OVL_DROP: penalize class by dropping 600 /* TC_CBQ_OVL_DROP: penalize class by dropping */
580 601
581 static void cbq_ovl_drop(struct cbq_class *cl) 602 static void cbq_ovl_drop(struct cbq_class *cl)
582 { 603 {
583 if (cl->q->ops->drop) 604 if (cl->q->ops->drop)
584 if (cl->q->ops->drop(cl->q)) 605 if (cl->q->ops->drop(cl->q))
585 cl->qdisc->q.qlen--; 606 cl->qdisc->q.qlen--;
586 cl->xstats.overactions++; 607 cl->xstats.overactions++;
587 cbq_ovl_classic(cl); 608 cbq_ovl_classic(cl);
588 } 609 }
589 610
590 static psched_tdiff_t cbq_undelay_prio(struct !! 611 static void cbq_watchdog(unsigned long arg)
591 psched_ !! 612 {
>> 613 struct Qdisc *sch = (struct Qdisc*)arg;
>> 614
>> 615 sch->flags &= ~TCQ_F_THROTTLED;
>> 616 netif_schedule(sch->dev);
>> 617 }
>> 618
>> 619 static unsigned long cbq_undelay_prio(struct cbq_sched_data *q, int prio)
592 { 620 {
593 struct cbq_class *cl; 621 struct cbq_class *cl;
594 struct cbq_class *cl_prev = q->active[ 622 struct cbq_class *cl_prev = q->active[prio];
595 psched_time_t sched = now; !! 623 unsigned long now = jiffies;
>> 624 unsigned long sched = now;
596 625
597 if (cl_prev == NULL) 626 if (cl_prev == NULL)
598 return 0; !! 627 return now;
599 628
600 do { 629 do {
601 cl = cl_prev->next_alive; 630 cl = cl_prev->next_alive;
602 if (now - cl->penalized > 0) { !! 631 if ((long)(now - cl->penalized) > 0) {
603 cl_prev->next_alive = 632 cl_prev->next_alive = cl->next_alive;
604 cl->next_alive = NULL; 633 cl->next_alive = NULL;
605 cl->cpriority = cl->pr 634 cl->cpriority = cl->priority;
606 cl->delayed = 0; 635 cl->delayed = 0;
607 cbq_activate_class(cl) 636 cbq_activate_class(cl);
608 637
609 if (cl == q->active[pr 638 if (cl == q->active[prio]) {
610 q->active[prio 639 q->active[prio] = cl_prev;
611 if (cl == q->a 640 if (cl == q->active[prio]) {
612 q->act 641 q->active[prio] = NULL;
613 return 642 return 0;
614 } 643 }
615 } 644 }
616 645
617 cl = cl_prev->next_ali 646 cl = cl_prev->next_alive;
618 } else if (sched - cl->penaliz !! 647 } else if ((long)(sched - cl->penalized) > 0)
619 sched = cl->penalized; 648 sched = cl->penalized;
620 } while ((cl_prev = cl) != q->active[p 649 } while ((cl_prev = cl) != q->active[prio]);
621 650
622 return sched - now; !! 651 return (long)(sched - now);
623 } 652 }
624 653
625 static enum hrtimer_restart cbq_undelay(struct !! 654 static void cbq_undelay(unsigned long arg)
626 { 655 {
627 struct cbq_sched_data *q = container_o !! 656 struct Qdisc *sch = (struct Qdisc*)arg;
628 !! 657 struct cbq_sched_data *q = qdisc_priv(sch);
629 struct Qdisc *sch = q->watchdog.qdisc; !! 658 long delay = 0;
630 psched_time_t now; <<
631 psched_tdiff_t delay = 0; <<
632 unsigned pmask; 659 unsigned pmask;
633 660
634 now = psched_get_time(); <<
635 <<
636 pmask = q->pmask; 661 pmask = q->pmask;
637 q->pmask = 0; 662 q->pmask = 0;
638 663
639 while (pmask) { 664 while (pmask) {
640 int prio = ffz(~pmask); 665 int prio = ffz(~pmask);
641 psched_tdiff_t tmp; !! 666 long tmp;
642 667
643 pmask &= ~(1<<prio); 668 pmask &= ~(1<<prio);
644 669
645 tmp = cbq_undelay_prio(q, prio !! 670 tmp = cbq_undelay_prio(q, prio);
646 if (tmp > 0) { 671 if (tmp > 0) {
647 q->pmask |= 1<<prio; 672 q->pmask |= 1<<prio;
648 if (tmp < delay || del 673 if (tmp < delay || delay == 0)
649 delay = tmp; 674 delay = tmp;
650 } 675 }
651 } 676 }
652 677
653 if (delay) { 678 if (delay) {
654 ktime_t time; !! 679 q->delay_timer.expires = jiffies + delay;
655 !! 680 add_timer(&q->delay_timer);
656 time = ktime_set(0, 0); <<
657 time = ktime_add_ns(time, PSCH <<
658 hrtimer_start(&q->delay_timer, <<
659 } 681 }
660 682
661 sch->flags &= ~TCQ_F_THROTTLED; 683 sch->flags &= ~TCQ_F_THROTTLED;
662 netif_schedule(sch->dev); 684 netif_schedule(sch->dev);
663 return HRTIMER_NORESTART; <<
664 } 685 }
665 686
666 #ifdef CONFIG_NET_CLS_ACT !! 687
>> 688 #ifdef CONFIG_NET_CLS_POLICE
>> 689
667 static int cbq_reshape_fail(struct sk_buff *sk 690 static int cbq_reshape_fail(struct sk_buff *skb, struct Qdisc *child)
668 { 691 {
669 int len = skb->len; 692 int len = skb->len;
670 struct Qdisc *sch = child->__parent; 693 struct Qdisc *sch = child->__parent;
671 struct cbq_sched_data *q = qdisc_priv( 694 struct cbq_sched_data *q = qdisc_priv(sch);
672 struct cbq_class *cl = q->rx_class; 695 struct cbq_class *cl = q->rx_class;
673 696
674 q->rx_class = NULL; 697 q->rx_class = NULL;
675 698
676 if (cl && (cl = cbq_reclassify(skb, cl 699 if (cl && (cl = cbq_reclassify(skb, cl)) != NULL) {
677 700
678 cbq_mark_toplevel(q, cl); 701 cbq_mark_toplevel(q, cl);
679 702
680 q->rx_class = cl; 703 q->rx_class = cl;
681 cl->q->__parent = sch; 704 cl->q->__parent = sch;
682 705
683 if (cl->q->enqueue(skb, cl->q) 706 if (cl->q->enqueue(skb, cl->q) == 0) {
684 sch->q.qlen++; 707 sch->q.qlen++;
685 sch->bstats.packets++; 708 sch->bstats.packets++;
686 sch->bstats.bytes+=len 709 sch->bstats.bytes+=len;
687 if (!cl->next_alive) 710 if (!cl->next_alive)
688 cbq_activate_c 711 cbq_activate_class(cl);
689 return 0; 712 return 0;
690 } 713 }
691 sch->qstats.drops++; 714 sch->qstats.drops++;
692 return 0; 715 return 0;
693 } 716 }
694 717
695 sch->qstats.drops++; 718 sch->qstats.drops++;
696 return -1; 719 return -1;
697 } 720 }
698 #endif 721 #endif
699 722
700 /* !! 723 /*
701 It is mission critical procedure. 724 It is mission critical procedure.
702 725
703 We "regenerate" toplevel cutoff, if transmi 726 We "regenerate" toplevel cutoff, if transmitting class
704 has backlog and it is not regulated. It is 727 has backlog and it is not regulated. It is not part of
705 original CBQ description, but looks more re 728 original CBQ description, but looks more reasonable.
706 Probably, it is wrong. This question needs 729 Probably, it is wrong. This question needs further investigation.
707 */ 730 */
708 731
709 static __inline__ void 732 static __inline__ void
710 cbq_update_toplevel(struct cbq_sched_data *q, 733 cbq_update_toplevel(struct cbq_sched_data *q, struct cbq_class *cl,
711 struct cbq_class *borrowed 734 struct cbq_class *borrowed)
712 { 735 {
713 if (cl && q->toplevel >= borrowed->lev 736 if (cl && q->toplevel >= borrowed->level) {
714 if (cl->q->q.qlen > 1) { 737 if (cl->q->q.qlen > 1) {
715 do { 738 do {
716 if (borrowed-> !! 739 if (PSCHED_IS_PASTPERFECT(borrowed->undertime)) {
717 q->top 740 q->toplevel = borrowed->level;
718 return 741 return;
719 } 742 }
720 } while ((borrowed=bor 743 } while ((borrowed=borrowed->borrow) != NULL);
721 } 744 }
722 #if 0 !! 745 #if 0
723 /* It is not necessary now. Uncommenti 746 /* It is not necessary now. Uncommenting it
724 will save CPU cycles, but decrease 747 will save CPU cycles, but decrease fairness.
725 */ 748 */
726 q->toplevel = TC_CBQ_MAXLEVEL; 749 q->toplevel = TC_CBQ_MAXLEVEL;
727 #endif 750 #endif
728 } 751 }
729 } 752 }
730 753
731 static void 754 static void
732 cbq_update(struct cbq_sched_data *q) 755 cbq_update(struct cbq_sched_data *q)
733 { 756 {
734 struct cbq_class *this = q->tx_class; 757 struct cbq_class *this = q->tx_class;
735 struct cbq_class *cl = this; 758 struct cbq_class *cl = this;
736 int len = q->tx_len; 759 int len = q->tx_len;
737 760
738 q->tx_class = NULL; 761 q->tx_class = NULL;
739 762
740 for ( ; cl; cl = cl->share) { 763 for ( ; cl; cl = cl->share) {
741 long avgidle = cl->avgidle; 764 long avgidle = cl->avgidle;
742 long idle; 765 long idle;
743 766
744 cl->bstats.packets++; 767 cl->bstats.packets++;
745 cl->bstats.bytes += len; 768 cl->bstats.bytes += len;
746 769
747 /* 770 /*
748 (now - last) is total time 771 (now - last) is total time between packet right edges.
749 (last_pktlen/rate) is "virt 772 (last_pktlen/rate) is "virtual" busy time, so that
750 773
751 idle = (now - last) - !! 774 idle = (now - last) - last_pktlen/rate
752 */ 775 */
753 776
754 idle = q->now - cl->last; !! 777 idle = PSCHED_TDIFF(q->now, cl->last);
755 if ((unsigned long)idle > 128* 778 if ((unsigned long)idle > 128*1024*1024) {
756 avgidle = cl->maxidle; 779 avgidle = cl->maxidle;
757 } else { 780 } else {
758 idle -= L2T(cl, len); 781 idle -= L2T(cl, len);
759 782
760 /* true_avgidle := (1-W)*true_ 783 /* true_avgidle := (1-W)*true_avgidle + W*idle,
761 where W=2^{-ewma_log}. But 784 where W=2^{-ewma_log}. But cl->avgidle is scaled:
762 cl->avgidle == true_avgidle 785 cl->avgidle == true_avgidle/W,
763 hence: 786 hence:
764 */ 787 */
765 avgidle += idle - (avg 788 avgidle += idle - (avgidle>>cl->ewma_log);
766 } 789 }
767 790
768 if (avgidle <= 0) { 791 if (avgidle <= 0) {
769 /* Overlimit or at-lim 792 /* Overlimit or at-limit */
770 793
771 if (avgidle < cl->mini 794 if (avgidle < cl->minidle)
772 avgidle = cl-> 795 avgidle = cl->minidle;
773 796
774 cl->avgidle = avgidle; 797 cl->avgidle = avgidle;
775 798
776 /* Calculate expected 799 /* Calculate expected time, when this class
777 will be allowed to 800 will be allowed to send.
778 It will occur, when 801 It will occur, when:
779 (1-W)*true_avgidle 802 (1-W)*true_avgidle + W*delay = 0, i.e.
780 idle = (1/W - 1)*(- 803 idle = (1/W - 1)*(-true_avgidle)
781 or 804 or
782 idle = (1 - W)*(-cl 805 idle = (1 - W)*(-cl->avgidle);
783 */ 806 */
784 idle = (-avgidle) - (( 807 idle = (-avgidle) - ((-avgidle) >> cl->ewma_log);
785 808
786 /* 809 /*
787 That is not all. 810 That is not all.
788 To maintain the rat 811 To maintain the rate allocated to the class,
789 we add to undertime 812 we add to undertime virtual clock,
790 necessary to comple 813 necessary to complete transmitted packet.
791 (len/phys_bandwidth 814 (len/phys_bandwidth has been already passed
792 to the moment of cb 815 to the moment of cbq_update)
793 */ 816 */
794 817
795 idle -= L2T(&q->link, 818 idle -= L2T(&q->link, len);
796 idle += L2T(cl, len); 819 idle += L2T(cl, len);
797 820
798 cl->undertime = q->now !! 821 PSCHED_AUDIT_TDIFF(idle);
>> 822
>> 823 PSCHED_TADD2(q->now, idle, cl->undertime);
799 } else { 824 } else {
800 /* Underlimit */ 825 /* Underlimit */
801 826
802 cl->undertime = PSCHED !! 827 PSCHED_SET_PASTPERFECT(cl->undertime);
803 if (avgidle > cl->maxi 828 if (avgidle > cl->maxidle)
804 cl->avgidle = 829 cl->avgidle = cl->maxidle;
805 else 830 else
806 cl->avgidle = 831 cl->avgidle = avgidle;
807 } 832 }
808 cl->last = q->now; 833 cl->last = q->now;
809 } 834 }
810 835
811 cbq_update_toplevel(q, this, q->tx_bor 836 cbq_update_toplevel(q, this, q->tx_borrowed);
812 } 837 }
813 838
814 static __inline__ struct cbq_class * 839 static __inline__ struct cbq_class *
815 cbq_under_limit(struct cbq_class *cl) 840 cbq_under_limit(struct cbq_class *cl)
816 { 841 {
817 struct cbq_sched_data *q = qdisc_priv( 842 struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
818 struct cbq_class *this_cl = cl; 843 struct cbq_class *this_cl = cl;
819 844
820 if (cl->tparent == NULL) 845 if (cl->tparent == NULL)
821 return cl; 846 return cl;
822 847
823 if (cl->undertime == PSCHED_PASTPERFEC !! 848 if (PSCHED_IS_PASTPERFECT(cl->undertime) ||
>> 849 !PSCHED_TLESS(q->now, cl->undertime)) {
824 cl->delayed = 0; 850 cl->delayed = 0;
825 return cl; 851 return cl;
826 } 852 }
827 853
828 do { 854 do {
829 /* It is very suspicious place 855 /* It is very suspicious place. Now overlimit
830 action is generated for not 856 action is generated for not bounded classes
831 only if link is completely 857 only if link is completely congested.
832 Though it is in agree with 858 Though it is in agree with ancestor-only paradigm,
833 it looks very stupid. Parti 859 it looks very stupid. Particularly,
834 it means that this chunk of 860 it means that this chunk of code will either
835 never be called or result i 861 never be called or result in strong amplification
836 of burstiness. Dangerous, s 862 of burstiness. Dangerous, silly, and, however,
837 no another solution exists. 863 no another solution exists.
838 */ 864 */
839 if ((cl = cl->borrow) == NULL) 865 if ((cl = cl->borrow) == NULL) {
840 this_cl->qstats.overli 866 this_cl->qstats.overlimits++;
841 this_cl->overlimit(thi 867 this_cl->overlimit(this_cl);
842 return NULL; 868 return NULL;
843 } 869 }
844 if (cl->level > q->toplevel) 870 if (cl->level > q->toplevel)
845 return NULL; 871 return NULL;
846 } while (cl->undertime != PSCHED_PASTP !! 872 } while (!PSCHED_IS_PASTPERFECT(cl->undertime) &&
>> 873 PSCHED_TLESS(q->now, cl->undertime));
847 874
848 cl->delayed = 0; 875 cl->delayed = 0;
849 return cl; 876 return cl;
850 } 877 }
851 878
852 static __inline__ struct sk_buff * 879 static __inline__ struct sk_buff *
853 cbq_dequeue_prio(struct Qdisc *sch, int prio) 880 cbq_dequeue_prio(struct Qdisc *sch, int prio)
854 { 881 {
855 struct cbq_sched_data *q = qdisc_priv( 882 struct cbq_sched_data *q = qdisc_priv(sch);
856 struct cbq_class *cl_tail, *cl_prev, * 883 struct cbq_class *cl_tail, *cl_prev, *cl;
857 struct sk_buff *skb; 884 struct sk_buff *skb;
858 int deficit; 885 int deficit;
859 886
860 cl_tail = cl_prev = q->active[prio]; 887 cl_tail = cl_prev = q->active[prio];
861 cl = cl_prev->next_alive; 888 cl = cl_prev->next_alive;
862 889
863 do { 890 do {
864 deficit = 0; 891 deficit = 0;
865 892
866 /* Start round */ 893 /* Start round */
867 do { 894 do {
868 struct cbq_class *borr 895 struct cbq_class *borrow = cl;
869 896
870 if (cl->q->q.qlen && 897 if (cl->q->q.qlen &&
871 (borrow = cbq_unde 898 (borrow = cbq_under_limit(cl)) == NULL)
872 goto skip_clas 899 goto skip_class;
873 900
874 if (cl->deficit <= 0) 901 if (cl->deficit <= 0) {
875 /* Class exhau 902 /* Class exhausted its allotment per
876 this round. 903 this round. Switch to the next one.
877 */ 904 */
878 deficit = 1; 905 deficit = 1;
879 cl->deficit += 906 cl->deficit += cl->quantum;
880 goto next_clas 907 goto next_class;
881 } 908 }
882 909
883 skb = cl->q->dequeue(c 910 skb = cl->q->dequeue(cl->q);
884 911
885 /* Class did not give 912 /* Class did not give us any skb :-(
886 It could occur even !! 913 It could occur even if cl->q->q.qlen != 0
887 f.e. if cl->q == "t 914 f.e. if cl->q == "tbf"
888 */ 915 */
889 if (skb == NULL) 916 if (skb == NULL)
890 goto skip_clas 917 goto skip_class;
891 918
892 cl->deficit -= skb->le 919 cl->deficit -= skb->len;
893 q->tx_class = cl; 920 q->tx_class = cl;
894 q->tx_borrowed = borro 921 q->tx_borrowed = borrow;
895 if (borrow != cl) { 922 if (borrow != cl) {
896 #ifndef CBQ_XSTATS_BORROWS_BYTES 923 #ifndef CBQ_XSTATS_BORROWS_BYTES
897 borrow->xstats 924 borrow->xstats.borrows++;
898 cl->xstats.bor 925 cl->xstats.borrows++;
899 #else 926 #else
900 borrow->xstats 927 borrow->xstats.borrows += skb->len;
901 cl->xstats.bor 928 cl->xstats.borrows += skb->len;
902 #endif 929 #endif
903 } 930 }
904 q->tx_len = skb->len; 931 q->tx_len = skb->len;
905 932
906 if (cl->deficit <= 0) 933 if (cl->deficit <= 0) {
907 q->active[prio 934 q->active[prio] = cl;
908 cl = cl->next_ 935 cl = cl->next_alive;
909 cl->deficit += 936 cl->deficit += cl->quantum;
910 } 937 }
911 return skb; 938 return skb;
912 939
913 skip_class: 940 skip_class:
914 if (cl->q->q.qlen == 0 941 if (cl->q->q.qlen == 0 || prio != cl->cpriority) {
915 /* Class is em 942 /* Class is empty or penalized.
916 Unlink it f 943 Unlink it from active chain.
917 */ 944 */
918 cl_prev->next_ 945 cl_prev->next_alive = cl->next_alive;
919 cl->next_alive 946 cl->next_alive = NULL;
920 947
921 /* Did cl_tail 948 /* Did cl_tail point to it? */
922 if (cl == cl_t 949 if (cl == cl_tail) {
923 /* Rep 950 /* Repair it! */
924 cl_tai 951 cl_tail = cl_prev;
925 952
926 /* Was 953 /* Was it the last class in this band? */
927 if (cl 954 if (cl == cl_tail) {
928 955 /* Kill the band! */
929 956 q->active[prio] = NULL;
930 957 q->activemask &= ~(1<<prio);
931 958 if (cl->q->q.qlen)
932 959 cbq_activate_class(cl);
933 960 return NULL;
934 } 961 }
935 962
936 q->act 963 q->active[prio] = cl_tail;
937 } 964 }
938 if (cl->q->q.q 965 if (cl->q->q.qlen)
939 cbq_ac 966 cbq_activate_class(cl);
940 967
941 cl = cl_prev; 968 cl = cl_prev;
942 } 969 }
943 970
944 next_class: 971 next_class:
945 cl_prev = cl; 972 cl_prev = cl;
946 cl = cl->next_alive; 973 cl = cl->next_alive;
947 } while (cl_prev != cl_tail); 974 } while (cl_prev != cl_tail);
948 } while (deficit); 975 } while (deficit);
949 976
950 q->active[prio] = cl_prev; 977 q->active[prio] = cl_prev;
951 978
952 return NULL; 979 return NULL;
953 } 980 }
954 981
955 static __inline__ struct sk_buff * 982 static __inline__ struct sk_buff *
956 cbq_dequeue_1(struct Qdisc *sch) 983 cbq_dequeue_1(struct Qdisc *sch)
957 { 984 {
958 struct cbq_sched_data *q = qdisc_priv( 985 struct cbq_sched_data *q = qdisc_priv(sch);
959 struct sk_buff *skb; 986 struct sk_buff *skb;
960 unsigned activemask; 987 unsigned activemask;
961 988
962 activemask = q->activemask&0xFF; 989 activemask = q->activemask&0xFF;
963 while (activemask) { 990 while (activemask) {
964 int prio = ffz(~activemask); 991 int prio = ffz(~activemask);
965 activemask &= ~(1<<prio); 992 activemask &= ~(1<<prio);
966 skb = cbq_dequeue_prio(sch, pr 993 skb = cbq_dequeue_prio(sch, prio);
967 if (skb) 994 if (skb)
968 return skb; 995 return skb;
969 } 996 }
970 return NULL; 997 return NULL;
971 } 998 }
972 999
973 static struct sk_buff * 1000 static struct sk_buff *
974 cbq_dequeue(struct Qdisc *sch) 1001 cbq_dequeue(struct Qdisc *sch)
975 { 1002 {
976 struct sk_buff *skb; 1003 struct sk_buff *skb;
977 struct cbq_sched_data *q = qdisc_priv( 1004 struct cbq_sched_data *q = qdisc_priv(sch);
978 psched_time_t now; 1005 psched_time_t now;
979 psched_tdiff_t incr; 1006 psched_tdiff_t incr;
980 1007
981 now = psched_get_time(); !! 1008 PSCHED_GET_TIME(now);
982 incr = now - q->now_rt; !! 1009 incr = PSCHED_TDIFF(now, q->now_rt);
983 1010
984 if (q->tx_class) { 1011 if (q->tx_class) {
985 psched_tdiff_t incr2; 1012 psched_tdiff_t incr2;
986 /* Time integrator. We calcula 1013 /* Time integrator. We calculate EOS time
987 by adding expected packet t 1014 by adding expected packet transmission time.
988 If real time is greater, we 1015 If real time is greater, we warp artificial clock,
989 so that: 1016 so that:
990 1017
991 cbq_time = max(real_time, w 1018 cbq_time = max(real_time, work);
992 */ 1019 */
993 incr2 = L2T(&q->link, q->tx_le 1020 incr2 = L2T(&q->link, q->tx_len);
994 q->now += incr2; !! 1021 PSCHED_TADD(q->now, incr2);
995 cbq_update(q); 1022 cbq_update(q);
996 if ((incr -= incr2) < 0) 1023 if ((incr -= incr2) < 0)
997 incr = 0; 1024 incr = 0;
998 } 1025 }
999 q->now += incr; !! 1026 PSCHED_TADD(q->now, incr);
1000 q->now_rt = now; 1027 q->now_rt = now;
1001 1028
1002 for (;;) { 1029 for (;;) {
1003 q->wd_expires = 0; 1030 q->wd_expires = 0;
1004 1031
1005 skb = cbq_dequeue_1(sch); 1032 skb = cbq_dequeue_1(sch);
1006 if (skb) { 1033 if (skb) {
1007 sch->q.qlen--; 1034 sch->q.qlen--;
1008 sch->flags &= ~TCQ_F_ 1035 sch->flags &= ~TCQ_F_THROTTLED;
1009 return skb; 1036 return skb;
1010 } 1037 }
1011 1038
1012 /* All the classes are overli 1039 /* All the classes are overlimit.
1013 1040
1014 It is possible, if: 1041 It is possible, if:
1015 1042
1016 1. Scheduler is empty. 1043 1. Scheduler is empty.
1017 2. Toplevel cutoff inhibit 1044 2. Toplevel cutoff inhibited borrowing.
1018 3. Root class is overlimit 1045 3. Root class is overlimit.
1019 1046
1020 Reset 2d and 3d conditions 1047 Reset 2d and 3d conditions and retry.
1021 1048
1022 Note, that NS and cbq-2.0 1049 Note, that NS and cbq-2.0 are buggy, peeking
1023 an arbitrary class is appr 1050 an arbitrary class is appropriate for ancestor-only
1024 sharing, but not for tople 1051 sharing, but not for toplevel algorithm.
1025 1052
1026 Our version is better, but 1053 Our version is better, but slower, because it requires
1027 two passes, but it is unav 1054 two passes, but it is unavoidable with top-level sharing.
1028 */ 1055 */
1029 1056
1030 if (q->toplevel == TC_CBQ_MAX 1057 if (q->toplevel == TC_CBQ_MAXLEVEL &&
1031 q->link.undertime == PSCH !! 1058 PSCHED_IS_PASTPERFECT(q->link.undertime))
1032 break; 1059 break;
1033 1060
1034 q->toplevel = TC_CBQ_MAXLEVEL 1061 q->toplevel = TC_CBQ_MAXLEVEL;
1035 q->link.undertime = PSCHED_PA !! 1062 PSCHED_SET_PASTPERFECT(q->link.undertime);
1036 } 1063 }
1037 1064
1038 /* No packets in scheduler or nobody 1065 /* No packets in scheduler or nobody wants to give them to us :-(
1039 Sigh... start watchdog timer in th 1066 Sigh... start watchdog timer in the last case. */
1040 1067
1041 if (sch->q.qlen) { 1068 if (sch->q.qlen) {
1042 sch->qstats.overlimits++; 1069 sch->qstats.overlimits++;
1043 if (q->wd_expires) !! 1070 if (q->wd_expires) {
1044 qdisc_watchdog_schedu !! 1071 long delay = PSCHED_US2JIFFIE(q->wd_expires);
1045 !! 1072 if (delay <= 0)
>> 1073 delay = 1;
>> 1074 mod_timer(&q->wd_timer, jiffies + delay);
>> 1075 sch->flags |= TCQ_F_THROTTLED;
>> 1076 }
1046 } 1077 }
1047 return NULL; 1078 return NULL;
1048 } 1079 }
1049 1080
1050 /* CBQ class maintanance routines */ 1081 /* CBQ class maintanance routines */
1051 1082
1052 static void cbq_adjust_levels(struct cbq_clas 1083 static void cbq_adjust_levels(struct cbq_class *this)
1053 { 1084 {
1054 if (this == NULL) 1085 if (this == NULL)
1055 return; 1086 return;
1056 1087
1057 do { 1088 do {
1058 int level = 0; 1089 int level = 0;
1059 struct cbq_class *cl; 1090 struct cbq_class *cl;
1060 1091
1061 if ((cl = this->children) != 1092 if ((cl = this->children) != NULL) {
1062 do { 1093 do {
1063 if (cl->level 1094 if (cl->level > level)
1064 level 1095 level = cl->level;
1065 } while ((cl = cl->si 1096 } while ((cl = cl->sibling) != this->children);
1066 } 1097 }
1067 this->level = level+1; 1098 this->level = level+1;
1068 } while ((this = this->tparent) != NU 1099 } while ((this = this->tparent) != NULL);
1069 } 1100 }
1070 1101
1071 static void cbq_normalize_quanta(struct cbq_s 1102 static void cbq_normalize_quanta(struct cbq_sched_data *q, int prio)
1072 { 1103 {
1073 struct cbq_class *cl; 1104 struct cbq_class *cl;
1074 unsigned h; 1105 unsigned h;
1075 1106
1076 if (q->quanta[prio] == 0) 1107 if (q->quanta[prio] == 0)
1077 return; 1108 return;
1078 1109
1079 for (h=0; h<16; h++) { 1110 for (h=0; h<16; h++) {
1080 for (cl = q->classes[h]; cl; 1111 for (cl = q->classes[h]; cl; cl = cl->next) {
1081 /* BUGGGG... Beware! 1112 /* BUGGGG... Beware! This expression suffer of
1082 arithmetic overflo 1113 arithmetic overflows!
1083 */ 1114 */
1084 if (cl->priority == p 1115 if (cl->priority == prio) {
1085 cl->quantum = 1116 cl->quantum = (cl->weight*cl->allot*q->nclasses[prio])/
1086 q->qu 1117 q->quanta[prio];
1087 } 1118 }
1088 if (cl->quantum <= 0 1119 if (cl->quantum <= 0 || cl->quantum>32*cl->qdisc->dev->mtu) {
1089 printk(KERN_W 1120 printk(KERN_WARNING "CBQ: class %08x has bad quantum==%ld, repaired.\n", cl->classid, cl->quantum);
1090 cl->quantum = 1121 cl->quantum = cl->qdisc->dev->mtu/2 + 1;
1091 } 1122 }
1092 } 1123 }
1093 } 1124 }
1094 } 1125 }
1095 1126
1096 static void cbq_sync_defmap(struct cbq_class 1127 static void cbq_sync_defmap(struct cbq_class *cl)
1097 { 1128 {
1098 struct cbq_sched_data *q = qdisc_priv 1129 struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
1099 struct cbq_class *split = cl->split; 1130 struct cbq_class *split = cl->split;
1100 unsigned h; 1131 unsigned h;
1101 int i; 1132 int i;
1102 1133
1103 if (split == NULL) 1134 if (split == NULL)
1104 return; 1135 return;
1105 1136
1106 for (i=0; i<=TC_PRIO_MAX; i++) { 1137 for (i=0; i<=TC_PRIO_MAX; i++) {
1107 if (split->defaults[i] == cl 1138 if (split->defaults[i] == cl && !(cl->defmap&(1<<i)))
1108 split->defaults[i] = 1139 split->defaults[i] = NULL;
1109 } 1140 }
1110 1141
1111 for (i=0; i<=TC_PRIO_MAX; i++) { 1142 for (i=0; i<=TC_PRIO_MAX; i++) {
1112 int level = split->level; 1143 int level = split->level;
1113 1144
1114 if (split->defaults[i]) 1145 if (split->defaults[i])
1115 continue; 1146 continue;
1116 1147
1117 for (h=0; h<16; h++) { 1148 for (h=0; h<16; h++) {
1118 struct cbq_class *c; 1149 struct cbq_class *c;
1119 1150
1120 for (c = q->classes[h 1151 for (c = q->classes[h]; c; c = c->next) {
1121 if (c->split 1152 if (c->split == split && c->level < level &&
1122 c->defmap 1153 c->defmap&(1<<i)) {
1123 split 1154 split->defaults[i] = c;
1124 level 1155 level = c->level;
1125 } 1156 }
1126 } 1157 }
1127 } 1158 }
1128 } 1159 }
1129 } 1160 }
1130 1161
1131 static void cbq_change_defmap(struct cbq_clas 1162 static void cbq_change_defmap(struct cbq_class *cl, u32 splitid, u32 def, u32 mask)
1132 { 1163 {
1133 struct cbq_class *split = NULL; 1164 struct cbq_class *split = NULL;
1134 1165
1135 if (splitid == 0) { 1166 if (splitid == 0) {
1136 if ((split = cl->split) == NU 1167 if ((split = cl->split) == NULL)
1137 return; 1168 return;
1138 splitid = split->classid; 1169 splitid = split->classid;
1139 } 1170 }
1140 1171
1141 if (split == NULL || split->classid ! 1172 if (split == NULL || split->classid != splitid) {
1142 for (split = cl->tparent; spl 1173 for (split = cl->tparent; split; split = split->tparent)
1143 if (split->classid == 1174 if (split->classid == splitid)
1144 break; 1175 break;
1145 } 1176 }
1146 1177
1147 if (split == NULL) 1178 if (split == NULL)
1148 return; 1179 return;
1149 1180
1150 if (cl->split != split) { 1181 if (cl->split != split) {
1151 cl->defmap = 0; 1182 cl->defmap = 0;
1152 cbq_sync_defmap(cl); 1183 cbq_sync_defmap(cl);
1153 cl->split = split; 1184 cl->split = split;
1154 cl->defmap = def&mask; 1185 cl->defmap = def&mask;
1155 } else 1186 } else
1156 cl->defmap = (cl->defmap&~mas 1187 cl->defmap = (cl->defmap&~mask)|(def&mask);
1157 1188
1158 cbq_sync_defmap(cl); 1189 cbq_sync_defmap(cl);
1159 } 1190 }
1160 1191
1161 static void cbq_unlink_class(struct cbq_class 1192 static void cbq_unlink_class(struct cbq_class *this)
1162 { 1193 {
1163 struct cbq_class *cl, **clp; 1194 struct cbq_class *cl, **clp;
1164 struct cbq_sched_data *q = qdisc_priv 1195 struct cbq_sched_data *q = qdisc_priv(this->qdisc);
1165 1196
1166 for (clp = &q->classes[cbq_hash(this- 1197 for (clp = &q->classes[cbq_hash(this->classid)]; (cl = *clp) != NULL; clp = &cl->next) {
1167 if (cl == this) { 1198 if (cl == this) {
1168 *clp = cl->next; 1199 *clp = cl->next;
1169 cl->next = NULL; 1200 cl->next = NULL;
1170 break; 1201 break;
1171 } 1202 }
1172 } 1203 }
1173 1204
1174 if (this->tparent) { 1205 if (this->tparent) {
1175 clp=&this->sibling; 1206 clp=&this->sibling;
1176 cl = *clp; 1207 cl = *clp;
1177 do { 1208 do {
1178 if (cl == this) { 1209 if (cl == this) {
1179 *clp = cl->si 1210 *clp = cl->sibling;
1180 break; 1211 break;
1181 } 1212 }
1182 clp = &cl->sibling; 1213 clp = &cl->sibling;
1183 } while ((cl = *clp) != this- 1214 } while ((cl = *clp) != this->sibling);
1184 1215
1185 if (this->tparent->children = 1216 if (this->tparent->children == this) {
1186 this->tparent->childr 1217 this->tparent->children = this->sibling;
1187 if (this->sibling == 1218 if (this->sibling == this)
1188 this->tparent 1219 this->tparent->children = NULL;
1189 } 1220 }
1190 } else { 1221 } else {
1191 BUG_TRAP(this->sibling == thi 1222 BUG_TRAP(this->sibling == this);
1192 } 1223 }
1193 } 1224 }
1194 1225
1195 static void cbq_link_class(struct cbq_class * 1226 static void cbq_link_class(struct cbq_class *this)
1196 { 1227 {
1197 struct cbq_sched_data *q = qdisc_priv 1228 struct cbq_sched_data *q = qdisc_priv(this->qdisc);
1198 unsigned h = cbq_hash(this->classid); 1229 unsigned h = cbq_hash(this->classid);
1199 struct cbq_class *parent = this->tpar 1230 struct cbq_class *parent = this->tparent;
1200 1231
1201 this->sibling = this; 1232 this->sibling = this;
1202 this->next = q->classes[h]; 1233 this->next = q->classes[h];
1203 q->classes[h] = this; 1234 q->classes[h] = this;
1204 1235
1205 if (parent == NULL) 1236 if (parent == NULL)
1206 return; 1237 return;
1207 1238
1208 if (parent->children == NULL) { 1239 if (parent->children == NULL) {
1209 parent->children = this; 1240 parent->children = this;
1210 } else { 1241 } else {
1211 this->sibling = parent->child 1242 this->sibling = parent->children->sibling;
1212 parent->children->sibling = t 1243 parent->children->sibling = this;
1213 } 1244 }
1214 } 1245 }
1215 1246
1216 static unsigned int cbq_drop(struct Qdisc* sc 1247 static unsigned int cbq_drop(struct Qdisc* sch)
1217 { 1248 {
1218 struct cbq_sched_data *q = qdisc_priv 1249 struct cbq_sched_data *q = qdisc_priv(sch);
1219 struct cbq_class *cl, *cl_head; 1250 struct cbq_class *cl, *cl_head;
1220 int prio; 1251 int prio;
1221 unsigned int len; 1252 unsigned int len;
1222 1253
1223 for (prio = TC_CBQ_MAXPRIO; prio >= 0 1254 for (prio = TC_CBQ_MAXPRIO; prio >= 0; prio--) {
1224 if ((cl_head = q->active[prio 1255 if ((cl_head = q->active[prio]) == NULL)
1225 continue; 1256 continue;
1226 1257
1227 cl = cl_head; 1258 cl = cl_head;
1228 do { 1259 do {
1229 if (cl->q->ops->drop 1260 if (cl->q->ops->drop && (len = cl->q->ops->drop(cl->q))) {
1230 sch->q.qlen-- 1261 sch->q.qlen--;
1231 if (!cl->q->q <<
1232 cbq_d <<
1233 return len; 1262 return len;
1234 } 1263 }
1235 } while ((cl = cl->next_alive 1264 } while ((cl = cl->next_alive) != cl_head);
1236 } 1265 }
1237 return 0; 1266 return 0;
1238 } 1267 }
1239 1268
1240 static void 1269 static void
1241 cbq_reset(struct Qdisc* sch) 1270 cbq_reset(struct Qdisc* sch)
1242 { 1271 {
1243 struct cbq_sched_data *q = qdisc_priv 1272 struct cbq_sched_data *q = qdisc_priv(sch);
1244 struct cbq_class *cl; 1273 struct cbq_class *cl;
1245 int prio; 1274 int prio;
1246 unsigned h; 1275 unsigned h;
1247 1276
1248 q->activemask = 0; 1277 q->activemask = 0;
1249 q->pmask = 0; 1278 q->pmask = 0;
1250 q->tx_class = NULL; 1279 q->tx_class = NULL;
1251 q->tx_borrowed = NULL; 1280 q->tx_borrowed = NULL;
1252 qdisc_watchdog_cancel(&q->watchdog); !! 1281 del_timer(&q->wd_timer);
1253 hrtimer_cancel(&q->delay_timer); !! 1282 del_timer(&q->delay_timer);
1254 q->toplevel = TC_CBQ_MAXLEVEL; 1283 q->toplevel = TC_CBQ_MAXLEVEL;
1255 q->now = psched_get_time(); !! 1284 PSCHED_GET_TIME(q->now);
1256 q->now_rt = q->now; 1285 q->now_rt = q->now;
1257 1286
1258 for (prio = 0; prio <= TC_CBQ_MAXPRIO 1287 for (prio = 0; prio <= TC_CBQ_MAXPRIO; prio++)
1259 q->active[prio] = NULL; 1288 q->active[prio] = NULL;
1260 1289
1261 for (h = 0; h < 16; h++) { 1290 for (h = 0; h < 16; h++) {
1262 for (cl = q->classes[h]; cl; 1291 for (cl = q->classes[h]; cl; cl = cl->next) {
1263 qdisc_reset(cl->q); 1292 qdisc_reset(cl->q);
1264 1293
1265 cl->next_alive = NULL 1294 cl->next_alive = NULL;
1266 cl->undertime = PSCHE !! 1295 PSCHED_SET_PASTPERFECT(cl->undertime);
1267 cl->avgidle = cl->max 1296 cl->avgidle = cl->maxidle;
1268 cl->deficit = cl->qua 1297 cl->deficit = cl->quantum;
1269 cl->cpriority = cl->p 1298 cl->cpriority = cl->priority;
1270 } 1299 }
1271 } 1300 }
1272 sch->q.qlen = 0; 1301 sch->q.qlen = 0;
1273 } 1302 }
1274 1303
1275 1304
1276 static int cbq_set_lss(struct cbq_class *cl, 1305 static int cbq_set_lss(struct cbq_class *cl, struct tc_cbq_lssopt *lss)
1277 { 1306 {
1278 if (lss->change&TCF_CBQ_LSS_FLAGS) { 1307 if (lss->change&TCF_CBQ_LSS_FLAGS) {
1279 cl->share = (lss->flags&TCF_C 1308 cl->share = (lss->flags&TCF_CBQ_LSS_ISOLATED) ? NULL : cl->tparent;
1280 cl->borrow = (lss->flags&TCF_ 1309 cl->borrow = (lss->flags&TCF_CBQ_LSS_BOUNDED) ? NULL : cl->tparent;
1281 } 1310 }
1282 if (lss->change&TCF_CBQ_LSS_EWMA) 1311 if (lss->change&TCF_CBQ_LSS_EWMA)
1283 cl->ewma_log = lss->ewma_log; 1312 cl->ewma_log = lss->ewma_log;
1284 if (lss->change&TCF_CBQ_LSS_AVPKT) 1313 if (lss->change&TCF_CBQ_LSS_AVPKT)
1285 cl->avpkt = lss->avpkt; 1314 cl->avpkt = lss->avpkt;
1286 if (lss->change&TCF_CBQ_LSS_MINIDLE) 1315 if (lss->change&TCF_CBQ_LSS_MINIDLE)
1287 cl->minidle = -(long)lss->min 1316 cl->minidle = -(long)lss->minidle;
1288 if (lss->change&TCF_CBQ_LSS_MAXIDLE) 1317 if (lss->change&TCF_CBQ_LSS_MAXIDLE) {
1289 cl->maxidle = lss->maxidle; 1318 cl->maxidle = lss->maxidle;
1290 cl->avgidle = lss->maxidle; 1319 cl->avgidle = lss->maxidle;
1291 } 1320 }
1292 if (lss->change&TCF_CBQ_LSS_OFFTIME) 1321 if (lss->change&TCF_CBQ_LSS_OFFTIME)
1293 cl->offtime = lss->offtime; 1322 cl->offtime = lss->offtime;
1294 return 0; 1323 return 0;
1295 } 1324 }
1296 1325
1297 static void cbq_rmprio(struct cbq_sched_data 1326 static void cbq_rmprio(struct cbq_sched_data *q, struct cbq_class *cl)
1298 { 1327 {
1299 q->nclasses[cl->priority]--; 1328 q->nclasses[cl->priority]--;
1300 q->quanta[cl->priority] -= cl->weight 1329 q->quanta[cl->priority] -= cl->weight;
1301 cbq_normalize_quanta(q, cl->priority) 1330 cbq_normalize_quanta(q, cl->priority);
1302 } 1331 }
1303 1332
1304 static void cbq_addprio(struct cbq_sched_data 1333 static void cbq_addprio(struct cbq_sched_data *q, struct cbq_class *cl)
1305 { 1334 {
1306 q->nclasses[cl->priority]++; 1335 q->nclasses[cl->priority]++;
1307 q->quanta[cl->priority] += cl->weight 1336 q->quanta[cl->priority] += cl->weight;
1308 cbq_normalize_quanta(q, cl->priority) 1337 cbq_normalize_quanta(q, cl->priority);
1309 } 1338 }
1310 1339
1311 static int cbq_set_wrr(struct cbq_class *cl, 1340 static int cbq_set_wrr(struct cbq_class *cl, struct tc_cbq_wrropt *wrr)
1312 { 1341 {
1313 struct cbq_sched_data *q = qdisc_priv 1342 struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
1314 1343
1315 if (wrr->allot) 1344 if (wrr->allot)
1316 cl->allot = wrr->allot; 1345 cl->allot = wrr->allot;
1317 if (wrr->weight) 1346 if (wrr->weight)
1318 cl->weight = wrr->weight; 1347 cl->weight = wrr->weight;
1319 if (wrr->priority) { 1348 if (wrr->priority) {
1320 cl->priority = wrr->priority- 1349 cl->priority = wrr->priority-1;
1321 cl->cpriority = cl->priority; 1350 cl->cpriority = cl->priority;
1322 if (cl->priority >= cl->prior 1351 if (cl->priority >= cl->priority2)
1323 cl->priority2 = TC_CB 1352 cl->priority2 = TC_CBQ_MAXPRIO-1;
1324 } 1353 }
1325 1354
1326 cbq_addprio(q, cl); 1355 cbq_addprio(q, cl);
1327 return 0; 1356 return 0;
1328 } 1357 }
1329 1358
1330 static int cbq_set_overlimit(struct cbq_class 1359 static int cbq_set_overlimit(struct cbq_class *cl, struct tc_cbq_ovl *ovl)
1331 { 1360 {
1332 switch (ovl->strategy) { 1361 switch (ovl->strategy) {
1333 case TC_CBQ_OVL_CLASSIC: 1362 case TC_CBQ_OVL_CLASSIC:
1334 cl->overlimit = cbq_ovl_class 1363 cl->overlimit = cbq_ovl_classic;
1335 break; 1364 break;
1336 case TC_CBQ_OVL_DELAY: 1365 case TC_CBQ_OVL_DELAY:
1337 cl->overlimit = cbq_ovl_delay 1366 cl->overlimit = cbq_ovl_delay;
1338 break; 1367 break;
1339 case TC_CBQ_OVL_LOWPRIO: 1368 case TC_CBQ_OVL_LOWPRIO:
1340 if (ovl->priority2-1 >= TC_CB 1369 if (ovl->priority2-1 >= TC_CBQ_MAXPRIO ||
1341 ovl->priority2-1 <= cl->p 1370 ovl->priority2-1 <= cl->priority)
1342 return -EINVAL; 1371 return -EINVAL;
1343 cl->priority2 = ovl->priority 1372 cl->priority2 = ovl->priority2-1;
1344 cl->overlimit = cbq_ovl_lowpr 1373 cl->overlimit = cbq_ovl_lowprio;
1345 break; 1374 break;
1346 case TC_CBQ_OVL_DROP: 1375 case TC_CBQ_OVL_DROP:
1347 cl->overlimit = cbq_ovl_drop; 1376 cl->overlimit = cbq_ovl_drop;
1348 break; 1377 break;
1349 case TC_CBQ_OVL_RCLASSIC: 1378 case TC_CBQ_OVL_RCLASSIC:
1350 cl->overlimit = cbq_ovl_rclas 1379 cl->overlimit = cbq_ovl_rclassic;
1351 break; 1380 break;
1352 default: 1381 default:
1353 return -EINVAL; 1382 return -EINVAL;
1354 } 1383 }
1355 cl->penalty = ovl->penalty; !! 1384 cl->penalty = (ovl->penalty*HZ)/1000;
1356 return 0; 1385 return 0;
1357 } 1386 }
1358 1387
1359 #ifdef CONFIG_NET_CLS_ACT !! 1388 #ifdef CONFIG_NET_CLS_POLICE
1360 static int cbq_set_police(struct cbq_class *c 1389 static int cbq_set_police(struct cbq_class *cl, struct tc_cbq_police *p)
1361 { 1390 {
1362 cl->police = p->police; 1391 cl->police = p->police;
1363 1392
1364 if (cl->q->handle) { 1393 if (cl->q->handle) {
1365 if (p->police == TC_POLICE_RE 1394 if (p->police == TC_POLICE_RECLASSIFY)
1366 cl->q->reshape_fail = 1395 cl->q->reshape_fail = cbq_reshape_fail;
1367 else 1396 else
1368 cl->q->reshape_fail = 1397 cl->q->reshape_fail = NULL;
1369 } 1398 }
1370 return 0; 1399 return 0;
1371 } 1400 }
1372 #endif 1401 #endif
1373 1402
1374 static int cbq_set_fopt(struct cbq_class *cl, 1403 static int cbq_set_fopt(struct cbq_class *cl, struct tc_cbq_fopt *fopt)
1375 { 1404 {
1376 cbq_change_defmap(cl, fopt->split, fo 1405 cbq_change_defmap(cl, fopt->split, fopt->defmap, fopt->defchange);
1377 return 0; 1406 return 0;
1378 } 1407 }
1379 1408
1380 static const struct nla_policy cbq_policy[TCA !! 1409 static int cbq_init(struct Qdisc *sch, struct rtattr *opt)
1381 [TCA_CBQ_LSSOPT] = { .len = si <<
1382 [TCA_CBQ_WRROPT] = { .len = si <<
1383 [TCA_CBQ_FOPT] = { .len = si <<
1384 [TCA_CBQ_OVL_STRATEGY] = { .len = si <<
1385 [TCA_CBQ_RATE] = { .len = si <<
1386 [TCA_CBQ_RTAB] = { .type = N <<
1387 [TCA_CBQ_POLICE] = { .len = si <<
1388 }; <<
1389 <<
1390 static int cbq_init(struct Qdisc *sch, struct <<
1391 { 1410 {
1392 struct cbq_sched_data *q = qdisc_priv 1411 struct cbq_sched_data *q = qdisc_priv(sch);
1393 struct nlattr *tb[TCA_CBQ_MAX + 1]; !! 1412 struct rtattr *tb[TCA_CBQ_MAX];
1394 struct tc_ratespec *r; 1413 struct tc_ratespec *r;
1395 int err; <<
1396 1414
1397 err = nla_parse_nested(tb, TCA_CBQ_MA !! 1415 if (rtattr_parse_nested(tb, TCA_CBQ_MAX, opt) < 0 ||
1398 if (err < 0) !! 1416 tb[TCA_CBQ_RTAB-1] == NULL || tb[TCA_CBQ_RATE-1] == NULL ||
1399 return err; !! 1417 RTA_PAYLOAD(tb[TCA_CBQ_RATE-1]) < sizeof(struct tc_ratespec))
>> 1418 return -EINVAL;
1400 1419
1401 if (tb[TCA_CBQ_RTAB] == NULL || tb[TC !! 1420 if (tb[TCA_CBQ_LSSOPT-1] &&
>> 1421 RTA_PAYLOAD(tb[TCA_CBQ_LSSOPT-1]) < sizeof(struct tc_cbq_lssopt))
1402 return -EINVAL; 1422 return -EINVAL;
1403 1423
1404 r = nla_data(tb[TCA_CBQ_RATE]); !! 1424 r = RTA_DATA(tb[TCA_CBQ_RATE-1]);
1405 1425
1406 if ((q->link.R_tab = qdisc_get_rtab(r !! 1426 if ((q->link.R_tab = qdisc_get_rtab(r, tb[TCA_CBQ_RTAB-1])) == NULL)
1407 return -EINVAL; 1427 return -EINVAL;
1408 1428
1409 q->link.refcnt = 1; 1429 q->link.refcnt = 1;
1410 q->link.sibling = &q->link; 1430 q->link.sibling = &q->link;
1411 q->link.classid = sch->handle; 1431 q->link.classid = sch->handle;
1412 q->link.qdisc = sch; 1432 q->link.qdisc = sch;
1413 if (!(q->link.q = qdisc_create_dflt(s !! 1433 if (!(q->link.q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops)))
1414 s <<
1415 q->link.q = &noop_qdisc; 1434 q->link.q = &noop_qdisc;
1416 1435
1417 q->link.priority = TC_CBQ_MAXPRIO-1; 1436 q->link.priority = TC_CBQ_MAXPRIO-1;
1418 q->link.priority2 = TC_CBQ_MAXPRIO-1; 1437 q->link.priority2 = TC_CBQ_MAXPRIO-1;
1419 q->link.cpriority = TC_CBQ_MAXPRIO-1; 1438 q->link.cpriority = TC_CBQ_MAXPRIO-1;
1420 q->link.ovl_strategy = TC_CBQ_OVL_CLA 1439 q->link.ovl_strategy = TC_CBQ_OVL_CLASSIC;
1421 q->link.overlimit = cbq_ovl_classic; 1440 q->link.overlimit = cbq_ovl_classic;
1422 q->link.allot = psched_mtu(sch->dev); 1441 q->link.allot = psched_mtu(sch->dev);
1423 q->link.quantum = q->link.allot; 1442 q->link.quantum = q->link.allot;
1424 q->link.weight = q->link.R_tab->rate. 1443 q->link.weight = q->link.R_tab->rate.rate;
1425 1444
1426 q->link.ewma_log = TC_CBQ_DEF_EWMA; 1445 q->link.ewma_log = TC_CBQ_DEF_EWMA;
1427 q->link.avpkt = q->link.allot/2; 1446 q->link.avpkt = q->link.allot/2;
1428 q->link.minidle = -0x7FFFFFFF; 1447 q->link.minidle = -0x7FFFFFFF;
>> 1448 q->link.stats_lock = &sch->dev->queue_lock;
1429 1449
1430 qdisc_watchdog_init(&q->watchdog, sch !! 1450 init_timer(&q->wd_timer);
1431 hrtimer_init(&q->delay_timer, CLOCK_M !! 1451 q->wd_timer.data = (unsigned long)sch;
>> 1452 q->wd_timer.function = cbq_watchdog;
>> 1453 init_timer(&q->delay_timer);
>> 1454 q->delay_timer.data = (unsigned long)sch;
1432 q->delay_timer.function = cbq_undelay 1455 q->delay_timer.function = cbq_undelay;
1433 q->toplevel = TC_CBQ_MAXLEVEL; 1456 q->toplevel = TC_CBQ_MAXLEVEL;
1434 q->now = psched_get_time(); !! 1457 PSCHED_GET_TIME(q->now);
1435 q->now_rt = q->now; 1458 q->now_rt = q->now;
1436 1459
1437 cbq_link_class(&q->link); 1460 cbq_link_class(&q->link);
1438 1461
1439 if (tb[TCA_CBQ_LSSOPT]) !! 1462 if (tb[TCA_CBQ_LSSOPT-1])
1440 cbq_set_lss(&q->link, nla_dat !! 1463 cbq_set_lss(&q->link, RTA_DATA(tb[TCA_CBQ_LSSOPT-1]));
1441 1464
1442 cbq_addprio(q, &q->link); 1465 cbq_addprio(q, &q->link);
1443 return 0; 1466 return 0;
1444 } 1467 }
1445 1468
1446 static __inline__ int cbq_dump_rate(struct sk 1469 static __inline__ int cbq_dump_rate(struct sk_buff *skb, struct cbq_class *cl)
1447 { 1470 {
1448 unsigned char *b = skb_tail_pointer(s !! 1471 unsigned char *b = skb->tail;
1449 1472
1450 NLA_PUT(skb, TCA_CBQ_RATE, sizeof(cl- !! 1473 RTA_PUT(skb, TCA_CBQ_RATE, sizeof(cl->R_tab->rate), &cl->R_tab->rate);
1451 return skb->len; 1474 return skb->len;
1452 1475
1453 nla_put_failure: !! 1476 rtattr_failure:
1454 nlmsg_trim(skb, b); !! 1477 skb_trim(skb, b - skb->data);
1455 return -1; 1478 return -1;
1456 } 1479 }
1457 1480
1458 static __inline__ int cbq_dump_lss(struct sk_ 1481 static __inline__ int cbq_dump_lss(struct sk_buff *skb, struct cbq_class *cl)
1459 { 1482 {
1460 unsigned char *b = skb_tail_pointer(s !! 1483 unsigned char *b = skb->tail;
1461 struct tc_cbq_lssopt opt; 1484 struct tc_cbq_lssopt opt;
1462 1485
1463 opt.flags = 0; 1486 opt.flags = 0;
1464 if (cl->borrow == NULL) 1487 if (cl->borrow == NULL)
1465 opt.flags |= TCF_CBQ_LSS_BOUN 1488 opt.flags |= TCF_CBQ_LSS_BOUNDED;
1466 if (cl->share == NULL) 1489 if (cl->share == NULL)
1467 opt.flags |= TCF_CBQ_LSS_ISOL 1490 opt.flags |= TCF_CBQ_LSS_ISOLATED;
1468 opt.ewma_log = cl->ewma_log; 1491 opt.ewma_log = cl->ewma_log;
1469 opt.level = cl->level; 1492 opt.level = cl->level;
1470 opt.avpkt = cl->avpkt; 1493 opt.avpkt = cl->avpkt;
1471 opt.maxidle = cl->maxidle; 1494 opt.maxidle = cl->maxidle;
1472 opt.minidle = (u32)(-cl->minidle); 1495 opt.minidle = (u32)(-cl->minidle);
1473 opt.offtime = cl->offtime; 1496 opt.offtime = cl->offtime;
1474 opt.change = ~0; 1497 opt.change = ~0;
1475 NLA_PUT(skb, TCA_CBQ_LSSOPT, sizeof(o !! 1498 RTA_PUT(skb, TCA_CBQ_LSSOPT, sizeof(opt), &opt);
1476 return skb->len; 1499 return skb->len;
1477 1500
1478 nla_put_failure: !! 1501 rtattr_failure:
1479 nlmsg_trim(skb, b); !! 1502 skb_trim(skb, b - skb->data);
1480 return -1; 1503 return -1;
1481 } 1504 }
1482 1505
1483 static __inline__ int cbq_dump_wrr(struct sk_ 1506 static __inline__ int cbq_dump_wrr(struct sk_buff *skb, struct cbq_class *cl)
1484 { 1507 {
1485 unsigned char *b = skb_tail_pointer(s !! 1508 unsigned char *b = skb->tail;
1486 struct tc_cbq_wrropt opt; 1509 struct tc_cbq_wrropt opt;
1487 1510
1488 opt.flags = 0; 1511 opt.flags = 0;
1489 opt.allot = cl->allot; 1512 opt.allot = cl->allot;
1490 opt.priority = cl->priority+1; 1513 opt.priority = cl->priority+1;
1491 opt.cpriority = cl->cpriority+1; 1514 opt.cpriority = cl->cpriority+1;
1492 opt.weight = cl->weight; 1515 opt.weight = cl->weight;
1493 NLA_PUT(skb, TCA_CBQ_WRROPT, sizeof(o !! 1516 RTA_PUT(skb, TCA_CBQ_WRROPT, sizeof(opt), &opt);
1494 return skb->len; 1517 return skb->len;
1495 1518
1496 nla_put_failure: !! 1519 rtattr_failure:
1497 nlmsg_trim(skb, b); !! 1520 skb_trim(skb, b - skb->data);
1498 return -1; 1521 return -1;
1499 } 1522 }
1500 1523
1501 static __inline__ int cbq_dump_ovl(struct sk_ 1524 static __inline__ int cbq_dump_ovl(struct sk_buff *skb, struct cbq_class *cl)
1502 { 1525 {
1503 unsigned char *b = skb_tail_pointer(s !! 1526 unsigned char *b = skb->tail;
1504 struct tc_cbq_ovl opt; 1527 struct tc_cbq_ovl opt;
1505 1528
1506 opt.strategy = cl->ovl_strategy; 1529 opt.strategy = cl->ovl_strategy;
1507 opt.priority2 = cl->priority2+1; 1530 opt.priority2 = cl->priority2+1;
1508 opt.pad = 0; !! 1531 opt.penalty = (cl->penalty*1000)/HZ;
1509 opt.penalty = cl->penalty; !! 1532 RTA_PUT(skb, TCA_CBQ_OVL_STRATEGY, sizeof(opt), &opt);
1510 NLA_PUT(skb, TCA_CBQ_OVL_STRATEGY, si <<
1511 return skb->len; 1533 return skb->len;
1512 1534
1513 nla_put_failure: !! 1535 rtattr_failure:
1514 nlmsg_trim(skb, b); !! 1536 skb_trim(skb, b - skb->data);
1515 return -1; 1537 return -1;
1516 } 1538 }
1517 1539
1518 static __inline__ int cbq_dump_fopt(struct sk 1540 static __inline__ int cbq_dump_fopt(struct sk_buff *skb, struct cbq_class *cl)
1519 { 1541 {
1520 unsigned char *b = skb_tail_pointer(s !! 1542 unsigned char *b = skb->tail;
1521 struct tc_cbq_fopt opt; 1543 struct tc_cbq_fopt opt;
1522 1544
1523 if (cl->split || cl->defmap) { 1545 if (cl->split || cl->defmap) {
1524 opt.split = cl->split ? cl->s 1546 opt.split = cl->split ? cl->split->classid : 0;
1525 opt.defmap = cl->defmap; 1547 opt.defmap = cl->defmap;
1526 opt.defchange = ~0; 1548 opt.defchange = ~0;
1527 NLA_PUT(skb, TCA_CBQ_FOPT, si !! 1549 RTA_PUT(skb, TCA_CBQ_FOPT, sizeof(opt), &opt);
1528 } 1550 }
1529 return skb->len; 1551 return skb->len;
1530 1552
1531 nla_put_failure: !! 1553 rtattr_failure:
1532 nlmsg_trim(skb, b); !! 1554 skb_trim(skb, b - skb->data);
1533 return -1; 1555 return -1;
1534 } 1556 }
1535 1557
1536 #ifdef CONFIG_NET_CLS_ACT !! 1558 #ifdef CONFIG_NET_CLS_POLICE
1537 static __inline__ int cbq_dump_police(struct 1559 static __inline__ int cbq_dump_police(struct sk_buff *skb, struct cbq_class *cl)
1538 { 1560 {
1539 unsigned char *b = skb_tail_pointer(s !! 1561 unsigned char *b = skb->tail;
1540 struct tc_cbq_police opt; 1562 struct tc_cbq_police opt;
1541 1563
1542 if (cl->police) { 1564 if (cl->police) {
1543 opt.police = cl->police; 1565 opt.police = cl->police;
1544 opt.__res1 = 0; !! 1566 RTA_PUT(skb, TCA_CBQ_POLICE, sizeof(opt), &opt);
1545 opt.__res2 = 0; <<
1546 NLA_PUT(skb, TCA_CBQ_POLICE, <<
1547 } 1567 }
1548 return skb->len; 1568 return skb->len;
1549 1569
1550 nla_put_failure: !! 1570 rtattr_failure:
1551 nlmsg_trim(skb, b); !! 1571 skb_trim(skb, b - skb->data);
1552 return -1; 1572 return -1;
1553 } 1573 }
1554 #endif 1574 #endif
1555 1575
1556 static int cbq_dump_attr(struct sk_buff *skb, 1576 static int cbq_dump_attr(struct sk_buff *skb, struct cbq_class *cl)
1557 { 1577 {
1558 if (cbq_dump_lss(skb, cl) < 0 || 1578 if (cbq_dump_lss(skb, cl) < 0 ||
1559 cbq_dump_rate(skb, cl) < 0 || 1579 cbq_dump_rate(skb, cl) < 0 ||
1560 cbq_dump_wrr(skb, cl) < 0 || 1580 cbq_dump_wrr(skb, cl) < 0 ||
1561 cbq_dump_ovl(skb, cl) < 0 || 1581 cbq_dump_ovl(skb, cl) < 0 ||
1562 #ifdef CONFIG_NET_CLS_ACT !! 1582 #ifdef CONFIG_NET_CLS_POLICE
1563 cbq_dump_police(skb, cl) < 0 || 1583 cbq_dump_police(skb, cl) < 0 ||
1564 #endif 1584 #endif
1565 cbq_dump_fopt(skb, cl) < 0) 1585 cbq_dump_fopt(skb, cl) < 0)
1566 return -1; 1586 return -1;
1567 return 0; 1587 return 0;
1568 } 1588 }
1569 1589
1570 static int cbq_dump(struct Qdisc *sch, struct 1590 static int cbq_dump(struct Qdisc *sch, struct sk_buff *skb)
1571 { 1591 {
1572 struct cbq_sched_data *q = qdisc_priv 1592 struct cbq_sched_data *q = qdisc_priv(sch);
1573 struct nlattr *nest; !! 1593 unsigned char *b = skb->tail;
>> 1594 struct rtattr *rta;
1574 1595
1575 nest = nla_nest_start(skb, TCA_OPTION !! 1596 rta = (struct rtattr*)b;
1576 if (nest == NULL) !! 1597 RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
1577 goto nla_put_failure; <<
1578 if (cbq_dump_attr(skb, &q->link) < 0) 1598 if (cbq_dump_attr(skb, &q->link) < 0)
1579 goto nla_put_failure; !! 1599 goto rtattr_failure;
1580 nla_nest_end(skb, nest); !! 1600 rta->rta_len = skb->tail - b;
1581 return skb->len; 1601 return skb->len;
1582 1602
1583 nla_put_failure: !! 1603 rtattr_failure:
1584 nla_nest_cancel(skb, nest); !! 1604 skb_trim(skb, b - skb->data);
1585 return -1; 1605 return -1;
1586 } 1606 }
1587 1607
1588 static int 1608 static int
1589 cbq_dump_stats(struct Qdisc *sch, struct gnet 1609 cbq_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
1590 { 1610 {
1591 struct cbq_sched_data *q = qdisc_priv 1611 struct cbq_sched_data *q = qdisc_priv(sch);
1592 1612
1593 q->link.xstats.avgidle = q->link.avgi 1613 q->link.xstats.avgidle = q->link.avgidle;
1594 return gnet_stats_copy_app(d, &q->lin 1614 return gnet_stats_copy_app(d, &q->link.xstats, sizeof(q->link.xstats));
1595 } 1615 }
1596 1616
1597 static int 1617 static int
1598 cbq_dump_class(struct Qdisc *sch, unsigned lo 1618 cbq_dump_class(struct Qdisc *sch, unsigned long arg,
1599 struct sk_buff *skb, struct tc 1619 struct sk_buff *skb, struct tcmsg *tcm)
1600 { 1620 {
1601 struct cbq_class *cl = (struct cbq_cl 1621 struct cbq_class *cl = (struct cbq_class*)arg;
1602 struct nlattr *nest; !! 1622 unsigned char *b = skb->tail;
>> 1623 struct rtattr *rta;
1603 1624
1604 if (cl->tparent) 1625 if (cl->tparent)
1605 tcm->tcm_parent = cl->tparent 1626 tcm->tcm_parent = cl->tparent->classid;
1606 else 1627 else
1607 tcm->tcm_parent = TC_H_ROOT; 1628 tcm->tcm_parent = TC_H_ROOT;
1608 tcm->tcm_handle = cl->classid; 1629 tcm->tcm_handle = cl->classid;
1609 tcm->tcm_info = cl->q->handle; 1630 tcm->tcm_info = cl->q->handle;
1610 1631
1611 nest = nla_nest_start(skb, TCA_OPTION !! 1632 rta = (struct rtattr*)b;
1612 if (nest == NULL) !! 1633 RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
1613 goto nla_put_failure; <<
1614 if (cbq_dump_attr(skb, cl) < 0) 1634 if (cbq_dump_attr(skb, cl) < 0)
1615 goto nla_put_failure; !! 1635 goto rtattr_failure;
1616 nla_nest_end(skb, nest); !! 1636 rta->rta_len = skb->tail - b;
1617 return skb->len; 1637 return skb->len;
1618 1638
1619 nla_put_failure: !! 1639 rtattr_failure:
1620 nla_nest_cancel(skb, nest); !! 1640 skb_trim(skb, b - skb->data);
1621 return -1; 1641 return -1;
1622 } 1642 }
1623 1643
1624 static int 1644 static int
1625 cbq_dump_class_stats(struct Qdisc *sch, unsig 1645 cbq_dump_class_stats(struct Qdisc *sch, unsigned long arg,
1626 struct gnet_dump *d) 1646 struct gnet_dump *d)
1627 { 1647 {
1628 struct cbq_sched_data *q = qdisc_priv 1648 struct cbq_sched_data *q = qdisc_priv(sch);
1629 struct cbq_class *cl = (struct cbq_cl 1649 struct cbq_class *cl = (struct cbq_class*)arg;
1630 1650
1631 cl->qstats.qlen = cl->q->q.qlen; 1651 cl->qstats.qlen = cl->q->q.qlen;
1632 cl->xstats.avgidle = cl->avgidle; 1652 cl->xstats.avgidle = cl->avgidle;
1633 cl->xstats.undertime = 0; 1653 cl->xstats.undertime = 0;
1634 1654
1635 if (cl->undertime != PSCHED_PASTPERFE !! 1655 if (!PSCHED_IS_PASTPERFECT(cl->undertime))
1636 cl->xstats.undertime = cl->un !! 1656 cl->xstats.undertime = PSCHED_TDIFF(cl->undertime, q->now);
1637 1657
1638 if (gnet_stats_copy_basic(d, &cl->bst 1658 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 ||
>> 1659 #ifdef CONFIG_NET_ESTIMATOR
1639 gnet_stats_copy_rate_est(d, &cl-> 1660 gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 ||
>> 1661 #endif
1640 gnet_stats_copy_queue(d, &cl->qst 1662 gnet_stats_copy_queue(d, &cl->qstats) < 0)
1641 return -1; 1663 return -1;
1642 1664
1643 return gnet_stats_copy_app(d, &cl->xs 1665 return gnet_stats_copy_app(d, &cl->xstats, sizeof(cl->xstats));
1644 } 1666 }
1645 1667
1646 static int cbq_graft(struct Qdisc *sch, unsig 1668 static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
1647 struct Qdisc **old) 1669 struct Qdisc **old)
1648 { 1670 {
1649 struct cbq_class *cl = (struct cbq_cl 1671 struct cbq_class *cl = (struct cbq_class*)arg;
1650 1672
1651 if (cl) { 1673 if (cl) {
1652 if (new == NULL) { 1674 if (new == NULL) {
1653 if ((new = qdisc_crea !! 1675 if ((new = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops)) == NULL)
1654 <<
1655 return -ENOBU 1676 return -ENOBUFS;
1656 } else { 1677 } else {
1657 #ifdef CONFIG_NET_CLS_ACT !! 1678 #ifdef CONFIG_NET_CLS_POLICE
1658 if (cl->police == TC_ 1679 if (cl->police == TC_POLICE_RECLASSIFY)
1659 new->reshape_ 1680 new->reshape_fail = cbq_reshape_fail;
1660 #endif 1681 #endif
1661 } 1682 }
1662 sch_tree_lock(sch); 1683 sch_tree_lock(sch);
1663 *old = xchg(&cl->q, new); !! 1684 *old = cl->q;
1664 qdisc_tree_decrease_qlen(*old !! 1685 cl->q = new;
>> 1686 sch->q.qlen -= (*old)->q.qlen;
1665 qdisc_reset(*old); 1687 qdisc_reset(*old);
1666 sch_tree_unlock(sch); 1688 sch_tree_unlock(sch);
1667 1689
1668 return 0; 1690 return 0;
1669 } 1691 }
1670 return -ENOENT; 1692 return -ENOENT;
1671 } 1693 }
1672 1694
1673 static struct Qdisc * 1695 static struct Qdisc *
1674 cbq_leaf(struct Qdisc *sch, unsigned long arg 1696 cbq_leaf(struct Qdisc *sch, unsigned long arg)
1675 { 1697 {
1676 struct cbq_class *cl = (struct cbq_cl 1698 struct cbq_class *cl = (struct cbq_class*)arg;
1677 1699
1678 return cl ? cl->q : NULL; 1700 return cl ? cl->q : NULL;
1679 } 1701 }
1680 1702
1681 static void cbq_qlen_notify(struct Qdisc *sch <<
1682 { <<
1683 struct cbq_class *cl = (struct cbq_cl <<
1684 <<
1685 if (cl->q->q.qlen == 0) <<
1686 cbq_deactivate_class(cl); <<
1687 } <<
1688 <<
1689 static unsigned long cbq_get(struct Qdisc *sc 1703 static unsigned long cbq_get(struct Qdisc *sch, u32 classid)
1690 { 1704 {
1691 struct cbq_sched_data *q = qdisc_priv 1705 struct cbq_sched_data *q = qdisc_priv(sch);
1692 struct cbq_class *cl = cbq_class_look 1706 struct cbq_class *cl = cbq_class_lookup(q, classid);
1693 1707
1694 if (cl) { 1708 if (cl) {
1695 cl->refcnt++; 1709 cl->refcnt++;
1696 return (unsigned long)cl; 1710 return (unsigned long)cl;
1697 } 1711 }
1698 return 0; 1712 return 0;
1699 } 1713 }
1700 1714
>> 1715 static void cbq_destroy_filters(struct cbq_class *cl)
>> 1716 {
>> 1717 struct tcf_proto *tp;
>> 1718
>> 1719 while ((tp = cl->filter_list) != NULL) {
>> 1720 cl->filter_list = tp->next;
>> 1721 tcf_destroy(tp);
>> 1722 }
>> 1723 }
>> 1724
1701 static void cbq_destroy_class(struct Qdisc *s 1725 static void cbq_destroy_class(struct Qdisc *sch, struct cbq_class *cl)
1702 { 1726 {
1703 struct cbq_sched_data *q = qdisc_priv 1727 struct cbq_sched_data *q = qdisc_priv(sch);
1704 1728
1705 BUG_TRAP(!cl->filters); 1729 BUG_TRAP(!cl->filters);
1706 1730
1707 tcf_destroy_chain(cl->filter_list); !! 1731 cbq_destroy_filters(cl);
1708 qdisc_destroy(cl->q); 1732 qdisc_destroy(cl->q);
1709 qdisc_put_rtab(cl->R_tab); 1733 qdisc_put_rtab(cl->R_tab);
>> 1734 #ifdef CONFIG_NET_ESTIMATOR
1710 gen_kill_estimator(&cl->bstats, &cl-> 1735 gen_kill_estimator(&cl->bstats, &cl->rate_est);
>> 1736 #endif
1711 if (cl != &q->link) 1737 if (cl != &q->link)
1712 kfree(cl); 1738 kfree(cl);
1713 } 1739 }
1714 1740
1715 static void 1741 static void
1716 cbq_destroy(struct Qdisc* sch) 1742 cbq_destroy(struct Qdisc* sch)
1717 { 1743 {
1718 struct cbq_sched_data *q = qdisc_priv 1744 struct cbq_sched_data *q = qdisc_priv(sch);
1719 struct cbq_class *cl; 1745 struct cbq_class *cl;
1720 unsigned h; 1746 unsigned h;
1721 1747
1722 #ifdef CONFIG_NET_CLS_ACT !! 1748 #ifdef CONFIG_NET_CLS_POLICE
1723 q->rx_class = NULL; 1749 q->rx_class = NULL;
1724 #endif 1750 #endif
1725 /* 1751 /*
1726 * Filters must be destroyed first be 1752 * Filters must be destroyed first because we don't destroy the
1727 * classes from root to leafs which m 1753 * classes from root to leafs which means that filters can still
1728 * be bound to classes which have bee 1754 * be bound to classes which have been destroyed already. --TGR '04
1729 */ 1755 */
1730 for (h = 0; h < 16; h++) { !! 1756 for (h = 0; h < 16; h++)
1731 for (cl = q->classes[h]; cl; !! 1757 for (cl = q->classes[h]; cl; cl = cl->next)
1732 tcf_destroy_chain(cl- !! 1758 cbq_destroy_filters(cl);
1733 cl->filter_list = NUL !! 1759
1734 } <<
1735 } <<
1736 for (h = 0; h < 16; h++) { 1760 for (h = 0; h < 16; h++) {
1737 struct cbq_class *next; 1761 struct cbq_class *next;
1738 1762
1739 for (cl = q->classes[h]; cl; 1763 for (cl = q->classes[h]; cl; cl = next) {
1740 next = cl->next; 1764 next = cl->next;
1741 cbq_destroy_class(sch 1765 cbq_destroy_class(sch, cl);
1742 } 1766 }
1743 } 1767 }
1744 } 1768 }
1745 1769
1746 static void cbq_put(struct Qdisc *sch, unsign 1770 static void cbq_put(struct Qdisc *sch, unsigned long arg)
1747 { 1771 {
1748 struct cbq_class *cl = (struct cbq_cl 1772 struct cbq_class *cl = (struct cbq_class*)arg;
1749 1773
1750 if (--cl->refcnt == 0) { 1774 if (--cl->refcnt == 0) {
1751 #ifdef CONFIG_NET_CLS_ACT !! 1775 #ifdef CONFIG_NET_CLS_POLICE
1752 struct cbq_sched_data *q = qd 1776 struct cbq_sched_data *q = qdisc_priv(sch);
1753 1777
1754 spin_lock_bh(&sch->dev->queue 1778 spin_lock_bh(&sch->dev->queue_lock);
1755 if (q->rx_class == cl) 1779 if (q->rx_class == cl)
1756 q->rx_class = NULL; 1780 q->rx_class = NULL;
1757 spin_unlock_bh(&sch->dev->que 1781 spin_unlock_bh(&sch->dev->queue_lock);
1758 #endif 1782 #endif
1759 1783
1760 cbq_destroy_class(sch, cl); 1784 cbq_destroy_class(sch, cl);
1761 } 1785 }
1762 } 1786 }
1763 1787
1764 static int 1788 static int
1765 cbq_change_class(struct Qdisc *sch, u32 class !! 1789 cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct rtattr **tca,
1766 unsigned long *arg) 1790 unsigned long *arg)
1767 { 1791 {
1768 int err; 1792 int err;
1769 struct cbq_sched_data *q = qdisc_priv 1793 struct cbq_sched_data *q = qdisc_priv(sch);
1770 struct cbq_class *cl = (struct cbq_cl 1794 struct cbq_class *cl = (struct cbq_class*)*arg;
1771 struct nlattr *opt = tca[TCA_OPTIONS] !! 1795 struct rtattr *opt = tca[TCA_OPTIONS-1];
1772 struct nlattr *tb[TCA_CBQ_MAX + 1]; !! 1796 struct rtattr *tb[TCA_CBQ_MAX];
1773 struct cbq_class *parent; 1797 struct cbq_class *parent;
1774 struct qdisc_rate_table *rtab = NULL; 1798 struct qdisc_rate_table *rtab = NULL;
1775 1799
1776 if (opt == NULL) !! 1800 if (opt==NULL || rtattr_parse_nested(tb, TCA_CBQ_MAX, opt))
>> 1801 return -EINVAL;
>> 1802
>> 1803 if (tb[TCA_CBQ_OVL_STRATEGY-1] &&
>> 1804 RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY-1]) < sizeof(struct tc_cbq_ovl))
>> 1805 return -EINVAL;
>> 1806
>> 1807 if (tb[TCA_CBQ_FOPT-1] &&
>> 1808 RTA_PAYLOAD(tb[TCA_CBQ_FOPT-1]) < sizeof(struct tc_cbq_fopt))
1777 return -EINVAL; 1809 return -EINVAL;
1778 1810
1779 err = nla_parse_nested(tb, TCA_CBQ_MA !! 1811 if (tb[TCA_CBQ_RATE-1] &&
1780 if (err < 0) !! 1812 RTA_PAYLOAD(tb[TCA_CBQ_RATE-1]) < sizeof(struct tc_ratespec))
1781 return err; !! 1813 return -EINVAL;
>> 1814
>> 1815 if (tb[TCA_CBQ_LSSOPT-1] &&
>> 1816 RTA_PAYLOAD(tb[TCA_CBQ_LSSOPT-1]) < sizeof(struct tc_cbq_lssopt))
>> 1817 return -EINVAL;
>> 1818
>> 1819 if (tb[TCA_CBQ_WRROPT-1] &&
>> 1820 RTA_PAYLOAD(tb[TCA_CBQ_WRROPT-1]) < sizeof(struct tc_cbq_wrropt))
>> 1821 return -EINVAL;
>> 1822
>> 1823 #ifdef CONFIG_NET_CLS_POLICE
>> 1824 if (tb[TCA_CBQ_POLICE-1] &&
>> 1825 RTA_PAYLOAD(tb[TCA_CBQ_POLICE-1]) < sizeof(struct tc_cbq_police))
>> 1826 return -EINVAL;
>> 1827 #endif
1782 1828
1783 if (cl) { 1829 if (cl) {
1784 /* Check parent */ 1830 /* Check parent */
1785 if (parentid) { 1831 if (parentid) {
1786 if (cl->tparent && cl 1832 if (cl->tparent && cl->tparent->classid != parentid)
1787 return -EINVA 1833 return -EINVAL;
1788 if (!cl->tparent && p 1834 if (!cl->tparent && parentid != TC_H_ROOT)
1789 return -EINVA 1835 return -EINVAL;
1790 } 1836 }
1791 1837
1792 if (tb[TCA_CBQ_RATE]) { !! 1838 if (tb[TCA_CBQ_RATE-1]) {
1793 rtab = qdisc_get_rtab !! 1839 rtab = qdisc_get_rtab(RTA_DATA(tb[TCA_CBQ_RATE-1]), tb[TCA_CBQ_RTAB-1]);
1794 if (rtab == NULL) 1840 if (rtab == NULL)
1795 return -EINVA 1841 return -EINVAL;
1796 } 1842 }
1797 1843
1798 /* Change class parameters */ 1844 /* Change class parameters */
1799 sch_tree_lock(sch); 1845 sch_tree_lock(sch);
1800 1846
1801 if (cl->next_alive != NULL) 1847 if (cl->next_alive != NULL)
1802 cbq_deactivate_class( 1848 cbq_deactivate_class(cl);
1803 1849
1804 if (rtab) { 1850 if (rtab) {
1805 rtab = xchg(&cl->R_ta 1851 rtab = xchg(&cl->R_tab, rtab);
1806 qdisc_put_rtab(rtab); 1852 qdisc_put_rtab(rtab);
1807 } 1853 }
1808 1854
1809 if (tb[TCA_CBQ_LSSOPT]) !! 1855 if (tb[TCA_CBQ_LSSOPT-1])
1810 cbq_set_lss(cl, nla_d !! 1856 cbq_set_lss(cl, RTA_DATA(tb[TCA_CBQ_LSSOPT-1]));
1811 1857
1812 if (tb[TCA_CBQ_WRROPT]) { !! 1858 if (tb[TCA_CBQ_WRROPT-1]) {
1813 cbq_rmprio(q, cl); 1859 cbq_rmprio(q, cl);
1814 cbq_set_wrr(cl, nla_d !! 1860 cbq_set_wrr(cl, RTA_DATA(tb[TCA_CBQ_WRROPT-1]));
1815 } 1861 }
1816 1862
1817 if (tb[TCA_CBQ_OVL_STRATEGY]) !! 1863 if (tb[TCA_CBQ_OVL_STRATEGY-1])
1818 cbq_set_overlimit(cl, !! 1864 cbq_set_overlimit(cl, RTA_DATA(tb[TCA_CBQ_OVL_STRATEGY-1]));
1819 1865
1820 #ifdef CONFIG_NET_CLS_ACT !! 1866 #ifdef CONFIG_NET_CLS_POLICE
1821 if (tb[TCA_CBQ_POLICE]) !! 1867 if (tb[TCA_CBQ_POLICE-1])
1822 cbq_set_police(cl, nl !! 1868 cbq_set_police(cl, RTA_DATA(tb[TCA_CBQ_POLICE-1]));
1823 #endif 1869 #endif
1824 1870
1825 if (tb[TCA_CBQ_FOPT]) !! 1871 if (tb[TCA_CBQ_FOPT-1])
1826 cbq_set_fopt(cl, nla_ !! 1872 cbq_set_fopt(cl, RTA_DATA(tb[TCA_CBQ_FOPT-1]));
1827 1873
1828 if (cl->q->q.qlen) 1874 if (cl->q->q.qlen)
1829 cbq_activate_class(cl 1875 cbq_activate_class(cl);
1830 1876
1831 sch_tree_unlock(sch); 1877 sch_tree_unlock(sch);
1832 1878
1833 if (tca[TCA_RATE]) !! 1879 #ifdef CONFIG_NET_ESTIMATOR
>> 1880 if (tca[TCA_RATE-1])
1834 gen_replace_estimator 1881 gen_replace_estimator(&cl->bstats, &cl->rate_est,
1835 !! 1882 cl->stats_lock, tca[TCA_RATE-1]);
1836 !! 1883 #endif
1837 return 0; 1884 return 0;
1838 } 1885 }
1839 1886
1840 if (parentid == TC_H_ROOT) 1887 if (parentid == TC_H_ROOT)
1841 return -EINVAL; 1888 return -EINVAL;
1842 1889
1843 if (tb[TCA_CBQ_WRROPT] == NULL || tb[ !! 1890 if (tb[TCA_CBQ_WRROPT-1] == NULL || tb[TCA_CBQ_RATE-1] == NULL ||
1844 tb[TCA_CBQ_LSSOPT] == NULL) !! 1891 tb[TCA_CBQ_LSSOPT-1] == NULL)
1845 return -EINVAL; 1892 return -EINVAL;
1846 1893
1847 rtab = qdisc_get_rtab(nla_data(tb[TCA !! 1894 rtab = qdisc_get_rtab(RTA_DATA(tb[TCA_CBQ_RATE-1]), tb[TCA_CBQ_RTAB-1]);
1848 if (rtab == NULL) 1895 if (rtab == NULL)
1849 return -EINVAL; 1896 return -EINVAL;
1850 1897
1851 if (classid) { 1898 if (classid) {
1852 err = -EINVAL; 1899 err = -EINVAL;
1853 if (TC_H_MAJ(classid^sch->han 1900 if (TC_H_MAJ(classid^sch->handle) || cbq_class_lookup(q, classid))
1854 goto failure; 1901 goto failure;
1855 } else { 1902 } else {
1856 int i; 1903 int i;
1857 classid = TC_H_MAKE(sch->hand 1904 classid = TC_H_MAKE(sch->handle,0x8000);
1858 1905
1859 for (i=0; i<0x8000; i++) { 1906 for (i=0; i<0x8000; i++) {
1860 if (++q->hgenerator > 1907 if (++q->hgenerator >= 0x8000)
1861 q->hgenerator 1908 q->hgenerator = 1;
1862 if (cbq_class_lookup( 1909 if (cbq_class_lookup(q, classid|q->hgenerator) == NULL)
1863 break; 1910 break;
1864 } 1911 }
1865 err = -ENOSR; 1912 err = -ENOSR;
1866 if (i >= 0x8000) 1913 if (i >= 0x8000)
1867 goto failure; 1914 goto failure;
1868 classid = classid|q->hgenerat 1915 classid = classid|q->hgenerator;
1869 } 1916 }
1870 1917
1871 parent = &q->link; 1918 parent = &q->link;
1872 if (parentid) { 1919 if (parentid) {
1873 parent = cbq_class_lookup(q, 1920 parent = cbq_class_lookup(q, parentid);
1874 err = -EINVAL; 1921 err = -EINVAL;
1875 if (parent == NULL) 1922 if (parent == NULL)
1876 goto failure; 1923 goto failure;
1877 } 1924 }
1878 1925
1879 err = -ENOBUFS; 1926 err = -ENOBUFS;
1880 cl = kzalloc(sizeof(*cl), GFP_KERNEL) !! 1927 cl = kmalloc(sizeof(*cl), GFP_KERNEL);
1881 if (cl == NULL) 1928 if (cl == NULL)
1882 goto failure; 1929 goto failure;
>> 1930 memset(cl, 0, sizeof(*cl));
1883 cl->R_tab = rtab; 1931 cl->R_tab = rtab;
1884 rtab = NULL; 1932 rtab = NULL;
1885 cl->refcnt = 1; 1933 cl->refcnt = 1;
1886 if (!(cl->q = qdisc_create_dflt(sch-> !! 1934 if (!(cl->q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops)))
1887 cl->q = &noop_qdisc; 1935 cl->q = &noop_qdisc;
1888 cl->classid = classid; 1936 cl->classid = classid;
1889 cl->tparent = parent; 1937 cl->tparent = parent;
1890 cl->qdisc = sch; 1938 cl->qdisc = sch;
1891 cl->allot = parent->allot; 1939 cl->allot = parent->allot;
1892 cl->quantum = cl->allot; 1940 cl->quantum = cl->allot;
1893 cl->weight = cl->R_tab->rate.rate; 1941 cl->weight = cl->R_tab->rate.rate;
>> 1942 cl->stats_lock = &sch->dev->queue_lock;
1894 1943
1895 sch_tree_lock(sch); 1944 sch_tree_lock(sch);
1896 cbq_link_class(cl); 1945 cbq_link_class(cl);
1897 cl->borrow = cl->tparent; 1946 cl->borrow = cl->tparent;
1898 if (cl->tparent != &q->link) 1947 if (cl->tparent != &q->link)
1899 cl->share = cl->tparent; 1948 cl->share = cl->tparent;
1900 cbq_adjust_levels(parent); 1949 cbq_adjust_levels(parent);
1901 cl->minidle = -0x7FFFFFFF; 1950 cl->minidle = -0x7FFFFFFF;
1902 cbq_set_lss(cl, nla_data(tb[TCA_CBQ_L !! 1951 cbq_set_lss(cl, RTA_DATA(tb[TCA_CBQ_LSSOPT-1]));
1903 cbq_set_wrr(cl, nla_data(tb[TCA_CBQ_W !! 1952 cbq_set_wrr(cl, RTA_DATA(tb[TCA_CBQ_WRROPT-1]));
1904 if (cl->ewma_log==0) 1953 if (cl->ewma_log==0)
1905 cl->ewma_log = q->link.ewma_l 1954 cl->ewma_log = q->link.ewma_log;
1906 if (cl->maxidle==0) 1955 if (cl->maxidle==0)
1907 cl->maxidle = q->link.maxidle 1956 cl->maxidle = q->link.maxidle;
1908 if (cl->avpkt==0) 1957 if (cl->avpkt==0)
1909 cl->avpkt = q->link.avpkt; 1958 cl->avpkt = q->link.avpkt;
1910 cl->overlimit = cbq_ovl_classic; 1959 cl->overlimit = cbq_ovl_classic;
1911 if (tb[TCA_CBQ_OVL_STRATEGY]) !! 1960 if (tb[TCA_CBQ_OVL_STRATEGY-1])
1912 cbq_set_overlimit(cl, nla_dat !! 1961 cbq_set_overlimit(cl, RTA_DATA(tb[TCA_CBQ_OVL_STRATEGY-1]));
1913 #ifdef CONFIG_NET_CLS_ACT !! 1962 #ifdef CONFIG_NET_CLS_POLICE
1914 if (tb[TCA_CBQ_POLICE]) !! 1963 if (tb[TCA_CBQ_POLICE-1])
1915 cbq_set_police(cl, nla_data(t !! 1964 cbq_set_police(cl, RTA_DATA(tb[TCA_CBQ_POLICE-1]));
1916 #endif 1965 #endif
1917 if (tb[TCA_CBQ_FOPT]) !! 1966 if (tb[TCA_CBQ_FOPT-1])
1918 cbq_set_fopt(cl, nla_data(tb[ !! 1967 cbq_set_fopt(cl, RTA_DATA(tb[TCA_CBQ_FOPT-1]));
1919 sch_tree_unlock(sch); 1968 sch_tree_unlock(sch);
1920 1969
1921 if (tca[TCA_RATE]) !! 1970 #ifdef CONFIG_NET_ESTIMATOR
>> 1971 if (tca[TCA_RATE-1])
1922 gen_new_estimator(&cl->bstats 1972 gen_new_estimator(&cl->bstats, &cl->rate_est,
1923 &sch->dev-> !! 1973 cl->stats_lock, tca[TCA_RATE-1]);
>> 1974 #endif
1924 1975
1925 *arg = (unsigned long)cl; 1976 *arg = (unsigned long)cl;
1926 return 0; 1977 return 0;
1927 1978
1928 failure: 1979 failure:
1929 qdisc_put_rtab(rtab); 1980 qdisc_put_rtab(rtab);
1930 return err; 1981 return err;
1931 } 1982 }
1932 1983
1933 static int cbq_delete(struct Qdisc *sch, unsi 1984 static int cbq_delete(struct Qdisc *sch, unsigned long arg)
1934 { 1985 {
1935 struct cbq_sched_data *q = qdisc_priv 1986 struct cbq_sched_data *q = qdisc_priv(sch);
1936 struct cbq_class *cl = (struct cbq_cl 1987 struct cbq_class *cl = (struct cbq_class*)arg;
1937 unsigned int qlen; <<
1938 1988
1939 if (cl->filters || cl->children || cl 1989 if (cl->filters || cl->children || cl == &q->link)
1940 return -EBUSY; 1990 return -EBUSY;
1941 1991
1942 sch_tree_lock(sch); 1992 sch_tree_lock(sch);
1943 1993
1944 qlen = cl->q->q.qlen; <<
1945 qdisc_reset(cl->q); <<
1946 qdisc_tree_decrease_qlen(cl->q, qlen) <<
1947 <<
1948 if (cl->next_alive) 1994 if (cl->next_alive)
1949 cbq_deactivate_class(cl); 1995 cbq_deactivate_class(cl);
1950 1996
1951 if (q->tx_borrowed == cl) 1997 if (q->tx_borrowed == cl)
1952 q->tx_borrowed = q->tx_class; 1998 q->tx_borrowed = q->tx_class;
1953 if (q->tx_class == cl) { 1999 if (q->tx_class == cl) {
1954 q->tx_class = NULL; 2000 q->tx_class = NULL;
1955 q->tx_borrowed = NULL; 2001 q->tx_borrowed = NULL;
1956 } 2002 }
1957 #ifdef CONFIG_NET_CLS_ACT !! 2003 #ifdef CONFIG_NET_CLS_POLICE
1958 if (q->rx_class == cl) 2004 if (q->rx_class == cl)
1959 q->rx_class = NULL; 2005 q->rx_class = NULL;
1960 #endif 2006 #endif
1961 2007
1962 cbq_unlink_class(cl); 2008 cbq_unlink_class(cl);
1963 cbq_adjust_levels(cl->tparent); 2009 cbq_adjust_levels(cl->tparent);
1964 cl->defmap = 0; 2010 cl->defmap = 0;
1965 cbq_sync_defmap(cl); 2011 cbq_sync_defmap(cl);
1966 2012
1967 cbq_rmprio(q, cl); 2013 cbq_rmprio(q, cl);
1968 sch_tree_unlock(sch); 2014 sch_tree_unlock(sch);
1969 2015
1970 if (--cl->refcnt == 0) 2016 if (--cl->refcnt == 0)
1971 cbq_destroy_class(sch, cl); 2017 cbq_destroy_class(sch, cl);
1972 2018
1973 return 0; 2019 return 0;
1974 } 2020 }
1975 2021
1976 static struct tcf_proto **cbq_find_tcf(struct 2022 static struct tcf_proto **cbq_find_tcf(struct Qdisc *sch, unsigned long arg)
1977 { 2023 {
1978 struct cbq_sched_data *q = qdisc_priv 2024 struct cbq_sched_data *q = qdisc_priv(sch);
1979 struct cbq_class *cl = (struct cbq_cl 2025 struct cbq_class *cl = (struct cbq_class *)arg;
1980 2026
1981 if (cl == NULL) 2027 if (cl == NULL)
1982 cl = &q->link; 2028 cl = &q->link;
1983 2029
1984 return &cl->filter_list; 2030 return &cl->filter_list;
1985 } 2031 }
1986 2032
1987 static unsigned long cbq_bind_filter(struct Q 2033 static unsigned long cbq_bind_filter(struct Qdisc *sch, unsigned long parent,
1988 u32 clas 2034 u32 classid)
1989 { 2035 {
1990 struct cbq_sched_data *q = qdisc_priv 2036 struct cbq_sched_data *q = qdisc_priv(sch);
1991 struct cbq_class *p = (struct cbq_cla 2037 struct cbq_class *p = (struct cbq_class*)parent;
1992 struct cbq_class *cl = cbq_class_look 2038 struct cbq_class *cl = cbq_class_lookup(q, classid);
1993 2039
1994 if (cl) { 2040 if (cl) {
1995 if (p && p->level <= cl->leve 2041 if (p && p->level <= cl->level)
1996 return 0; 2042 return 0;
1997 cl->filters++; 2043 cl->filters++;
1998 return (unsigned long)cl; 2044 return (unsigned long)cl;
1999 } 2045 }
2000 return 0; 2046 return 0;
2001 } 2047 }
2002 2048
2003 static void cbq_unbind_filter(struct Qdisc *s 2049 static void cbq_unbind_filter(struct Qdisc *sch, unsigned long arg)
2004 { 2050 {
2005 struct cbq_class *cl = (struct cbq_cl 2051 struct cbq_class *cl = (struct cbq_class*)arg;
2006 2052
2007 cl->filters--; 2053 cl->filters--;
2008 } 2054 }
2009 2055
2010 static void cbq_walk(struct Qdisc *sch, struc 2056 static void cbq_walk(struct Qdisc *sch, struct qdisc_walker *arg)
2011 { 2057 {
2012 struct cbq_sched_data *q = qdisc_priv 2058 struct cbq_sched_data *q = qdisc_priv(sch);
2013 unsigned h; 2059 unsigned h;
2014 2060
2015 if (arg->stop) 2061 if (arg->stop)
2016 return; 2062 return;
2017 2063
2018 for (h = 0; h < 16; h++) { 2064 for (h = 0; h < 16; h++) {
2019 struct cbq_class *cl; 2065 struct cbq_class *cl;
2020 2066
2021 for (cl = q->classes[h]; cl; 2067 for (cl = q->classes[h]; cl; cl = cl->next) {
2022 if (arg->count < arg- 2068 if (arg->count < arg->skip) {
2023 arg->count++; 2069 arg->count++;
2024 continue; 2070 continue;
2025 } 2071 }
2026 if (arg->fn(sch, (uns 2072 if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
2027 arg->stop = 1 2073 arg->stop = 1;
2028 return; 2074 return;
2029 } 2075 }
2030 arg->count++; 2076 arg->count++;
2031 } 2077 }
2032 } 2078 }
2033 } 2079 }
2034 2080
2035 static const struct Qdisc_class_ops cbq_class !! 2081 static struct Qdisc_class_ops cbq_class_ops = {
2036 .graft = cbq_graft, 2082 .graft = cbq_graft,
2037 .leaf = cbq_leaf, 2083 .leaf = cbq_leaf,
2038 .qlen_notify = cbq_qlen_noti <<
2039 .get = cbq_get, 2084 .get = cbq_get,
2040 .put = cbq_put, 2085 .put = cbq_put,
2041 .change = cbq_change_cl 2086 .change = cbq_change_class,
2042 .delete = cbq_delete, 2087 .delete = cbq_delete,
2043 .walk = cbq_walk, 2088 .walk = cbq_walk,
2044 .tcf_chain = cbq_find_tcf, 2089 .tcf_chain = cbq_find_tcf,
2045 .bind_tcf = cbq_bind_filt 2090 .bind_tcf = cbq_bind_filter,
2046 .unbind_tcf = cbq_unbind_fi 2091 .unbind_tcf = cbq_unbind_filter,
2047 .dump = cbq_dump_clas 2092 .dump = cbq_dump_class,
2048 .dump_stats = cbq_dump_clas 2093 .dump_stats = cbq_dump_class_stats,
2049 }; 2094 };
2050 2095
2051 static struct Qdisc_ops cbq_qdisc_ops __read_ !! 2096 static struct Qdisc_ops cbq_qdisc_ops = {
2052 .next = NULL, 2097 .next = NULL,
2053 .cl_ops = &cbq_class_op 2098 .cl_ops = &cbq_class_ops,
2054 .id = "cbq", 2099 .id = "cbq",
2055 .priv_size = sizeof(struct 2100 .priv_size = sizeof(struct cbq_sched_data),
2056 .enqueue = cbq_enqueue, 2101 .enqueue = cbq_enqueue,
2057 .dequeue = cbq_dequeue, 2102 .dequeue = cbq_dequeue,
2058 .requeue = cbq_requeue, 2103 .requeue = cbq_requeue,
2059 .drop = cbq_drop, 2104 .drop = cbq_drop,
2060 .init = cbq_init, 2105 .init = cbq_init,
2061 .reset = cbq_reset, 2106 .reset = cbq_reset,
2062 .destroy = cbq_destroy, 2107 .destroy = cbq_destroy,
2063 .change = NULL, 2108 .change = NULL,
2064 .dump = cbq_dump, 2109 .dump = cbq_dump,
2065 .dump_stats = cbq_dump_stat 2110 .dump_stats = cbq_dump_stats,
2066 .owner = THIS_MODULE, 2111 .owner = THIS_MODULE,
2067 }; 2112 };
2068 2113
2069 static int __init cbq_module_init(void) 2114 static int __init cbq_module_init(void)
2070 { 2115 {
2071 return register_qdisc(&cbq_qdisc_ops) 2116 return register_qdisc(&cbq_qdisc_ops);
2072 } 2117 }
2073 static void __exit cbq_module_exit(void) !! 2118 static void __exit cbq_module_exit(void)
2074 { 2119 {
2075 unregister_qdisc(&cbq_qdisc_ops); 2120 unregister_qdisc(&cbq_qdisc_ops);
2076 } 2121 }
2077 module_init(cbq_module_init) 2122 module_init(cbq_module_init)
2078 module_exit(cbq_module_exit) 2123 module_exit(cbq_module_exit)
2079 MODULE_LICENSE("GPL"); 2124 MODULE_LICENSE("GPL");
2080 2125
|
This page was automatically generated by the
LXR engine.
|