SOURCES (LINUX_2_6): esfq-kernel.patch (NEW) - this release has a ...

pluto pluto at pld-linux.org
Wed Nov 2 12:15:48 CET 2005


Author: pluto                        Date: Wed Nov  2 11:15:48 2005 GMT
Module: SOURCES                       Tag: LINUX_2_6
---- Log message:
- this release has a few new features. In brief, there is now hashing
  by fwmark and a new "direct" hashing method that eliminates collisions
  when the range of input values is smaller than the size of the hash table.
  see the expanded, updated http://fatooh.org/esfq-2.6/current/README
  for information on the new features, scroll down to the "HASH TYPES"
  and "EXAMPLES" sections.

---- Files affected:
SOURCES:
   esfq-kernel.patch (NONE -> 1.1.2.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/esfq-kernel.patch
diff -u /dev/null SOURCES/esfq-kernel.patch:1.1.2.1
--- /dev/null	Wed Nov  2 12:15:48 2005
+++ SOURCES/esfq-kernel.patch	Wed Nov  2 12:15:43 2005
@@ -0,0 +1,725 @@
+diff -Naur linux-2.6.13.3.old/include/linux/pkt_sched.h linux-2.6.13.3/include/linux/pkt_sched.h
+--- linux-2.6.13.3.old/include/linux/pkt_sched.h	2005-10-23 17:39:16.000000000 -0700
++++ linux-2.6.13.3/include/linux/pkt_sched.h	2005-10-21 18:13:37.000000000 -0700
+@@ -145,8 +145,35 @@
+  *
+  *	The only reason for this is efficiency, it is possible
+  *	to change these parameters in compile time.
++ *	
++ *	If you need to play with these values use esfq instead.
+  */
+ 
++/* ESFQ section */
++
++enum
++{
++        /* traditional */
++	TCA_SFQ_HASH_CLASSIC,
++	TCA_SFQ_HASH_DST,
++	TCA_SFQ_HASH_SRC,
++	TCA_SFQ_HASH_FWMARK,
++        /* direct */
++	TCA_SFQ_HASH_DSTDIR,
++	TCA_SFQ_HASH_SRCDIR,
++	TCA_SFQ_HASH_FWMARKDIR,
++};
++
++struct tc_esfq_qopt
++{
++	unsigned	quantum;	/* Bytes per round allocated to flow */
++	int		perturb_period;	/* Period of hash perturbation */
++	__u32		limit;		/* Maximal packets in queue */
++	unsigned	divisor;	/* Hash divisor  */
++	unsigned	flows;		/* Maximal number of flows  */
++	unsigned	hash_kind;	/* Hash function to use for flow identification */
++};
++
+ /* RED section */
+ 
+ enum
+diff -Naur linux-2.6.13.3.old/net/sched/Kconfig linux-2.6.13.3/net/sched/Kconfig
+--- linux-2.6.13.3.old/net/sched/Kconfig	2005-10-23 17:39:16.000000000 -0700
++++ linux-2.6.13.3/net/sched/Kconfig	2005-10-09 16:56:27.000000000 -0700
+@@ -191,6 +191,28 @@
+ 	  To compile this code as a module, choose M here: the
+ 	  module will be called sch_sfq.
+ 
++config NET_SCH_ESFQ
++	tristate "ESFQ queue"
++	depends on NET_SCHED
++	---help---
++	  Say Y here if you want to use the Enhanced Stochastic Fairness
++	  Queueing (ESFQ) packet scheduling algorithm for some of your network
++	  devices or as a leaf discipline for a classful qdisc such as HTB or
++	  CBQ (see the top of <file:net/sched/sch_esfq.c> for details and
++	  references to the SFQ algorithm).
++	  
++	  This is an enchanced SFQ version which allows you to control some
++	  hardcoded values in the SFQ scheduler: queue depth, hash table size,
++	  and queues limit.
++	  
++	  ESFQ also adds control to the hash function used to identify packet
++	  flows. The original SFQ hashes by individual flow (TCP session or UDP
++	  stream); ESFQ can hash by src or dst IP as well, which can be more
++	  fair to users in some networking situations.
++	  
++	  To compile this code as a module, choose M here: the
++	  module will be called sch_esfq.
++
+ config NET_SCH_TEQL
+ 	tristate "TEQL queue"
+ 	depends on NET_SCHED
+diff -Naur linux-2.6.13.3.old/net/sched/Makefile linux-2.6.13.3/net/sched/Makefile
+--- linux-2.6.13.3.old/net/sched/Makefile	2005-10-23 17:39:16.000000000 -0700
++++ linux-2.6.13.3/net/sched/Makefile	2005-10-09 16:56:27.000000000 -0700
+@@ -23,6 +23,7 @@
+ obj-$(CONFIG_NET_SCH_INGRESS)	+= sch_ingress.o 
+ obj-$(CONFIG_NET_SCH_DSMARK)	+= sch_dsmark.o
+ obj-$(CONFIG_NET_SCH_SFQ)	+= sch_sfq.o
++obj-$(CONFIG_NET_SCH_ESFQ)	+= sch_esfq.o
+ obj-$(CONFIG_NET_SCH_TBF)	+= sch_tbf.o
+ obj-$(CONFIG_NET_SCH_TEQL)	+= sch_teql.o
+ obj-$(CONFIG_NET_SCH_PRIO)	+= sch_prio.o
+diff -Naur linux-2.6.13.3.old/net/sched/sch_esfq.c linux-2.6.13.3/net/sched/sch_esfq.c
+--- linux-2.6.13.3.old/net/sched/sch_esfq.c	1969-12-31 16:00:00.000000000 -0800
++++ linux-2.6.13.3/net/sched/sch_esfq.c	2005-10-23 17:32:19.000000000 -0700
+@@ -0,0 +1,639 @@
++/*
++ * net/sched/sch_esfq.c	Extended Stochastic Fairness Queueing discipline.
++ *
++ *		This program is free software; you can redistribute it and/or
++ *		modify it under the terms of the GNU General Public License
++ *		as published by the Free Software Foundation; either version
++ *		2 of the License, or (at your option) any later version.
++ *
++ * Authors:	Alexey Kuznetsov, <kuznet at ms2.inr.ac.ru>
++ *
++ * Changes:	Alexander Atanasov, <alex at ssi.bg>
++ *		Added dynamic depth,limit,divisor,hash_kind options.
++ *		Added dst and src hashes.
++ *
++ * 		Alexander Clouter, <alex at digriz.org.uk>
++ *		Ported ESFQ to Linux 2.6.
++ *
++ * 		Corey Hickey, <bugfood-c at fatooh.org>
++ *		Maintenance of the Linux 2.6 port.
++ *		Added fwmark hash (thanks to Robert Kurjata)
++ *		Added direct hashing for src, dst, and fwmark.
++ *		
++ */
++
++#include <linux/config.h>
++#include <linux/module.h>
++#include <asm/uaccess.h>
++#include <asm/system.h>
++#include <linux/bitops.h>
++#include <linux/types.h>
++#include <linux/kernel.h>
++#include <linux/jiffies.h>
++#include <linux/string.h>
++#include <linux/mm.h>
++#include <linux/socket.h>
++#include <linux/sockios.h>
++#include <linux/in.h>
++#include <linux/errno.h>
++#include <linux/interrupt.h>
++#include <linux/if_ether.h>
++#include <linux/inet.h>
++#include <linux/netdevice.h>
++#include <linux/etherdevice.h>
++#include <linux/notifier.h>
++#include <linux/init.h>
++#include <net/ip.h>
++#include <linux/ipv6.h>
++#include <net/route.h>
++#include <linux/skbuff.h>
++#include <net/sock.h>
++#include <net/pkt_sched.h>
++
++
++/*	Stochastic Fairness Queuing algorithm.
++	For more comments look at sch_sfq.c.
++	The difference is that you can change limit, depth,
++	hash table size and choose 7 hash types.
++	
++	classic:	same as in sch_sfq.c
++	dst:		destination IP address
++	src:		source IP address
++	fwmark:         netfilter mark value
++	dst_direct:
++	src_direct:
++	fwmark_direct:  direct hashing of the above sources
++	
++	TODO: 
++		make sfq_change work.
++*/
++
++
++/* This type should contain at least SFQ_DEPTH*2 values */
++typedef unsigned int esfq_index;
++
++struct esfq_head
++{
++	esfq_index	next;
++	esfq_index	prev;
++};
++
++struct esfq_sched_data
++{
++/* Parameters */
++	int		perturb_period;
++	unsigned	quantum;	/* Allotment per round: MUST BE >= MTU */
++	int		limit;
++	unsigned	depth;
++	unsigned	hash_divisor;
++	unsigned	hash_kind;
++/* Variables */
++	struct timer_list perturb_timer;
++	int		perturbation;
++	esfq_index	tail;		/* Index of current slot in round */
++	esfq_index	max_depth;	/* Maximal depth */
++
++	esfq_index	*ht;			/* Hash table */
++	esfq_index	*next;			/* Active slots link */
++	short		*allot;			/* Current allotment per slot */
++	unsigned short	*hash;			/* Hash value indexed by slots */
++	struct sk_buff_head	*qs;		/* Slot queue */
++	struct esfq_head	*dep;		/* Linked list of slots, indexed by depth */
++	unsigned	dyn_min;	/* For dynamic divisor adjustment; minimum value seen */
++	unsigned	dyn_max;	/*                                 maximum value seen */
++	unsigned	dyn_range;	/*	        		   saved range */
++};
++
++static __inline__ unsigned esfq_hash_u32(struct esfq_sched_data *q,u32 h)
++{
++	int pert = q->perturbation;
++
++	if (pert)
++		h = (h<<pert) ^ (h>>(0x1F - pert));
++
++	h = ntohl(h) * 2654435761UL;
++	return h & (q->hash_divisor-1);
++}
++
++/* Hash input values directly into the "nearest" slot, taking into account the
++ * range of input values seen. This is most useful when the hash table is at
++ * least as large as the range of possible values. */
++static __inline__ unsigned esfq_hash_direct(struct esfq_sched_data *q, u32 h)
++{
++	/* adjust minimum and maximum */
++	if (h < q->dyn_min || h > q->dyn_max) {
++		q->dyn_min = h < q->dyn_min ? h : q->dyn_min;
++		q->dyn_max = h > q->dyn_max ? h : q->dyn_max;
++	
++		/* find new range */
++		if ((q->dyn_range = q->dyn_max - q->dyn_min) >= q->hash_divisor)
++			printk(KERN_WARNING "ESFQ: (direct hash) Input range %u is larger than hash "
++					"table. See ESFQ README for details.\n", q->dyn_range);
++	}
++	
++	/* hash input values into slot numbers */
++	if (q->dyn_min == q->dyn_max)
++		return 0; /* only one value seen; avoid division by 0 */
++	else
++		return (h - q->dyn_min) * (q->hash_divisor - 1) / q->dyn_range;
++}
++
++static __inline__ unsigned esfq_fold_hash_classic(struct esfq_sched_data *q, u32 h, u32 h1)
++{
++	int pert = q->perturbation;
++
++	/* Have we any rotation primitives? If not, WHY? */
++	h ^= (h1<<pert) ^ (h1>>(0x1F - pert));
++	h ^= h>>10;
++	return h & (q->hash_divisor-1);
++}
++
++static unsigned esfq_hash(struct esfq_sched_data *q, struct sk_buff *skb)
++{
++	u32 h, h2;
++	u32 hs;
++	u32 nfm;
++
++	switch (skb->protocol) {
++	case __constant_htons(ETH_P_IP):
++	{
++		struct iphdr *iph = skb->nh.iph;
++		h = iph->daddr;
++		hs = iph->saddr;
++		nfm = skb->nfmark;
++		h2 = hs^iph->protocol;
++		if (!(iph->frag_off&htons(IP_MF|IP_OFFSET)) &&
++		    (iph->protocol == IPPROTO_TCP ||
++		     iph->protocol == IPPROTO_UDP ||
++		     iph->protocol == IPPROTO_ESP))
++			h2 ^= *(((u32*)iph) + iph->ihl);
++		break;
++	}
++	case __constant_htons(ETH_P_IPV6):
++	{
++		struct ipv6hdr *iph = skb->nh.ipv6h;
++		h = iph->daddr.s6_addr32[3];
++		hs = iph->saddr.s6_addr32[3];
++		nfm = skb->nfmark;
++		h2 = hs^iph->nexthdr;
++		if (iph->nexthdr == IPPROTO_TCP ||
++		    iph->nexthdr == IPPROTO_UDP ||
++		    iph->nexthdr == IPPROTO_ESP)
++			h2 ^= *(u32*)&iph[1];
++		break;
++	}
++	default:
++		h = (u32)(unsigned long)skb->dst;
++		hs = (u32)(unsigned long)skb->sk;
++		nfm = skb->nfmark;
++		h2 = hs^skb->protocol;
++	}
++	switch(q->hash_kind)
++	{
++	case TCA_SFQ_HASH_CLASSIC:
++		return esfq_fold_hash_classic(q, h, h2);
++	case TCA_SFQ_HASH_DST:
++		return esfq_hash_u32(q,h);
++	case TCA_SFQ_HASH_DSTDIR:
++		return esfq_hash_direct(q, ntohl(h));
++	case TCA_SFQ_HASH_SRC:
++		return esfq_hash_u32(q,hs);
++	case TCA_SFQ_HASH_SRCDIR:
++		return esfq_hash_direct(q, ntohl(hs));
++#ifdef CONFIG_NETFILTER
++	case TCA_SFQ_HASH_FWMARK:
++		return esfq_hash_u32(q,nfm);
++	case TCA_SFQ_HASH_FWMARKDIR:
++		return esfq_hash_direct(q,nfm);
++#endif
++	default:
++		if (net_ratelimit())
++			printk(KERN_WARNING "ESFQ: Unknown hash method. Falling back to classic.\n");
++	}
++	return esfq_fold_hash_classic(q, h, h2);
++}
++
++static inline void esfq_link(struct esfq_sched_data *q, esfq_index x)
++{
++	esfq_index p, n;
++	int d = q->qs[x].qlen + q->depth;
++
++	p = d;
++	n = q->dep[d].next;
++	q->dep[x].next = n;
++	q->dep[x].prev = p;
++	q->dep[p].next = q->dep[n].prev = x;
++}
++
++static inline void esfq_dec(struct esfq_sched_data *q, esfq_index x)
++{
++	esfq_index p, n;
++
++	n = q->dep[x].next;
++	p = q->dep[x].prev;
++	q->dep[p].next = n;
++	q->dep[n].prev = p;
++
++	if (n == p && q->max_depth == q->qs[x].qlen + 1)
++		q->max_depth--;
++
++	esfq_link(q, x);
++}
++
++static inline void esfq_inc(struct esfq_sched_data *q, esfq_index x)
++{
++	esfq_index p, n;
++	int d;
++
++	n = q->dep[x].next;
++	p = q->dep[x].prev;
++	q->dep[p].next = n;
++	q->dep[n].prev = p;
++	d = q->qs[x].qlen;
++	if (q->max_depth < d)
++		q->max_depth = d;
++
++	esfq_link(q, x);
++}
++
++static unsigned int esfq_drop(struct Qdisc *sch)
++{
++	struct esfq_sched_data *q = qdisc_priv(sch);
++	esfq_index d = q->max_depth;
++	struct sk_buff *skb;
++	unsigned int len;
++
++	/* Queue is full! Find the longest slot and
++	   drop a packet from it */
++
++	if (d > 1) {
++		esfq_index x = q->dep[d+q->depth].next;
++		skb = q->qs[x].prev;
++		len = skb->len;
++		__skb_unlink(skb, &q->qs[x]);
++		kfree_skb(skb);
++		esfq_dec(q, x);
++		sch->q.qlen--;
++		sch->qstats.drops++;
++		return len;
++	}
++
++	if (d == 1) {
++		/* It is difficult to believe, but ALL THE SLOTS HAVE LENGTH 1. */
++		d = q->next[q->tail];
++		q->next[q->tail] = q->next[d];
++		q->allot[q->next[d]] += q->quantum;
++		skb = q->qs[d].prev;
++		len = skb->len;
++		__skb_unlink(skb, &q->qs[d]);
++		kfree_skb(skb);
++		esfq_dec(q, d);
++		sch->q.qlen--;
++		q->ht[q->hash[d]] = q->depth;
++		sch->qstats.drops++;
++		return len;
++	}
++
++	return 0;
++}
++
++static int
++esfq_enqueue(struct sk_buff *skb, struct Qdisc* sch)
++{
++	struct esfq_sched_data *q = qdisc_priv(sch);
++	unsigned hash = esfq_hash(q, skb);
++	unsigned depth = q->depth;
++	esfq_index x;
++
++	x = q->ht[hash];
++	if (x == depth) {
++		q->ht[hash] = x = q->dep[depth].next;
++		q->hash[x] = hash;
++	}
++	__skb_queue_tail(&q->qs[x], skb);
++	esfq_inc(q, x);
++	if (q->qs[x].qlen == 1) {		/* The flow is new */
++		if (q->tail == depth) {	/* It is the first flow */
++			q->tail = x;
++			q->next[x] = x;
++			q->allot[x] = q->quantum;
++		} else {
++			q->next[x] = q->next[q->tail];
++			q->next[q->tail] = x;
++			q->tail = x;
++		}
++	}
++	if (++sch->q.qlen < q->limit-1) {
++		sch->bstats.bytes += skb->len;
++		sch->bstats.packets++;
++		return 0;
++	}
++
++	esfq_drop(sch);
++	return NET_XMIT_CN;
++}
++
++static int
++esfq_requeue(struct sk_buff *skb, struct Qdisc* sch)
++{
++	struct esfq_sched_data *q = qdisc_priv(sch);
++	unsigned hash = esfq_hash(q, skb);
++	unsigned depth = q->depth;
++	esfq_index x;
++
++	x = q->ht[hash];
++	if (x == depth) {
++		q->ht[hash] = x = q->dep[depth].next;
++		q->hash[x] = hash;
++	}
++	__skb_queue_head(&q->qs[x], skb);
++	esfq_inc(q, x);
++	if (q->qs[x].qlen == 1) {		/* The flow is new */
++		if (q->tail == depth) {	/* It is the first flow */
++			q->tail = x;
++			q->next[x] = x;
++			q->allot[x] = q->quantum;
++		} else {
++			q->next[x] = q->next[q->tail];
++			q->next[q->tail] = x;
++			q->tail = x;
++		}
++	}
++	if (++sch->q.qlen < q->limit - 1) {
++		sch->qstats.requeues++;
++		return 0;
++	}
++
++	sch->qstats.drops++;
++	esfq_drop(sch);
++	return NET_XMIT_CN;
++}
++
++
++
++
++static struct sk_buff *
++esfq_dequeue(struct Qdisc* sch)
++{
++	struct esfq_sched_data *q = qdisc_priv(sch);
++	struct sk_buff *skb;
++	unsigned depth = q->depth;
++	esfq_index a, old_a;
++
++	/* No active slots */
++	if (q->tail == depth)
++		return NULL;
++	
++	a = old_a = q->next[q->tail];
++	
++	/* Grab packet */
++	skb = __skb_dequeue(&q->qs[a]);
++	esfq_dec(q, a);
++	sch->q.qlen--;
++	
++	/* Is the slot empty? */
++	if (q->qs[a].qlen == 0) {
++		q->ht[q->hash[a]] = depth;
++		a = q->next[a];
++		if (a == old_a) {
++			q->tail = depth;
++			return skb;
++		}
++		q->next[q->tail] = a;
++		q->allot[a] += q->quantum;
++	} else if ((q->allot[a] -= skb->len) <= 0) {
++		q->tail = a;
++		a = q->next[a];
++		q->allot[a] += q->quantum;
++	}
++	
++	return skb;
++}
++
++static void
++esfq_reset(struct Qdisc* sch)
++{
++	struct sk_buff *skb;
++
++	while ((skb = esfq_dequeue(sch)) != NULL)
++		kfree_skb(skb);
++}
++
++static void esfq_perturbation(unsigned long arg)
++{
++	struct Qdisc *sch = (struct Qdisc*)arg;
++	struct esfq_sched_data *q = qdisc_priv(sch);
++
++	q->perturbation = net_random()&0x1F;
++
++	if (q->perturb_period) {
++		q->perturb_timer.expires = jiffies + q->perturb_period;
++		add_timer(&q->perturb_timer);
++	}
++}
++
++static int esfq_change(struct Qdisc *sch, struct rtattr *opt)
++{
++	struct esfq_sched_data *q = qdisc_priv(sch);
++	struct tc_esfq_qopt *ctl = RTA_DATA(opt);
++	int old_perturb = q->perturb_period;
++	
++	if (opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
++		return -EINVAL;
++	
++	sch_tree_lock(sch);
++	q->quantum = ctl->quantum ? : psched_mtu(sch->dev);
++	q->perturb_period = ctl->perturb_period*HZ;
++//	q->hash_divisor = ctl->divisor;
++//	q->tail = q->limit = q->depth = ctl->flows;
++	
++	if (ctl->limit)
++		q->limit = min_t(u32, ctl->limit, q->depth);
++	
++	if (ctl->hash_kind) {
++		q->hash_kind = ctl->hash_kind;
++		if (q->hash_kind !=  TCA_SFQ_HASH_CLASSIC)
++			q->perturb_period = 0;
++	}
++	
++	// is sch_tree_lock enough to do this ?
++	while (sch->q.qlen >= q->limit-1)
++		esfq_drop(sch);
++	
++	if (old_perturb)
++		del_timer(&q->perturb_timer);
++	if (q->perturb_period) {
++		q->perturb_timer.expires = jiffies + q->perturb_period;
++		add_timer(&q->perturb_timer);
++	} else {
++		q->perturbation = 0;
++	}
++	sch_tree_unlock(sch);
++	return 0;
++}
++
++static int esfq_init(struct Qdisc *sch, struct rtattr *opt)
++{
++	struct esfq_sched_data *q = qdisc_priv(sch);
++	struct tc_esfq_qopt *ctl;
++	esfq_index p = ~0UL/2;
++	int i;
++	
++	if (opt && opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
++		return -EINVAL;
++
++	init_timer(&q->perturb_timer);
++	q->perturb_timer.data = (unsigned long)sch;
++	q->perturb_timer.function = esfq_perturbation;
++	q->perturbation = 0;
++	q->hash_kind = TCA_SFQ_HASH_CLASSIC;
++	q->max_depth = 0;
++	q->dyn_min = ~0U; /* maximum value for this type */
++	q->dyn_max = 0;  /* dyn_min/dyn_max will be set properly upon first packet */
++	if (opt == NULL) {
++		q->quantum = psched_mtu(sch->dev);
++		q->perturb_period = 0;
++		q->hash_divisor = 1024;
++		q->tail = q->limit = q->depth = 128;
++		
++	} else {
++		ctl = RTA_DATA(opt);
++		q->quantum = ctl->quantum ? : psched_mtu(sch->dev);
++		q->perturb_period = ctl->perturb_period*HZ;
++		q->hash_divisor = ctl->divisor ? : 1024;
++		q->tail = q->limit = q->depth = ctl->flows ? : 128;
++		
<<Diff was trimmed, longer than 597 lines>>



More information about the pld-cvs-commit mailing list