From owner-svn-src-all@freebsd.org Wed Jun 1 20:04:26 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3FE35B60F26; Wed, 1 Jun 2016 20:04:26 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1B5F4145B; Wed, 1 Jun 2016 20:04:26 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u51K4PjR012155; Wed, 1 Jun 2016 20:04:25 GMT (envelope-from truckman@FreeBSD.org) Received: (from truckman@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u51K4PIr012152; Wed, 1 Jun 2016 20:04:25 GMT (envelope-from truckman@FreeBSD.org) Message-Id: <201606012004.u51K4PIr012152@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: truckman set sender to truckman@FreeBSD.org using -f From: Don Lewis Date: Wed, 1 Jun 2016 20:04:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301162 - head/sys/netpfil/ipfw X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jun 2016 20:04:26 -0000 Author: truckman Date: Wed Jun 1 20:04:24 2016 New Revision: 301162 URL: https://svnweb.freebsd.org/changeset/base/301162 Log: 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 MFC after: 8 days (with r300779 and r300949) Modified: head/sys/netpfil/ipfw/dn_aqm_pie.c head/sys/netpfil/ipfw/dn_aqm_pie.h head/sys/netpfil/ipfw/dn_sched_fq_pie.c Modified: head/sys/netpfil/ipfw/dn_aqm_pie.c ============================================================================== --- head/sys/netpfil/ipfw/dn_aqm_pie.c Wed Jun 1 19:54:17 2016 (r301161) +++ head/sys/netpfil/ipfw/dn_aqm_pie.c Wed Jun 1 20:04:24 2016 (r301162) @@ -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; Modified: head/sys/netpfil/ipfw/dn_aqm_pie.h ============================================================================== --- head/sys/netpfil/ipfw/dn_aqm_pie.h Wed Jun 1 19:54:17 2016 (r301161) +++ head/sys/netpfil/ipfw/dn_aqm_pie.h Wed Jun 1 20:04:24 2016 (r301162) @@ -132,11 +132,13 @@ drop_early(struct pie_status *pst, uint3 * 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; } Modified: head/sys/netpfil/ipfw/dn_sched_fq_pie.c ============================================================================== --- head/sys/netpfil/ipfw/dn_sched_fq_pie.c Wed Jun 1 19:54:17 2016 (r301161) +++ head/sys/netpfil/ipfw/dn_sched_fq_pie.c Wed Jun 1 20:04:24 2016 (r301162) @@ -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;