Root/target/linux/generic-2.4/patches/622-tc_esfq.patch

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

Archive Download this file



interactive