FreeBSD Bugzilla – Attachment 208668 Details for
Bug 241563
pf: altq Adaptive RED (Random Early Detection) queuing support
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
ared.diff
ared.diff (text/plain), 5.58 KB, created by
Archit Pandey
on 2019-10-29 04:56:57 UTC
(
hide
)
Description:
ared.diff
Filename:
MIME Type:
Creator:
Archit Pandey
Created:
2019-10-29 04:56:57 UTC
Size:
5.58 KB
patch
obsolete
>diff -u -r -N freebsd/sys/conf/options freebsd-ared/sys/conf/options >--- freebsd/sys/conf/options 2019-10-26 23:13:15.600930206 +0530 >+++ freebsd-ared/sys/conf/options 2019-10-26 23:11:11.521858737 +0530 >@@ -408,6 +408,7 @@ > ACCEPT_FILTER_DNS > ACCEPT_FILTER_HTTP > ALTQ opt_global.h >+ALTQ_ADAPTIVE_RED opt_altq.h > ALTQ_CBQ opt_altq.h > ALTQ_CDNR opt_altq.h > ALTQ_CODEL opt_altq.h >diff -u -r -N freebsd/sys/net/altq/altq_red.c freebsd-ared/sys/net/altq/altq_red.c >--- freebsd/sys/net/altq/altq_red.c 2019-10-26 23:13:15.600930206 +0530 >+++ freebsd-ared/sys/net/altq/altq_red.c 2019-10-26 23:11:12.214974354 +0530 >@@ -57,7 +57,7 @@ > * SUCH DAMAGE. > * > * $KAME: altq_red.c,v 1.18 2003/09/05 22:40:36 itojun Exp $ >- * $FreeBSD$ >+ * $FreeBSD$ > */ > > #include "opt_altq.h" >@@ -71,6 +71,8 @@ > #include <sys/socket.h> > #include <sys/systm.h> > #include <sys/errno.h> >+#include <sys/types.h> >+ > #if 1 /* ALTQ3_COMPAT */ > #include <sys/sockio.h> > #include <sys/proc.h> >@@ -161,6 +163,12 @@ > #define RED_LIMIT 60 /* default max queue length */ > #define RED_STATS /* collect statistics */ > >+/* parameters needed for adaptive-red */ >+#define INV_MIN_P 100 /* denominator of minimum drop probability */ >+#define INV_MAX_P 2 /* denominator of maximum drop probability */ >+#define RED_ALPHA_INV(val) max(100<<FP_SHIFT,val<<2) /* inverse of Additive adjustment factor for adaptive red */ >+#define RED_BETA 0.9 /* multiplicative adjustment factor for adaptive red */ >+ > /* > * our default policy for forced-drop is drop-tail. > * (in altq-1.1.2 or earlier, the default was random-drop. >@@ -250,9 +258,9 @@ > rp->red_idle = 1; > > if (inv_pmax == 0) >- rp->red_inv_pmax = default_inv_pmax; >+ rp->red_inv_pmax = default_inv_pmax<<FP_SHIFT; > else >- rp->red_inv_pmax = inv_pmax; >+ rp->red_inv_pmax = inv_pmax<<FP_SHIFT; > if (th_min == 0) > rp->red_thmin = default_th_min; > else >@@ -306,9 +314,20 @@ > * probd = (2 * (TH_MAX-TH_MIN) / pmax) in fixed-point > */ > rp->red_probd = (2 * (rp->red_thmax - rp->red_thmin) >- * rp->red_inv_pmax) << FP_SHIFT; >+ * rp->red_inv_pmax); > > microtime(&rp->red_last); >+#ifdef ALTQ_ADAPTIVE_RED >+ int delta = (rp->red_thmax_s-rp->red_thmin_s)/5; >+ rp->target_min = rp->red_thmin_s + 2*delta; >+ rp->target_max = rp->red_thmin_s + 3*delta; >+ mtx_init(&rp->lock_mtx, "mtx_red", NULL, MTX_DEF); >+ callout_init_mtx(&rp->adaptive_callout, &rp->lock_mtx, >+ CALLOUT_RETURNUNLOCKED); >+ mtx_lock(&rp->lock_mtx); >+ callout_reset_sbt(&rp->adaptive_callout, 500*SBT_1MS, 0, red_adaptive_timer, (void *)rp, 0); >+ mtx_unlock(&rp->lock_mtx); >+#endif > return (rp); > } > >@@ -322,6 +341,10 @@ > #endif > #endif /* ALTQ3_COMPAT */ > wtab_destroy(rp->red_wtab); >+ /* stop any pending callouts */ >+ mtx_lock(&rp->lock_mtx); >+ callout_stop(&rp->adaptive_callout); >+ mtx_unlock(&rp->lock_mtx); > free(rp, M_DEVBUF); > } > >@@ -707,6 +730,52 @@ > return (val); > } > >+#ifdef ALTQ_ADAPTIVE_RED >+/* >+ * calling function for Adaptive-RED >+ */ >+void >+red_adaptive_timer(void *params) >+{ >+ red_t *rp = (red_t *)params; >+ red_adaptive_algo(rp); >+ callout_reset_sbt(&rp->adaptive_callout, 500*SBT_1MS, 0, red_adaptive_timer, (void *)rp, 0); >+ mtx_unlock(&rp->lock_mtx); >+} >+ >+/* >+ * Adaptive-RED algorithm >+ */ >+void >+red_adaptive_algo(red_t *rp) >+{ >+ if(rp->red_inv_pmax > INV_MAX_P<<FP_SHIFT && rp->red_avg >= rp->target_max) >+ { >+ /* >+ * Additively increase RED drop >+ * probability using RED_ALPHA_INV >+ * red_inv_pmax = 1/((1/red_inv_pmax)+(1/RED_ALPHA_INV(red_inv_pmax))); >+ */ >+ 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))); >+ } >+ else if(rp->red_inv_pmax < INV_MIN_P<<FP_SHIFT && rp->red_avg <= rp->target_min) >+ { >+ /* >+ * Multiplicately decrease RED drop >+ * probability using RED_BETA >+ * red_inv_pmax = red_inv_pmax/RED_BETA; >+ */ >+ rp->red_inv_pmax = (rp->red_inv_pmax*10)/9; >+ } >+ /* >+ * precompute probability denominator >+ * probd = (2 * (TH_MAX-TH_MIN) / pmax) in fixed-point >+ */ >+ rp->red_probd = (2 * (rp->red_thmax - rp->red_thmin)*rp->red_inv_pmax); >+} >+ >+#endif /* ALTQ_ADAPTIVE_RED */ >+ > #ifdef ALTQ3_COMPAT > /* > * red device interface >diff -u -r -N freebsd/sys/net/altq/altq_red.h freebsd-ared/sys/net/altq/altq_red.h >--- freebsd/sys/net/altq/altq_red.h 2019-10-26 23:13:15.600930206 +0530 >+++ freebsd-ared/sys/net/altq/altq_red.h 2019-10-26 23:11:12.214974354 +0530 >@@ -31,6 +31,9 @@ > #define _ALTQ_ALTQ_RED_H_ > > #include <net/altq/altq_classq.h> >+#include <sys/types.h> >+#include <sys/mutex.h> >+#include <sys/lock.h> > > #ifdef ALTQ3_COMPAT > struct red_interface { >@@ -135,7 +138,7 @@ > > /* red parameters */ > int red_weight; /* weight for EWMA */ >- int red_inv_pmax; /* inverse of max drop probability */ >+ uint64_t red_inv_pmax; /* inverse of max drop probability */ > int red_thmin; /* red min threshold */ > int red_thmax; /* red max threshold */ > >@@ -153,6 +156,14 @@ > struct wtab *red_wtab; /* weight table */ > struct timeval red_last; /* time when the queue becomes idle */ > >+#ifdef ALTQ_ADAPTIVE_RED >+ /* variables for Adaptive RED */ >+ struct callout adaptive_callout; /* callout structure for use with Adaptive-RED */ >+ int target_min; /* target minimum for the queue */ >+ int target_max; /* target maximum for the queue */ >+ struct mtx lock_mtx; >+#endif >+ > #ifdef ALTQ3_COMPAT > struct flowvalve *red_flowvalve; /* flowvalve state */ > #endif >@@ -193,6 +204,8 @@ > extern struct wtab *wtab_alloc(int); > extern int wtab_destroy(struct wtab *); > extern int32_t pow_w(struct wtab *, int); >+extern void red_adaptive_timer(void *); >+extern void red_adaptive_algo(red_t *); > > #endif /* _KERNEL */ >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 241563
: 208668