xref: /openbsd/sys/net/hfsc.h (revision 74d689df)
1 /*	$OpenBSD: hfsc.h,v 1.13 2017/05/02 12:27:37 mikeb Exp $	*/
2 
3 /*
4  * Copyright (c) 2012-2013 Henning Brauer <henning@openbsd.org>
5  * Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved.
6  *
7  * Permission to use, copy, modify, and distribute this software and
8  * its documentation is hereby granted (including for commercial or
9  * for-profit use), provided that both the copyright notice and this
10  * permission notice appear in all copies of the software, derivative
11  * works, or modified versions, and any portions thereof.
12  *
13  * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF
14  * WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON PROVIDES THIS
15  * SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED
16  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26  * DAMAGE.
27  *
28  * Carnegie Mellon encourages (but does not require) users of this
29  * software to return any improvements or extensions that they make,
30  * and to grant Carnegie Mellon the rights to redistribute these
31  * changes without encumbrance.
32  */
33 #ifndef _HFSC_H_
34 #define	_HFSC_H_
35 
36 /* hfsc class flags */
37 #define	HFSC_DEFAULTCLASS	0x1000	/* default class */
38 
39 struct hfsc_pktcntr {
40 	u_int64_t	packets;
41 	u_int64_t	bytes;
42 };
43 
44 #define	PKTCNTR_INC(cntr, len)	\
45 	do { (cntr)->packets++; (cntr)->bytes += len; } while (0)
46 
47 struct hfsc_sc {
48 	u_int	m1;	/* slope of the first segment in bits/sec */
49 	u_int	d;	/* the x-projection of the first segment in msec */
50 	u_int	m2;	/* slope of the second segment in bits/sec */
51 };
52 
53 /* special class handles */
54 #define	HFSC_ROOT_CLASS		0x10000
55 #define	HFSC_DEFAULT_CLASSES	64
56 #define	HFSC_MAX_CLASSES	65535
57 
58 /* service curve types */
59 #define	HFSC_REALTIMESC		1
60 #define	HFSC_LINKSHARINGSC	2
61 #define	HFSC_UPPERLIMITSC	4
62 #define	HFSC_DEFAULTSC		(HFSC_REALTIMESC|HFSC_LINKSHARINGSC)
63 
64 struct hfsc_class_stats {
65 	struct hfsc_pktcntr	xmit_cnt;
66 	struct hfsc_pktcntr	drop_cnt;
67 
68 	u_int			qlength;
69 	u_int			qlimit;
70 	u_int			period;
71 
72 	u_int			class_id;
73 	u_int32_t		class_handle;
74 	struct hfsc_sc		rsc;
75 	struct hfsc_sc		fsc;
76 	struct hfsc_sc		usc;	/* upper limit service curve */
77 
78 	u_int64_t		total;	/* total work in bytes */
79 	u_int64_t		cumul;	/* cumulative work in bytes
80 					   done by real-time criteria */
81 	u_int64_t		d;		/* deadline */
82 	u_int64_t		e;		/* eligible time */
83 	u_int64_t		vt;		/* virtual time */
84 	u_int64_t		f;		/* fit time for upper-limit */
85 
86 	/* info helpful for debugging */
87 	u_int64_t		initvt;		/* init virtual time */
88 	u_int64_t		vtoff;		/* cl_vt_ipoff */
89 	u_int64_t		cvtmax;		/* cl_maxvt */
90 	u_int64_t		myf;		/* cl_myf */
91 	u_int64_t		cfmin;		/* cl_mincf */
92 	u_int64_t		cvtmin;		/* cl_mincvt */
93 	u_int64_t		myfadj;		/* cl_myfadj */
94 	u_int64_t		vtadj;		/* cl_vtadj */
95 	u_int64_t		cur_time;
96 	u_int32_t		machclk_freq;
97 
98 	u_int			vtperiod;	/* vt period sequence no */
99 	u_int			parentperiod;	/* parent's vt period seqno */
100 	int			nactive;	/* number of active children */
101 
102 	/* red and rio related info */
103 	int			qtype;
104 /*	struct redstats		red[3]; */
105 };
106 
107 #ifdef _KERNEL
108 struct ifnet;
109 struct ifqueue;
110 struct pf_queuespec;
111 struct hfsc_if;
112 
113 extern const struct ifq_ops * const ifq_hfsc_ops;
114 extern const struct pfq_ops * const pfq_hfsc_ops;
115 
116 #define	HFSC_ENABLED(ifq)	((ifq)->ifq_ops == ifq_hfsc_ops)
117 #define	HFSC_DEFAULT_QLIMIT	50
118 
119 void		 hfsc_initialize(void);
120 u_int64_t	 hfsc_microuptime(void);
121 
122 #endif /* _KERNEL */
123 #endif /* _HFSC_H_ */
124