Lines 57-63
Link Here
|
57 |
* SUCH DAMAGE. |
57 |
* SUCH DAMAGE. |
58 |
* |
58 |
* |
59 |
* $KAME: altq_red.c,v 1.18 2003/09/05 22:40:36 itojun Exp $ |
59 |
* $KAME: altq_red.c,v 1.18 2003/09/05 22:40:36 itojun Exp $ |
60 |
* $FreeBSD$ |
60 |
* $FreeBSD$ |
61 |
*/ |
61 |
*/ |
62 |
|
62 |
|
63 |
#include "opt_altq.h" |
63 |
#include "opt_altq.h" |
Lines 71-76
Link Here
|
71 |
#include <sys/socket.h> |
71 |
#include <sys/socket.h> |
72 |
#include <sys/systm.h> |
72 |
#include <sys/systm.h> |
73 |
#include <sys/errno.h> |
73 |
#include <sys/errno.h> |
|
|
74 |
#include <sys/types.h> |
75 |
|
74 |
#if 1 /* ALTQ3_COMPAT */ |
76 |
#if 1 /* ALTQ3_COMPAT */ |
75 |
#include <sys/sockio.h> |
77 |
#include <sys/sockio.h> |
76 |
#include <sys/proc.h> |
78 |
#include <sys/proc.h> |
Lines 161-166
Link Here
|
161 |
#define RED_LIMIT 60 /* default max queue length */ |
163 |
#define RED_LIMIT 60 /* default max queue length */ |
162 |
#define RED_STATS /* collect statistics */ |
164 |
#define RED_STATS /* collect statistics */ |
163 |
|
165 |
|
|
|
166 |
/* parameters needed for adaptive-red */ |
167 |
#define INV_MIN_P 100 /* denominator of minimum drop probability */ |
168 |
#define INV_MAX_P 2 /* denominator of maximum drop probability */ |
169 |
#define RED_ALPHA_INV(val) max(100<<FP_SHIFT,val<<2) /* inverse of Additive adjustment factor for adaptive red */ |
170 |
#define RED_BETA 0.9 /* multiplicative adjustment factor for adaptive red */ |
171 |
|
164 |
/* |
172 |
/* |
165 |
* our default policy for forced-drop is drop-tail. |
173 |
* our default policy for forced-drop is drop-tail. |
166 |
* (in altq-1.1.2 or earlier, the default was random-drop. |
174 |
* (in altq-1.1.2 or earlier, the default was random-drop. |
Lines 250-258
Link Here
|
250 |
rp->red_idle = 1; |
258 |
rp->red_idle = 1; |
251 |
|
259 |
|
252 |
if (inv_pmax == 0) |
260 |
if (inv_pmax == 0) |
253 |
rp->red_inv_pmax = default_inv_pmax; |
261 |
rp->red_inv_pmax = default_inv_pmax<<FP_SHIFT; |
254 |
else |
262 |
else |
255 |
rp->red_inv_pmax = inv_pmax; |
263 |
rp->red_inv_pmax = inv_pmax<<FP_SHIFT; |
256 |
if (th_min == 0) |
264 |
if (th_min == 0) |
257 |
rp->red_thmin = default_th_min; |
265 |
rp->red_thmin = default_th_min; |
258 |
else |
266 |
else |
Lines 306-314
Link Here
|
306 |
* probd = (2 * (TH_MAX-TH_MIN) / pmax) in fixed-point |
314 |
* probd = (2 * (TH_MAX-TH_MIN) / pmax) in fixed-point |
307 |
*/ |
315 |
*/ |
308 |
rp->red_probd = (2 * (rp->red_thmax - rp->red_thmin) |
316 |
rp->red_probd = (2 * (rp->red_thmax - rp->red_thmin) |
309 |
* rp->red_inv_pmax) << FP_SHIFT; |
317 |
* rp->red_inv_pmax); |
310 |
|
318 |
|
311 |
microtime(&rp->red_last); |
319 |
microtime(&rp->red_last); |
|
|
320 |
#ifdef ALTQ_ADAPTIVE_RED |
321 |
int delta = (rp->red_thmax_s-rp->red_thmin_s)/5; |
322 |
rp->target_min = rp->red_thmin_s + 2*delta; |
323 |
rp->target_max = rp->red_thmin_s + 3*delta; |
324 |
mtx_init(&rp->lock_mtx, "mtx_red", NULL, MTX_DEF); |
325 |
callout_init_mtx(&rp->adaptive_callout, &rp->lock_mtx, |
326 |
CALLOUT_RETURNUNLOCKED); |
327 |
mtx_lock(&rp->lock_mtx); |
328 |
callout_reset_sbt(&rp->adaptive_callout, 500*SBT_1MS, 0, red_adaptive_timer, (void *)rp, 0); |
329 |
mtx_unlock(&rp->lock_mtx); |
330 |
#endif |
312 |
return (rp); |
331 |
return (rp); |
313 |
} |
332 |
} |
314 |
|
333 |
|
Lines 322-327
Link Here
|
322 |
#endif |
341 |
#endif |
323 |
#endif /* ALTQ3_COMPAT */ |
342 |
#endif /* ALTQ3_COMPAT */ |
324 |
wtab_destroy(rp->red_wtab); |
343 |
wtab_destroy(rp->red_wtab); |
|
|
344 |
/* stop any pending callouts */ |
345 |
mtx_lock(&rp->lock_mtx); |
346 |
callout_stop(&rp->adaptive_callout); |
347 |
mtx_unlock(&rp->lock_mtx); |
325 |
free(rp, M_DEVBUF); |
348 |
free(rp, M_DEVBUF); |
326 |
} |
349 |
} |
327 |
|
350 |
|
Lines 707-712
Link Here
|
707 |
return (val); |
730 |
return (val); |
708 |
} |
731 |
} |
709 |
|
732 |
|
|
|
733 |
#ifdef ALTQ_ADAPTIVE_RED |
734 |
/* |
735 |
* calling function for Adaptive-RED |
736 |
*/ |
737 |
void |
738 |
red_adaptive_timer(void *params) |
739 |
{ |
740 |
red_t *rp = (red_t *)params; |
741 |
red_adaptive_algo(rp); |
742 |
callout_reset_sbt(&rp->adaptive_callout, 500*SBT_1MS, 0, red_adaptive_timer, (void *)rp, 0); |
743 |
mtx_unlock(&rp->lock_mtx); |
744 |
} |
745 |
|
746 |
/* |
747 |
* Adaptive-RED algorithm |
748 |
*/ |
749 |
void |
750 |
red_adaptive_algo(red_t *rp) |
751 |
{ |
752 |
if(rp->red_inv_pmax > INV_MAX_P<<FP_SHIFT && rp->red_avg >= rp->target_max) |
753 |
{ |
754 |
/* |
755 |
* Additively increase RED drop |
756 |
* probability using RED_ALPHA_INV |
757 |
* red_inv_pmax = 1/((1/red_inv_pmax)+(1/RED_ALPHA_INV(red_inv_pmax))); |
758 |
*/ |
759 |
rp->red_inv_pmax = (rp->red_inv_pmax*(RED_ALPHA_INV(rp->red_inv_pmax)))/(rp->red_inv_pmax+(RED_ALPHA_INV(rp->red_inv_pmax))); |
760 |
} |
761 |
else if(rp->red_inv_pmax < INV_MIN_P<<FP_SHIFT && rp->red_avg <= rp->target_min) |
762 |
{ |
763 |
/* |
764 |
* Multiplicately decrease RED drop |
765 |
* probability using RED_BETA |
766 |
* red_inv_pmax = red_inv_pmax/RED_BETA; |
767 |
*/ |
768 |
rp->red_inv_pmax = (rp->red_inv_pmax*10)/9; |
769 |
} |
770 |
/* |
771 |
* precompute probability denominator |
772 |
* probd = (2 * (TH_MAX-TH_MIN) / pmax) in fixed-point |
773 |
*/ |
774 |
rp->red_probd = (2 * (rp->red_thmax - rp->red_thmin)*rp->red_inv_pmax); |
775 |
} |
776 |
|
777 |
#endif /* ALTQ_ADAPTIVE_RED */ |
778 |
|
710 |
#ifdef ALTQ3_COMPAT |
779 |
#ifdef ALTQ3_COMPAT |
711 |
/* |
780 |
/* |
712 |
* red device interface |
781 |
* red device interface |