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

Stephen Hemminger stephen at networkplumber.org
Fri Jun 28 17:19:58 CEST 2024


On Fri, 28 Jun 2024 11:05:20 +0100
Daniel Gregory <daniel.gregory at 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; })




More information about the dev mailing list