[v2] eal/arm: replace RTE_BUILD_BUG on non-constant

Message ID 20240503182730.31693-1-daniel.gregory@bytedance.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series [v2] eal/arm: replace RTE_BUILD_BUG on non-constant |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Daniel Gregory May 3, 2024, 6:27 p.m. UTC
The ARM implementation of rte_pause uses RTE_BUILD_BUG_ON to check
memorder, which is not constant. This causes compile errors when it is
enabled with RTE_ARM_USE_WFE. eg.

../lib/eal/arm/include/rte_pause_64.h: In function ‘rte_wait_until_equal_16’:
../lib/eal/include/rte_common.h:530:56: error: expression in static assertion is not constant
  530 | #define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0)
      |                                                        ^~~~~~~~~~~~
../lib/eal/arm/include/rte_pause_64.h:156:9: note: in expansion of macro ‘RTE_BUILD_BUG_ON’
  156 |         RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
      |         ^~~~~~~~~~~~~~~~

Fix the compile errors by replacing the check with an assert, like in
the generic implementation (lib/eal/include/generic/rte_pause.h).

Fixes: 875f350924b8 ("eal: add a new helper for wait until scheme")

Signed-off-by: Daniel Gregory <daniel.gregory@bytedance.com>
---
Cc: feifei.wang2@arm.com
---
 lib/eal/arm/include/rte_pause_64.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Comments

Daniel Gregory May 3, 2024, 6:30 p.m. UTC | #1
Apologies, mis-sent this before attaching a changelog:

v2:
* replaced RTE_ASSERT with assert
* added Fixes: tag
  
Stephen Hemminger May 4, 2024, 12:59 a.m. UTC | #2
On Fri,  3 May 2024 19:27:30 +0100
Daniel Gregory <daniel.gregory@bytedance.com> wrote:

> The ARM implementation of rte_pause uses RTE_BUILD_BUG_ON to check
> memorder, which is not constant. This causes compile errors when it is
> enabled with RTE_ARM_USE_WFE. eg.
> 
> ../lib/eal/arm/include/rte_pause_64.h: In function ‘rte_wait_until_equal_16’:
> ../lib/eal/include/rte_common.h:530:56: error: expression in static assertion is not constant
>   530 | #define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0)
>       |                                                        ^~~~~~~~~~~~
> ../lib/eal/arm/include/rte_pause_64.h:156:9: note: in expansion of macro ‘RTE_BUILD_BUG_ON’
>   156 |         RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
>       |         ^~~~~~~~~~~~~~~~
> 
> Fix the compile errors by replacing the check with an assert, like in
> the generic implementation (lib/eal/include/generic/rte_pause.h).

No, don't hide the problem.

What code is calling these. Looks like a real bug. Could be behind layers of wrappers.
  
Ruifeng Wang May 6, 2024, 9:30 a.m. UTC | #3
+ Arm team to the loop.
Removed invalid email address.

From: Daniel Gregory <daniel.gregory@bytedance.com>
Date: Saturday, May 4, 2024 at 2:27 AM
To: Ruifeng Wang <Ruifeng.Wang@arm.com>
Cc: dev@dpdk.org <dev@dpdk.org>, Punit Agrawal <punit.agrawal@bytedance.com>, Liang Ma <liangma@bytedance.com>, Daniel Gregory <daniel.gregory@bytedance.com>, Feifei Wang <Feifei.Wang2@arm.com>
Subject: [PATCH v2] eal/arm: replace RTE_BUILD_BUG on non-constant
The ARM implementation of rte_pause uses RTE_BUILD_BUG_ON to check
memorder, which is not constant. This causes compile errors when it is
enabled with RTE_ARM_USE_WFE. eg.

../lib/eal/arm/include/rte_pause_64.h: In function ‘rte_wait_until_equal_16’:
../lib/eal/include/rte_common.h:530:56: error: expression in static assertion is not constant
  530 | #define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0)
      |                                                        ^~~~~~~~~~~~
