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