add new au1000 profiles
[openwrt.git] / target / linux / generic-2.4 / patches / 621-tc_esfq.patch
1 diff -urN linux-2.4.34/Documentation/Configure.help linux-2.4.34/Documentation/Configure.help
2 --- linux-2.4.34/Documentation/Configure.help 2007-05-10 19:37:42.000000000 -0400
3 +++ linux-2.4.34/Documentation/Configure.help 2007-05-10 19:49:49.000000000 -0400
4 @@ -11127,6 +11127,24 @@
5 whenever you want). If you want to compile it as a module, say M
6 here and read <file:Documentation/modules.txt>.
7
8 +ESFQ queue
9 +CONFIG_NET_SCH_ESFQ
10 + Say Y here if you want to use the Stochastic Fairness Queueing (SFQ)
11 + packet scheduling algorithm for some of your network devices or as a
12 + leaf discipline for the CBQ scheduling algorithm (see the top of
13 + <file:net/sched/sch_esfq.c> for details and references about the SFQ
14 + algorithm).
15 +
16 + This is an enchanced SFQ version which allows you to control the
17 + hardcoded values in the SFQ scheduler: queue depth, hash table size,
18 + queues limit. Also adds control to the hash function used to identify
19 + packet flows. Hash by src or dst ip and original sfq hash.
20 +
21 + This code is also available as a module called sch_esfq.o ( = code
22 + which can be inserted in and removed from the running kernel
23 + whenever you want). If you want to compile it as a module, say M
24 + here and read <file:Documentation/modules.txt>.
25 +
26 CSZ packet scheduler
27 CONFIG_NET_SCH_CSZ
28 Say Y here if you want to use the Clark-Shenker-Zhang (CSZ) packet
29 diff -urN linux-2.4.34/include/linux/pkt_sched.h linux-2.4.34/include/linux/pkt_sched.h
30 --- linux-2.4.34/include/linux/pkt_sched.h 2007-05-10 19:38:19.000000000 -0400
31 +++ linux-2.4.34/include/linux/pkt_sched.h 2007-05-10 19:53:59.000000000 -0400
32 @@ -173,8 +173,36 @@
33 *
34 * The only reason for this is efficiency, it is possible
35 * to change these parameters in compile time.
36 + *
37 + * If you need to play with these values use esfq instead.
38 */
39
40 +/* ESFQ section */
41 +
42 +enum
43 +{
44 + /* traditional */
45 + TCA_SFQ_HASH_CLASSIC,
46 + TCA_SFQ_HASH_DST,
47 + TCA_SFQ_HASH_SRC,
48 + /* conntrack */
49 + TCA_SFQ_HASH_CTORIGDST,
50 + TCA_SFQ_HASH_CTORIGSRC,
51 + TCA_SFQ_HASH_CTREPLDST,
52 + TCA_SFQ_HASH_CTREPLSRC,
53 + TCA_SFQ_HASH_CTNATCHG,
54 +};
55 +
56 +struct tc_esfq_qopt
57 +{
58 + unsigned quantum; /* Bytes per round allocated to flow */
59 + int perturb_period; /* Period of hash perturbation */
60 + __u32 limit; /* Maximal packets in queue */
61 + unsigned divisor; /* Hash divisor */
62 + unsigned flows; /* Maximal number of flows */
63 + unsigned hash_kind; /* Hash function to use for flow identification */
64 +};
65 +
66 /* RED section */
67
68 enum
69 diff -urN linux-2.4.34/net/sched/Config.in linux-2.4.34/net/sched/Config.in
70 --- linux-2.4.34/net/sched/Config.in 2007-05-10 19:38:31.000000000 -0400
71 +++ linux-2.4.34/net/sched/Config.in 2007-05-10 19:54:45.000000000 -0400
72 @@ -12,6 +12,7 @@
73 tristate ' The simplest PRIO pseudoscheduler' CONFIG_NET_SCH_PRIO
74 tristate ' RED queue' CONFIG_NET_SCH_RED
75 tristate ' SFQ queue' CONFIG_NET_SCH_SFQ
76 +tristate ' ESFQ queue' CONFIG_NET_SCH_ESFQ
77 tristate ' TEQL queue' CONFIG_NET_SCH_TEQL
78 tristate ' TBF queue' CONFIG_NET_SCH_TBF
79 tristate ' GRED queue' CONFIG_NET_SCH_GRED
80 diff -urN linux-2.4.34/net/sched/Makefile linux-2.4.34/net/sched/Makefile
81 --- linux-2.4.34/net/sched/Makefile 2007-05-10 19:38:31.000000000 -0400
82 +++ linux-2.4.34/net/sched/Makefile 2007-05-10 19:55:13.000000000 -0400
83 @@ -19,6 +19,7 @@
84 obj-$(CONFIG_NET_SCH_HFSC) += sch_hfsc.o
85 obj-$(CONFIG_NET_SCH_HTB) += sch_htb.o
86 obj-$(CONFIG_NET_SCH_SFQ) += sch_sfq.o
87 +obj-$(CONFIG_NET_SCH_ESFQ) += sch_esfq.o
88 obj-$(CONFIG_NET_SCH_RED) += sch_red.o
89 obj-$(CONFIG_NET_SCH_TBF) += sch_tbf.o
90 obj-$(CONFIG_NET_SCH_PRIO) += sch_prio.o
91 diff -urN linux-2.4.34/net/sched/sch_esfq.c linux-2.4.34/net/sched/sch_esfq.c
92 --- linux-2.4.34/net/sched/sch_esfq.c 1969-12-31 19:00:00.000000000 -0500
93 +++ linux-2.4.34/net/sched/sch_esfq.c 2007-05-10 19:57:15.000000000 -0400
94 @@ -0,0 +1,649 @@
95 +/*
96 + * net/sched/sch_esfq.c Extended Stochastic Fairness Queueing discipline.
97 + *
98 + * This program is free software; you can redistribute it and/or
99 + * modify it under the terms of the GNU General Public License
100 + * as published by the Free Software Foundation; either version
101 + * 2 of the License, or (at your option) any later version.
102 + *
103 + * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
104 + *
105 + * Changes: Alexander Atanasov, <alex@ssi.bg>
106 + * Added dynamic depth,limit,divisor,hash_kind options.
107 + * Added dst and src hashes.
108 + *
109 + * Alexander Clouter, <alex@digriz.org.uk>
110 + * Ported ESFQ to Linux 2.6.
111 + *
112 + * Corey Hickey, <bugfood-c@fatooh.org>
113 + * Maintenance of the Linux 2.6 port.
114 + * Added fwmark hash (thanks to Robert Kurjata).
115 + * Added usage of jhash.
116 + *
117 + */
118 +
119 +#include <linux/config.h>
120 +#include <linux/module.h>
121 +#include <asm/uaccess.h>
122 +#include <asm/system.h>
123 +#include <linux/bitops.h>
124 +#include <linux/types.h>
125 +#include <linux/kernel.h>
126 +#include <linux/sched.h>
127 +#include <linux/string.h>
128 +#include <linux/mm.h>
129 +#include <linux/socket.h>
130 +#include <linux/sockios.h>
131 +#include <linux/in.h>
132 +#include <linux/errno.h>
133 +#include <linux/interrupt.h>
134 +#include <linux/if_ether.h>
135 +#include <linux/inet.h>
136 +#include <linux/netdevice.h>
137 +#include <linux/etherdevice.h>
138 +#include <linux/notifier.h>
139 +#include <linux/init.h>
140 +#include <net/ip.h>
141 +#include <net/route.h>
142 +#include <linux/skbuff.h>
143 +#include <net/sock.h>
144 +#include <net/pkt_sched.h>
145 +#include <linux/jhash.h>
146 +
147 +#define IPPROTO_DCCP 33
148 +#define qdisc_priv(q) ((void *)(q->data))
149 +
150 +#ifdef CONFIG_IP_NF_CONNTRACK
151 +/* #include <net/netfilter/nf_conntrack.h> */
152 +#include <linux/netfilter_ipv4/ip_conntrack.h>
153 +#endif
154 +
155 +/* Stochastic Fairness Queuing algorithm.
156 + For more comments look at sch_sfq.c.
157 + The difference is that you can change limit, depth,
158 + hash table size and choose alternate hash types.
159 +
160 + classic: same as in sch_sfq.c
161 + dst: destination IP address
162 + src: source IP address
163 + ctorigdst: original destination IP address
164 + ctorigsrc: original source IP address
165 + ctrepldst: reply destination IP address
166 + ctreplsrc: reply source IP
167 + ctnatchg: use the address which changed via nat
168 +
169 +*/
170 +
171 +
172 +/* This type should contain at least SFQ_DEPTH*2 values */
173 +typedef unsigned int esfq_index;
174 +
175 +struct esfq_head
176 +{
177 + esfq_index next;
178 + esfq_index prev;
179 +};
180 +
181 +struct esfq_sched_data
182 +{
183 +/* Parameters */
184 + int perturb_period;
185 + unsigned quantum; /* Allotment per round: MUST BE >= MTU */
186 + int limit;
187 + unsigned depth;
188 + unsigned hash_divisor;
189 + unsigned hash_kind;
190 +/* Variables */
191 + struct timer_list perturb_timer;
192 + int perturbation;
193 + esfq_index tail; /* Index of current slot in round */
194 + esfq_index max_depth; /* Maximal depth */
195 +
196 + esfq_index *ht; /* Hash table */
197 + esfq_index *next; /* Active slots link */
198 + short *allot; /* Current allotment per slot */
199 + unsigned short *hash; /* Hash value indexed by slots */
200 + struct sk_buff_head *qs; /* Slot queue */
201 + struct esfq_head *dep; /* Linked list of slots, indexed by depth */
202 + unsigned dyn_min; /* For dynamic divisor adjustment; minimum value seen */
203 + unsigned dyn_max; /* maximum value seen */
204 + unsigned dyn_range; /* saved range */
205 +};
206 +
207 +/* This contains the info we will hash. */
208 +struct esfq_packet_info
209 +{
210 + u32 proto; /* protocol or port */
211 + u32 src; /* source from packet header */
212 + u32 dst; /* destination from packet header */
213 + u32 ctorigsrc; /* original source from conntrack */
214 + u32 ctorigdst; /* original destination from conntrack */
215 + u32 ctreplsrc; /* reply source from conntrack */
216 + u32 ctrepldst; /* reply destination from conntrack */
217 +};
218 +
219 +static __inline__ unsigned esfq_jhash_1word(struct esfq_sched_data *q,u32 a)
220 +{
221 + return jhash_1word(a, q->perturbation) & (q->hash_divisor-1);
222 +}
223 +
224 +static __inline__ unsigned esfq_jhash_2words(struct esfq_sched_data *q, u32 a, u32 b)
225 +{
226 + return jhash_2words(a, b, q->perturbation) & (q->hash_divisor-1);
227 +}
228 +
229 +static __inline__ unsigned esfq_jhash_3words(struct esfq_sched_data *q, u32 a, u32 b, u32 c)
230 +{
231 + return jhash_3words(a, b, c, q->perturbation) & (q->hash_divisor-1);
232 +}
233 +
234 +
235 +static unsigned esfq_hash(struct esfq_sched_data *q, struct sk_buff *skb)
236 +{
237 + struct esfq_packet_info info;
238 +#ifdef CONFIG_IP_NF_CONNTRACK
239 + enum ip_conntrack_info ctinfo;
240 + struct ip_conntrack *ct = ip_conntrack_get(skb, &ctinfo);
241 +#endif
242 +
243 + switch (skb->protocol) {
244 + case __constant_htons(ETH_P_IP):
245 + {
246 + struct iphdr *iph = skb->nh.iph;
247 + info.dst = iph->daddr;
248 + info.src = iph->saddr;
249 + if (!(iph->frag_off&htons(IP_MF|IP_OFFSET)) &&
250 + (iph->protocol == IPPROTO_TCP ||
251 + iph->protocol == IPPROTO_UDP ||
252 + iph->protocol == IPPROTO_SCTP ||
253 + iph->protocol == IPPROTO_DCCP ||
254 + iph->protocol == IPPROTO_ESP))
255 + info.proto = *(((u32*)iph) + iph->ihl);
256 + else
257 + info.proto = iph->protocol;
258 + break;
259 + }
260 + default:
261 + info.dst = (u32)(unsigned long)skb->dst;
262 + info.src = (u32)(unsigned long)skb->sk;
263 + info.proto = skb->protocol;
264 + }
265 +
266 +#ifdef CONFIG_IP_NF_CONNTRACK
267 + /* defaults if there is no conntrack info */
268 + info.ctorigsrc = info.src;
269 + info.ctorigdst = info.dst;
270 + info.ctreplsrc = info.dst;
271 + info.ctrepldst = info.src;
272 + /* collect conntrack info */
273 + IP_NF_ASSERT(ct);
274 + if (ct) {
275 + if (skb->protocol == __constant_htons(ETH_P_IP)) {
276 + info.ctorigsrc = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
277 + info.ctorigdst = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
278 + info.ctreplsrc = ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
279 + info.ctrepldst = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
280 + }
281 + }
282 +#endif
283 +
284 + switch(q->hash_kind)
285 + {
286 + case TCA_SFQ_HASH_CLASSIC:
287 + return esfq_jhash_3words(q, info.dst, info.src, info.proto);
288 + case TCA_SFQ_HASH_DST:
289 + return esfq_jhash_1word(q, info.dst);
290 + case TCA_SFQ_HASH_SRC:
291 + return esfq_jhash_1word(q, info.src);
292 +#ifdef CONFIG_IP_NF_CONNTRACK
293 + case TCA_SFQ_HASH_CTORIGDST:
294 + return esfq_jhash_1word(q, info.ctorigdst);
295 + case TCA_SFQ_HASH_CTORIGSRC:
296 + return esfq_jhash_1word(q, info.ctorigsrc);
297 + case TCA_SFQ_HASH_CTREPLDST:
298 + return esfq_jhash_1word(q, info.ctrepldst);
299 + case TCA_SFQ_HASH_CTREPLSRC:
300 + return esfq_jhash_1word(q, info.ctreplsrc);
301 + case TCA_SFQ_HASH_CTNATCHG:
302 + {
303 + if (info.ctorigdst == info.ctreplsrc)
304 + return esfq_jhash_1word(q, info.ctorigsrc);
305 + else
306 + return esfq_jhash_1word(q, info.ctreplsrc);
307 + }
308 +#endif
309 + default:
310 + if (net_ratelimit())
311 + printk(KERN_WARNING "ESFQ: Unknown hash method. Falling back to classic.\n");
312 + }
313 + return esfq_jhash_3words(q, info.dst, info.src, info.proto);
314 +}
315 +
316 +static inline void esfq_link(struct esfq_sched_data *q, esfq_index x)
317 +{
318 + esfq_index p, n;
319 + int d = q->qs[x].qlen + q->depth;
320 +
321 + p = d;
322 + n = q->dep[d].next;
323 + q->dep[x].next = n;
324 + q->dep[x].prev = p;
325 + q->dep[p].next = q->dep[n].prev = x;
326 +}
327 +
328 +static inline void esfq_dec(struct esfq_sched_data *q, esfq_index x)
329 +{
330 + esfq_index p, n;
331 +
332 + n = q->dep[x].next;
333 + p = q->dep[x].prev;
334 + q->dep[p].next = n;
335 + q->dep[n].prev = p;
336 +
337 + if (n == p && q->max_depth == q->qs[x].qlen + 1)
338 + q->max_depth--;
339 +
340 + esfq_link(q, x);
341 +}
342 +
343 +static inline void esfq_inc(struct esfq_sched_data *q, esfq_index x)
344 +{
345 + esfq_index p, n;
346 + int d;
347 +
348 + n = q->dep[x].next;
349 + p = q->dep[x].prev;
350 + q->dep[p].next = n;
351 + q->dep[n].prev = p;
352 + d = q->qs[x].qlen;
353 + if (q->max_depth < d)
354 + q->max_depth = d;
355 +
356 + esfq_link(q, x);
357 +}
358 +
359 +static unsigned int esfq_drop(struct Qdisc *sch)
360 +{
361 + struct esfq_sched_data *q = qdisc_priv(sch);
362 + esfq_index d = q->max_depth;
363 + struct sk_buff *skb;
364 + unsigned int len;
365 +
366 + /* Queue is full! Find the longest slot and
367 + drop a packet from it */
368 +
369 + if (d > 1) {
370 + esfq_index x = q->dep[d+q->depth].next;
371 + skb = q->qs[x].prev;
372 + len = skb->len;
373 + __skb_unlink(skb, &q->qs[x]);
374 + kfree_skb(skb);
375 + esfq_dec(q, x);
376 + sch->q.qlen--;
377 + sch->stats.drops++;
378 + sch->stats.backlog -= len;
379 + return len;
380 + }
381 +
382 + if (d == 1) {
383 + /* It is difficult to believe, but ALL THE SLOTS HAVE LENGTH 1. */
384 + d = q->next[q->tail];
385 + q->next[q->tail] = q->next[d];
386 + q->allot[q->next[d]] += q->quantum;
387 + skb = q->qs[d].prev;
388 + len = skb->len;
389 + __skb_unlink(skb, &q->qs[d]);
390 + kfree_skb(skb);
391 + esfq_dec(q, d);
392 + sch->q.qlen--;
393 + q->ht[q->hash[d]] = q->depth;
394 + sch->stats.drops++;
395 + sch->stats.backlog -= len;
396 + return len;
397 + }
398 +
399 + return 0;
400 +}
401 +
402 +static int
403 +esfq_enqueue(struct sk_buff *skb, struct Qdisc* sch)
404 +{
405 + struct esfq_sched_data *q = qdisc_priv(sch);
406 + unsigned hash = esfq_hash(q, skb);
407 + unsigned depth = q->depth;
408 + esfq_index x;
409 +
410 + x = q->ht[hash];
411 + if (x == depth) {
412 + q->ht[hash] = x = q->dep[depth].next;
413 + q->hash[x] = hash;
414 + }
415 + sch->stats.backlog += skb->len;
416 + __skb_queue_tail(&q->qs[x], skb);
417 + esfq_inc(q, x);
418 + if (q->qs[x].qlen == 1) { /* The flow is new */
419 + if (q->tail == depth) { /* It is the first flow */
420 + q->tail = x;
421 + q->next[x] = x;
422 + q->allot[x] = q->quantum;
423 + } else {
424 + q->next[x] = q->next[q->tail];
425 + q->next[q->tail] = x;
426 + q->tail = x;
427 + }
428 + }
429 + if (++sch->q.qlen < q->limit-1) {
430 + sch->stats.bytes += skb->len;
431 + sch->stats.packets++;
432 + return 0;
433 + }
434 +
435 + esfq_drop(sch);
436 + return NET_XMIT_CN;
437 +}
438 +
439 +static int
440 +esfq_requeue(struct sk_buff *skb, struct Qdisc* sch)
441 +{
442 + struct esfq_sched_data *q = qdisc_priv(sch);
443 + unsigned hash = esfq_hash(q, skb);
444 + unsigned depth = q->depth;
445 + esfq_index x;
446 +
447 + x = q->ht[hash];
448 + if (x == depth) {
449 + q->ht[hash] = x = q->dep[depth].next;
450 + q->hash[x] = hash;
451 + }
452 + sch->stats.backlog += skb->len;
453 + __skb_queue_head(&q->qs[x], skb);
454 + esfq_inc(q, x);
455 + if (q->qs[x].qlen == 1) { /* The flow is new */
456 + if (q->tail == depth) { /* It is the first flow */
457 + q->tail = x;
458 + q->next[x] = x;
459 + q->allot[x] = q->quantum;
460 + } else {
461 + q->next[x] = q->next[q->tail];
462 + q->next[q->tail] = x;
463 + q->tail = x;
464 + }
465 + }
466 + if (++sch->q.qlen < q->limit - 1) {
467 + return 0;
468 + }
469 +
470 + sch->stats.drops++;
471 + esfq_drop(sch);
472 + return NET_XMIT_CN;
473 +}
474 +
475 +
476 +
477 +
478 +static struct sk_buff *
479 +esfq_dequeue(struct Qdisc* sch)
480 +{
481 + struct esfq_sched_data *q = qdisc_priv(sch);
482 + struct sk_buff *skb;
483 + unsigned depth = q->depth;
484 + esfq_index a, old_a;
485 +
486 + /* No active slots */
487 + if (q->tail == depth)
488 + return NULL;
489 +
490 + a = old_a = q->next[q->tail];
491 +
492 + /* Grab packet */
493 + skb = __skb_dequeue(&q->qs[a]);
494 + esfq_dec(q, a);
495 + sch->q.qlen--;
496 + sch->stats.backlog -= skb->len;
497 +
498 + /* Is the slot empty? */
499 + if (q->qs[a].qlen == 0) {
500 + q->ht[q->hash[a]] = depth;
501 + a = q->next[a];
502 + if (a == old_a) {
503 + q->tail = depth;
504 + return skb;
505 + }
506 + q->next[q->tail] = a;
507 + q->allot[a] += q->quantum;
508 + } else if ((q->allot[a] -= skb->len) <= 0) {
509 + q->tail = a;
510 + a = q->next[a];
511 + q->allot[a] += q->quantum;
512 + }
513 +
514 + return skb;
515 +}
516 +
517 +static void
518 +esfq_reset(struct Qdisc* sch)
519 +{
520 + struct sk_buff *skb;
521 +
522 + while ((skb = esfq_dequeue(sch)) != NULL)
523 + kfree_skb(skb);
524 +}
525 +
526 +static void esfq_perturbation(unsigned long arg)
527 +{
528 + struct Qdisc *sch = (struct Qdisc*)arg;
529 + struct esfq_sched_data *q = qdisc_priv(sch);
530 +
531 + q->perturbation = net_random()&0x1F;
532 +
533 + if (q->perturb_period) {
534 + q->perturb_timer.expires = jiffies + q->perturb_period;
535 + add_timer(&q->perturb_timer);
536 + }
537 +}
538 +
539 +static int esfq_change(struct Qdisc *sch, struct rtattr *opt)
540 +{
541 + struct esfq_sched_data *q = qdisc_priv(sch);
542 + struct tc_esfq_qopt *ctl = RTA_DATA(opt);
543 + int old_perturb = q->perturb_period;
544 +
545 + if (opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
546 + return -EINVAL;
547 +
548 + sch_tree_lock(sch);
549 + q->quantum = ctl->quantum ? : psched_mtu(sch->dev);
550 + q->perturb_period = ctl->perturb_period*HZ;
551 +// q->hash_divisor = ctl->divisor;
552 +// q->tail = q->limit = q->depth = ctl->flows;
553 +
554 + if (ctl->limit)
555 + q->limit = min_t(u32, ctl->limit, q->depth);
556 +
557 + if (ctl->hash_kind) {
558 + q->hash_kind = ctl->hash_kind;
559 + if (q->hash_kind != TCA_SFQ_HASH_CLASSIC)
560 + q->perturb_period = 0;
561 + }
562 +
563 + // is sch_tree_lock enough to do this ?
564 + while (sch->q.qlen >= q->limit-1)
565 + esfq_drop(sch);
566 +
567 + if (old_perturb)
568 + del_timer(&q->perturb_timer);
569 + if (q->perturb_period) {
570 + q->perturb_timer.expires = jiffies + q->perturb_period;
571 + add_timer(&q->perturb_timer);
572 + } else {
573 + q->perturbation = 0;
574 + }
575 + sch_tree_unlock(sch);
576 + return 0;
577 +}
578 +
579 +static int esfq_init(struct Qdisc *sch, struct rtattr *opt)
580 +{
581 + struct esfq_sched_data *q = qdisc_priv(sch);
582 + struct tc_esfq_qopt *ctl;
583 + esfq_index p = ~0U/2;
584 + int i;
585 +
586 + if (opt && opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
587 + return -EINVAL;
588 +
589 + init_timer(&q->perturb_timer);
590 + q->perturb_timer.data = (unsigned long)sch;
591 + q->perturb_timer.function = esfq_perturbation;
592 + q->perturbation = 0;
593 + q->hash_kind = TCA_SFQ_HASH_CLASSIC;
594 + q->max_depth = 0;
595 + q->dyn_min = ~0U; /* maximum value for this type */
596 + q->dyn_max = 0; /* dyn_min/dyn_max will be set properly upon first packet */
597 + if (opt == NULL) {
598 + q->quantum = psched_mtu(sch->dev);
599 + q->perturb_period = 0;
600 + q->hash_divisor = 1024;
601 + q->tail = q->limit = q->depth = 128;
602 +
603 + } else {
604 + ctl = RTA_DATA(opt);
605 + q->quantum = ctl->quantum ? : psched_mtu(sch->dev);
606 + q->perturb_period = ctl->perturb_period*HZ;
607 + q->hash_divisor = ctl->divisor ? : 1024;
608 + q->tail = q->limit = q->depth = ctl->flows ? : 128;
609 +
610 + if ( q->depth > p - 1 )
611 + return -EINVAL;
612 +
613 + if (ctl->limit)
614 + q->limit = min_t(u32, ctl->limit, q->depth);
615 +
616 + if (ctl->hash_kind) {
617 + q->hash_kind = ctl->hash_kind;
618 + }
619 +
620 + if (q->perturb_period) {
621 + q->perturb_timer.expires = jiffies + q->perturb_period;
622 + add_timer(&q->perturb_timer);
623 + }
624 + }
625 +
626 + q->ht = kmalloc(q->hash_divisor*sizeof(esfq_index), GFP_KERNEL);
627 + if (!q->ht)
628 + goto err_case;
629 +
630 + q->dep = kmalloc((1+q->depth*2)*sizeof(struct esfq_head), GFP_KERNEL);
631 + if (!q->dep)
632 + goto err_case;
633 + q->next = kmalloc(q->depth*sizeof(esfq_index), GFP_KERNEL);
634 + if (!q->next)
635 + goto err_case;
636 +
637 + q->allot = kmalloc(q->depth*sizeof(short), GFP_KERNEL);
638 + if (!q->allot)
639 + goto err_case;
640 + q->hash = kmalloc(q->depth*sizeof(unsigned short), GFP_KERNEL);
641 + if (!q->hash)
642 + goto err_case;
643 + q->qs = kmalloc(q->depth*sizeof(struct sk_buff_head), GFP_KERNEL);
644 + if (!q->qs)
645 + goto err_case;
646 +
647 + for (i=0; i< q->hash_divisor; i++)
648 + q->ht[i] = q->depth;
649 + for (i=0; i<q->depth; i++) {
650 + skb_queue_head_init(&q->qs[i]);
651 + q->dep[i+q->depth].next = i+q->depth;
652 + q->dep[i+q->depth].prev = i+q->depth;
653 + }
654 +
655 + for (i=0; i<q->depth; i++)
656 + esfq_link(q, i);
657 + return 0;
658 +err_case:
659 + del_timer(&q->perturb_timer);
660 + if (q->ht)
661 + kfree(q->ht);
662 + if (q->dep)
663 + kfree(q->dep);
664 + if (q->next)
665 + kfree(q->next);
666 + if (q->allot)
667 + kfree(q->allot);
668 + if (q->hash)
669 + kfree(q->hash);
670 + if (q->qs)
671 + kfree(q->qs);
672 + return -ENOBUFS;
673 +}
674 +
675 +static void esfq_destroy(struct Qdisc *sch)
676 +{
677 + struct esfq_sched_data *q = qdisc_priv(sch);
678 + del_timer(&q->perturb_timer);
679 + if(q->ht)
680 + kfree(q->ht);
681 + if(q->dep)
682 + kfree(q->dep);
683 + if(q->next)
684 + kfree(q->next);
685 + if(q->allot)
686 + kfree(q->allot);
687 + if(q->hash)
688 + kfree(q->hash);
689 + if(q->qs)
690 + kfree(q->qs);
691 +}
692 +
693 +static int esfq_dump(struct Qdisc *sch, struct sk_buff *skb)
694 +{
695 + struct esfq_sched_data *q = qdisc_priv(sch);
696 + unsigned char *b = skb->tail;
697 + struct tc_esfq_qopt opt;
698 +
699 + opt.quantum = q->quantum;
700 + opt.perturb_period = q->perturb_period/HZ;
701 +
702 + opt.limit = q->limit;
703 + opt.divisor = q->hash_divisor;
704 + opt.flows = q->depth;
705 + opt.hash_kind = q->hash_kind;
706 +
707 + RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
708 +
709 + return skb->len;
710 +
711 +rtattr_failure:
712 + skb_trim(skb, b - skb->data);
713 + return -1;
714 +}
715 +
716 +static struct Qdisc_ops esfq_qdisc_ops =
717 +{
718 + .next = NULL,
719 + .cl_ops = NULL,
720 + .id = "esfq",
721 + .priv_size = sizeof(struct esfq_sched_data),
722 + .enqueue = esfq_enqueue,
723 + .dequeue = esfq_dequeue,
724 + .requeue = esfq_requeue,
725 + .drop = esfq_drop,
726 + .init = esfq_init,
727 + .reset = esfq_reset,
728 + .destroy = esfq_destroy,
729 + .change = NULL, /* esfq_change - needs more work */
730 + .dump = esfq_dump,
731 +};
732 +
733 +static int __init esfq_module_init(void)
734 +{
735 + return register_qdisc(&esfq_qdisc_ops);
736 +}
737 +static void __exit esfq_module_exit(void)
738 +{
739 + unregister_qdisc(&esfq_qdisc_ops);
740 +}
741 +module_init(esfq_module_init)
742 +module_exit(esfq_module_exit)
743 +MODULE_LICENSE("GPL");
This page took 0.101695 seconds and 5 git commands to generate.