Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / altq / altq_jobs.h
blob403f517bf49453938f0ab0ff4e22bc217ec7d194
1 /* $NetBSD: altq_jobs.h,v 1.3 2006/10/12 21:13:53 peter Exp $ */
2 /* $KAME: altq_jobs.h,v 1.6 2003/07/10 12:07:48 kjc Exp $ */
3 /*
4 * Copyright (c) 2001, Rector and Visitors of the University of
5 * Virginia.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted provided
10 * that the following conditions are met:
12 * Redistributions of source code must retain the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer.
16 * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
21 * Neither the name of the University of Virginia nor the names
22 * of its contributors may be used to endorse or promote products
23 * derived from this software without specific prior written
24 * permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
27 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
28 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
32 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
38 * THE POSSIBILITY OF SUCH DAMAGE.
40 /*
41 * JoBS - altq prototype implementation
43 * Author: Nicolas Christin <nicolas@cs.virginia.edu>
45 * JoBS algorithms originally devised and proposed by
46 * Nicolas Christin and Jorg Liebeherr.
47 * Grateful Acknowledgments to Tarek Abdelzaher for his help and
48 * comments, and to Kenjiro Cho for some helpful advice.
49 * Contributed by the Multimedia Networks Group at the University
50 * of Virginia.
52 * Papers and additional info can be found at
53 * http://qosbox.cs.virginia.edu
55 */
57 #ifndef _ALTQ_ALTQ_JOBS_H_
58 #define _ALTQ_ALTQ_JOBS_H_
60 #include <altq/altq.h>
61 #include <altq/altq_classq.h>
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
67 #define JOBS_MAXPRI 16 /* upper limit on the number of priorities */
68 #define SCALE_RATE 32
69 #define SCALE_LOSS 32
70 #define SCALE_SHARE 16
71 #define GRANULARITY 1000000 /* microseconds */
72 #ifndef INFINITY
73 #define INFINITY LLONG_MAX
74 #endif
76 /* list of packet arrival times */
77 struct _tsentry;
78 typedef TAILQ_HEAD(_timestamps, _tsentry) TSLIST;
79 typedef struct _tsentry {
80 TAILQ_ENTRY(_tsentry) ts_list;
81 uint64_t timestamp;
82 } TSENTRY;
85 * timestamp list macros
88 #define tslist_first(s) TAILQ_FIRST(s)
89 #define tslist_last(s) TAILQ_LAST(s, _timestamps)
90 #define tslist_empty(s) TAILQ_EMPTY(s)
93 * scaling/conversion macros
94 * none of these macros present side-effects, hence the lowercase
97 #define secs_to_ticks(x) ((x) * machclk_freq)
98 #define ticks_to_secs(x) ((x) / machclk_freq)
99 #define invsecs_to_invticks(x) ticks_to_secs(x)
100 #define invticks_to_invsecs(x) secs_to_ticks(x)
101 #define bits_to_bytes(x) ((x) >> 3)
102 #define bytes_to_bits(x) ((x) << 3)
103 #define scale_rate(x) ((x) << SCALE_RATE)
104 #define unscale_rate(x) ((x) >> SCALE_RATE)
105 #define bps_to_internal(x) (invsecs_to_invticks(bits_to_bytes(scale_rate(x))))
106 #define internal_to_bps(x) (unscale_rate(invticks_to_invsecs(bytes_to_bits(x))))
109 * this macro takes care of possible wraparound
110 * effects in the computation of a delay
111 * no side-effects here either
114 #define delay_diff(x, y) ((x >= y)?(x - y):((ULLONG_MAX-y)+x+1))
117 * additional macros (PKTCNTR_ADD can be found
118 * in the original distribution)
121 #define PKTCNTR_SUB(cntr, len) do { \
122 (cntr)->packets--; \
123 (cntr)->bytes -= len; \
124 } while (/*CONSTCOND*/ 0)
126 #define PKTCNTR_RESET(cntr) do { \
127 (cntr)->packets = 0; \
128 (cntr)->bytes = 0; \
129 } while (/*CONSTCOND*/ 0)
131 struct jobs_interface {
132 char jobs_ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */
133 u_long arg; /* request-specific argument */
135 struct jobs_attach {
136 struct jobs_interface iface;
137 u_int bandwidth; /* link bandwidth in bits/sec */
138 u_int qlimit; /* buffer size in packets */
139 u_int separate; /* separate buffers flag */
142 struct jobs_add_class {
143 struct jobs_interface iface;
144 int pri; /* priority (0 is the lowest) */
145 int flags; /* misc flags (see below) */
148 * Delay Bound (-1 = NO ADC) is provided in us,
149 * and is converted to clock ticks
151 int64_t cl_adc;
154 * Loss Rate Bound (-1 = NO ALC) is provided in fraction of 1
155 * and is converted to a fraction of 2^(SCALE_LOSS)
157 int64_t cl_alc;
160 * lower bound on throughput (-1 = no ARC)
161 * is provided in (string) and
162 * is converted to internal format
164 int64_t cl_arc;
166 /* RDC weight (-1 = NO RDC) - no unit */
167 int64_t cl_rdc;
169 /* RLC weight (-1 = NO RLC) - no unit */
170 int64_t cl_rlc;
172 u_long class_handle; /* return value */
175 /* jobs class flags */
176 #define JOCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
177 #define JOCF_DEFAULTCLASS 0x1000 /* default class */
179 /* special class handles */
180 #define JOBS_NULLCLASS_HANDLE 0
182 struct jobs_delete_class {
183 struct jobs_interface iface;
184 u_long class_handle;
187 struct jobs_modify_class {
188 struct jobs_interface iface;
189 u_long class_handle;
190 int pri;
193 * Delay Bound (-1 = NO ADC) is provided in us,
194 * and is converted to clock ticks
196 int64_t cl_adc;
199 * Loss Rate Bound (-1 = NO ALC) is provided in fraction of 1
200 * and is converted to a fraction of 2^(SCALE_LOSS)
202 int64_t cl_alc;
205 * lower bound on throughput (-1 = no ARC)
206 * is provided in (string) and
207 * is converted to internal format
209 int64_t cl_arc;
211 /* RDC weight (-1 = NO RDC) - no unit */
212 int64_t cl_rdc;
214 /* RLC weight (-1 = NO RLC) - no unit */
215 int64_t cl_rlc;
217 int flags;
220 struct jobs_add_filter {
221 struct jobs_interface iface;
222 u_long class_handle;
223 #ifdef ALTQ3_CLFIER_COMPAT
224 struct flow_filter filter;
225 #endif
226 u_long filter_handle; /* return value */
229 struct jobs_delete_filter {
230 struct jobs_interface iface;
231 u_long filter_handle;
234 struct class_stats {
235 u_int adc_violations;
236 u_int totallength;
237 u_int period;
238 u_int qlength;
240 u_long class_handle;
242 int64_t service_rate; /* bps that should be out */
244 u_int64_t avg_cycles_dequeue;
245 u_int64_t avg_cycles_enqueue;
246 u_int64_t avg_cycles2_dequeue;
247 u_int64_t avg_cycles2_enqueue;
248 u_int64_t avgdel; /* in us */
249 u_int64_t bc_cycles_dequeue;
250 u_int64_t bc_cycles_enqueue;
251 u_int64_t busylength; /* in ms */
252 u_int64_t lastdel; /* in us */
253 u_int64_t total_dequeued;
254 u_int64_t total_enqueued;
255 u_int64_t wc_cycles_dequeue;
256 u_int64_t wc_cycles_enqueue;
258 struct pktcntr arrival; /* rin+dropped */
259 struct pktcntr arrivalbusy;
260 struct pktcntr rin; /* dropped packet counter */
261 struct pktcntr rout; /* transmitted packet counter */
262 struct pktcntr dropcnt; /* dropped packet counter */
265 struct jobs_class_stats {
266 struct class_stats *stats; /* pointer to stats array */
267 int maxpri; /* in/out */
268 struct jobs_interface iface;
271 #define JOBS_IF_ATTACH _IOW('Q', 1, struct jobs_attach)
272 #define JOBS_IF_DETACH _IOW('Q', 2, struct jobs_interface)
273 #define JOBS_ENABLE _IOW('Q', 3, struct jobs_interface)
274 #define JOBS_DISABLE _IOW('Q', 4, struct jobs_interface)
275 #define JOBS_CLEAR _IOW('Q', 6, struct jobs_interface)
276 #define JOBS_ADD_CLASS _IOWR('Q', 7, struct jobs_add_class)
277 #define JOBS_DEL_CLASS _IOW('Q', 8, struct jobs_delete_class)
278 #define JOBS_MOD_CLASS _IOW('Q', 9, struct jobs_modify_class)
279 #define JOBS_ADD_FILTER _IOWR('Q', 10, struct jobs_add_filter)
280 #define JOBS_DEL_FILTER _IOW('Q', 11, struct jobs_delete_filter)
281 #define JOBS_GETSTATS _IOWR('Q', 12, struct jobs_class_stats)
283 #ifdef _KERNEL
285 struct jobs_class {
286 TSLIST *arv_tm; /* list of timestamps */
287 struct jobs_if *cl_jif; /* back pointer to jif */
288 class_queue_t *cl_q; /* class queue structure */
290 int cl_pri; /* priority */
291 int cl_flags; /* class flags */
293 u_long cl_handle; /* class handle */
295 /* control variables */
298 * internal representation:
299 * bytes/unit_time << 32 = (bps /8 << 32)*1/machclk_freq
301 int64_t service_rate; /* bps that should be out */
302 int64_t min_rate_adc; /* bps that should be out for ADC/ARC */
304 u_int64_t current_loss; /* % of packets dropped */
305 u_int64_t cl_lastdel; /* in clock ticks */
306 u_int64_t cl_avgdel;
308 /* statistics */
309 u_int cl_period; /* backlog period */
310 struct pktcntr cl_arrival; /* arrived packet counter */
311 struct pktcntr cl_dropcnt; /* dropped packet counter */
312 struct pktcntr cl_rin; /* let in packet counter */
313 struct pktcntr cl_rout; /* transmitted packet counter */
316 /* modified deficit round-robin specific variables */
319 * rout_th is SCALED for precision, as opposed to rout.
321 int64_t st_service_rate;
322 u_int64_t cl_last_rate_update;
323 struct pktcntr cl_rout_th; /* theoretical transmissions */
324 struct pktcntr st_arrival; /* rin+dropped */
325 struct pktcntr st_rin; /* dropped packet counter */
326 struct pktcntr st_rout; /* transmitted packet counter */
327 struct pktcntr st_dropcnt; /* dropped packet counter */
329 /* service guarantees */
330 u_int adc_violations;
331 int concerned_adc;
332 int concerned_alc;
333 int concerned_arc;
334 int concerned_rdc;
335 int concerned_rlc;
337 * Delay Bound (-1 = NO ADC) is provided in us,
338 * and is converted to clock ticks
340 int64_t cl_adc;
343 * Loss Rate Bound (-1 = NO ALC) is provided in fraction of 1
344 * and is converted to a fraction of 2^(SCALE_LOSS)
346 int64_t cl_alc;
349 * lower bound on throughput (-1 = no ARC)
350 * is provided in (string) and
351 * is converted to internal format
353 int64_t cl_arc;
355 /* RDC weight (-1 = NO RDC) - no unit */
356 int64_t cl_rdc;
358 /* RLC weight (-1 = NO RLC) - no unit */
359 int64_t cl_rlc;
361 u_int64_t delay_prod_others;
362 u_int64_t loss_prod_others;
363 u_int64_t idletime;
367 * jobs interface state
369 struct jobs_if {
370 struct jobs_if *jif_next; /* interface state list */
371 struct ifaltq *jif_ifq; /* backpointer to ifaltq */
372 struct jobs_class *jif_default; /* default class */
373 struct jobs_class *jif_classes[JOBS_MAXPRI]; /* classes */
374 #ifdef ALTQ3_CLFIER_COMPAT
375 struct acc_classifier jif_classifier; /* classifier */
376 #endif
377 int jif_maxpri; /* max priority in use */
379 u_int jif_bandwidth; /* link bandwidth in bps */
380 u_int jif_qlimit; /* buffer size in packets */
381 u_int jif_separate; /* separate buffers or not */
382 u_int64_t avg_cycles_dequeue;
383 u_int64_t avg_cycles_enqueue;
384 u_int64_t avg_cycles2_dequeue;
385 u_int64_t avg_cycles2_enqueue;
386 u_int64_t bc_cycles_dequeue;
387 u_int64_t bc_cycles_enqueue;
388 u_int64_t wc_cycles_dequeue;
389 u_int64_t wc_cycles_enqueue;
390 u_int64_t total_dequeued;
391 u_int64_t total_enqueued;
394 #endif /* _KERNEL */
396 #ifdef __cplusplus
398 #endif
400 #endif /* _ALTQ_ALTQ_JOBS_H_ */