[v3,4/5] mempool: avoid floating point expression in static assertion

Message ID 20240116184307.162882-5-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series use static_assert to catch build errors |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Jan. 16, 2024, 6:41 p.m. UTC
  Clang does not handle casts in static_assert() expressions.
It doesn't like use of floating point to calculate threshold.
Use a different expression with same effect; yes this will cause
checkpatch nag.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/mempool/rte_mempool.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
  

Comments

Andrew Rybchenko Jan. 17, 2024, 8:06 a.m. UTC | #1
On 1/16/24 21:41, Stephen Hemminger wrote:
> Clang does not handle casts in static_assert() expressions.
> It doesn't like use of floating point to calculate threshold.
> Use a different expression with same effect; yes this will cause
> checkpatch nag.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>   lib/mempool/rte_mempool.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
> index b7a19bea7185..ba3a54cfc298 100644
> --- a/lib/mempool/rte_mempool.c
> +++ b/lib/mempool/rte_mempool.c
> @@ -50,9 +50,7 @@ static void
>   mempool_event_callback_invoke(enum rte_mempool_event event,
>   			      struct rte_mempool *mp);
>   
> -#define CACHE_FLUSHTHRESH_MULTIPLIER 1.5

drivers/net/mlx5/mlx5_rxq.c:1447:        * CACHE_FLUSHTHRESH_MULTIPLIER 
is defined in a C file, so using a

> -#define CALC_CACHE_FLUSHTHRESH(c)	\
> -	((typeof(c))((c) * CACHE_FLUSHTHRESH_MULTIPLIER))
> +#define CALC_CACHE_FLUSHTHRESH(c) ((c) + (c) / 2)

Maybe ((c) * 3 / 2) to avoid double usage of arg in macro?

>   
>   #if defined(RTE_ARCH_X86)
>   /*
  

Patch

diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
index b7a19bea7185..ba3a54cfc298 100644
--- a/lib/mempool/rte_mempool.c
+++ b/lib/mempool/rte_mempool.c
@@ -50,9 +50,7 @@  static void
 mempool_event_callback_invoke(enum rte_mempool_event event,
 			      struct rte_mempool *mp);
 
-#define CACHE_FLUSHTHRESH_MULTIPLIER 1.5
-#define CALC_CACHE_FLUSHTHRESH(c)	\
-	((typeof(c))((c) * CACHE_FLUSHTHRESH_MULTIPLIER))
+#define CALC_CACHE_FLUSHTHRESH(c) ((c) + (c) / 2)
 
 #if defined(RTE_ARCH_X86)
 /*