../lib/eal/arm/include/rte_pause_64.h:156:9: note: in expansion of macro ‘RTE_BUILD_BUG_ON’
  156 |         RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
      |         ^~~~~~~~~~~~~~~~

Fix the compile errors by replacing the check with an assert, like in
the generic implementation (lib/eal/include/generic/rte_pause.h).

Fixes: 875f350924b8 ("eal: add a new helper for wait until scheme")

Signed-off-by: Daniel Gregory <daniel.gregory@bytedance.com>
---
Cc: feifei.wang2@arm.com
---
 lib/eal/arm/include/rte_pause_64.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  
Wathsala Wathawana Vithanage May 11, 2024, 5 p.m. UTC | #4
> ../lib/eal/arm/include/rte_pause_64.h: In function ‘rte_wait_until_equal_16’:
> ../lib/eal/include/rte_common.h:530:56: error: expression in static assertion
> is not constant
>   530 | #define RTE_BUILD_BUG_ON(condition) do {
> static_assert(!(condition), #condition); } while (0)
>       |                                                        ^~~~~~~~~~~~
> ../lib/eal/arm/include/rte_pause_64.h:156:9: note: in expansion of macro
> ‘RTE_BUILD_BUG_ON’
>   156 |         RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
>       |         ^~~~~~~~~~~~~~~~
> 
> Fix the compile errors by replacing the check with an assert, like in the generic
> implementation (lib/eal/include/generic/rte_pause.h).
> 
> Fixes: 875f350924b8 ("eal: add a new helper for wait until scheme")
> 
> Signed-off-by: Daniel Gregory <daniel.gregory@bytedance.com>

Acked-by: Wathsala Vithanage <wathsala.vithanage@arm.com>
  
Thomas Monjalon June 27, 2024, 3:08 p.m. UTC | #5
04/05/2024 02:59, Stephen Hemminger:
> On Fri,  3 May 2024 19:27:30 +0100
> Daniel Gregory <daniel.gregory@bytedance.com> wrote:
> 
> > The ARM implementation of rte_pause uses RTE_BUILD_BUG_ON to check
> > memorder, which is not constant. This causes compile errors when it is
> > enabled with RTE_ARM_USE_WFE. eg.
> > 
> > ../lib/eal/arm/include/rte_pause_64.h: In function ‘rte_wait_until_equal_16’:
> > ../lib/eal/include/rte_common.h:530:56: error: expression in static assertion is not constant
> >   530 | #define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0)
> >       |                                                        ^~~~~~~~~~~~
> > ../lib/eal/arm/include/rte_pause_64.h:156:9: note: in expansion of macro ‘RTE_BUILD_BUG_ON’
> >   156 |         RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
> >       |         ^~~~~~~~~~~~~~~~
> > 
> > Fix the compile errors by replacing the check with an assert, like in
> > the generic implementation (lib/eal/include/generic/rte_pause.h).
> 
> No, don't hide the problem.
> 
> What code is calling these. Looks like a real bug. Could be behind layers of wrappers.

I support Stephen's opinion.
Please look for the real issue.
  
Daniel Gregory June 28, 2024, 10:05 a.m. UTC | #6
On Thu, Jun 27, 2024 at 05:08:51PM +0200, Thomas Monjalon wrote:
> 04/05/2024 02:59, Stephen Hemminger:
> > On Fri,  3 May 2024 19:27:30 +0100
> > Daniel Gregory <daniel.gregory@bytedance.com> wrote:
> > 
> > > The ARM implementation of rte_pause uses RTE_BUILD_BUG_ON to check
> > > memorder, which is not constant. This causes compile errors when it is
> > > enabled with RTE_ARM_USE_WFE. eg.
> > > 
> > > ../lib/eal/arm/include/rte_pause_64.h: In function ‘rte_wait_until_equal_16’:
> > > ../lib/eal/include/rte_common.h:530:56: error: expression in static assertion is not constant
> > >   530 | #define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0)
> > >       |                                                        ^~~~~~~~~~~~
> > > ../lib/eal/arm/include/rte_pause_64.h:156:9: note: in expansion of macro ‘RTE_BUILD_BUG_ON’
> > >   156 |         RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
> > >       |         ^~~~~~~~~~~~~~~~
> > > 
> > > Fix the compile errors by replacing the check with an assert, like in
> > > the generic implementation (lib/eal/include/generic/rte_pause.h).
> > 
> > No, don't hide the problem.
> > 
> > What code is calling these. Looks like a real bug. Could be behind layers of wrappers.
> 
> I support Stephen's opinion.
> Please look for the real issue.

In DPDK, I have found 26 calls of rte_wait_until_equal_16, largely split
between app/test-bbdev/test_bbdev_perf.c and app/test/test_timer.c, with
a couple calls in lib/eal/include/rte_pflock.h and
lib/eal/include/rte_ticketlock.h as well. 16 calls of
rte_wait_until_equal_32, spread amongst various test cases
(test_func_reentrancy.c test_mcslock.c, test_mempool_perf.c, ...), two
drivers (drivers/event/opdl/opdl_ring.c and
drivers/net/thunderx/nicvf_rxrx.c), lib/eal/common/eal_common_mcfg.c,
lib/eal/include/generic/rte_spinlock.h, lib/ring/rte_ring_c11_pvt.h,
lib/ring/rte_ring_generic_pvt.h and lib/eal/include/rte_mcslock.h. There
is a single call to rte_wait_until_equal_64 in app/test/test_pmd_perf.c

They all correctly use the primitives from rte_stdatomic.h

As I discussed on another chain
https://lore.kernel.org/dpdk-dev/20240509110251.GA3795959@ste-uk-lab-gw/
from what I've seen, it seems that neither Clang nor GCC allow for
static checks on the parameters of inline functions. For instance, the
following does not compile:

static inline __attribute__((always_inline)) int
fn(int val)
{
	_Static_assert(val == 0, "val nonzero");
	return 0;
}

int main(void) {
	return fn(0);
}

( https://godbolt.org/z/TrfWqYoGo )

With the same "expression in static assertion is not constant" error
that I get when cross-compiling DPDK for ARM with WFE enabled on main:

diff --git a/config/arm/meson.build b/config/arm/meson.build
index a45aa9e466..661c735977 100644
--- a/config/arm/meson.build
+++ b/config/arm/meson.build
@@ -18,7 +18,7 @@ flags_common = [
         #    ['RTE_ARM64_MEMCPY_STRICT_ALIGN', false],
 
         # Enable use of ARM wait for event instruction.
-        # ['RTE_ARM_USE_WFE', false],
+        ['RTE_ARM_USE_WFE', true],
 
         ['RTE_ARCH_ARM64', true],
         ['RTE_CACHE_LINE_SIZE', 128]
  
Stephen Hemminger June 28, 2024, 3:19 p.m. UTC | #7
On Fri, 28 Jun 2024 11:05:20 +0100
Daniel Gregory <daniel.gregory@bytedance.com> wrote:

> > > > The ARM implementation of rte_pause uses RTE_BUILD_BUG_ON to check
> > > > memorder, which is not constant. This causes compile errors when it is
> > > > enabled with RTE_ARM_USE_WFE. eg.
> > > > 
> > > > ../lib/eal/arm/include/rte_pause_64.h: In function ‘rte_wait_until_equal_16’:
> > > > ../lib/eal/include/rte_common.h:530:56: error: expression in static assertion is not constant
> > > >   530 | #define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0)
> > > >       |                                                        ^~~~~~~~~~~~
> > > > ../lib/eal/arm/include/rte_pause_64.h:156:9: note: in expansion of macro ‘RTE_BUILD_BUG_ON’
> > > >   156 |         RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
> > > >       |         ^~~~~~~~~~~~~~~~
> > > > 
> > > > Fix the compile errors by replacing the check with an assert, like in
> > > > the generic implementation (lib/eal/include/generic/rte_pause.h).  
> > > 
> > > No, don't hide the problem.
> > > 
> > > What code is calling these. Looks like a real bug. Could be behind layers of wrappers.  
> > 
> > I support Stephen's opinion.
> > Please look for the real issue.  
> 
> In DPDK, I have found 26 calls of rte_wait_until_equal_16, largely split
> between app/test-bbdev/test_bbdev_perf.c and app/test/test_timer.c, with
> a couple calls in lib/eal/include/rte_pflock.h and
> lib/eal/include/rte_ticketlock.h as well. 16 calls of
> rte_wait_until_equal_32, spread amongst various test cases
> (test_func_reentrancy.c test_mcslock.c, test_mempool_perf.c, ...), two
> drivers (drivers/event/opdl/opdl_ring.c and
> drivers/net/thunderx/nicvf_rxrx.c), lib/eal/common/eal_common_mcfg.c,
> lib/eal/include/generic/rte_spinlock.h, lib/ring/rte_ring_c11_pvt.h,
> lib/ring/rte_ring_generic_pvt.h and lib/eal/include/rte_mcslock.h. There
> is a single call to rte_wait_until_equal_64 in app/test/test_pmd_perf.c
> 
> They all correctly use the primitives from rte_stdatomic.h
> 
> As I discussed on another chain
> https://lore.kernel.org/dpdk-dev/20240509110251.GA3795959@ste-uk-lab-gw/
> from what I've seen, it seems that neither Clang nor GCC allow for
> static checks on the parameters of inline functions. For instance, the
> following does not compile:
> 
> static inline __attribute__((always_inline)) int
> fn(int val)
> {
> 	_Static_assert(val == 0, "val nonzero");
> 	return 0;
> }
> 
> int main(void) {
> 	return fn(0);
> }
> 
> ( https://godbolt.org/z/TrfWqYoGo )
> 
> With the same "expression in static assertion is not constant" error
> that I get when cross-compiling DPDK for ARM with WFE enabled on main:

This is unexpected, but I can validate that it works that way.
Maybe because of combination of how inlining works and how the
static asserts are evaluated.

It does work if fn() is a macro

#define fn(val) ({ static_assert(val == 0, "val nonzero"); 0; })
  

Patch

diff --git a/lib/eal/arm/include/rte_pause_64.h b/lib/eal/arm/include/rte_pause_64.h
index 5cb8b59056..852660091a 100644
--- a/lib/eal/arm/include/rte_pause_64.h
+++ b/lib/eal/arm/include/rte_pause_64.h
@@ -10,6 +10,8 @@ 
 extern "C" {
 #endif
 
+#include <assert.h>
+
 #include <rte_common.h>
 
 #ifdef RTE_ARM_USE_WFE
@@ -153,7 +155,7 @@  rte_wait_until_equal_16(volatile uint16_t *addr, uint16_t expected,
 {
 	uint16_t value;
 
-	RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
+	assert(memorder != rte_memory_order_acquire &&
 		memorder != rte_memory_order_relaxed);
 
 	__RTE_ARM_LOAD_EXC_16(addr, value, memorder)
@@ -172,7 +174,7 @@  rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected,
 {
 	uint32_t value;
 
-	RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
+	assert(memorder != rte_memory_order_acquire &&
 		memorder != rte_memory_order_relaxed);
 
 	__RTE_ARM_LOAD_EXC_32(addr, value, memorder)
@@ -191,7 +193,7 @@  rte_wait_until_equal_64(volatile uint64_t *addr, uint64_t expected,
 {
 	uint64_t value;
 
-	RTE_BUILD_BUG_ON(memorder != rte_memory_order_acquire &&
+	assert(memorder != rte_memory_order_acquire &&
 		memorder != rte_memory_order_relaxed);
 
 	__RTE_ARM_LOAD_EXC_64(addr, value, memorder)