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