summaryrefslogtreecommitdiffstats
path: root/sys/netpfil/ipfw
diff options
context:
space:
mode:
authortruckman <truckman@FreeBSD.org>2016-06-01 20:04:24 +0000
committertruckman <truckman@FreeBSD.org>2016-06-01 20:04:24 +0000
commitfc1de16102dddb41dbc0c49ce2d96f3c048578e5 (patch)
treea7a0ac14595fcb3872f488ce10d64b46d0506657 /sys/netpfil/ipfw
parent23ea14c2b83bec41b935d3e4ee3e42688d90d87a (diff)
downloadFreeBSD-src-fc1de16102dddb41dbc0c49ce2d96f3c048578e5.zip
FreeBSD-src-fc1de16102dddb41dbc0c49ce2d96f3c048578e5.tar.gz
Replace constant expressions that contain multiplications by
fractional floating point values with integer divides. This will eliminate any chance that the compiler will generate code to evaluate the expression using floating point at runtime. Suggested by: bde Submitted by: Rasool Al-Saadi <ralsaadi@swin.edu.au> MFC after: 8 days (with r300779 and r300949)
Diffstat (limited to 'sys/netpfil/ipfw')
-rw-r--r--sys/netpfil/ipfw/dn_aqm_pie.c26
-rw-r--r--sys/netpfil/ipfw/dn_aqm_pie.h6
-rw-r--r--sys/netpfil/ipfw/dn_sched_fq_pie.c26
3 files changed, 30 insertions, 28 deletions
diff --git a/sys/netpfil/ipfw/dn_aqm_pie.c b/sys/netpfil/ipfw/dn_aqm_pie.c
index eedbb51..c4b9401 100644
--- a/sys/netpfil/ipfw/dn_aqm_pie.c
+++ b/sys/netpfil/ipfw/dn_aqm_pie.c
@@ -244,20 +244,20 @@ calculate_drop_prob(void *x)
p *= (PIE_MAX_PROB << 12) / AQM_TIME_1S;
/* auto-tune drop probability */
- if (prob < (int64_t)(PIE_MAX_PROB * 0.000001))
- p >>= 11 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.00001))
- p >>= 9 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.0001))
- p >>= 7 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.001))
- p >>= 5 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.01))
- p >>= 3 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.1))
- p >>= 1 + PIE_FIX_POINT_BITS+12;
+ if (prob < (PIE_MAX_PROB / 1000000)) /* 0.000001 */
+ p >>= 11 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 100000)) /* 0.00001 */
+ p >>= 9 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 10000)) /* 0.0001 */
+ p >>= 7 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 1000)) /* 0.001 */
+ p >>= 5 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 100)) /* 0.01 */
+ p >>= 3 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 10)) /* 0.1 */
+ p >>= 1 + PIE_FIX_POINT_BITS + 12;
else
- p >>= PIE_FIX_POINT_BITS+12;
+ p >>= PIE_FIX_POINT_BITS + 12;
oldprob = prob;
diff --git a/sys/netpfil/ipfw/dn_aqm_pie.h b/sys/netpfil/ipfw/dn_aqm_pie.h
index b045077..aa2fceb 100644
--- a/sys/netpfil/ipfw/dn_aqm_pie.h
+++ b/sys/netpfil/ipfw/dn_aqm_pie.h
@@ -132,11 +132,13 @@ drop_early(struct pie_status *pst, uint32_t qlen)
* if accu_prob < 0.85 -> enqueue
* if accu_prob>8.5 ->drop
* between 0.85 and 8.5 || !De-randomize --> drop on prob
+ *
+ * (0.85 = 17/20 ,8.5 = 17/2)
*/
if (pprms->flags & PIE_DERAND_ENABLED) {
- if(pst->accu_prob < (uint64_t) (PIE_MAX_PROB * 0.85))
+ if(pst->accu_prob < (uint64_t) (PIE_MAX_PROB * 17 / 20))
return ENQUE;
- if( pst->accu_prob >= (uint64_t) (PIE_MAX_PROB * 8.5))
+ if( pst->accu_prob >= (uint64_t) (PIE_MAX_PROB * 17 / 2))
return DROP;
}
diff --git a/sys/netpfil/ipfw/dn_sched_fq_pie.c b/sys/netpfil/ipfw/dn_sched_fq_pie.c
index 4d25db4..2883cf8 100644
--- a/sys/netpfil/ipfw/dn_sched_fq_pie.c
+++ b/sys/netpfil/ipfw/dn_sched_fq_pie.c
@@ -407,20 +407,20 @@ fq_calculate_drop_prob(void *x)
p *= (PIE_MAX_PROB << 12) / AQM_TIME_1S;
/* auto-tune drop probability */
- if (prob < (int64_t)(PIE_MAX_PROB * 0.000001))
- p >>= 11 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.00001))
- p >>= 9 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.0001))
- p >>= 7 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.001))
- p >>= 5 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.01))
- p >>= 3 + PIE_FIX_POINT_BITS+12;
- else if (prob < (int64_t)(PIE_MAX_PROB * 0.1))
- p >>= 1 + PIE_FIX_POINT_BITS+12;
+ if (prob < (PIE_MAX_PROB / 1000000)) /* 0.000001 */
+ p >>= 11 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 100000)) /* 0.00001 */
+ p >>= 9 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 10000)) /* 0.0001 */
+ p >>= 7 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 1000)) /* 0.001 */
+ p >>= 5 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 100)) /* 0.01 */
+ p >>= 3 + PIE_FIX_POINT_BITS + 12;
+ else if (prob < (PIE_MAX_PROB / 10)) /* 0.1 */
+ p >>= 1 + PIE_FIX_POINT_BITS + 12;
else
- p >>= PIE_FIX_POINT_BITS+12;
+ p >>= PIE_FIX_POINT_BITS + 12;
oldprob = prob;
OpenPOWER on IntegriCloud