/*-1* Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved.2*3* Permission to use, copy, modify, and distribute this software and4* its documentation is hereby granted (including for commercial or5* for-profit use), provided that both the copyright notice and this6* permission notice appear in all copies of the software, derivative7* works, or modified versions, and any portions thereof.8*9* THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF10* WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS11* SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED12* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES13* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE14* DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE15* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR16* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT17* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR18* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF19* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT20* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE21* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH22* DAMAGE.23*24* Carnegie Mellon encourages (but does not require) users of this25* software to return any improvements or extensions that they make,26* and to grant Carnegie Mellon the rights to redistribute these27* changes without encumbrance.28*29* $KAME: altq_hfsc.h,v 1.12 2003/12/05 05:40:46 kjc Exp $30*/31#ifndef _ALTQ_ALTQ_HFSC_H_32#define _ALTQ_ALTQ_HFSC_H_3334#include <net/altq/altq.h>35#include <net/altq/altq_classq.h>36#include <net/altq/altq_codel.h>37#include <net/altq/altq_red.h>38#include <net/altq/altq_rio.h>3940#ifdef __cplusplus41extern "C" {42#endif4344struct service_curve_v0 {45u_int m1; /* slope of the first segment in bits/sec */46u_int d; /* the x-projection of the first segment in msec */47u_int m2; /* slope of the second segment in bits/sec */48};4950struct service_curve_v1 {51u_int64_t m1; /* slope of the first segment in bits/sec */52u_int d; /* the x-projection of the first segment in msec */53u_int64_t m2; /* slope of the second segment in bits/sec */54};5556/* Latest version of struct service_curve_vX */57#define HFSC_SERVICE_CURVE_VERSION 15859/* special class handles */60#define HFSC_NULLCLASS_HANDLE 061#define HFSC_MAX_CLASSES 20486263/* hfsc class flags */64#define HFCF_RED 0x0001 /* use RED */65#define HFCF_ECN 0x0002 /* use RED/ECN */66#define HFCF_RIO 0x0004 /* use RIO */67#define HFCF_CODEL 0x0008 /* use CoDel */68#define HFCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */69#define HFCF_DEFAULTCLASS 0x1000 /* default class */7071/* service curve types */72#define HFSC_REALTIMESC 173#define HFSC_LINKSHARINGSC 274#define HFSC_UPPERLIMITSC 475#define HFSC_DEFAULTSC (HFSC_REALTIMESC|HFSC_LINKSHARINGSC)7677struct hfsc_classstats_v0 {78u_int class_id;79u_int32_t class_handle;80struct service_curve_v0 rsc;81struct service_curve_v0 fsc;82struct service_curve_v0 usc; /* upper limit service curve */8384u_int64_t total; /* total work in bytes */85u_int64_t cumul; /* cumulative work in bytes86done by real-time criteria */87u_int64_t d; /* deadline */88u_int64_t e; /* eligible time */89u_int64_t vt; /* virtual time */90u_int64_t f; /* fit time for upper-limit */9192/* info helpful for debugging */93u_int64_t initvt; /* init virtual time */94u_int64_t vtoff; /* cl_vt_ipoff */95u_int64_t cvtmax; /* cl_maxvt */96u_int64_t myf; /* cl_myf */97u_int64_t cfmin; /* cl_mincf */98u_int64_t cvtmin; /* cl_mincvt */99u_int64_t myfadj; /* cl_myfadj */100u_int64_t vtadj; /* cl_vtadj */101u_int64_t cur_time;102u_int32_t machclk_freq;103104u_int qlength;105u_int qlimit;106struct pktcntr xmit_cnt;107struct pktcntr drop_cnt;108u_int period;109110u_int vtperiod; /* vt period sequence no */111u_int parentperiod; /* parent's vt period seqno */112int nactive; /* number of active children */113114/* codel, red and rio related info */115int qtype;116struct redstats red[3];117struct codel_stats codel;118};119120struct hfsc_classstats_v1 {121u_int class_id;122u_int32_t class_handle;123struct service_curve_v1 rsc;124struct service_curve_v1 fsc;125struct service_curve_v1 usc; /* upper limit service curve */126127u_int64_t total; /* total work in bytes */128u_int64_t cumul; /* cumulative work in bytes129done by real-time criteria */130u_int64_t d; /* deadline */131u_int64_t e; /* eligible time */132u_int64_t vt; /* virtual time */133u_int64_t f; /* fit time for upper-limit */134135/* info helpful for debugging */136u_int64_t initvt; /* init virtual time */137u_int64_t vtoff; /* cl_vt_ipoff */138u_int64_t cvtmax; /* cl_maxvt */139u_int64_t myf; /* cl_myf */140u_int64_t cfmin; /* cl_mincf */141u_int64_t cvtmin; /* cl_mincvt */142u_int64_t myfadj; /* cl_myfadj */143u_int64_t vtadj; /* cl_vtadj */144u_int64_t cur_time;145u_int32_t machclk_freq;146147u_int qlength;148u_int qlimit;149struct pktcntr xmit_cnt;150struct pktcntr drop_cnt;151u_int period;152153u_int vtperiod; /* vt period sequence no */154u_int parentperiod; /* parent's vt period seqno */155int nactive; /* number of active children */156157/* codel, red and rio related info */158int qtype;159struct redstats red[3];160struct codel_stats codel;161};162163/*164* HFSC_STATS_VERSION is defined in altq.h to work around issues stemming165* from mixing of public-API and internal bits in each scheduler-specific166* header.167*/168169#ifdef _KERNEL170/*171* kernel internal service curve representation172* coordinates are given by 64 bit unsigned integers.173* x-axis: unit is clock count. for the intel x86 architecture,174* the raw Pentium TSC (Timestamp Counter) value is used.175* virtual time is also calculated in this time scale.176* y-axis: unit is byte.177*178* the service curve parameters are converted to the internal179* representation.180* the slope values are scaled to avoid overflow.181* the inverse slope values as well as the y-projection of the 1st182* segment are kept in order to avoid 64-bit divide operations183* that are expensive on 32-bit architectures.184*185* note: Intel Pentium TSC never wraps around in several thousands of years.186* x-axis doesn't wrap around for 1089 years with 1GHz clock.187* y-axis doesn't wrap around for 4358 years with 1Gbps bandwidth.188*/189190/* kernel internal representation of a service curve */191struct internal_sc {192u_int64_t sm1; /* scaled slope of the 1st segment */193u_int64_t ism1; /* scaled inverse-slope of the 1st segment */194u_int64_t dx; /* the x-projection of the 1st segment */195u_int64_t dy; /* the y-projection of the 1st segment */196u_int64_t sm2; /* scaled slope of the 2nd segment */197u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */198};199200/* runtime service curve */201struct runtime_sc {202u_int64_t x; /* current starting position on x-axis */203u_int64_t y; /* current starting position on x-axis */204u_int64_t sm1; /* scaled slope of the 1st segment */205u_int64_t ism1; /* scaled inverse-slope of the 1st segment */206u_int64_t dx; /* the x-projection of the 1st segment */207u_int64_t dy; /* the y-projection of the 1st segment */208u_int64_t sm2; /* scaled slope of the 2nd segment */209u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */210};211212struct hfsc_class {213u_int cl_id; /* class id (just for debug) */214u_int cl_slot; /* slot in hif class table */215u_int32_t cl_handle; /* class handle */216struct hfsc_if *cl_hif; /* back pointer to struct hfsc_if */217int cl_flags; /* misc flags */218219struct hfsc_class *cl_parent; /* parent class */220struct hfsc_class *cl_siblings; /* sibling classes */221struct hfsc_class *cl_children; /* child classes */222223class_queue_t *cl_q; /* class queue structure */224union {225struct red *cl_red; /* RED state */226struct codel *cl_codel; /* CoDel state */227} cl_aqm;228#define cl_red cl_aqm.cl_red229#define cl_codel cl_aqm.cl_codel230struct altq_pktattr *cl_pktattr; /* saved header used by ECN */231232u_int64_t cl_total; /* total work in bytes */233u_int64_t cl_cumul; /* cumulative work in bytes234done by real-time criteria */235u_int64_t cl_d; /* deadline */236u_int64_t cl_e; /* eligible time */237u_int64_t cl_vt; /* virtual time */238u_int64_t cl_f; /* time when this class will fit for239link-sharing, max(myf, cfmin) */240u_int64_t cl_myf; /* my fit-time (as calculated from this241class's own upperlimit curve) */242u_int64_t cl_myfadj; /* my fit-time adjustment243(to cancel history dependence) */244u_int64_t cl_cfmin; /* earliest children's fit-time (used245with cl_myf to obtain cl_f) */246u_int64_t cl_cvtmin; /* minimal virtual time among the247children fit for link-sharing248(monotonic within a period) */249u_int64_t cl_vtadj; /* intra-period cumulative vt250adjustment */251u_int64_t cl_vtoff; /* inter-period cumulative vt offset */252u_int64_t cl_cvtmax; /* max child's vt in the last period */253254u_int64_t cl_initvt; /* init virtual time (for debugging) */255256struct internal_sc *cl_rsc; /* internal real-time service curve */257struct internal_sc *cl_fsc; /* internal fair service curve */258struct internal_sc *cl_usc; /* internal upperlimit service curve */259struct runtime_sc cl_deadline; /* deadline curve */260struct runtime_sc cl_eligible; /* eligible curve */261struct runtime_sc cl_virtual; /* virtual curve */262struct runtime_sc cl_ulimit; /* upperlimit curve */263264u_int cl_vtperiod; /* vt period sequence no */265u_int cl_parentperiod; /* parent's vt period seqno */266int cl_nactive; /* number of active children */267268TAILQ_HEAD(acthead, hfsc_class) cl_actc; /* active children list */269TAILQ_ENTRY(hfsc_class) cl_actlist; /* active children list entry */270TAILQ_ENTRY(hfsc_class) cl_ellist; /* eligible list entry */271272struct {273struct pktcntr xmit_cnt;274struct pktcntr drop_cnt;275u_int period;276} cl_stats;277};278279/*280* hfsc interface state281*/282struct hfsc_if {283struct hfsc_if *hif_next; /* interface state list */284struct ifaltq *hif_ifq; /* backpointer to ifaltq */285struct hfsc_class *hif_rootclass; /* root class */286struct hfsc_class *hif_defaultclass; /* default class */287struct hfsc_class *hif_class_tbl[HFSC_MAX_CLASSES];288struct hfsc_class *hif_pollcache; /* cache for poll operation */289290u_int hif_classes; /* # of classes in the tree */291u_int hif_packets; /* # of packets in the tree */292u_int hif_classid; /* class id sequence number */293294TAILQ_HEAD(elighead, hfsc_class) hif_eligible; /* eligible list */295296#ifdef ALTQ3_CLFIER_COMPAT297struct acc_classifier hif_classifier;298#endif299};300301/*302* Kernel code always wants the latest version - avoid a bunch of renames in303* the code to the current latest versioned name.304*/305#define service_curve __CONCAT(service_curve_v, HFSC_SERVICE_CURVE_VERSION)306307#else /* _KERNEL */308309#ifdef PFIOC_USE_LATEST310/*311* Maintaining in-tree consumers of the ioctl interface is easier when that312* code can be written in terms old names that refer to the latest interface313* version as that reduces the required changes in the consumers to those314* that are functionally necessary to accommodate a new interface version.315*/316#define hfsc_classstats __CONCAT(hfsc_classstats_v, HFSC_STATS_VERSION)317#define service_curve __CONCAT(service_curve_v, HFSC_SERVICE_CURVE_VERSION)318319#else320/*321* When building out-of-tree code that is written for the old interface,322* such as may exist in ports for example, resolve the old struct tags to323* the v0 versions.324*/325#define hfsc_classstats __CONCAT(hfsc_classstats_v, 0)326#define service_curve __CONCAT(service_curve_v, 0)327328#endif /* PFIOC_USE_LATEST */329330#endif /* _KERNEL */331332#ifdef __cplusplus333}334#endif335336#endif /* _ALTQ_ALTQ_HFSC_H_ */337338339