Home | History | Annotate | Line # | Download | only in altq
altq_hfsc.h revision 1.6.4.1
      1  1.6.4.1     yamt /*	$NetBSD: altq_hfsc.h,v 1.6.4.1 2006/12/30 20:45:17 yamt Exp $	*/
      2  1.6.4.1     yamt /*	$KAME: altq_hfsc.h,v 1.12 2003/12/05 05:40:46 kjc Exp $	*/
      3      1.1  thorpej 
      4      1.1  thorpej /*
      5      1.1  thorpej  * Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved.
      6      1.1  thorpej  *
      7      1.1  thorpej  * Permission to use, copy, modify, and distribute this software and
      8      1.1  thorpej  * its documentation is hereby granted (including for commercial or
      9      1.1  thorpej  * for-profit use), provided that both the copyright notice and this
     10      1.1  thorpej  * permission notice appear in all copies of the software, derivative
     11  1.6.4.1     yamt  * works, or modified versions, and any portions thereof.
     12      1.1  thorpej  *
     13      1.1  thorpej  * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF
     14      1.1  thorpej  * WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON PROVIDES THIS
     15      1.1  thorpej  * SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED
     16      1.1  thorpej  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17      1.1  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18      1.1  thorpej  * DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
     19      1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20      1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
     21      1.1  thorpej  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     22      1.1  thorpej  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     23      1.1  thorpej  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24      1.1  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
     25      1.1  thorpej  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
     26      1.1  thorpej  * DAMAGE.
     27      1.1  thorpej  *
     28      1.1  thorpej  * Carnegie Mellon encourages (but does not require) users of this
     29      1.1  thorpej  * software to return any improvements or extensions that they make,
     30      1.1  thorpej  * and to grant Carnegie Mellon the rights to redistribute these
     31      1.1  thorpej  * changes without encumbrance.
     32      1.1  thorpej  */
     33      1.1  thorpej #ifndef _ALTQ_ALTQ_HFSC_H_
     34      1.1  thorpej #define	_ALTQ_ALTQ_HFSC_H_
     35      1.1  thorpej 
     36      1.1  thorpej #include <altq/altq.h>
     37      1.1  thorpej #include <altq/altq_classq.h>
     38      1.1  thorpej #include <altq/altq_red.h>
     39      1.1  thorpej #include <altq/altq_rio.h>
     40      1.1  thorpej 
     41      1.1  thorpej #ifdef __cplusplus
     42      1.1  thorpej extern "C" {
     43      1.6    perry #endif
     44      1.1  thorpej 
     45      1.1  thorpej struct service_curve {
     46      1.1  thorpej 	u_int	m1;	/* slope of the first segment in bits/sec */
     47      1.1  thorpej 	u_int	d;	/* the x-projection of the first segment in msec */
     48      1.1  thorpej 	u_int	m2;	/* slope of the second segment in bits/sec */
     49      1.1  thorpej };
     50      1.1  thorpej 
     51      1.1  thorpej /* special class handles */
     52      1.1  thorpej #define	HFSC_NULLCLASS_HANDLE	0
     53  1.6.4.1     yamt #define	HFSC_MAX_CLASSES	64
     54      1.1  thorpej 
     55      1.1  thorpej /* hfsc class flags */
     56      1.1  thorpej #define	HFCF_RED		0x0001	/* use RED */
     57      1.1  thorpej #define	HFCF_ECN		0x0002  /* use RED/ECN */
     58      1.1  thorpej #define	HFCF_RIO		0x0004  /* use RIO */
     59      1.1  thorpej #define	HFCF_CLEARDSCP		0x0010  /* clear diffserv codepoint */
     60      1.1  thorpej #define	HFCF_DEFAULTCLASS	0x1000	/* default class */
     61      1.1  thorpej 
     62      1.1  thorpej /* service curve types */
     63      1.1  thorpej #define	HFSC_REALTIMESC		1
     64      1.1  thorpej #define	HFSC_LINKSHARINGSC	2
     65  1.6.4.1     yamt #define	HFSC_UPPERLIMITSC	4
     66      1.1  thorpej #define	HFSC_DEFAULTSC		(HFSC_REALTIMESC|HFSC_LINKSHARINGSC)
     67      1.1  thorpej 
     68  1.6.4.1     yamt struct hfsc_classstats {
     69      1.1  thorpej 	u_int			class_id;
     70  1.6.4.1     yamt 	u_int32_t		class_handle;
     71      1.1  thorpej 	struct service_curve	rsc;
     72      1.1  thorpej 	struct service_curve	fsc;
     73  1.6.4.1     yamt 	struct service_curve	usc;	/* upper limit service curve */
     74      1.1  thorpej 
     75      1.1  thorpej 	u_int64_t		total;	/* total work in bytes */
     76      1.1  thorpej 	u_int64_t		cumul;	/* cumulative work in bytes
     77      1.1  thorpej 					   done by real-time criteria */
     78      1.1  thorpej 	u_int64_t		d;		/* deadline */
     79      1.1  thorpej 	u_int64_t		e;		/* eligible time */
     80      1.1  thorpej 	u_int64_t		vt;		/* virtual time */
     81  1.6.4.1     yamt 	u_int64_t		f;		/* fit time for upper-limit */
     82  1.6.4.1     yamt 
     83  1.6.4.1     yamt 	/* info helpful for debugging */
     84  1.6.4.1     yamt 	u_int64_t		initvt;		/* init virtual time */
     85  1.6.4.1     yamt 	u_int64_t		vtoff;		/* cl_vt_ipoff */
     86  1.6.4.1     yamt 	u_int64_t		cvtmax;		/* cl_maxvt */
     87  1.6.4.1     yamt 	u_int64_t		myf;		/* cl_myf */
     88  1.6.4.1     yamt 	u_int64_t		cfmin;		/* cl_mincf */
     89  1.6.4.1     yamt 	u_int64_t		cvtmin;		/* cl_mincvt */
     90  1.6.4.1     yamt 	u_int64_t		myfadj;		/* cl_myfadj */
     91  1.6.4.1     yamt 	u_int64_t		vtadj;		/* cl_vtadj */
     92  1.6.4.1     yamt 	u_int64_t		cur_time;
     93  1.6.4.1     yamt 	u_int32_t		machclk_freq;
     94      1.1  thorpej 
     95      1.1  thorpej 	u_int			qlength;
     96  1.6.4.1     yamt 	u_int			qlimit;
     97      1.1  thorpej 	struct pktcntr		xmit_cnt;
     98      1.1  thorpej 	struct pktcntr		drop_cnt;
     99  1.6.4.1     yamt 	u_int			period;
    100  1.6.4.1     yamt 
    101  1.6.4.1     yamt 	u_int			vtperiod;	/* vt period sequence no */
    102  1.6.4.1     yamt 	u_int			parentperiod;	/* parent's vt period seqno */
    103  1.6.4.1     yamt 	int			nactive;	/* number of active children */
    104      1.1  thorpej 
    105      1.1  thorpej 	/* red and rio related info */
    106  1.6.4.1     yamt 	int			qtype;
    107  1.6.4.1     yamt 	struct redstats		red[3];
    108  1.6.4.1     yamt };
    109  1.6.4.1     yamt 
    110  1.6.4.1     yamt #ifdef ALTQ3_COMPAT
    111  1.6.4.1     yamt struct hfsc_interface {
    112  1.6.4.1     yamt 	char	hfsc_ifname[IFNAMSIZ];  /* interface name (e.g., fxp0) */
    113  1.6.4.1     yamt };
    114  1.6.4.1     yamt 
    115  1.6.4.1     yamt struct hfsc_attach {
    116  1.6.4.1     yamt 	struct hfsc_interface	iface;
    117  1.6.4.1     yamt 	u_int			bandwidth;  /* link bandwidth in bits/sec */
    118  1.6.4.1     yamt };
    119  1.6.4.1     yamt 
    120  1.6.4.1     yamt struct hfsc_add_class {
    121  1.6.4.1     yamt 	struct hfsc_interface	iface;
    122  1.6.4.1     yamt 	u_int32_t		parent_handle;
    123  1.6.4.1     yamt 	struct service_curve	service_curve;
    124  1.6.4.1     yamt 	int			qlimit;
    125  1.6.4.1     yamt 	int			flags;
    126  1.6.4.1     yamt 
    127  1.6.4.1     yamt 	u_int32_t		class_handle;  /* return value */
    128  1.6.4.1     yamt };
    129  1.6.4.1     yamt 
    130  1.6.4.1     yamt struct hfsc_delete_class {
    131  1.6.4.1     yamt 	struct hfsc_interface	iface;
    132  1.6.4.1     yamt 	u_int32_t		class_handle;
    133  1.6.4.1     yamt };
    134  1.6.4.1     yamt 
    135  1.6.4.1     yamt struct hfsc_modify_class {
    136  1.6.4.1     yamt 	struct hfsc_interface	iface;
    137  1.6.4.1     yamt 	u_int32_t		class_handle;
    138  1.6.4.1     yamt 	struct service_curve	service_curve;
    139  1.6.4.1     yamt 	int			sctype;
    140  1.6.4.1     yamt };
    141  1.6.4.1     yamt 
    142  1.6.4.1     yamt struct hfsc_add_filter {
    143  1.6.4.1     yamt 	struct hfsc_interface	iface;
    144  1.6.4.1     yamt 	u_int32_t		class_handle;
    145  1.6.4.1     yamt 	struct flow_filter	filter;
    146  1.6.4.1     yamt 
    147  1.6.4.1     yamt 	u_long			filter_handle;  /* return value */
    148  1.6.4.1     yamt };
    149  1.6.4.1     yamt 
    150  1.6.4.1     yamt struct hfsc_delete_filter {
    151  1.6.4.1     yamt 	struct hfsc_interface	iface;
    152  1.6.4.1     yamt 	u_long			filter_handle;
    153      1.1  thorpej };
    154      1.1  thorpej 
    155      1.1  thorpej struct hfsc_class_stats {
    156      1.1  thorpej 	struct hfsc_interface	iface;
    157      1.1  thorpej 	int			nskip;		/* skip # of classes */
    158      1.1  thorpej 	int			nclasses;	/* # of class stats (WR) */
    159      1.1  thorpej 	u_int64_t		cur_time;	/* current time */
    160  1.6.4.1     yamt 	u_int32_t		machclk_freq;	/* machine clock frequency */
    161      1.1  thorpej 	u_int			hif_classes;	/* # of classes in the tree */
    162      1.1  thorpej 	u_int			hif_packets;	/* # of packets in the tree */
    163  1.6.4.1     yamt 	struct hfsc_classstats	*stats;		/* pointer to stats array */
    164      1.1  thorpej };
    165      1.1  thorpej 
    166      1.1  thorpej #define	HFSC_IF_ATTACH		_IOW('Q', 1, struct hfsc_attach)
    167      1.1  thorpej #define	HFSC_IF_DETACH		_IOW('Q', 2, struct hfsc_interface)
    168      1.1  thorpej #define	HFSC_ENABLE		_IOW('Q', 3, struct hfsc_interface)
    169      1.1  thorpej #define	HFSC_DISABLE		_IOW('Q', 4, struct hfsc_interface)
    170      1.1  thorpej #define	HFSC_CLEAR_HIERARCHY	_IOW('Q', 5, struct hfsc_interface)
    171      1.1  thorpej #define	HFSC_ADD_CLASS		_IOWR('Q', 7, struct hfsc_add_class)
    172      1.1  thorpej #define	HFSC_DEL_CLASS		_IOW('Q', 8, struct hfsc_delete_class)
    173      1.1  thorpej #define	HFSC_MOD_CLASS		_IOW('Q', 9, struct hfsc_modify_class)
    174      1.1  thorpej #define	HFSC_ADD_FILTER		_IOWR('Q', 10, struct hfsc_add_filter)
    175      1.1  thorpej #define	HFSC_DEL_FILTER		_IOW('Q', 11, struct hfsc_delete_filter)
    176      1.1  thorpej #define	HFSC_GETSTATS		_IOWR('Q', 12, struct hfsc_class_stats)
    177  1.6.4.1     yamt #endif /* ALTQ3_COMPAT */
    178      1.1  thorpej 
    179      1.1  thorpej #ifdef _KERNEL
    180      1.1  thorpej /*
    181      1.1  thorpej  * kernel internal service curve representation
    182      1.1  thorpej  *	coordinates are given by 64 bit unsigned integers.
    183      1.1  thorpej  *	x-axis: unit is clock count.  for the intel x86 architecture,
    184      1.1  thorpej  *		the raw Pentium TSC (Timestamp Counter) value is used.
    185      1.1  thorpej  *		virtual time is also calculated in this time scale.
    186      1.1  thorpej  *	y-axis: unit is byte.
    187      1.1  thorpej  *
    188      1.1  thorpej  *	the service curve parameters are converted to the internal
    189      1.1  thorpej  *	representation.
    190      1.1  thorpej  *	the slope values are scaled to avoid overflow.
    191      1.1  thorpej  *	the inverse slope values as well as the y-projection of the 1st
    192      1.1  thorpej  *	segment are kept in order to to avoid 64-bit divide operations
    193      1.1  thorpej  *	that are expensive on 32-bit architectures.
    194      1.1  thorpej  *
    195      1.1  thorpej  *  note: Intel Pentium TSC never wraps around in several thousands of years.
    196      1.1  thorpej  *	x-axis doesn't wrap around for 1089 years with 1GHz clock.
    197      1.1  thorpej  *      y-axis doesn't wrap around for 4358 years with 1Gbps bandwidth.
    198      1.1  thorpej  */
    199      1.1  thorpej 
    200      1.1  thorpej /* kernel internal representation of a service curve */
    201      1.1  thorpej struct internal_sc {
    202      1.1  thorpej 	u_int64_t	sm1;	/* scaled slope of the 1st segment */
    203      1.1  thorpej 	u_int64_t	ism1;	/* scaled inverse-slope of the 1st segment */
    204      1.1  thorpej 	u_int64_t	dx;	/* the x-projection of the 1st segment */
    205      1.1  thorpej 	u_int64_t	dy;	/* the y-projection of the 1st segment */
    206      1.1  thorpej 	u_int64_t	sm2;	/* scaled slope of the 2nd segment */
    207      1.1  thorpej 	u_int64_t	ism2;	/* scaled inverse-slope of the 2nd segment */
    208      1.1  thorpej };
    209      1.1  thorpej 
    210      1.1  thorpej /* runtime service curve */
    211      1.1  thorpej struct runtime_sc {
    212      1.1  thorpej 	u_int64_t	x;	/* current starting position on x-axis */
    213      1.1  thorpej 	u_int64_t	y;	/* current starting position on x-axis */
    214      1.1  thorpej 	u_int64_t	sm1;	/* scaled slope of the 1st segment */
    215      1.1  thorpej 	u_int64_t	ism1;	/* scaled inverse-slope of the 1st segment */
    216      1.1  thorpej 	u_int64_t	dx;	/* the x-projection of the 1st segment */
    217      1.1  thorpej 	u_int64_t	dy;	/* the y-projection of the 1st segment */
    218      1.1  thorpej 	u_int64_t	sm2;	/* scaled slope of the 2nd segment */
    219      1.1  thorpej 	u_int64_t	ism2;	/* scaled inverse-slope of the 2nd segment */
    220      1.1  thorpej };
    221      1.1  thorpej 
    222      1.1  thorpej /* for TAILQ based ellist and actlist implementation */
    223      1.1  thorpej struct hfsc_class;
    224      1.1  thorpej typedef TAILQ_HEAD(_eligible, hfsc_class) ellist_t;
    225      1.1  thorpej typedef TAILQ_ENTRY(hfsc_class) elentry_t;
    226      1.1  thorpej typedef TAILQ_HEAD(_active, hfsc_class) actlist_t;
    227      1.1  thorpej typedef TAILQ_ENTRY(hfsc_class) actentry_t;
    228      1.1  thorpej #define	ellist_first(s)		TAILQ_FIRST(s)
    229      1.1  thorpej #define	actlist_first(s)	TAILQ_FIRST(s)
    230      1.1  thorpej #define	actlist_last(s)		TAILQ_LAST(s, _active)
    231      1.1  thorpej 
    232      1.1  thorpej struct hfsc_class {
    233      1.1  thorpej 	u_int		cl_id;		/* class id (just for debug) */
    234  1.6.4.1     yamt 	u_int32_t	cl_handle;	/* class handle */
    235      1.1  thorpej 	struct hfsc_if	*cl_hif;	/* back pointer to struct hfsc_if */
    236      1.1  thorpej 	int		cl_flags;	/* misc flags */
    237      1.1  thorpej 
    238      1.1  thorpej 	struct hfsc_class *cl_parent;	/* parent class */
    239      1.1  thorpej 	struct hfsc_class *cl_siblings;	/* sibling classes */
    240      1.1  thorpej 	struct hfsc_class *cl_children;	/* child classes */
    241      1.1  thorpej 
    242      1.1  thorpej 	class_queue_t	*cl_q;		/* class queue structure */
    243      1.1  thorpej 	struct red	*cl_red;	/* RED state */
    244      1.1  thorpej 	struct altq_pktattr *cl_pktattr; /* saved header used by ECN */
    245      1.1  thorpej 
    246      1.1  thorpej 	u_int64_t	cl_total;	/* total work in bytes */
    247      1.1  thorpej 	u_int64_t	cl_cumul;	/* cumulative work in bytes
    248      1.1  thorpej 					   done by real-time criteria */
    249      1.1  thorpej 	u_int64_t	cl_d;		/* deadline */
    250      1.1  thorpej 	u_int64_t	cl_e;		/* eligible time */
    251      1.1  thorpej 	u_int64_t	cl_vt;		/* virtual time */
    252  1.6.4.1     yamt 	u_int64_t	cl_f;		/* time when this class will fit for
    253  1.6.4.1     yamt 					   link-sharing, max(myf, cfmin) */
    254  1.6.4.1     yamt 	u_int64_t	cl_myf;		/* my fit-time (as calculated from this
    255  1.6.4.1     yamt 					   class's own upperlimit curve) */
    256  1.6.4.1     yamt 	u_int64_t	cl_myfadj;	/* my fit-time adjustment
    257  1.6.4.1     yamt 					   (to cancel history dependence) */
    258  1.6.4.1     yamt 	u_int64_t	cl_cfmin;	/* earliest children's fit-time (used
    259  1.6.4.1     yamt 					   with cl_myf to obtain cl_f) */
    260  1.6.4.1     yamt 	u_int64_t	cl_cvtmin;	/* minimal virtual time among the
    261  1.6.4.1     yamt 					   children fit for link-sharing
    262  1.6.4.1     yamt 					   (monotonic within a period) */
    263  1.6.4.1     yamt 	u_int64_t	cl_vtadj;	/* intra-period cumulative vt
    264  1.6.4.1     yamt 					   adjustment */
    265  1.6.4.1     yamt 	u_int64_t	cl_vtoff;	/* inter-period cumulative vt offset */
    266  1.6.4.1     yamt 	u_int64_t	cl_cvtmax;	/* max child's vt in the last period */
    267  1.6.4.1     yamt 
    268  1.6.4.1     yamt 	u_int64_t	cl_initvt;	/* init virtual time (for debugging) */
    269      1.1  thorpej 
    270      1.1  thorpej 	struct internal_sc *cl_rsc;	/* internal real-time service curve */
    271      1.1  thorpej 	struct internal_sc *cl_fsc;	/* internal fair service curve */
    272  1.6.4.1     yamt 	struct internal_sc *cl_usc;	/* internal upperlimit service curve */
    273      1.1  thorpej 	struct runtime_sc  cl_deadline;	/* deadline curve */
    274      1.1  thorpej 	struct runtime_sc  cl_eligible;	/* eligible curve */
    275      1.1  thorpej 	struct runtime_sc  cl_virtual;	/* virtual curve */
    276  1.6.4.1     yamt 	struct runtime_sc  cl_ulimit;	/* upperlimit curve */
    277      1.1  thorpej 
    278      1.1  thorpej 	u_int		cl_vtperiod;	/* vt period sequence no */
    279      1.1  thorpej 	u_int		cl_parentperiod;  /* parent's vt period seqno */
    280      1.1  thorpej 	int		cl_nactive;	/* number of active children */
    281      1.1  thorpej 	actlist_t	*cl_actc;	/* active children list */
    282      1.1  thorpej 
    283      1.1  thorpej 	actentry_t	cl_actlist;	/* active children list entry */
    284      1.1  thorpej 	elentry_t	cl_ellist;	/* eligible list entry */
    285      1.1  thorpej 
    286      1.1  thorpej 	struct {
    287      1.1  thorpej 		struct pktcntr	xmit_cnt;
    288      1.1  thorpej 		struct pktcntr	drop_cnt;
    289      1.1  thorpej 		u_int period;
    290      1.1  thorpej 	} cl_stats;
    291      1.1  thorpej };
    292      1.1  thorpej 
    293      1.1  thorpej /*
    294      1.1  thorpej  * hfsc interface state
    295      1.1  thorpej  */
    296      1.1  thorpej struct hfsc_if {
    297      1.1  thorpej 	struct hfsc_if		*hif_next;	/* interface state list */
    298      1.1  thorpej 	struct ifaltq		*hif_ifq;	/* backpointer to ifaltq */
    299      1.1  thorpej 	struct hfsc_class	*hif_rootclass;		/* root class */
    300      1.1  thorpej 	struct hfsc_class	*hif_defaultclass;	/* default class */
    301  1.6.4.1     yamt 	struct hfsc_class	*hif_class_tbl[HFSC_MAX_CLASSES];
    302      1.1  thorpej 	struct hfsc_class	*hif_pollcache;	/* cache for poll operation */
    303      1.1  thorpej 
    304      1.1  thorpej 	u_int	hif_classes;			/* # of classes in the tree */
    305      1.1  thorpej 	u_int	hif_packets;			/* # of packets in the tree */
    306      1.1  thorpej 	u_int	hif_classid;			/* class id sequence number */
    307      1.6    perry 
    308      1.1  thorpej 	ellist_t *hif_eligible;			/* eligible list */
    309      1.1  thorpej 
    310  1.6.4.1     yamt #ifdef ALTQ3_CLFIER_COMPAT
    311      1.1  thorpej 	struct acc_classifier	hif_classifier;
    312  1.6.4.1     yamt #endif
    313      1.1  thorpej };
    314      1.1  thorpej 
    315      1.1  thorpej #endif /* _KERNEL */
    316      1.1  thorpej 
    317      1.1  thorpej #ifdef __cplusplus
    318      1.1  thorpej }
    319      1.6    perry #endif
    320      1.1  thorpej 
    321      1.1  thorpej #endif /* _ALTQ_ALTQ_HFSC_H_ */
    322