FreeBSD/Linux Kernel Cross Reference
sys/altq/altq_jobs.h
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.
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted provided
10 * that the following conditions are met:
11 *
12 * Redistributions of source code must retain the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer.
15 *
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.
20 *
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.
25 *
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.
39 */
40 /*
41 * JoBS - altq prototype implementation
42 *
43 * Author: Nicolas Christin <nicolas@cs.virginia.edu>
44 *
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.
51 *
52 * Papers and additional info can be found at
53 * http://qosbox.cs.virginia.edu
54 *
55 */
56
57 #ifndef _ALTQ_ALTQ_JOBS_H_
58 #define _ALTQ_ALTQ_JOBS_H_
59
60 #include <altq/altq.h>
61 #include <altq/altq_classq.h>
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
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 #define INFINITY LLONG_MAX
73
74 /* list of packet arrival times */
75 struct _tsentry;
76 typedef TAILQ_HEAD(_timestamps, _tsentry) TSLIST;
77 typedef struct _tsentry {
78 TAILQ_ENTRY(_tsentry) ts_list;
79 uint64_t timestamp;
80 } TSENTRY;
81
82 /*
83 * timestamp list macros
84 */
85
86 #define tslist_first(s) TAILQ_FIRST(s)
87 #define tslist_last(s) TAILQ_LAST(s, _timestamps)
88 #define tslist_empty(s) TAILQ_EMPTY(s)
89
90 /*
91 * scaling/conversion macros
92 * none of these macros present side-effects, hence the lowercase
93 */
94
95 #define secs_to_ticks(x) ((x) * machclk_freq)
96 #define ticks_to_secs(x) ((x) / machclk_freq)
97 #define invsecs_to_invticks(x) ticks_to_secs(x)
98 #define invticks_to_invsecs(x) secs_to_ticks(x)
99 #define bits_to_bytes(x) ((x) >> 3)
100 #define bytes_to_bits(x) ((x) << 3)
101 #define scale_rate(x) ((x) << SCALE_RATE)
102 #define unscale_rate(x) ((x) >> SCALE_RATE)
103 #define bps_to_internal(x) (invsecs_to_invticks(bits_to_bytes(scale_rate(x))))
104 #define internal_to_bps(x) (unscale_rate(invticks_to_invsecs(bytes_to_bits(x))))
105
106 /*
107 * this macro takes care of possible wraparound
108 * effects in the computation of a delay
109 * no side-effects here either
110 */
111
112 #define delay_diff(x, y) ((x >= y)?(x - y):((ULLONG_MAX-y)+x+1))
113
114 /*
115 * additional macros (PKTCNTR_ADD can be found
116 * in the original distribution)
117 */
118
119 #define PKTCNTR_SUB(cntr, len) do { \
120 (cntr)->packets--; \
121 (cntr)->bytes -= len; \
122 } while (/*CONSTCOND*/ 0)
123
124 #define PKTCNTR_RESET(cntr) do { \
125 (cntr)->packets = 0; \
126 (cntr)->bytes = 0; \
127 } while (/*CONSTCOND*/ 0)
128
129 struct jobs_interface {
130 char jobs_ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */
131 u_long arg; /* request-specific argument */
132 };
133 struct jobs_attach {
134 struct jobs_interface iface;
135 u_int bandwidth; /* link bandwidth in bits/sec */
136 u_int qlimit; /* buffer size in packets */
137 u_int separate; /* separate buffers flag */
138 };
139
140 struct jobs_add_class {
141 struct jobs_interface iface;
142 int pri; /* priority (0 is the lowest) */
143 int flags; /* misc flags (see below) */
144
145 /*
146 * Delay Bound (-1 = NO ADC) is provided in us,
147 * and is converted to clock ticks
148 */
149 int64_t cl_adc;
150
151 /*
152 * Loss Rate Bound (-1 = NO ALC) is provided in fraction of 1
153 * and is converted to a fraction of 2^(SCALE_LOSS)
154 */
155 int64_t cl_alc;
156
157 /*
158 * lower bound on throughput (-1 = no ARC)
159 * is provided in (string) and
160 * is converted to internal format
161 */
162 int64_t cl_arc;
163
164 /* RDC weight (-1 = NO RDC) - no unit */
165 int64_t cl_rdc;
166
167 /* RLC weight (-1 = NO RLC) - no unit */
168 int64_t cl_rlc;
169
170 u_long class_handle; /* return value */
171 };
172
173 /* jobs class flags */
174 #define JOCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
175 #define JOCF_DEFAULTCLASS 0x1000 /* default class */
176
177 /* special class handles */
178 #define JOBS_NULLCLASS_HANDLE 0
179
180 struct jobs_delete_class {
181 struct jobs_interface iface;
182 u_long class_handle;
183 };
184
185 struct jobs_modify_class {
186 struct jobs_interface iface;
187 u_long class_handle;
188 int pri;
189
190 /*
191 * Delay Bound (-1 = NO ADC) is provided in us,
192 * and is converted to clock ticks
193 */
194 int64_t cl_adc;
195
196 /*
197 * Loss Rate Bound (-1 = NO ALC) is provided in fraction of 1
198 * and is converted to a fraction of 2^(SCALE_LOSS)
199 */
200 int64_t cl_alc;
201
202 /*
203 * lower bound on throughput (-1 = no ARC)
204 * is provided in (string) and
205 * is converted to internal format
206 */
207 int64_t cl_arc;
208
209 /* RDC weight (-1 = NO RDC) - no unit */
210 int64_t cl_rdc;
211
212 /* RLC weight (-1 = NO RLC) - no unit */
213 int64_t cl_rlc;
214
215 int flags;
216 };
217
218 struct jobs_add_filter {
219 struct jobs_interface iface;
220 u_long class_handle;
221 #ifdef ALTQ3_CLFIER_COMPAT
222 struct flow_filter filter;
223 #endif
224 u_long filter_handle; /* return value */
225 };
226
227 struct jobs_delete_filter {
228 struct jobs_interface iface;
229 u_long filter_handle;
230 };
231
232 struct class_stats {
233 u_int adc_violations;
234 u_int totallength;
235 u_int period;
236 u_int qlength;
237
238 u_long class_handle;
239
240 int64_t service_rate; /* bps that should be out */
241
242 u_int64_t avg_cycles_dequeue;
243 u_int64_t avg_cycles_enqueue;
244 u_int64_t avg_cycles2_dequeue;
245 u_int64_t avg_cycles2_enqueue;
246 u_int64_t avgdel; /* in us */
247 u_int64_t bc_cycles_dequeue;
248 u_int64_t bc_cycles_enqueue;
249 u_int64_t busylength; /* in ms */
250 u_int64_t lastdel; /* in us */
251 u_int64_t total_dequeued;
252 u_int64_t total_enqueued;
253 u_int64_t wc_cycles_dequeue;
254 u_int64_t wc_cycles_enqueue;
255
256 struct pktcntr arrival; /* rin+dropped */
257 struct pktcntr arrivalbusy;
258 struct pktcntr rin; /* dropped packet counter */
259 struct pktcntr rout; /* transmitted packet counter */
260 struct pktcntr dropcnt; /* dropped packet counter */
261 };
262
263 struct jobs_class_stats {
264 struct class_stats *stats; /* pointer to stats array */
265 int maxpri; /* in/out */
266 struct jobs_interface iface;
267 };
268
269 #define JOBS_IF_ATTACH _IOW('Q', 1, struct jobs_attach)
270 #define JOBS_IF_DETACH _IOW('Q', 2, struct jobs_interface)
271 #define JOBS_ENABLE _IOW('Q', 3, struct jobs_interface)
272 #define JOBS_DISABLE _IOW('Q', 4, struct jobs_interface)
273 #define JOBS_CLEAR _IOW('Q', 6, struct jobs_interface)
274 #define JOBS_ADD_CLASS _IOWR('Q', 7, struct jobs_add_class)
275 #define JOBS_DEL_CLASS _IOW('Q', 8, struct jobs_delete_class)
276 #define JOBS_MOD_CLASS _IOW('Q', 9, struct jobs_modify_class)
277 #define JOBS_ADD_FILTER _IOWR('Q', 10, struct jobs_add_filter)
278 #define JOBS_DEL_FILTER _IOW('Q', 11, struct jobs_delete_filter)
279 #define JOBS_GETSTATS _IOWR('Q', 12, struct jobs_class_stats)
280
281 #ifdef _KERNEL
282
283 struct jobs_class {
284 TSLIST *arv_tm; /* list of timestamps */
285 struct jobs_if *cl_jif; /* back pointer to jif */
286 class_queue_t *cl_q; /* class queue structure */
287
288 int cl_pri; /* priority */
289 int cl_flags; /* class flags */
290
291 u_long cl_handle; /* class handle */
292
293 /* control variables */
294
295 /*
296 * internal representation:
297 * bytes/unit_time << 32 = (bps /8 << 32)*1/machclk_freq
298 */
299 int64_t service_rate; /* bps that should be out */
300 int64_t min_rate_adc; /* bps that should be out for ADC/ARC */
301
302 u_int64_t current_loss; /* % of packets dropped */
303 u_int64_t cl_lastdel; /* in clock ticks */
304 u_int64_t cl_avgdel;
305
306 /* statistics */
307 u_int cl_period; /* backlog period */
308 struct pktcntr cl_arrival; /* arrived packet counter */
309 struct pktcntr cl_dropcnt; /* dropped packet counter */
310 struct pktcntr cl_rin; /* let in packet counter */
311 struct pktcntr cl_rout; /* transmitted packet counter */
312
313
314 /* modified deficit round-robin specific variables */
315
316 /*
317 * rout_th is SCALED for precision, as opposed to rout.
318 */
319 int64_t st_service_rate;
320 u_int64_t cl_last_rate_update;
321 struct pktcntr cl_rout_th; /* theoretical transmissions */
322 struct pktcntr st_arrival; /* rin+dropped */
323 struct pktcntr st_rin; /* dropped packet counter */
324 struct pktcntr st_rout; /* transmitted packet counter */
325 struct pktcntr st_dropcnt; /* dropped packet counter */
326
327 /* service guarantees */
328 u_int adc_violations;
329 int concerned_adc;
330 int concerned_alc;
331 int concerned_arc;
332 int concerned_rdc;
333 int concerned_rlc;
334 /*
335 * Delay Bound (-1 = NO ADC) is provided in us,
336 * and is converted to clock ticks
337 */
338 int64_t cl_adc;
339
340 /*
341 * Loss Rate Bound (-1 = NO ALC) is provided in fraction of 1
342 * and is converted to a fraction of 2^(SCALE_LOSS)
343 */
344 int64_t cl_alc;
345
346 /*
347 * lower bound on throughput (-1 = no ARC)
348 * is provided in (string) and
349 * is converted to internal format
350 */
351 int64_t cl_arc;
352
353 /* RDC weight (-1 = NO RDC) - no unit */
354 int64_t cl_rdc;
355
356 /* RLC weight (-1 = NO RLC) - no unit */
357 int64_t cl_rlc;
358
359 u_int64_t delay_prod_others;
360 u_int64_t loss_prod_others;
361 u_int64_t idletime;
362 };
363
364 /*
365 * jobs interface state
366 */
367 struct jobs_if {
368 struct jobs_if *jif_next; /* interface state list */
369 struct ifaltq *jif_ifq; /* backpointer to ifaltq */
370 struct jobs_class *jif_default; /* default class */
371 struct jobs_class *jif_classes[JOBS_MAXPRI]; /* classes */
372 #ifdef ALTQ3_CLFIER_COMPAT
373 struct acc_classifier jif_classifier; /* classifier */
374 #endif
375 int jif_maxpri; /* max priority in use */
376
377 u_int jif_bandwidth; /* link bandwidth in bps */
378 u_int jif_qlimit; /* buffer size in packets */
379 u_int jif_separate; /* separate buffers or not */
380 u_int64_t avg_cycles_dequeue;
381 u_int64_t avg_cycles_enqueue;
382 u_int64_t avg_cycles2_dequeue;
383 u_int64_t avg_cycles2_enqueue;
384 u_int64_t bc_cycles_dequeue;
385 u_int64_t bc_cycles_enqueue;
386 u_int64_t wc_cycles_dequeue;
387 u_int64_t wc_cycles_enqueue;
388 u_int64_t total_dequeued;
389 u_int64_t total_enqueued;
390 };
391
392 #endif /* _KERNEL */
393
394 #ifdef __cplusplus
395 }
396 #endif
397
398 #endif /* _ALTQ_ALTQ_JOBS_H_ */
Cache object: d38e1b41e6643f982480e341a6298597
|