[v4,5/6] mempool: avoid floating point expression in static assertion

Message ID 20240117182541.211125-6-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series use static assert to cathc build errors |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Jan. 17, 2024, 6:19 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.

Modify comment in mlx5 so that developers don't go searching
for old value.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/mlx5/mlx5_rxq.c | 2 +-
 lib/mempool/rte_mempool.c   | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)
  

Comments

Morten Brørup Jan. 17, 2024, 6:32 p.m. UTC | #1
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Wednesday, 17 January 2024 19.20
> 
> 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.
> 
> Modify comment in mlx5 so that developers don't go searching
> for old value.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Acked-by: Morten Brørup <mb@smartsharesystems.com>
  
Konstantin Ananyev Jan. 18, 2024, 9:32 a.m. UTC | #2
> 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.
> 
> Modify comment in mlx5 so that developers don't go searching
> for old value.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  drivers/net/mlx5/mlx5_rxq.c | 2 +-
>  lib/mempool/rte_mempool.c   | 7 ++++---
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_rxq.c b/drivers/net/mlx5/mlx5_rxq.c
> index 1bb036afebb3..7d972b6d927c 100644
> --- a/drivers/net/mlx5/mlx5_rxq.c
> +++ b/drivers/net/mlx5/mlx5_rxq.c
> @@ -1444,7 +1444,7 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)
>  	/*
>  	 * rte_mempool_create_empty() has sanity check to refuse large cache
>  	 * size compared to the number of elements.
> -	 * CACHE_FLUSHTHRESH_MULTIPLIER is defined in a C file, so using a
> +	 * CALC_CACHE_FLUSHTHRESH() is defined in a C file, so using a
>  	 * constant number 2 instead.
>  	 */
>  	obj_num = RTE_MAX(obj_num, MLX5_MPRQ_MP_CACHE_SZ * 2);
> diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
> index b7a19bea7185..12390a2c8155 100644
> --- a/lib/mempool/rte_mempool.c
> +++ b/lib/mempool/rte_mempool.c
> @@ -50,9 +50,10 @@ 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))
> +/* Note: avoid using floating point since that compiler
> + * may not think that is constant.
> + */
> +#define CALC_CACHE_FLUSHTHRESH(c) (((c) * 3) / 2)
> 
>  #if defined(RTE_ARCH_X86)
>  /*

Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>

> --
> 2.43.0
  
Andrew Rybchenko Jan. 18, 2024, 9:41 a.m. UTC | #3
On 1/17/24 21:32, Morten Brørup wrote:
>> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
>> Sent: Wednesday, 17 January 2024 19.20
>>
>> 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.
>>
>> Modify comment in mlx5 so that developers don't go searching
>> for old value.
>>
>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> 
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> 

Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
  

Patch

diff --git a/drivers/net/mlx5/mlx5_rxq.c b/drivers/net/mlx5/mlx5_rxq.c
index 1bb036afebb3..7d972b6d927c 100644
--- a/drivers/net/mlx5/mlx5_rxq.c
+++ b/drivers/net/mlx5/mlx5_rxq.c
@@ -1444,7 +1444,7 @@  mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)
 	/*
 	 * rte_mempool_create_empty() has sanity check to refuse large cache
 	 * size compared to the number of elements.
-	 * CACHE_FLUSHTHRESH_MULTIPLIER is defined in a C file, so using a
+	 * CALC_CACHE_FLUSHTHRESH() is defined in a C file, so using a
 	 * constant number 2 instead.
 	 */
 	obj_num = RTE_MAX(obj_num, MLX5_MPRQ_MP_CACHE_SZ * 2);
diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
index b7a19bea7185..12390a2c8155 100644
--- a/lib/mempool/rte_mempool.c
+++ b/lib/mempool/rte_mempool.c
@@ -50,9 +50,10 @@  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))
+/* Note: avoid using floating point since that compiler
+ * may not think that is constant.
+ */
+#define CALC_CACHE_FLUSHTHRESH(c) (((c) * 3) / 2)
 
 #if defined(RTE_ARCH_X86)
 /*