[v5,3/3] rte_pie: fix incorrect floating point math

Message ID 20220526202653.99796-4-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series introduce random floating point function |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Stephen Hemminger May 26, 2022, 8:26 p.m. UTC
  The function rte_pie_drop was attempting to do a random probability
drop, but because of incorrect usage of fixed point divide
it would always return 1.

Change to use new rte_drand() instead.

Fixes: 44c730b0e379 ("sched: add PIE based congestion management")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/sched/rte_pie.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
  

Comments

Cristian Dumitrescu May 30, 2022, 11:50 a.m. UTC | #1
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Thursday, May 26, 2022 9:27 PM
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Dumitrescu,
> Cristian <cristian.dumitrescu@intel.com>; Singh, Jasvinder
> <jasvinder.singh@intel.com>; Wojciech Liguzinski
> <wojciechx.liguzinski@intel.com>
> Subject: [PATCH v5 3/3] rte_pie: fix incorrect floating point math
> 
> The function rte_pie_drop was attempting to do a random probability
> drop, but because of incorrect usage of fixed point divide
> it would always return 1.
> 
> Change to use new rte_drand() instead.
> 
> Fixes: 44c730b0e379 ("sched: add PIE based congestion management")
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/sched/rte_pie.h | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/lib/sched/rte_pie.h b/lib/sched/rte_pie.h
> index 3e2c1ef46721..528f2ea878e8 100644
> --- a/lib/sched/rte_pie.h
> +++ b/lib/sched/rte_pie.h
> @@ -217,7 +217,6 @@ __rte_experimental
>  _rte_pie_drop(const struct rte_pie_config *pie_cfg,
>  	struct rte_pie *pie)
>  {
> -	uint64_t rand_value;
>  	uint64_t qdelay = pie_cfg->qdelay_ref / 2;
> 
>  	/* PIE is active but the queue is not congested: return 0 */
> @@ -240,9 +239,7 @@ _rte_pie_drop(const struct rte_pie_config *pie_cfg,
>  	if (pie->accu_prob >= 8.5)
>  		return 1;
> 
> -	rand_value = rte_rand()/RTE_RAND_MAX;
> -
> -	if ((double)rand_value < pie->drop_prob) {
> +	if (rte_drand() < pie->drop_prob) {
>  		pie->accu_prob = 0;
>  		return 1;
>  	}
> --
> 2.35.1

Hi Stephen,

Thanks for your proposed fix. It looks good to me, but since Jasvinder handled the PIE integration, I am going to defer this for his review once he comes back from vacation, just to make sure I am not missing anything here.

Regards,
Cristian
  
Jasvinder Singh June 21, 2022, 8:18 a.m. UTC | #2
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Thursday, May 26, 2022 9:27 PM
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Dumitrescu,
> Cristian <cristian.dumitrescu@intel.com>; Singh, Jasvinder
> <jasvinder.singh@intel.com>; Wojciech Liguzinski
> <wojciechx.liguzinski@intel.com>
> Subject: [PATCH v5 3/3] rte_pie: fix incorrect floating point math
> 
> The function rte_pie_drop was attempting to do a random probability drop,
> but because of incorrect usage of fixed point divide it would always return 1.
> 
> Change to use new rte_drand() instead.
> 
> Fixes: 44c730b0e379 ("sched: add PIE based congestion management")
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/sched/rte_pie.h | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/lib/sched/rte_pie.h b/lib/sched/rte_pie.h index
> 3e2c1ef46721..528f2ea878e8 100644
> --- a/lib/sched/rte_pie.h
> +++ b/lib/sched/rte_pie.h
> @@ -217,7 +217,6 @@ __rte_experimental
>  _rte_pie_drop(const struct rte_pie_config *pie_cfg,
>  	struct rte_pie *pie)
>  {
> -	uint64_t rand_value;
>  	uint64_t qdelay = pie_cfg->qdelay_ref / 2;
> 
>  	/* PIE is active but the queue is not congested: return 0 */ @@ -
> 240,9 +239,7 @@ _rte_pie_drop(const struct rte_pie_config *pie_cfg,
>  	if (pie->accu_prob >= 8.5)
>  		return 1;
> 
> -	rand_value = rte_rand()/RTE_RAND_MAX;
> -
> -	if ((double)rand_value < pie->drop_prob) {
> +	if (rte_drand() < pie->drop_prob) {
>  		pie->accu_prob = 0;
>  		return 1;
>  	}
> --
> 2.35.1


Acked-by: Jasvinder Singh <jasvinder.singh@intel.com>
  

Patch

diff --git a/lib/sched/rte_pie.h b/lib/sched/rte_pie.h
index 3e2c1ef46721..528f2ea878e8 100644
--- a/lib/sched/rte_pie.h
+++ b/lib/sched/rte_pie.h
@@ -217,7 +217,6 @@  __rte_experimental
 _rte_pie_drop(const struct rte_pie_config *pie_cfg,
 	struct rte_pie *pie)
 {
-	uint64_t rand_value;
 	uint64_t qdelay = pie_cfg->qdelay_ref / 2;
 
 	/* PIE is active but the queue is not congested: return 0 */
@@ -240,9 +239,7 @@  _rte_pie_drop(const struct rte_pie_config *pie_cfg,
 	if (pie->accu_prob >= 8.5)
 		return 1;
 
-	rand_value = rte_rand()/RTE_RAND_MAX;
-
-	if ((double)rand_value < pie->drop_prob) {
+	if (rte_drand() < pie->drop_prob) {
 		pie->accu_prob = 0;
 		return 1;
 	}