eal: abstract compiler atomics
Subsystems (2)
PATCH 1/1 eal: abstract compiler atomics
Introduce an abstraction for compiler specific atomics and a meson option to allow standard C11 atomics use.
Note, this series does not attempt to convert to the use of the abstraction it only introduces it as per the plan discussed here.
http://mails.dpdk.org/archives/dev/2023-January/258693.html
devtools checkatches warnings are expected as we intend no functional change with this series. Subsequent series will address the use of __sync_xxx builtins warning.
Tyler Retzlaff (1):
eal: introduce atomics abstraction
config/meson.build | 11 +++ lib/eal/arm/include/rte_atomic_32.h | 6 +- lib/eal/arm/include/rte_atomic_64.h | 6 +- lib/eal/include/generic/rte_atomic.h | 156 ++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 +- lib/eal/ppc/include/rte_atomic.h | 6 +- lib/eal/riscv/include/rte_atomic.h | 6 +- lib/eal/x86/include/rte_atomic.h | 8 +- meson_options.txt | 2 + 9 files changed, 199 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/1 eal: introduce atomics abstraction
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
--- config/meson.build | 11 +++ lib/eal/arm/include/rte_atomic_32.h | 6 +- lib/eal/arm/include/rte_atomic_64.h | 6 +- lib/eal/include/generic/rte_atomic.h | 156 ++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 +- lib/eal/ppc/include/rte_atomic.h | 6 +- lib/eal/riscv/include/rte_atomic.h | 6 +- lib/eal/x86/include/rte_atomic.h | 8 +- meson_options.txt | 2 + 9 files changed, 199 insertions(+), 8 deletions(-)
config/meson.build +11 -0
@@ -254,6 +254,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') +else + add_project_arguments('-std=c11', language: 'c') +endif +endif + # enable extra warnings and disable any unwanted warnings # -Wall is added by default at warning level 1, and -Wextra # at warning level 2 (DPDK default)
lib/eal/arm/include/rte_atomic_32.h +5 -1
@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cplusplus
lib/eal/arm/include/rte_atomic_64.h +5 -1
@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations -------------------------*/
lib/eal/include/generic/rte_atomic.h +155 -1
168 lines not on this page · raw message
lib/eal/loongarch/include/rte_atomic.h +5 -1
@@ -35,9 +35,13 @@#define rte_io_rmb () rte_mb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cplusplus
lib/eal/ppc/include/rte_atomic.h +5 -1
@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/
lib/eal/riscv/include/rte_atomic.h +5 -1
@@ -40,9 +40,13 @@#define rte_io_rmb () asm volatile("fence ir, ir" : : : "memory") static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cplusplus
lib/eal/x86/include/rte_atomic.h +6 -2
@@ -87,12 +87,16 @@* used instead. */ static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { -if (memorder == __ATOMIC_SEQ_CST) +if (memorder == rte_memory_order_seq_cst)rte_smp_mb (); else +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/
meson_options.txt +2 -0
@@ -46,6 +46,8 @@ option('mbuf_refcnt_atomic', type: 'boolean', value: true, description: 'Atomically access the mbuf refcnt.') option('platform', type: 'string', value: 'native', description: 'Platform to build, either "native", "generic" or a SoC. Please refer to the Linux build guide for more information.') +option('enable_stdatomics', type: 'boolean', value: false, description: + 'enable use of standard C11 atomics.') option('enable_trace_fp', type: 'boolean', value: false, description: 'enable fast path trace points.') option('tests', type: 'boolean', value: true, description:
Signature · 1 line
1.8.3.1
Re: [PATCH] eal: introduce atomics abstraction
Honnappa, please could you give your view on the future of atomics in DPDK?
12/01/2023 22:26, Tyler Retzlaff:
Quoted 344 lines
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 +++ lib/eal/arm/include/rte_atomic_32.h | 6 +- lib/eal/arm/include/rte_atomic_64.h | 6 +- lib/eal/include/generic/rte_atomic.h | 156 ++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 +- lib/eal/ppc/include/rte_atomic.h | 6 +- lib/eal/riscv/include/rte_atomic.h | 6 +- lib/eal/x86/include/rte_atomic.h | 8 +- meson_options.txt | 2 + 9 files changed, 199 insertions(+), 8 deletions(-)config/meson.build +11
-0@@ -254,6 +254,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') +else + add_project_arguments('-std=c11', language: 'c') +endif +endif + # enable extra warnings and disable any unwanted warnings # -Wall is added by default at warning level 1, and -Wextra # at warning level 2 (DPDK default)lib/eal/arm/include/rte_atomic_32.h +5
-1@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/arm/include/rte_atomic_64.h +5
-1@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations -------------------------*/ lib/eal/include/generic/rte_atomic.h +155
-1@@ -110,6 +110,160 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ <201112L || defined(__STDC_NO_ATOMICS__) +#error compiler does not support C11 standard atomics +#else +#include <stdatomic.h> +#endif + +#define __rte_atomic _Atomic + +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed memory_order_relaxed +#define rte_memory_order_consume memory_order_consume +#define rte_memory_order_acquire memory_order_acquire +#define rte_memory_order_release memory_order_release +#define rte_memory_order_acq_rel memory_order_acq_rel +#define rte_memory_order_seq_cst memory_order_seq_cst + +#define rte_atomic_store (obj, desired) \ + atomic_store_explicit(obj, desired) + +#define rte_atomic_store_explicit (obj, desired, order) \ + atomic_store_explicit(obj, desired, order) + +#define rte_atomic_load (obj) \ + atomic_load_explicit(obj) + +#define rte_atomic_load_explicit (obj, order) \ + atomic_load_explicit(obj, order) + +#define rte_atomic_exchange (obj, desired) \ + atomic_exchange(obj, desired) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + atomic_exchange_explicit(obj, desired, order) + +#define rte_atomic_compare_exchange_strong (obj, expected, desired) \ + atomic_compare_exchange_strong(obj, expected, desired) + +#define rte_atomic_compare_exchange_strong_explicit (obj, expected, desired, success, fail) \ + atomic_compare_exchange_strong_explicit(obj, expected, desired, success, fail) + +#define rte_atomic_compare_exchange_weak (obj, expected, desired) \ + atomic_compare_exchange_weak(obj, expected, desired) + +#define rte_atomic_compare_exchange_weak_explicit (obj, expected, desired, success, fail) \ + atomic_compare_exchange_weak_explicit(obj, expected, desired, success, fail) + +#define rte_atomic_fetch_add (obj, arg) \ + atomic_fetch_add(obj, arg) + +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + atomic_fetch_add_explicit(obj, arg, order) + +#define rte_atomic_fetch_sub (obj, arg) \ + atomic_fetch_sub(obj, arg) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + atomic_fetch_sub_explicit(obj, arg, order) + +#define rte_atomic_fetch_or (obj, arg) \ + atomic_fetch_or(obj, arg) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + atomic_fetch_or_explicit(obj, arg, order) + +#define rte_atomic_fetch_xor (obj, arg) \ + atomic_fetch_xor(obj, arg) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + atomic_fetch_xor_explicit(obj, arg, order) + +#define rte_atomic_fetch_and (obj, arg) \ + atomic_fetch_and(obj, arg) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + atomic_fetch_and_explicit(obj, arg, order) + +#else + +#define __rte_atomic + +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed __ATOMIC_RELAXED +#define rte_memory_order_consume __ATOMIC_CONSUME +#define rte_memory_order_acquire __ATOMIC_ACQUIRE +#define rte_memory_order_release __ATOMIC_RELEASE +#define rte_memory_order_acq_rel __ATOMIC_ACQ_REL +#define rte_memory_order_seq_cst __ATOMIC_SEQ_CST + +#define rte_atomic_store (obj, desired) \ + __atomic_store_n(obj, desired, rte_memory_order_seq_cst) + +#define rte_atomic_store_explicit (obj, desired, order) \ + __atomic_store_n(obj, desired, order) + +#define rte_atomic_load (obj) \ + __atomic_load_n(obj, rte_memory_order_seq_cst) + +#define rte_atomic_load_explicit (obj, order) \ + __atomic_load_n(obj, order) + +#define rte_atomic_exchange (obj, desired) \ + __atomic_exchange_n(obj, desired, rte_memory_order_seq_cst) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + __atomic_exchange_n(obj, desired, order) + +#define rte_atomic_compare_exchange_strong (obj, expected, desired) \ + __sync_bool_compare_and_swap(obj, expected, desired) + +#define rte_atomic_compare_exchange_strong_explicit (obj, expected, desired, success, fail) \ + __atomic_compare_exchange_n(obj, expected, desired, 0, success, fail) + +#define rte_atomic_compare_exchange_weak (obj, expected, desired) \ + __atomic_compare_exchange_n(obj, expected, desired, 1, rte_memory_order_seq_cst, rte_memory_order_seq_cst) + +#define rte_atomic_compare_exchange_weak_explicit (obj, expected, desired, success, fail) \ + __atomic_compare_exchange_n(obj, expected, desired, 1, success, fail) + +#define rte_atomic_fetch_add (obj, arg) \ + __atomic_fetch_add(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + __atomic_fetch_add(obj, arg, order) + +#define rte_atomic_fetch_sub (obj, arg) \ + __atomic_fetch_sub(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + __atomic_fetch_sub(obj, arg, order) + +#define rte_atomic_fetch_or (obj, arg) \ + __atomic_fetch_or(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + __atomic_fetch_or(obj, arg, order) + +#define rte_atomic_fetch_xor (obj, arg) \ + __atomic_fetch_xor(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + __atomic_fetch_xor(obj, arg, order) + +#define rte_atomic_fetch_and (obj, arg) \ + __atomic_fetch_and(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + __atomic_fetch_and(obj, arg, order) + +#endif +/** * Compiler barrier. * @@ -123,7 +277,7 @@/** * Synchronization fence between threads based on the specified memory order. */ -static inline void rte_atomic_thread_fence (int memorder); +static inline void rte_atomic_thread_fence (rte_memory_order memorder);/*------------------------- 16 bit atomic operations -------------------------*/ lib/eal/loongarch/include/rte_atomic.h +5
-1@@ -35,9 +35,13 @@#define rte_io_rmb () rte_mb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/ppc/include/rte_atomic.h +5
-1@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/ lib/eal/riscv/include/rte_atomic.h +5
-1@@ -40,9 +40,13 @@#define rte_io_rmb () asm volatile("fence ir, ir" : : : "memory") static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/x86/include/rte_atomic.h +6
-2@@ -87,12 +87,16 @@* used instead. */ static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { -if (memorder == __ATOMIC_SEQ_CST) +if (memorder == rte_memory_order_seq_cst)rte_smp_mb (); else +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/ meson_options.txt +2
-0@@ -46,6 +46,8 @@ option('mbuf_refcnt_atomic', type: 'boolean', value: true, description: 'Atomically access the mbuf refcnt.') option('platform', type: 'string', value: 'native', description: 'Platform to build, either "native", "generic" or a SoC. Please refer to the Linux build guide for more information.') +option('enable_stdatomics', type: 'boolean', value: false, description: + 'enable use of standard C11 atomics.') option('enable_trace_fp', type: 'boolean', value: false, description: 'enable fast path trace points.') option('tests', type: 'boolean', value: true, description:
RE: [PATCH] eal: introduce atomics abstraction
Quoted 11 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PM
To: Honnappa Nagarahalli <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Tyler Retzlaff <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] eal: introduce atomics abstractionHonnappa, please could you give your view on the future of atomics in DPDK?
Thanks Thomas, apologies it has taken me a while to get to this discussion.
IMO, we do not need DPDK's own abstractions. APIs from stdatomic.h (stdatomics as is called here) already serve the purpose. These APIs are well understood and documented.
For environments where stdatomics are not supported, we could have a stdatomic.h in DPDK implementing the same APIs (we have to support only _explicit APIs). This allows the code to use stdatomics APIs and when we move to minimum supported standard C11, we just need to get rid of the file in DPDK repo.
Quoted 370 lines
12/01/2023 22:26, Tyler Retzlaff:
Quoted 2 lines
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true
option.
Quoted 7 lines
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 +++ lib/eal/arm/include/rte_atomic_32.h | 6 +- lib/eal/arm/include/rte_atomic_64.h | 6 +- lib/eal/include/generic/rte_atomic.h | 156++++++++++++++++++++++++++++++++-
Quoted 104 lines
lib/eal/loongarch/include/rte_atomic.h | 6 +- lib/eal/ppc/include/rte_atomic.h | 6 +- lib/eal/riscv/include/rte_atomic.h | 6 +- lib/eal/x86/include/rte_atomic.h | 8 +- meson_options.txt | 2 + 9 files changed, 199 insertions(+), 8 deletions(-)config/meson.build index renamed from config/meson.build +0
-06d9ffd4..9515ce9 100644
config/meson.build +8
-0@@ -254,6 +254,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') else + add_project_arguments('-std=c11', language: 'c') endif endif + # enable extra warnings and disable any unwanted warnings # -Wall isadded by default at warning level 1, and -Wextra # at warning level 2 (DPDK default) diff --git
a/lib/eal/arm/include/rte_atomic_32.hb/lib/eal/arm/include/rte_atomic_32.h
index c00ab78..7088a12 100644lib/eal/arm/include/rte_atomic_32.h +5
-1@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/arm/include/rte_atomic_64.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations -------------------------*/ diff --git
a/lib/eal/include/generic/rte_atomic.hb/lib/eal/include/generic/rte_atomic.h
index f5c49a9..cb71c0d 100644lib/eal/include/generic/rte_atomic.h +29
-0@@ -110,6 +110,160 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || +defined(__STDC_NO_ATOMICS__) #error compiler does not support C11 +standard atomics #else #include <stdatomic.h> #endif + +#define __rte_atomic _Atomic + +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed memory_order_relaxed #define +rte_memory_order_consume memory_order_consume #define +rte_memory_order_acquire memory_order_acquire #define +rte_memory_order_release memory_order_release #define +rte_memory_order_acq_rel memory_order_acq_rel #define +rte_memory_order_seq_cst memory_order_seq_cst + +#define rte_atomic_store (obj, desired) \ + atomic_store_explicit(obj, desired) + +#define rte_atomic_store_explicit (obj, desired, order) \ + atomic_store_explicit(obj, desired, order) + +#define rte_atomic_load (obj) \ + atomic_load_explicit(obj) + +#define rte_atomic_load_explicit (obj, order) \ + atomic_load_explicit(obj, order) +lib/eal/include/generic/rte_atomic.h line 151
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +10
-0+#define rte_atomic_exchange (obj, desired) \ + atomic_exchange(obj, desired) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + atomic_exchange_explicit(obj, desired, order) + +#define rte_atomic_compare_exchange_strong (obj, expected, desired) \ + atomic_compare_exchange_strong(obj, expected, desired) + +#define rte_atomic_compare_exchange_strong_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h
Quoted 7 lines
lib/eal/include/generic/rte_atomic.h +7
-0+atomic_compare_exchange_strong_explicit (obj, expected, desired, +success, fail) + +#define rte_atomic_compare_exchange_weak (obj, expected, desired) \ + atomic_compare_exchange_weak(obj, expected, desired) + +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
Quoted 58 lines
lib/eal/include/generic/rte_atomic.h +58
-0+atomic_compare_exchange_weak_explicit (obj, expected, desired, +success, fail) + +#define rte_atomic_fetch_add (obj, arg) \ + atomic_fetch_add(obj, arg) + +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + atomic_fetch_add_explicit(obj, arg, order) + +#define rte_atomic_fetch_sub (obj, arg) \ + atomic_fetch_sub(obj, arg) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + atomic_fetch_sub_explicit(obj, arg, order) + +#define rte_atomic_fetch_or (obj, arg) \ + atomic_fetch_or(obj, arg) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + atomic_fetch_or_explicit(obj, arg, order) + +#define rte_atomic_fetch_xor (obj, arg) \ + atomic_fetch_xor(obj, arg) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + atomic_fetch_xor_explicit(obj, arg, order) + +#define rte_atomic_fetch_and (obj, arg) \ + atomic_fetch_and(obj, arg) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + atomic_fetch_and_explicit(obj, arg, order) + +#else + +#define __rte_atomic + +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed __ATOMIC_RELAXED #define +rte_memory_order_consume __ATOMIC_CONSUME #define +rte_memory_order_acquire __ATOMIC_ACQUIRE #define +rte_memory_order_release __ATOMIC_RELEASE #define +rte_memory_order_acq_rel __ATOMIC_ACQ_REL #define +rte_memory_order_seq_cst __ATOMIC_SEQ_CST + +#define rte_atomic_store (obj, desired) \ + __atomic_store_n(obj, desired, rte_memory_order_seq_cst) + +#define rte_atomic_store_explicit (obj, desired, order) \ + __atomic_store_n(obj, desired, order) + +#define rte_atomic_load (obj) \ + __atomic_load_n(obj, rte_memory_order_seq_cst) + +#define rte_atomic_load_explicit (obj, order) \ + __atomic_load_n(obj, order) +lib/eal/include/generic/rte_atomic.h
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +10
-0+#define rte_atomic_exchange (obj, desired) \ + __atomic_exchange_n(obj, desired, rte_memory_order_seq_cst) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + __atomic_exchange_n(obj, desired, order) + +#define rte_atomic_compare_exchange_strong (obj, expected, desired) \ + __sync_bool_compare_and_swap(obj, expected, desired) + +#define rte_atomic_compare_exchange_strong_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h line 234
Quoted 8 lines
lib/eal/include/generic/rte_atomic.h +8
-0+__atomic_compare_exchange_n (obj, expected, desired,0 , success, +fail) + +#define rte_atomic_compare_exchange_weak (obj, expected, desired) \ + __atomic_compare_exchange_n(obj, expected, desired, 1, +rte_memory_order_seq_cst, rte_memory_order_seq_cst) + +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
Quoted 39 lines
lib/eal/include/generic/rte_atomic.h +35
-0+__atomic_compare_exchange_n (obj, expected, desired,1 , success, +fail) + +#define rte_atomic_fetch_add (obj, arg) \ + __atomic_fetch_add(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + __atomic_fetch_add(obj, arg, order) + +#define rte_atomic_fetch_sub (obj, arg) \ + __atomic_fetch_sub(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + __atomic_fetch_sub(obj, arg, order) + +#define rte_atomic_fetch_or (obj, arg) \ + __atomic_fetch_or(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + __atomic_fetch_or(obj, arg, order) + +#define rte_atomic_fetch_xor (obj, arg) \ + __atomic_fetch_xor(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + __atomic_fetch_xor(obj, arg, order) + +#define rte_atomic_fetch_and (obj, arg) \ + __atomic_fetch_and(obj, arg, rte_memory_order_seq_cst) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + __atomic_fetch_and(obj, arg, order) + +#endif +/** * Compiler barrier. * lib/eal/include/generic/rte_atomic.h line 278
Quoted 2 lines
lib/eal/include/generic/rte_atomic.h +0
-0@@ -123,7 +277,7 @@/** * Synchronization fence between threads based on the specified memory order.
meson_options.txt option('mbuf_refcnt_atomic', type: 'boolean', value:
Quoted 98 lines
lib/eal/include/generic/rte_atomic.h +2
-2*/ -static inline void rte_atomic_thread_fence (int memorder); +static inline void rte_atomic_thread_fence (rte_memory_order +memorder);/*------------------------- 16 bit atomic operations -------------------------*/ lib/eal/loongarch/include/rte_atomic.h +5
-1@@ -35,9 +35,13 @@#define rte_io_rmb () rte_mb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/ppc/include/rte_atomic.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/ diff --git
a/lib/eal/riscv/include/rte_atomic.hb/lib/eal/riscv/include/rte_atomic.h
index 4b4633c..3c203a9 100644lib/eal/riscv/include/rte_atomic.h +5
-1@@ -40,9 +40,13 @@#define rte_io_rmb () asm volatile("fence ir, ir" : : : "memory") static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/x86/include/rte_atomic.h +6
-3@@ -87,12 +87,16 @@* used instead. */ static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { -if (memorder == __ATOMIC_SEQ_CST) +if (memorder == rte_memory_order_seq_cst)rte_smp_mb (); else +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/ diff --git a/meson_options.txt
b/meson_options.txtindex 0852849..acbcbb8 100644meson_options.txt +0
-0@@ -46,6 +46,8 @@ option('mbuf_refcnt_atomic', type: 'boolean', value:true, description:
Quoted 10 lines
meson_options.txt +0
-0'Atomically access the mbuf refcnt.') option('platform',type: 'string', value: 'native', description:
'Platform to build, either "native", "generic" or a SoC.
Please refer to the Linux build guide for more information.')meson_options.txt +2
-0+option('enable_stdatomics', type: 'boolean', value: false, description: + 'enable use of standard C11 atomics.') option('enable_trace_fp', type: 'boolean', value: false, description: 'enable fast path trace points.') option('tests', type:'boolean', value: true, description:
RE: [PATCH] eal: introduce atomics abstraction
Quoted 15 lines
From: Honnappa Nagarahalli [mailto:[email protected]]
Sent: Wednesday, 1 February 2023 02.08Quoted 4 lines
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PMHonnappa, please could you give your view on the future of atomics in
DPDK?
Thanks Thomas, apologies it has taken me a while to get to this discussion.IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.h(stdatomics as is called here) already serve the purpose. These APIs are well understood and documented.
Quoted 5 lines
For environments where stdatomics are not supported, we could have a
stdatomic.hin DPDK implementing the same APIs (we have to support only_explicitAPIs). This allows the code to use stdatomics APIs and when we move to minimum supported standard C11, we just need to get rid of the file in DPDK repo.
I agree with Honnappa.
DPDK should include a shim to expose the C11 stdatomic.h API for environments not already having the C11 stdatomic.h.
With this, DPDK steps outside its native rte_ prefixed namespace, but it should not collide with anyone else's namespace.
It could collide with someone else's namespace if the application implements a similar shim. We cannot prevent this from happening, but if it does, it should be fixed in the application.
Quoted 9 lines
Quoted 9 lines
12/01/2023 22:26, Tyler Retzlaff:
Quoted 2 lines
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true
option.
Quoted 2 lines
Signed-off-by Tyler Retzlaff <[email protected]>
Re: [PATCH] eal: introduce atomics abstraction
In reply to Honnappa NagarahalliQuoted 10 lines · Honnappa Nagarahalli
Quoted 10 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PM
To: Honnappa Nagarahalli <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Tyler Retzlaff <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] eal: introduce atomics abstraction
Quoted 4 lines
Quoted 1 line
Honnappa, please could you give your view on the future of atomics in DPDK?
Thanks Thomas, apologies it has taken me a while to get to this discussion.
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.h(stdatomics as is called here) already serve the purpose. These APIs are well understood and documented.
i agree that whatever atomics APIs we advocate for should align with the standard C atomics for the reasons you state including implied semantics.
Quoted 2 lines
For environments where stdatomics are not supported, we could have a
stdatomic.hin DPDK implementing the same APIs (we have to support only_explicitAPIs). This allows the code to use stdatomics APIs and when we move to minimum supported standard C11, we just need to get rid of the file in DPDK repo.
my concern with this is that if we provide a stdatomic.h or introduce names from stdatomic.h it's a violation of the C standard.
references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html
in effect the header, the names and in some instances namespaces introduced are reserved by the implementation. there are several reasons in the GNU libc manual that explain the justification for these reservations and if if we think about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX standard implicitly exposed as a part of the EAL public API has been problematic for portability.
let's discuss this from here. if there's still overwhelming desire to go this route then we'll just do our best.
ty
RE: [PATCH] eal: introduce atomics abstraction
Quoted 23 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 1 February 2023 22.41Quoted 5 lines · Honnappa Nagarahalli
Quoted 5 lines
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PMHonnappa, please could you give your view on the future of atomics
in DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to this
discussion.
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.h(stdatomics as is called here) already serve the purpose. These APIs are well understood and documented.
i agree that whatever atomics APIs we advocate for should align with the
standard C atomics for the reasons you state including implied semantics.Quoted 1 line
Quoted 5 lines
Quoted 1 line
For environments where stdatomics are not supported, we could have a
stdatomic.hin DPDK implementing the same APIs (we have to support only_explicitAPIs). This allows the code to use stdatomics APIs and when we move to minimum supported standard C11, we just need to get rid of the file in DPDK repo.
Perhaps we can use something already existing, such as this:
https://android.googlesource.com/platform/bionic/+/lollipop-release/libc/include/stdatomic.h
Quoted 11 lines
my concern with this is that if we provide a
stdatomic.hor introduce names
fromstdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.html
Quoted 6 lines
in effect the header, the names and in some instances namespaces introduced
are reserved by the implementation. there are several reasons in the GNU libc
manual that explain the justification for these reservations and if if we think about ODR and ABI compatibility we can conceive of others.
I we are going to move to C11 soon, I consider the shim interim, and am inclined to ignore these warning factors.
If we are not moving to C11 soon, I would consider these disadvantages more seriously.
Quoted 4 lines
i'll also remark that the inter-mingling of names from the POSIX standard implicitly exposed as a part of the EAL public API has been problematic for portability.
This is a very important remark, which should be considered carefully! Tyler has firsthand experience with DPDK portability. If he thinks porting to Windows is going to be a headache if we expose the stdatomic.h API, we must listen! So, what is your gut feeling here, Tyler?
Quoted 6 lines
let's discuss this from here. if there's still overwhelming desire to go
this route then we'll just do our best.ty
I have a preference for exposing the stdatomic.h API. Tyler listed the disadvantages above. (I also have a preference for moving to C11 soon.)
Exposing a 1:1 similar API with RTE prefixes would also be acceptable for me. The disadvantage is that the names are different than the C11 names, which might lead to some confusion. And from an ABI stability perspective, such an important API should not be marked experimental. This means that years will pass before we can get rid of it again, due to ABI stability policies.
-Morten
Re: [PATCH] eal: introduce atomics abstraction
Quoted 50 lines · Morten Brørup
Quoted 23 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 1 February 2023 22.41Quoted 5 lines · Honnappa Nagarahalli
Quoted 5 lines
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PMHonnappa, please could you give your view on the future of atomics
in DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to this
discussion.
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.h(stdatomics as is called here) already serve the purpose. These APIs are well understood and documented.
i agree that whatever atomics APIs we advocate for should align with the
standard C atomics for the reasons you state including implied semantics.Quoted 1 line
Quoted 5 lines
Quoted 1 line
For environments where stdatomics are not supported, we could have a
stdatomic.hin DPDK implementing the same APIs (we have to support only_explicitAPIs). This allows the code to use stdatomics APIs and when we move to minimum supported standard C11, we just need to get rid of the file in DPDK repo.Perhaps we can use something already existing, such as this:
https://android.googlesource.com/platform/bionic/+/lollipop-release/libc/include/stdatomic.hQuoted 11 lines
my concern with this is that if we provide a
stdatomic.hor introduce names
fromstdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlQuoted 6 lines
in effect the header, the names and in some instances namespaces introduced
are reserved by the implementation. there are several reasons in the GNU libc
manual that explain the justification for these reservations and if if we think about ODR and ABI compatibility we can conceive of others.
Quoted 3 lines
I we are going to move to C11 soon, I consider the shim interim, and am inclined to ignore these warning factors.
If we are not moving to C11 soon, I would consider these disadvantages more seriously.
I think it's reasonable to assume that we are talking years here.
We've had a few discussions about minimum C standard. I think my first mailing list exchanges about C99 was almost 2 years ago. Given that we still aren't on C99 now (though i know Bruce has a series up) indicates that progression to C11 isn't going to happen any time soon and even if it was the baseline we still can't just use it (reasons described later).
Also, i'll point out that we seem to have accepted moving to C99 with one of the holdback compilers technically being non-conformant but it isn't blocking us because it provides the subset of C99 features without being conforming that we happen to be using.
Quoted 7 lines
Quoted 5 lines
i'll also remark that the inter-mingling of names from the POSIX standard implicitly exposed as a part of the EAL public API has been problematic for portability.
This is a very important remark, which should be considered carefully! Tyler has firsthand experience with DPDK portability. If he thinks porting to Windows is going to be a headache if we expose the
stdatomic.hAPI, we must listen! So, what is your gut feeling here, Tyler?
I think this is even more of a concern with language standard than it is with a platform standard. Because the language standard is used across platforms.
On the surface it looks appealing to just go through all the dpdk code one last time and #include <stdatomic.h> and directly depend on names that "look" standard. In practice though we aren't depending on the toolchain / libc surface we are binding ourselves to the shim and the implementation it provides.
This is aside from the mechanics of making it work in the different contexts we now have to care about. Here is a story of how things become tricky.
When i #include <stdatomic.h> which one gets used if the implementation provides one? Let's force our stdatomic.h
Now i need to force the build system to prefer my shim header? Keeping in mind that the presence of a libc stdatomic.h does not mean that the toolchain in fact supports standard atomics. Okay, that's under our control by editing some meson.build files maybe it isn't so bad but...
It seems my application also has to do the same in their build system now because...
The type definitions (size, alignment) and code generated from the body of inline functions as seen by the application built translation units may differ from those in the dpdk translation units if they don't use our header. The potential for ABI compat problems is increasing but maybe it is managable? it can be worse...
We can't limit our scope to thinking that there is just an application (a single binary) and dpdk. Complex applications will invariably depend on other libraries and if the application needs to interface with those compatibily at the ABI level using standard atomics then we've made it very difficult since the application has to choose to use our conflicting named atomic types which may not be compatible or the real standard atomics. They can of course produce horrible shims of their own to interoperate.
We need consistency across the entire binary at runtime and i don't think it's practical to say that anyone who uses dpdk has to compile their whole world with our shim. So dealing with all this complexity for the sake of asthetics "looking" like the standard api seems kind of not worth it. Sure it saves having to deprecate later and one last session of shotgun surgery but that's kind of all we get.
Don't think i'm being biased in favor of windows/msvc here. From the perspective of the windows/msvc combination i intend to use only the standard C ABI provided by the implementation. I have no intention of trying to introduce support for the current ABI that doesn't use the standard atomic types. my discouraging of this approach is about avoiding subtle to detect but very painful problems on {linux,unix}/compiler<version> combinations that already have a shipped/stable ABI.
Quoted 8 lines
Quoted 6 lines
let's discuss this from here. if there's still overwhelming desire to go
this route then we'll just do our best.ty
I have a preference for exposing the
stdatomic.hAPI. Tyler listed the disadvantages above. (I also have a preference for moving to C11 soon.)
I am eager to see this happen, but as explained in my original proposal it doesn't eliminate the need for an abstraction. Unless we are willing to break our compatibility promises and potentially take a performance hit on some platform/compiler combinations which as i understand is not acceptable.
Quoted 2 lines
Exposing a 1:1 similar API with RTE prefixes would also be acceptable for me. The disadvantage is that the names are different than the C11 names, which might lead to some confusion. And from an ABI stability perspective, such an important API should not be marked experimental. This means that years will pass before we can get rid of it again, due to ABI stability policies.
I think the key to success with rte_ prefixed names is making absolutely sure we mirror the semantics and types in the standard.
I will point out one bit of fine print here is that we will not support atomic operations on struct/union types (something the standard supports). With the rte_ namespace i think this becomes less ambiguous, if we present standard C names though what's to avoid the confusion? Aside from it fails to compile with one compiler vs another.
I agree that this may be around for years. But how many years depends a lot on how long we have to maintain compatibility for the existing platform/compiler combinations that can't (and aren't enabled) to use the standard.
Even if we introduced standard names we still have to undergo some kind of mutant deprecation process to get the world to recompile everything against the actual standard, so it doesn't give us forward compatibility.
Let me know what folks would like to do, i guess i'm firmly leaned toward no-shim and just rte_ explicit. But as a community i'll pursue whatever you decide.
Thanks!
RE: [PATCH] eal: introduce atomics abstraction
Quoted 210 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Thursday, 2 February 2023 20.00Quoted 4 lines · Morten Brørup
Quoted 4 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 1 February 2023 22.41On Wed, Feb 01, 2023 at 01:07:59AM +0000, Honnappa Nagarahalli
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PMHonnappa, please could you give your view on the future of
atomics
Quoted 5 lines
Quoted 5 lines
in DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to this
discussion.
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.hQuoted 1 line
Quoted 1 line
(stdatomics as is called here) already serve the purpose. These
APIs
Quoted 3 lines
Quoted 3 lines
are well understood and documented.
i agree that whatever atomics APIs we advocate for should align
with
Quoted 6 lines
Quoted 6 lines
the
standard C atomics for the reasons you state including implied semantics.Quoted 2 lines
For environments where stdatomics are not supported, we could
have a
Quoted 1 line
Quoted 1 line
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 1 line
Quoted 1 line
_explicitAPIs). This allows the code to use stdatomics APIs andwhen
Quoted 1 line
Quoted 1 line
we move to minimum supported standard C11, we just need to get rid
of
Quoted 4 lines
Quoted 1 line
the file in DPDK repo.
Perhaps we can use something already existing, such as this:
https://android.googlesource.com/platform/bionic/+/lollipop-
release/libc/include/stdatomic.hQuoted 3 lines
Quoted 3 lines
my concern with this is that if we provide a
stdatomic.horintroduce
Quoted 9 lines
Quoted 9 lines
names
fromstdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlQuoted 3 lines
Quoted 3 lines
in effect the header, the names and in some instances namespaces introduced
are reserved by the implementation. there are several reasons inthe
Quoted 3 lines
Quoted 3 lines
GNU libc
manual that explain the justification for these reservations and if if we think about ODR and ABI compatibility we can conceive ofothers.
Quoted 2 lines
I we are going to move to C11 soon, I consider the shim interim, and
am inclined to ignore these warning factors.
Quoted 2 lines
If we are not moving to C11 soon, I would consider these
disadvantages more seriously.
I think it's reasonable to assume that we are talking years here.
We've had a few discussions about minimum C standard. I think my first mailing list exchanges about C99 was almost 2 years ago. Given that we still aren't on C99 now (though i know Bruce has a series up) indicates that progression to C11 isn't going to happen any time soon and even if it was the baseline we still can't just use it (reasons described later).
Also, i'll point out that we seem to have accepted moving to C99 with one of the holdback compilers technically being non-conformant but it isn't blocking us because it provides the subset of C99 features without
being conforming that we happen to be using.Quoted 4 lines
Quoted 4 lines
i'll also remark that the inter-mingling of names from the POSIX standard implicitly exposed as a part of the EAL public API has
been
Quoted 3 lines
Quoted 1 line
problematic for portability.
This is a very important remark, which should be considered
carefully! Tyler has firsthand experience with DPDK portability. If he thinks porting to Windows is going to be a headache if we expose the
stdatomic.hAPI, we must listen! So, what is your gut feeling here, Tyler?I think this is even more of a concern with language standard than it is
with a platform standard. Because the language standard is used across platforms.On the surface it looks appealing to just go through all the dpdk code one last time and #include <
stdatomic.h> and directly depend on names that "look" standard. In practice though we aren't depending on the toolchain / libc surface we are binding ourselves to the shim and the implementation it provides.This is aside from the mechanics of making it work in the different contexts we now have to care about. Here is a story of how things become tricky.
When i #include <
stdatomic.h> which one gets used if the implementation provides one? Let's force ourstdatomic.hNow i need to force the build system to prefer my shim header? Keeping in mind that the presence of a libc
stdatomic.hdoes not mean that the toolchain in fact supports standard atomics. Okay, that's under our control by editing some meson.build files maybe it isn't so bad but...It seems my application also has to do the same in their build system now because...
The type definitions (size, alignment) and code generated from the body of inline functions as seen by the application built translation units may differ from those in the dpdk translation units if they don't use our header. The potential for ABI compat problems is increasing but maybe it is managable? it can be worse...
We can't limit our scope to thinking that there is just an application (a single binary) and dpdk. Complex applications will invariably depend on other libraries and if the application needs to interface with those compatibily at the ABI level using standard atomics
then we've made it very difficult since the application has to choose to
use our conflicting named atomic types which may not be compatible or the real standard atomics. They can of course produce horrible shims of their own to interoperate.We need consistency across the entire binary at runtime and i don't think it's practical to say that anyone who uses dpdk has to compile their whole world with our shim. So dealing with all this complexity for the sake of asthetics "looking" like the standard api seems kind of not worth it. Sure it saves having to deprecate later and one last session of shotgun surgery but that's kind of all we get.
Don't think i'm being biased in favor of windows/msvc here. From the perspective of the windows/msvc combination i intend to use only the standard C ABI provided by the implementation. I have no intention of trying to introduce support for the current ABI that doesn't use the standard atomic types. my discouraging of this approach is about avoiding
subtle to detect but very painful problems on {linux,unix}/compiler<version>
combinations that already have a shipped/stable ABI.Quoted 2 lines
Quoted 2 lines
let's discuss this from here. if there's still overwhelming desire
to
Quoted 6 lines
Quoted 4 lines
go
this route then we'll just do our best.ty
I have a preference for exposing the
stdatomic.hAPI. Tyler listedthe disadvantages above. (I also have a preference for moving to C11 soon.)
I am eager to see this happen, but as explained in my original proposal it doesn't eliminate the need for an abstraction. Unless we are willing to break our compatibility promises and potentially take a performance hit on some platform/compiler combinations which as i understand is not acceptable.
Quoted 2 lines
Exposing a 1:1 similar API with RTE prefixes would also be acceptable
for me. The disadvantage is that the names are different than the C11 names, which might lead to some confusion. And from an ABI stability perspective, such an important API should not be marked experimental. This means that years will pass before we can get rid of it again, due to ABI stability policies.
I think the key to success with
rte_prefixed names is making absolutely
sure we mirror the semantics and types in the standard.I will point out one bit of fine print here is that we will not support atomic operations on struct/union types (something the standard supports).
With therte_namespace i think this becomes less ambiguous, if we present
standard C names though what's to avoid the confusion? Aside from it fails
to compile with one compiler vs another.I agree that this may be around for years. But how many years depends a lot on how long we have to maintain compatibility for the existing platform/compiler combinations that can't (and aren't enabled) to use the standard.
Even if we introduced standard names we still have to undergo some kind of mutant deprecation process to get the world to recompile everything against the actual standard, so it doesn't give us forward compatibility.
Quoted 5 lines
Let me know what folks would like to do, i guess i'm firmly leaned toward no-shim and just
rte_explicit. But as a community i'll pursue whatever you decide.Thanks!
Tyler is making a very strong case here.
I have changed my mind, and now support Tyler's approach.
-Morten
Re: [PATCH] eal: introduce atomics abstraction
Quoted 214 lines · Morten Brørup
Quoted 214 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Thursday, 2 February 2023 20.00Quoted 4 lines · Morten Brørup
Quoted 4 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 1 February 2023 22.41On Wed, Feb 01, 2023 at 01:07:59AM +0000, Honnappa Nagarahalli
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PMHonnappa, please could you give your view on the future of
atomics
Quoted 5 lines
Quoted 5 lines
in DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to this
discussion.
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.hQuoted 1 line
Quoted 1 line
(stdatomics as is called here) already serve the purpose. These
APIs
Quoted 3 lines
Quoted 3 lines
are well understood and documented.
i agree that whatever atomics APIs we advocate for should align
with
Quoted 6 lines
Quoted 6 lines
the
standard C atomics for the reasons you state including implied semantics.Quoted 2 lines
For environments where stdatomics are not supported, we could
have a
Quoted 1 line
Quoted 1 line
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 1 line
Quoted 1 line
_explicitAPIs). This allows the code to use stdatomics APIs andwhen
Quoted 1 line
Quoted 1 line
we move to minimum supported standard C11, we just need to get rid
of
Quoted 4 lines
Quoted 1 line
the file in DPDK repo.
Perhaps we can use something already existing, such as this:
https://android.googlesource.com/platform/bionic/+/lollipop-
release/libc/include/stdatomic.hQuoted 3 lines
Quoted 3 lines
my concern with this is that if we provide a
stdatomic.horintroduce
Quoted 9 lines
Quoted 9 lines
names
fromstdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlQuoted 3 lines
Quoted 3 lines
in effect the header, the names and in some instances namespaces introduced
are reserved by the implementation. there are several reasons inthe
Quoted 3 lines
Quoted 3 lines
GNU libc
manual that explain the justification for these reservations and if if we think about ODR and ABI compatibility we can conceive ofothers.
Quoted 2 lines
I we are going to move to C11 soon, I consider the shim interim, and
am inclined to ignore these warning factors.
Quoted 2 lines
If we are not moving to C11 soon, I would consider these
disadvantages more seriously.
I think it's reasonable to assume that we are talking years here.
We've had a few discussions about minimum C standard. I think my first mailing list exchanges about C99 was almost 2 years ago. Given that we still aren't on C99 now (though i know Bruce has a series up) indicates that progression to C11 isn't going to happen any time soon and even if it was the baseline we still can't just use it (reasons described later).
Also, i'll point out that we seem to have accepted moving to C99 with one of the holdback compilers technically being non-conformant but it isn't blocking us because it provides the subset of C99 features without
being conforming that we happen to be using.Quoted 4 lines
Quoted 4 lines
i'll also remark that the inter-mingling of names from the POSIX standard implicitly exposed as a part of the EAL public API has
been
Quoted 3 lines
Quoted 1 line
problematic for portability.
This is a very important remark, which should be considered
carefully! Tyler has firsthand experience with DPDK portability. If he thinks porting to Windows is going to be a headache if we expose the
stdatomic.hAPI, we must listen! So, what is your gut feeling here, Tyler?I think this is even more of a concern with language standard than it is
with a platform standard. Because the language standard is used across platforms.On the surface it looks appealing to just go through all the dpdk code one last time and #include <
stdatomic.h> and directly depend on names that "look" standard. In practice though we aren't depending on the toolchain / libc surface we are binding ourselves to the shim and the implementation it provides.This is aside from the mechanics of making it work in the different contexts we now have to care about. Here is a story of how things become tricky.
When i #include <
stdatomic.h> which one gets used if the implementation provides one? Let's force ourstdatomic.hNow i need to force the build system to prefer my shim header? Keeping in mind that the presence of a libc
stdatomic.hdoes not mean that the toolchain in fact supports standard atomics. Okay, that's under our control by editing some meson.build files maybe it isn't so bad but...It seems my application also has to do the same in their build system now because...
The type definitions (size, alignment) and code generated from the body of inline functions as seen by the application built translation units may differ from those in the dpdk translation units if they don't use our header. The potential for ABI compat problems is increasing but maybe it is managable? it can be worse...
We can't limit our scope to thinking that there is just an application (a single binary) and dpdk. Complex applications will invariably depend on other libraries and if the application needs to interface with those compatibily at the ABI level using standard atomics
then we've made it very difficult since the application has to choose to
use our conflicting named atomic types which may not be compatible or the real standard atomics. They can of course produce horrible shims of their own to interoperate.We need consistency across the entire binary at runtime and i don't think it's practical to say that anyone who uses dpdk has to compile their whole world with our shim. So dealing with all this complexity for the sake of asthetics "looking" like the standard api seems kind of not worth it. Sure it saves having to deprecate later and one last session of shotgun surgery but that's kind of all we get.
Don't think i'm being biased in favor of windows/msvc here. From the perspective of the windows/msvc combination i intend to use only the standard C ABI provided by the implementation. I have no intention of trying to introduce support for the current ABI that doesn't use the standard atomic types. my discouraging of this approach is about avoiding
subtle to detect but very painful problems on {linux,unix}/compiler<version>
combinations that already have a shipped/stable ABI.Quoted 2 lines
Quoted 2 lines
let's discuss this from here. if there's still overwhelming desire
to
Quoted 6 lines
Quoted 4 lines
go
this route then we'll just do our best.ty
I have a preference for exposing the
stdatomic.hAPI. Tyler listedthe disadvantages above. (I also have a preference for moving to C11 soon.)
I am eager to see this happen, but as explained in my original proposal it doesn't eliminate the need for an abstraction. Unless we are willing to break our compatibility promises and potentially take a performance hit on some platform/compiler combinations which as i understand is not acceptable.
Quoted 2 lines
Exposing a 1:1 similar API with RTE prefixes would also be acceptable
for me. The disadvantage is that the names are different than the C11 names, which might lead to some confusion. And from an ABI stability perspective, such an important API should not be marked experimental. This means that years will pass before we can get rid of it again, due to ABI stability policies.
I think the key to success with
rte_prefixed names is making absolutely
sure we mirror the semantics and types in the standard.I will point out one bit of fine print here is that we will not support atomic operations on struct/union types (something the standard supports).
With therte_namespace i think this becomes less ambiguous, if we present
standard C names though what's to avoid the confusion? Aside from it fails
to compile with one compiler vs another.I agree that this may be around for years. But how many years depends a lot on how long we have to maintain compatibility for the existing platform/compiler combinations that can't (and aren't enabled) to use the standard.
Even if we introduced standard names we still have to undergo some kind of mutant deprecation process to get the world to recompile everything against the actual standard, so it doesn't give us forward compatibility.
Let me know what folks would like to do, i guess i'm firmly leaned toward no-shim and just
rte_explicit. But as a community i'll pursue whatever you decide.
Quoted 6 lines
Quoted 1 line
Thanks!
Tyler is making a very strong case here.
I have changed my mind, and now support Tyler's approach.
Having read through the whole thread a second time, I am starting to realise how complex a problem this could be. From what I read, I would tend towards the opinion that we shouldn't provide any atomics in DPDK at all, and just rely on the C standard ones. The main complication in any solution I suspect is going to be the use of atomics in static inline functions we have in our header files.
/Bruce
RE: [PATCH] eal: introduce atomics abstraction
Quoted 9 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 3 February 2023 14.57Having read through the whole thread a second time, I am starting to realise how complex a problem this could be. From what I read, I would tend
towards the opinion that we shouldn't provide any atomics in DPDK at all,
and just rely on the C standard ones.
Yes, but atomics were only standardized for C with C11. So that is the problem - and a good reason for pushing for C11.
Before C11, there were only compiler specific intrinsics.
Quoted 5 lines
The main complication in any
solution
I suspect is going to be the use of atomics in static inline functions we
have in our header files.
Not only that.
If we consider atomic variables (and the type of such variables) private to DPDK, we would need to provide public functions to manipulate those atomic variables. If not, the application will be unable to interact with them.
And if we expose such functions, why not also make the DPDK atomic type itself public? In other words, expose a DPDK API for atomics, such as Tyler's.
(And as I mentioned on the techboard meeting, I think atomic operations should be available in inline code, for performance reasons.)
-Morten
Re: [PATCH] eal: introduce atomics abstraction
In reply to Tyler RetzlaffQuoted 64 lines · Tyler Retzlaff
Quoted 50 lines · Morten Brørup
Quoted 23 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 1 February 2023 22.41Quoted 5 lines · Honnappa Nagarahalli
Quoted 5 lines
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PMHonnappa, please could you give your view on the future of atomics
in DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to this
discussion.
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.h(stdatomics as is called here) already serve the purpose. These APIs are well understood and documented.
i agree that whatever atomics APIs we advocate for should align with the
standard C atomics for the reasons you state including implied semantics.Quoted 1 line
Quoted 5 lines
Quoted 1 line
For environments where stdatomics are not supported, we could have a
stdatomic.hin DPDK implementing the same APIs (we have to support only_explicitAPIs). This allows the code to use stdatomics APIs and when we move to minimum supported standard C11, we just need to get rid of the file in DPDK repo.Perhaps we can use something already existing, such as this:
https://android.googlesource.com/platform/bionic/+/lollipop-release/libc/include/stdatomic.hQuoted 11 lines
my concern with this is that if we provide a
stdatomic.hor introduce names
fromstdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlQuoted 6 lines
in effect the header, the names and in some instances namespaces introduced
are reserved by the implementation. there are several reasons in the GNU libc
manual that explain the justification for these reservations and if if we think about ODR and ABI compatibility we can conceive of others.Quoted 3 lines
I we are going to move to C11 soon, I consider the shim interim, and am inclined to ignore these warning factors.
If we are not moving to C11 soon, I would consider these disadvantages more seriously.
I think it's reasonable to assume that we are talking years here.
We've had a few discussions about minimum C standard. I think my first mailing list exchanges about C99 was almost 2 years ago. Given that we still aren't on C99 now (though i know Bruce has a series up) indicates that progression to C11 isn't going to happen any time soon and even if it was the baseline we still can't just use it (reasons described later).
Quoted 5 lines
Also, i'll point out that we seem to have accepted moving to C99 with one of the holdback compilers technically being non-conformant but it isn't blocking us because it provides the subset of C99 features without being conforming that we happen to be using.
What compiler is this? As far as I know, all our currently support compilers claim to support C99 fully. All should support C11 also, except for GCC 4.8 on RHEL/CentOS 7. Once we drop support for Centos 7, I think we can require at minimum a c11 compiler for building DPDK itself. I'm still a little uncertain about requiring that users build their own code with -std=c11, though.
/Bruce
Re: [PATCH] eal: introduce atomics abstraction
Quoted 70 lines · Bruce Richardson
Quoted 64 lines · Tyler Retzlaff
Quoted 50 lines · Morten Brørup
Quoted 23 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 1 February 2023 22.41Quoted 5 lines · Honnappa Nagarahalli
Quoted 5 lines
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PMHonnappa, please could you give your view on the future of atomics
in DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to this
discussion.
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.h(stdatomics as is called here) already serve the purpose. These APIs are well understood and documented.
i agree that whatever atomics APIs we advocate for should align with the
standard C atomics for the reasons you state including implied semantics.Quoted 1 line
Quoted 5 lines
Quoted 1 line
For environments where stdatomics are not supported, we could have a
stdatomic.hin DPDK implementing the same APIs (we have to support only_explicitAPIs). This allows the code to use stdatomics APIs and when we move to minimum supported standard C11, we just need to get rid of the file in DPDK repo.Perhaps we can use something already existing, such as this:
https://android.googlesource.com/platform/bionic/+/lollipop-release/libc/include/stdatomic.hQuoted 11 lines
my concern with this is that if we provide a
stdatomic.hor introduce names
fromstdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlQuoted 6 lines
in effect the header, the names and in some instances namespaces introduced
are reserved by the implementation. there are several reasons in the GNU libc
manual that explain the justification for these reservations and if if we think about ODR and ABI compatibility we can conceive of others.Quoted 3 lines
I we are going to move to C11 soon, I consider the shim interim, and am inclined to ignore these warning factors.
If we are not moving to C11 soon, I would consider these disadvantages more seriously.
I think it's reasonable to assume that we are talking years here.
We've had a few discussions about minimum C standard. I think my first mailing list exchanges about C99 was almost 2 years ago. Given that we still aren't on C99 now (though i know Bruce has a series up) indicates that progression to C11 isn't going to happen any time soon and even if it was the baseline we still can't just use it (reasons described later).
Quoted 5 lines
Also, i'll point out that we seem to have accepted moving to C99 with one of the holdback compilers technically being non-conformant but it isn't blocking us because it provides the subset of C99 features without being conforming that we happen to be using.
Quoted 6 lines
What compiler is this? As far as I know, all our currently support compilers claim to support C99 fully. All should support C11 also, except for GCC 4.8 on RHEL/CentOS 7. Once we drop support for Centos 7, I think we can require at minimum a c11 compiler for building DPDK itself. I'm still a little uncertain about requiring that users build their own code with -std=c11, though.
perhaps i'm mistaken but it was my understanding that the gcc version on RHEL 7 did not fully conform to C99? maybe i read C99 when it was actually C11.
regardless, even if every supported compiler for dpdk was C11 conformant including stdatomics which are optional we can't just move from intrinsic/builtins to standard C atomics (because of the compatibility and performance issues mentioned previously).
so just re-orienting this discussion, the purpose of this abstraction is to allow the optional use of standard C atomics when a conformant compiler is available and satisfactory code is generated for the desired target.
Quoted 2 lines
/Bruce
RE: [PATCH] eal: introduce atomics abstraction
Quoted 106 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Friday, 3 February 2023 21.49Quoted 6 lines · Bruce Richardson
Quoted 5 lines · Tyler Retzlaff
Quoted 4 lines · Morten Brørup
Quoted 4 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 1 February 2023 22.41On Wed, Feb 01, 2023 at 01:07:59AM +0000, Honnappa Nagarahalli
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PMHonnappa, please could you give your view on the future of
atomics
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
in DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to
this
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
discussion.
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.hQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
(stdatomics as is called here) already serve the purpose. These
APIs
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
are well understood and documented.
i agree that whatever atomics APIs we advocate for should align
with
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
the
standard C atomics for the reasons you state including implied semantics.Quoted 2 lines
For environments where stdatomics are not supported, we could
have a
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
stdatomic.hin DPDK implementing the same APIs (we have tosupport only
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
_explicitAPIs). This allows the code to use stdatomics APIsand when
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
we move to minimum supported standard C11, we just need to get
rid of
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
the file in DPDK repo.
Perhaps we can use something already existing, such as this:
https://android.googlesource.com/platform/bionic/+/lollipop-
release/libc/include/stdatomic.hQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
my concern with this is that if we provide a
stdatomic.horintroduce
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
names
fromstdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlin effect the header, the names and in some instances
namespaces
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
introduced
are reserved by the implementation. there are several reasonsin the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
GNU libc
manual that explain the justification for these reservationsand if
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
if we think about ODR and ABI compatibility we can conceive of
others.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I we are going to move to C11 soon, I consider the shim interim,
and am inclined to ignore these warning factors.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
If we are not moving to C11 soon, I would consider these
disadvantages more seriously.
Quoted 4 lines
Quoted 4 lines
I think it's reasonable to assume that we are talking years here.
We've had a few discussions about minimum C standard. I think my
first
Quoted 1 line
Quoted 1 line
mailing list exchanges about C99 was almost 2 years ago. Given that
we
Quoted 1 line
Quoted 1 line
still aren't on C99 now (though i know Bruce has a series up)
indicates
Quoted 1 line
Quoted 1 line
that progression to C11 isn't going to happen any time soon and
even if
Quoted 4 lines
Quoted 4 lines
it was the baseline we still can't just use it (reasons described later).
Also, i'll point out that we seem to have accepted moving to C99
with
Quoted 1 line
Quoted 1 line
one of the holdback compilers technically being non-conformant but
it
Quoted 1 line
Quoted 1 line
isn't blocking us because it provides the subset of C99 features
without
Quoted 5 lines
Quoted 2 lines
being conforming that we happen to be using.
What compiler is this? As far as I know, all our currently support compilers claim to support C99 fully. All should support C11 also, except for GCC 4.8 on RHEL/CentOS 7. Once we drop support for Centos
7, I
Quoted 1 line
think we can require at minimum a c11 compiler for building DPDK
itself.
Quoted 1 line
I'm still a little uncertain about requiring that users build their
Quoted 8 lines
own
Quoted 1 line
code with -std=c11, though.
perhaps i'm mistaken but it was my understanding that the gcc version on
RHEL 7 did not fully conform to C99? maybe i read C99 when it was actually
C11.
RHEL does supports C99, it's C11 that it doesn't support [1].
[1]: http://inbox.dpdk.org/dev/[email protected]/
Quoted 6 lines
regardless, even if every supported compiler for dpdk was C11 conformant
including stdatomics which are optional we can't just move from intrinsic/builtins to standard C atomics (because of the compatibility and performance issues mentioned previously).
For example, with C11, you can make structures atomic. And an atomic instance of a type can have a different size than the non-atomic type.
If do we make a shim, it will have some limitations compared to C11 atomics, e.g. it cannot handle atomic structures.
Either we accept these limitations of the shim, or we use our own namespace. If we accept the limitations, we risk that someone with a C11 build environment uses them anyway, and it will not work in non-C11 build environments. So a shim is not a rose without thorns.
Quoted 6 lines
so just re-orienting this discussion, the purpose of this abstraction is
to allow the optional use of standard C atomics when a conformant compiler
is available and satisfactory code is generated for the desired target.
I think it is more important getting this feature into DPDK than using the C11 stdatomic.h API for atomics in DPDK.
I don't feel strongly about this API, and will accept either the proposed patch series (with the C11-like API, but rte_ prefixed namespace), or a C11 stdatomic.h API shim.
Re: [PATCH] eal: introduce atomics abstraction
Quoted 126 lines · Morten Brørup
Quoted 106 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Friday, 3 February 2023 21.49Quoted 6 lines · Bruce Richardson
Quoted 5 lines · Tyler Retzlaff
Quoted 4 lines · Morten Brørup
Quoted 4 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 1 February 2023 22.41On Wed, Feb 01, 2023 at 01:07:59AM +0000, Honnappa Nagarahalli
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 31, 2023 4:42 PMHonnappa, please could you give your view on the future of
atomics
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
in DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to
this
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
discussion.
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.hQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
(stdatomics as is called here) already serve the purpose. These
APIs
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
are well understood and documented.
i agree that whatever atomics APIs we advocate for should align
with
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
the
standard C atomics for the reasons you state including implied semantics.Quoted 2 lines
For environments where stdatomics are not supported, we could
have a
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
stdatomic.hin DPDK implementing the same APIs (we have tosupport only
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
_explicitAPIs). This allows the code to use stdatomics APIsand when
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
we move to minimum supported standard C11, we just need to get
rid of
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
the file in DPDK repo.
Perhaps we can use something already existing, such as this:
https://android.googlesource.com/platform/bionic/+/lollipop-
release/libc/include/stdatomic.hQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
my concern with this is that if we provide a
stdatomic.horintroduce
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
names
fromstdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlin effect the header, the names and in some instances
namespaces
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
introduced
are reserved by the implementation. there are several reasonsin the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
GNU libc
manual that explain the justification for these reservationsand if
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
if we think about ODR and ABI compatibility we can conceive of
others.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I we are going to move to C11 soon, I consider the shim interim,
and am inclined to ignore these warning factors.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
If we are not moving to C11 soon, I would consider these
disadvantages more seriously.
Quoted 4 lines
Quoted 4 lines
I think it's reasonable to assume that we are talking years here.
We've had a few discussions about minimum C standard. I think my
first
Quoted 1 line
Quoted 1 line
mailing list exchanges about C99 was almost 2 years ago. Given that
we
Quoted 1 line
Quoted 1 line
still aren't on C99 now (though i know Bruce has a series up)
indicates
Quoted 1 line
Quoted 1 line
that progression to C11 isn't going to happen any time soon and
even if
Quoted 4 lines
Quoted 4 lines
it was the baseline we still can't just use it (reasons described later).
Also, i'll point out that we seem to have accepted moving to C99
with
Quoted 1 line
Quoted 1 line
one of the holdback compilers technically being non-conformant but
it
Quoted 1 line
Quoted 1 line
isn't blocking us because it provides the subset of C99 features
without
Quoted 5 lines
Quoted 2 lines
being conforming that we happen to be using.
What compiler is this? As far as I know, all our currently support compilers claim to support C99 fully. All should support C11 also, except for GCC 4.8 on RHEL/CentOS 7. Once we drop support for Centos
7, I
Quoted 1 line
think we can require at minimum a c11 compiler for building DPDK
itself.
Quoted 1 line
I'm still a little uncertain about requiring that users build their
Quoted 8 lines
own
Quoted 1 line
code with -std=c11, though.
perhaps i'm mistaken but it was my understanding that the gcc version on
RHEL 7 did not fully conform to C99? maybe i read C99 when it was actually
C11.RHEL does supports C99, it's C11 that it doesn't support [1].
[1]: http://inbox.dpdk.org/dev/[email protected]/
Quoted 6 lines
regardless, even if every supported compiler for dpdk was C11 conformant
including stdatomics which are optional we can't just move from intrinsic/builtins to standard C atomics (because of the compatibility and performance issues mentioned previously).
Quoted 3 lines
For example, with C11, you can make structures atomic. And an atomic instance of a type can have a different size than the non-atomic type.
If do we make a shim, it will have some limitations compared to C11 atomics, e.g. it cannot handle atomic structures.
right, so it "looks" like standard but then doesn't work like standard.
Quoted 2 lines
Either we accept these limitations of the shim, or we use our own namespace. If we accept the limitations, we risk that someone with a C11 build environment uses them anyway, and it will not work in non-C11 build environments. So a shim is not a rose without thorns.
the standard says even integer types can have different alignment and size so it isn't strictly portable to replace any integer type with the similar _Atomic type. here is an example of something i would prefer not to have to navigate which using a shim would sign us up for.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65146
Quoted 10 lines
Quoted 6 lines
so just re-orienting this discussion, the purpose of this abstraction is
to allow the optional use of standard C atomics when a conformant compiler
is available and satisfactory code is generated for the desired target.I think it is more important getting this feature into DPDK than using the C11
stdatomic.hAPI for atomics in DPDK.I don't feel strongly about this API, and will accept either the proposed patch series (with the C11-like API, but
rte_prefixed namespace), or a C11stdatomic.hAPI shim.
let's just stay out of the standard namespace, it doesn't buy us the forward compatibility we want and being explicit in the namespace makes it obvious that we aren't.
ty
RE: [PATCH] eal: introduce atomics abstraction
In reply to Tyler Retzlaff<snip>
Quoted 11 lines
Quoted 2 lines
Quoted 2 lines
Honnappa, please could you give your view on the future of atomics in
DPDK?
Quoted 3 lines
Thanks Thomas, apologies it has taken me a while to get to this discussion.
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.h(stdatomics as is called here) already serve the purpose. These APIs are well understood and documented.
i agree that whatever atomics APIs we advocate for should align with the standard C atomics for the reasons you state including implied semantics.
Another point I want to make is, we need 'xxx_explicit' APIs only, as we want memory ordering explicitly provided at each call site. (This can be discussed later).
Quoted 11 lines
Quoted 3 lines
For environments where stdatomics are not supported, we could have a
stdatomic.hin DPDK implementing the same APIs (we have to support only_explicitAPIs). This allows the code to use stdatomics APIs and when we move to minimum supported standard C11, we just need to get rid of the file in DPDK repo.my concern with this is that if we provide a
stdatomic.hor introduce names fromstdatomic.hit's a violation of the C standard.
Quoted 8 lines
references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlin effect the header, the names and in some instances namespaces introduced are reserved by the implementation. there are several reasons in the GNU libc
Wouldn't this apply only after the particular APIs were introduced? i.e. it should not apply if the compiler does not support stdatomics.
Quoted 6 lines
manual that explain the justification for these reservations and if if we think about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX standard implicitly exposed as a part of the EAL public API has been problematic for portability.
These should be exposed as EAL APIs only when compiled with a compiler that does not support stdatomics.
Quoted 5 lines
let's discuss this from here. if there's still overwhelming desire to go this route then we'll just do our best.
ty
Re: [PATCH] eal: introduce atomics abstraction
Quoted 7 lines · Honnappa Nagarahalli
<snip>
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Honnappa, please could you give your view on the future of atomics in
DPDK?
Quoted 2 lines
Thanks Thomas, apologies it has taken me a while to get to this discussion.
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.h(stdatomics as is called here) already serve the purpose. These APIs are well understood and documented.
i agree that whatever atomics APIs we advocate for should align with the standard C atomics for the reasons you state including implied semantics.
Another point I want to make is, we need '
xxx_explicit' APIs only, as we want memory ordering explicitly provided at each call site. (This can be discussed later).
i don't have any issue with removing the non-explicit versions. they're just just convenience for seq_cst anyway. if people don't want them we don't have to have them.
Quoted 18 lines
Quoted 18 lines
Quoted 4 lines
For environments where stdatomics are not supported, we could have a
stdatomic.hin DPDK implementing the same APIs (we have to support only_explicitAPIs). This allows the code to use stdatomics APIs and when we move to minimum supported standard C11, we just need to get rid of the file in DPDK repo.my concern with this is that if we provide a
stdatomic.hor introduce names fromstdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.html
Quoted 3 lines
Quoted 2 lines
in effect the header, the names and in some instances namespaces introduced are reserved by the implementation. there are several reasons in the GNU libc
Wouldn't this apply only after the particular APIs were introduced? i.e. it should not apply if the compiler does not support stdatomics.
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 8 lines
Quoted 7 lines
manual that explain the justification for these reservations and if if we think about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX standard implicitly exposed as a part of the EAL public API has been problematic for portability.
These should be exposed as EAL APIs only when compiled with a compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time. i.e. basically the model of any dpdk-dev package on any linux distribution.
if dpdk is built without real stdatomic types but the application has to interoperate with a different kit or library that does they would be forced to dance around dpdk with their own version of a shim to hide our faked up stdatomics.
Quoted 6 lines
Quoted 6 lines
let's discuss this from here. if there's still overwhelming desire to go this route then we'll just do our best.
ty
RE: [PATCH] eal: introduce atomics abstraction
Quoted 22 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 8 February 2023 02.21Quoted 4 lines · Honnappa Nagarahalli
<snip>
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Honnappa, please could you give your view on the future of
atomics in
Quoted 2 lines
Quoted 2 lines
DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to this
discussion.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.hQuoted 1 line
Quoted 1 line
(stdatomics as is called here) already serve the purpose. These
APIs are well
Quoted 3 lines
Quoted 3 lines
understood and documented.
i agree that whatever atomics APIs we advocate for should align
with the
Quoted 1 line
Quoted 1 line
standard C atomics for the reasons you state including implied
Quoted 8 lines
semantics.
Quoted 1 line
Another point I want to make is, we need '
xxx_explicit' APIs only, aswe want memory ordering explicitly provided at each call site. (This can be discussed later).
i don't have any issue with removing the non-explicit versions. they're just just convenience for
seq_cstanyway. if people don't want them we don't have to have them.
I agree with Honnappa on this point.
The non-explicit versions are for lazy (or not so experienced) developers, and might impact performance if used instead of the correct explicit versions.
I'm working on porting some of our application code from DPDK's rte_atomic32 operations to modern atomics, and I'm temporarily using acq_rel with a FIXME comment on each operation until I have the overview to determine if another memory order is better for each operation. And if I don't get around to fixing the memory order, it is still a step in the right direct direction to get rid of the old __sync based atomics; and the FIXME's remain to be fixed in a later release.
So here's an idea: Alternatively to omitting the non-explicit versions, we could include them for application developers, but document them as placeholders for "memory order to be determined later" and emit a warning when used. It might speed up the transition away from old atomic operations. Alternatively, we risk thoughtless use of seq_cst with the explicit versions, which might be difficult to detect in code reviews.
Either way, with or without non-explicit versions, is fine with me.
Quoted 54 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
For environments where stdatomics are not supported, we could
have a
Quoted 1 line
Quoted 1 line
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 1 line
Quoted 1 line
_explicitAPIs). This allows the code to use stdatomics APIs andwhen we move
Quoted 1 line
Quoted 1 line
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 3 lines
Quoted 3 lines
repo.
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 9 lines
Quoted 9 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlin effect the header, the names and in some instances namespaces
introduced
Quoted 1 line
Quoted 1 line
are reserved by the implementation. there are several reasons in
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were introduced?
i.e. it should not apply if the compiler does not support stdatomics.
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 2 lines
Quoted 2 lines
manual that explain the justification for these reservations and if
if we think
Quoted 3 lines
Quoted 3 lines
about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX
standard
Quoted 1 line
Quoted 1 line
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 2 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time.
i.e. basically the model of any dpdk-dev package on any linux distribution.
Quoted 7 lines
if dpdk is built without real stdatomic types but the application has to
interoperate with a different kit or library that does they would be forced
to dance around dpdk with their own version of a shim to hide our faked up stdatomics.
So basically, if we want a binary DPDK distribution to be compatible with a separate application build environment, they both have to implement atomics the same way, i.e. agree on the ABI for atomics.
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application build environment to support C11 stdatomics.
2. Provide our own DPDK atomics library.
(As mentioned by Tyler, the third option - using C11 stdatomics inside DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
I strongly want atomics to be available for use across inline and compiled code; i.e. it must be possible for both compiled DPDK functions and inline functions to perform atomic transactions on the same atomic variable.
So either we upgrade the DPDK build requirements to support C11 (including the optional stdatomics), or we provide our own DPDK atomics.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
let's discuss this from here. if there's still overwhelming desire
to go this route
Quoted 3 lines
Quoted 3 lines
then we'll just do our best.
ty
Re: [PATCH] eal: introduce atomics abstraction
Quoted 31 lines · Morten Brørup
Quoted 22 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 8 February 2023 02.21Quoted 4 lines · Honnappa Nagarahalli
<snip>
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Honnappa, please could you give your view on the future of
atomics in
Quoted 2 lines
Quoted 2 lines
DPDK?
Quoted 1 line
Thanks Thomas, apologies it has taken me a while to get to this
discussion.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
IMO, we do not need DPDK's own abstractions. APIs from
stdatomic.hQuoted 1 line
Quoted 1 line
(stdatomics as is called here) already serve the purpose. These
APIs are well
Quoted 3 lines
Quoted 3 lines
understood and documented.
i agree that whatever atomics APIs we advocate for should align
with the
Quoted 1 line
Quoted 1 line
standard C atomics for the reasons you state including implied
Quoted 8 lines
semantics.
Quoted 1 line
Another point I want to make is, we need '
xxx_explicit' APIs only, aswe want memory ordering explicitly provided at each call site. (This can be discussed later).
i don't have any issue with removing the non-explicit versions. they're just just convenience for
seq_cstanyway. if people don't want them we don't have to have them.
Quoted 7 lines
I agree with Honnappa on this point.
The non-explicit versions are for lazy (or not so experienced) developers, and might impact performance if used instead of the correct explicit versions.
I'm working on porting some of our application code from DPDK's
rte_atomic32operations to modern atomics, and I'm temporarily usingacq_relwith a FIXME comment on each operation until I have the overview to determine if another memory order is better for each operation. And if I don't get around to fixing the memory order, it is still a step in the right direct direction to get rid of the old__syncbased atomics; and the FIXME's remain to be fixed in a later release.So here's an idea: Alternatively to omitting the non-explicit versions, we could include them for application developers, but document them as placeholders for "memory order to be determined later" and emit a warning when used. It might speed up the transition away from old atomic operations. Alternatively, we risk thoughtless use of
seq_cstwith the explicit versions, which might be difficult to detect in code reviews.
i think it may be cleaner to ust remove the non-explicit versions. if we are publishing api in the rte_xxx namespace then there are no pre-existing expectations that they are present.
it also reduces the api surface that eventually gets retired ~years from now when all ports and compilers in the matrix are std=C11.
i'll update the patch accordingly just so we have a visual.
Quoted 67 lines
Either way, with or without non-explicit versions, is fine with me.
Quoted 54 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
For environments where stdatomics are not supported, we could
have a
Quoted 1 line
Quoted 1 line
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 1 line
Quoted 1 line
_explicitAPIs). This allows the code to use stdatomics APIs andwhen we move
Quoted 1 line
Quoted 1 line
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 3 lines
Quoted 3 lines
repo.
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 9 lines
Quoted 9 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlin effect the header, the names and in some instances namespaces
introduced
Quoted 1 line
Quoted 1 line
are reserved by the implementation. there are several reasons in
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were introduced?
i.e. it should not apply if the compiler does not support stdatomics.
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 2 lines
Quoted 2 lines
manual that explain the justification for these reservations and if
if we think
Quoted 3 lines
Quoted 3 lines
about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX
standard
Quoted 1 line
Quoted 1 line
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 2 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time.
i.e. basically the model of any dpdk-dev package on any linux distribution.Quoted 7 lines
if dpdk is built without real stdatomic types but the application has to
interoperate with a different kit or library that does they would be forced
to dance around dpdk with their own version of a shim to hide our faked up stdatomics.So basically, if we want a binary DPDK distribution to be compatible with a separate application build environment, they both have to implement atomics the same way, i.e. agree on the ABI for atomics.
Quoted 8 lines
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application build environment to support C11 stdatomics.
2. Provide our own DPDK atomics library.(As mentioned by Tyler, the third option - using C11 stdatomics inside DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
I strongly want atomics to be available for use across inline and compiled code; i.e. it must be possible for both compiled DPDK functions and inline functions to perform atomic transactions on the same atomic variable.
i consider it a mandatory requirement. i don't see practically how we could withdraw existing use and even if we had clean way i don't see why we would want to. so this item is defintely settled if you were concerned.
Quoted 2 lines
So either we upgrade the DPDK build requirements to support C11 (including the optional stdatomics), or we provide our own DPDK atomics.
i think the issue of requiring a toolchain conformant to a specific standard is a separate matter because any adoption of C11 standard atomics is a potential abi break from the current use of intrinsics.
the abstraction (whatever namespace it resides) allows the existing toolchain/platform combinations to maintain compatibility by defaulting to current non-standard intrinsics.
once in place it provides an opportunity to introduce new toolchain/platform combinations and enables an opt-in capability to use stdatomics on existing toolchain/platform combinations subject to community discussion on how/if/when.
it would be good to get more participants into the discussion so i'll cc techboard for some attention. i feel like the only area that isn't decided is to do or not do this in rte_ namespace.
i'm strongly in favor of rte_ namespace after discussion, mainly due to to disadvantages of trying to overlap with the standard namespace while not providing a compatible api/abi and because it provides clear disambiguation of that difference in semantics and compatibility with the standard api.
so far i've noted the following
* we will not provide the non-explicit apis.
* we will make no attempt to support operate on struct/union atomics with our apis.
* we will mirror the standard api potentially in the rte_ namespace to
- reference the standard api documentation.
- assume compatible semantics (sans exceptions from first 2 points).
my vote is to remove 'potentially' from the last point above for reasons previously discussed in postings to the mail thread.
thanks all for the discussion, i'll send up a patch removing non-explicit apis for viewing.
ty
RE: [PATCH] eal: introduce atomics abstraction
<snip>
Quoted 75 lines
Quoted 55 lines
Quoted 55 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
For environments where stdatomics are not supported, we could
have a
Quoted 2 lines
Quoted 2 lines
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 1 line
Quoted 1 line
_explicitAPIs). This allows the code to use stdatomics APIs andwhen we move
Quoted 2 lines
Quoted 2 lines
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 3 lines
Quoted 3 lines
repo.
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 9 lines
Quoted 9 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlin effect the header, the names and in some instances namespaces
introduced
Quoted 1 line
Quoted 1 line
are reserved by the implementation. there are several reasons in
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were introduced?
i.e. it should not apply if the compiler does not support stdatomics.
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 3 lines
Quoted 3 lines
manual that explain the justification for these reservations and if
if we think
Quoted 3 lines
Quoted 3 lines
about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX
standard
Quoted 1 line
Quoted 1 line
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 2 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time.
i.e. basically the model of any dpdk-dev package on any linux distribution.Quoted 7 lines
Quoted 5 lines
if dpdk is built without real stdatomic types but the application has to interoperate with a different kit or library that does they would be forced to dance around dpdk with their own version of a shim to hide our faked up stdatomics.
So basically, if we want a binary DPDK distribution to be compatible with a
separate application build environment, they both have to implement atomics the same way, i.e. agree on the ABI for atomics.
Quoted 4 lines
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application build
environment to support C11 stdatomics.
Quoted 6 lines
2. Provide our own DPDK atomics library.
(As mentioned by Tyler, the third option - using C11 stdatomics inside DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
Quoted 7 lines
Quoted 1 line
I strongly want atomics to be available for use across inline and compiled
code; i.e. it must be possible for both compiled DPDK functions and inline functions to perform atomic transactions on the same atomic variable.
i consider it a mandatory requirement. i don't see practically how we could withdraw existing use and even if we had clean way i don't see why we would want to. so this item is defintely settled if you were concerned.
I think I agree here.
Quoted 8 lines
Quoted 3 lines
So either we upgrade the DPDK build requirements to support C11 (including
the optional stdatomics), or we provide our own DPDK atomics.
i think the issue of requiring a toolchain conformant to a specific standard is a separate matter because any adoption of C11 standard atomics is a potential abi break from the current use of intrinsics.
I am not sure why you are calling it as ABI break. Referring to [1], I just see wrappers around intrinsics (though [2] does not use the intrinsics).
[1] https://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/stdatomic.h
[2] https://github.com/llvm-mirror/clang/blob/master/lib/Headers/stdatomic.h
Quoted 4 lines
the abstraction (whatever namespace it resides) allows the existing toolchain/platform combinations to maintain compatibility by defaulting to current non-standard intrinsics.
How about using the intrinsics (__atomic_xxx) name space for abstraction? This covers the GCC and Clang compilers. If there is another platform that uses the same name space for something else, I think DPDK should not be supporting that platform. What problems do you see?
Quoted 10 lines
once in place it provides an opportunity to introduce new toolchain/platform combinations and enables an opt-in capability to use stdatomics on existing toolchain/platform combinations subject to community discussion on how/if/when.
it would be good to get more participants into the discussion so i'll cc techboard for some attention. i feel like the only area that isn't decided is to do or not do this in
rte_namespace.
Quoted 8 lines
i'm strongly in favor of
rte_namespace after discussion, mainly due to to disadvantages of trying to overlap with the standard namespace while not providing a compatible api/abi and because it provides clear disambiguation of that difference in semantics and compatibility with the standard api.so far i've noted the following
* we will not provide the non-explicit apis.
+1
Quoted 2 lines
* we will make no attempt to support operate on struct/union atomics with our apis.
+1
Quoted 11 lines
* we will mirror the standard api potentially in the
rte_namespace to
- reference the standard api documentation.
- assume compatible semantics (sans exceptions from first 2 points).my vote is to remove 'potentially' from the last point above for reasons previously discussed in postings to the mail thread.
thanks all for the discussion, i'll send up a patch removing non-explicit apis for viewing.
ty
RE: [PATCH] eal: introduce atomics abstraction
Quoted 119 lines
From: Honnappa Nagarahalli [mailto:[email protected]]
Sent: Thursday, 9 February 2023 01.17<snip>
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
For environments where stdatomics are not supported, we
could
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
have a
Quoted 2 lines
Quoted 2 lines
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 1 line
Quoted 1 line
_explicitAPIs). This allows the code to use stdatomics APIsand
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
when we move
Quoted 2 lines
Quoted 2 lines
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 2 lines
Quoted 2 lines
repo.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 6 lines
Quoted 6 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manualhttps://www.gnu.org/software/libc/manual/html_node/Reserved-
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Names.html
in effect the header, the names and in some instances
namespaces
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
introduced
Quoted 1 line
Quoted 1 line
are reserved by the implementation. there are several reasons
in
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were
introduced?
Quoted 1 line
Quoted 1 line
Quoted 1 line
i.e. it should not apply if the compiler does not support
stdatomics.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 2 lines
Quoted 2 lines
manual that explain the justification for these reservations
and
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
if
if we think
Quoted 3 lines
Quoted 3 lines
about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the
POSIX
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
standard
Quoted 1 line
Quoted 1 line
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 2 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the
same
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
time.
i.e. basically the model of any dpdk-dev package on any linux distribution.if dpdk is built without real stdatomic types but the application has to interoperate with a different kit or library that does
they
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
would be forced to dance around dpdk with their own version of a shim to hide our faked up stdatomics.
So basically, if we want a binary DPDK distribution to be
compatible with a
Quoted 1 line
separate application build environment, they both have to implement
atomics
Quoted 5 lines
the same way, i.e. agree on the ABI for atomics.
Quoted 4 lines
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application
build
Quoted 4 lines
environment to support C11 stdatomics.
Quoted 3 lines
2. Provide our own DPDK atomics library.
(As mentioned by Tyler, the third option - using C11 stdatomics
inside
Quoted 4 lines
Quoted 4 lines
DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
I strongly want atomics to be available for use across inline and
compiled
Quoted 1 line
code; i.e. it must be possible for both compiled DPDK functions and
inline
Quoted 3 lines
functions to perform atomic transactions on the same atomic variable.
i consider it a mandatory requirement. i don't see practically how we
could
Quoted 1 line
withdraw existing use and even if we had clean way i don't see why we
would
Quoted 1 line
want to. so this item is defintely settled if you were concerned.
I think I agree here.
Quoted 3 lines
Quoted 3 lines
So either we upgrade the DPDK build requirements to support C11
(including
Quoted 3 lines
the optional stdatomics), or we provide our own DPDK atomics.
i think the issue of requiring a toolchain conformant to a specific
standard is a
Quoted 1 line
separate matter because any adoption of C11 standard atomics is a
potential
Quoted 1 line
abi break from the current use of intrinsics.
Quoted 8 lines
I am not sure why you are calling it as ABI break. Referring to [1], I just see wrappers around intrinsics (though [2] does not use the intrinsics).
[1] https://github.com/gcc-
mirror/gcc/blob/master/gcc/ginclude/stdatomic.h
[2] https://github.com/llvm-mirror/clang/blob/master/lib/Headers/stdatomic.h
Good input, Honnappa.
This means that the ABI break is purely academic, and there is no ABI breakage in reality.
Since the underlying implementation is the same, it is perfectly OK to mix C11 and intrinsic atomics, even when the DPDK and the application are built in different environments (with and without C11 atomics, or vice versa).
This eliminates my only remaining practical concern about this approach.
Quoted 58 lines
Quoted 4 lines
the abstraction (whatever namespace it resides) allows the existing toolchain/platform combinations to maintain compatibility by
defaulting to
Quoted 1 line
current non-standard intrinsics.
How about using the intrinsics (
__atomic_xxx) name space for abstraction? This covers the GCC and Clang compilers.
If there is another platform that uses the same name space for something else, I think DPDK should not be supporting that platform. What problems do you see?Quoted 2 lines
once in place it provides an opportunity to introduce new
toolchain/platform
Quoted 1 line
combinations and enables an opt-in capability to use stdatomics on
existing
Quoted 4 lines
toolchain/platform combinations subject to community discussion on how/if/when.
it would be good to get more participants into the discussion so i'll
cc techboard
Quoted 1 line
for some attention. i feel like the only area that isn't decided is
to do or not do
Quoted 3 lines
this in
rte_namespace.i'm strongly in favor of
rte_namespace after discussion, mainly dueto to
Quoted 1 line
disadvantages of trying to overlap with the standard namespace while
not
Quoted 1 line
providing a compatible api/abi and because it provides clear
disambiguation of
Quoted 5 lines
that difference in semantics and compatibility with the standard api.
so far i've noted the following
* we will not provide the non-explicit apis.
+1
Quoted 2 lines
* we will make no attempt to support operate on struct/union atomics with our apis.
+1
Quoted 1 line
* we will mirror the standard api potentially in the
rte_namespaceto
Quoted 2 lines
- reference the standard api documentation.
- assume compatible semantics (sans exceptions from first 2points).
Quoted 2 lines
my vote is to remove 'potentially' from the last point above for
reasons
Quoted 3 lines
previously discussed in postings to the mail thread.
thanks all for the discussion, i'll send up a patch removing non-
explicit apis for
Quoted 3 lines
viewing.
ty
Re: [PATCH] eal: introduce atomics abstraction
In reply to Honnappa NagarahalliQuoted 91 lines · Honnappa Nagarahalli
<snip>
Quoted 75 lines
Quoted 55 lines
Quoted 55 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
For environments where stdatomics are not supported, we could
have a
Quoted 2 lines
Quoted 2 lines
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 1 line
Quoted 1 line
_explicitAPIs). This allows the code to use stdatomics APIs andwhen we move
Quoted 2 lines
Quoted 2 lines
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 3 lines
Quoted 3 lines
repo.
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 9 lines
Quoted 9 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manual
https://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlin effect the header, the names and in some instances namespaces
introduced
Quoted 1 line
Quoted 1 line
are reserved by the implementation. there are several reasons in
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were introduced?
i.e. it should not apply if the compiler does not support stdatomics.
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 3 lines
Quoted 3 lines
manual that explain the justification for these reservations and if
if we think
Quoted 3 lines
Quoted 3 lines
about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX
standard
Quoted 1 line
Quoted 1 line
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 2 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time.
i.e. basically the model of any dpdk-dev package on any linux distribution.Quoted 7 lines
Quoted 5 lines
if dpdk is built without real stdatomic types but the application has to interoperate with a different kit or library that does they would be forced to dance around dpdk with their own version of a shim to hide our faked up stdatomics.
So basically, if we want a binary DPDK distribution to be compatible with a
separate application build environment, they both have to implement atomics the same way, i.e. agree on the ABI for atomics.
Quoted 4 lines
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application build
environment to support C11 stdatomics.
Quoted 6 lines
2. Provide our own DPDK atomics library.
(As mentioned by Tyler, the third option - using C11 stdatomics inside DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
Quoted 7 lines
Quoted 1 line
I strongly want atomics to be available for use across inline and compiled
code; i.e. it must be possible for both compiled DPDK functions and inline functions to perform atomic transactions on the same atomic variable.
i consider it a mandatory requirement. i don't see practically how we could withdraw existing use and even if we had clean way i don't see why we would want to. so this item is defintely settled if you were concerned.
I think I agree here.
Quoted 5 lines
Quoted 3 lines
So either we upgrade the DPDK build requirements to support C11 (including
the optional stdatomics), or we provide our own DPDK atomics.
Quoted 7 lines
Quoted 3 lines
i think the issue of requiring a toolchain conformant to a specific standard is a separate matter because any adoption of C11 standard atomics is a potential abi break from the current use of intrinsics.
I am not sure why you are calling it as ABI break. Referring to [1], I just see wrappers around intrinsics (though [2] does not use the intrinsics).
[1] https://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/stdatomic.h
[2] https://github.com/llvm-mirror/clang/blob/master/lib/Headers/stdatomic.h
it's a potential abi break because atomic types are not the same types as their corresponding integer types etc.. (or at least are not guaranteed to be by all implementations of c as an abstract language).
ISO/IEC 9899:2011
6.2.5 (27)
Further, there is the _Atomic qualifier. The presence of the _Atomic qualifier designates an atomic type. The size, representation, and alignment of an atomic type need not be the same as those of the corresponding unqualified type.
7.17.6 (3)
NOTE The representation of atomic integer types need not have the same size as their corresponding regular types. They should have the same size whenever possible, as it eases effort required to port existing code.
i use the term `potential abi break' with intent because for me to assert in absolute terms i would have to evaluate the implementation of every current and potential future compilers atomic vs non-atomic types. this as i'm sure you understand is not practical, it would also defeat the purpose of moving to a standard. therefore i rely on the specification prescribed by the standard not the detail of a specific implementation.
Quoted 4 lines
Quoted 3 lines
the abstraction (whatever namespace it resides) allows the existing toolchain/platform combinations to maintain compatibility by defaulting to current non-standard intrinsics.
How about using the intrinsics (
__atomic_xxx) name space for abstraction? This covers the GCC and Clang compilers.
the namespace starting with __ is also reserved for the implementation. this is why compilers gcc/clang/msvc place name their intrinsic and builtin functions starting with __ to explicitly avoid collision with the application namespace.
ISO/IEC 9899:2011
7.1.3 (1)
All identifiers that begin with an underscore and either an uppercase
letter or another underscore are always reserved for any use.
...Quoted 1 line
If there is another platform that uses the same name space for something else, I think DPDK should not be supporting that platform.
that's effectively a statement excluding windows platform and all non-gcc compilers from ever supporting dpdk.
Quoted 1 line
What problems do you see?
i'm fairly certain at least one other compiler uses the __atomic namespace but it would take me time to check, the most notable potential issue that comes to mind is if such an intrinsic with the same name is provided in a different implementation and has either regressive code generation or different semantics it would be bad because it is intrinsic you can't just hack around it with #undef __atomic to shim in a semantically correct version.
how about this, is there another possible namespace you might suggest that conforms or doesn't conflict with the the rules defined in ISO/IEC 9899:2011 7.1.3 i think if there were that would satisfy all of my concerns related to namespaces.
keep in mind the point of moving to a standard is to achieve portability so if we do things that will regress us back to being dependent on an implementation we haven't succeeded. that's all i'm trying to guarantee here.
i feel like we are really close on this discussion, if we can just iron this issue out we can probably get going on the actual changes.
thanks for the consideration.
Quoted 36 lines
Quoted 11 lines
once in place it provides an opportunity to introduce new toolchain/platform combinations and enables an opt-in capability to use stdatomics on existing toolchain/platform combinations subject to community discussion on how/if/when.
it would be good to get more participants into the discussion so i'll cc techboard for some attention. i feel like the only area that isn't decided is to do or not do this in
rte_namespace.Quoted 8 lines
i'm strongly in favor of
rte_namespace after discussion, mainly due to to disadvantages of trying to overlap with the standard namespace while not providing a compatible api/abi and because it provides clear disambiguation of that difference in semantics and compatibility with the standard api.so far i've noted the following
* we will not provide the non-explicit apis.
+1
Quoted 2 lines
* we will make no attempt to support operate on struct/union atomics with our apis.
+1
Quoted 11 lines
* we will mirror the standard api potentially in the
rte_namespace to
- reference the standard api documentation.
- assume compatible semantics (sans exceptions from first 2 points).my vote is to remove 'potentially' from the last point above for reasons previously discussed in postings to the mail thread.
thanks all for the discussion, i'll send up a patch removing non-explicit apis for viewing.
ty
RE: [PATCH] eal: introduce atomics abstraction
<snip>
Quoted 133 lines · Honnappa Nagarahalli
Quoted 85 lines
<snip>
Quoted 83 lines
Quoted 61 lines
Quoted 61 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
For environments where stdatomics are not supported, we could
have a
Quoted 2 lines
Quoted 2 lines
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 2 lines
Quoted 2 lines
_explicitAPIs). This allows the code to use stdatomics APIs andwhen we move
Quoted 2 lines
Quoted 2 lines
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 3 lines
Quoted 3 lines
repo.
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 11 lines
Quoted 11 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manualhttps://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlin effect the header, the names and in some instances namespaces
introduced
Quoted 2 lines
Quoted 2 lines
are reserved by the implementation. there are several reasons in
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were introduced?
i.e. it should not apply if the compiler does not support stdatomics.
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 3 lines
Quoted 3 lines
manual that explain the justification for these reservations and if
if we think
Quoted 4 lines
Quoted 4 lines
about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX
standard
Quoted 1 line
Quoted 1 line
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 2 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time.
i.e. basically the model of any dpdk-dev package on any linux distribution.Quoted 8 lines
Quoted 5 lines
if dpdk is built without real stdatomic types but the application has to interoperate with a different kit or library that does they would be forced to dance around dpdk with their own version of a shim to hide our faked up stdatomics.
So basically, if we want a binary DPDK distribution to be compatible with a
separate application build environment, they both have to implement atomics the same way, i.e. agree on the ABI for atomics.
Quoted 5 lines
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application build
environment to support C11 stdatomics.
Quoted 6 lines
2. Provide our own DPDK atomics library.
(As mentioned by Tyler, the third option - using C11 stdatomics inside DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
I strongly want atomics to be available for use across inline and compiled
code; i.e. it must be possible for both compiled DPDK functions and inline functions to perform atomic transactions on the same atomic variable.
i consider it a mandatory requirement. i don't see practically how we could withdraw existing use and even if we had clean way i don't see why we would want to. so this item is defintely settled if you were
concerned.
Quoted 4 lines
I think I agree here.
Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
So either we upgrade the DPDK build requirements to support C11 (including
the optional stdatomics), or we provide our own DPDK atomics.
i think the issue of requiring a toolchain conformant to a specific standard is a separate matter because any adoption of C11 standard atomics is a potential abi break from the current use of intrinsics.
I am not sure why you are calling it as ABI break. Referring to [1], I just see
wrappers around intrinsics (though [2] does not use the intrinsics).
Quoted 6 lines
[1]
https://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/stdatomic.h
[2]
https://github.com/llvm-mirror/clang/blob/master/lib/Headers/stdatomic
.hit's a potential abi break because atomic types are not the same types as their corresponding integer types etc.. (or at least are not guaranteed to be by all implementations of c as an abstract language).
ISO/IEC 9899:2011
6.2.5 (27)
Further, there is the_Atomicqualifier. The presence of the_Atomicqualifier designates an atomic type. The size, representation, and alignment of an atomic type need not be the same as those of the corresponding unqualified type.7.17.6 (3)
NOTE The representation of atomic integer types need not have the same size as their corresponding regular types. They should have the same size
whenever
possible, as it eases effort required to port existing code.
Quoted 6 lines
i use the term `potential abi break' with intent because for me to assert in absolute terms i would have to evaluate the implementation of every current and potential future compilers atomic vs non-atomic types. this as i'm sure you understand is not practical, it would also defeat the purpose of moving to a standard. therefore i rely on the specification prescribed by the standard not the detail of a specific implementation.
Can we say that the platforms 'supported' by DPDK today do not have this problem? Any future platforms that will come to DPDK have to evaluate this.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
the abstraction (whatever namespace it resides) allows the existing toolchain/platform combinations to maintain compatibility by defaulting to current non-standard intrinsics.
Quoted 7 lines
Quoted 1 line
How about using the intrinsics (
__atomic_xxx) name space for abstraction?This covers the GCC and Clang compilers.
the namespace starting with
__is also reserved for the implementation. this is why compilers gcc/clang/msvc place name their intrinsic and builtin functions starting with __ to explicitly avoid collision with the application namespace.
Agreed. But, here we are considering '__atomic_' specifically (i.e. not just '__')
Quoted 9 lines
ISO/IEC 9899:2011
7.1.3 (1)
All identifiers that begin with an underscore and either an uppercase
letter or another underscore are always reserved for any use.
...Quoted 5 lines
Quoted 1 line
If there is another platform that uses the same name space for something
else, I think DPDK should not be supporting that platform.
that's effectively a statement excluding windows platform and all non-gcc compilers from ever supporting dpdk.
Apologies, I did not understand your comment on windows platform. Do you mean to say a compiler for windows platform uses '__atomic_xxx' name space to provide some other functionality (and hence it would get excluded)? Clang supports these intrinsics. I am not sure about the merit of supporting other non-gcc compilers. May be a topic Techboard discussion.
Quoted 4 lines
Quoted 2 lines
What problems do you see?
i'm fairly certain at least one other compiler uses the
__atomicnamespace but
Do you mean __atomic namespace is used for some other purpose?
Quoted 5 lines
it would take me time to check, the most notable potential issue that comes to mind is if such an intrinsic with the same name is provided in a different implementation and has either regressive code generation or different semantics it would be bad because it is intrinsic you can't just hack around it with #undef
__atomicto shim in a semantically correct version.
I do not think we should worry about regressive code generation problem. It should be fixed by that compiler. Different semantics is something we need to worry about. It would be good to find out more about a compiler that does this.
Quoted 9 lines
how about this, is there another possible namespace you might suggest that conforms or doesn't conflict with the the rules defined in ISO/IEC 9899:2011 7.1.3 i think if there were that would satisfy all of my concerns related to namespaces.
keep in mind the point of moving to a standard is to achieve portability so if we do things that will regress us back to being dependent on an implementation we haven't succeeded. that's all i'm trying to guarantee here.
Agree. We are trying to solve a problem that is temporary. I am trying to keep the problem scope narrow which might help us push to adopt the standard sooner.
Quoted 43 lines
i feel like we are really close on this discussion, if we can just iron this issue out we can probably get going on the actual changes.
thanks for the consideration.
Quoted 7 lines
Quoted 7 lines
once in place it provides an opportunity to introduce new toolchain/platform combinations and enables an opt-in capability to use stdatomics on existing toolchain/platform combinations subject to community discussion on how/if/when.
Quoted 8 lines
Quoted 8 lines
it would be good to get more participants into the discussion so i'll cc techboard for some attention. i feel like the only area that isn't decided is to do or not do this in
rte_namespace.i'm strongly in favor of
rte_namespace after discussion, mainly due to to disadvantages of trying to overlap with the standard namespace while not providing a compatible api/abi and because it provides clear disambiguation of that difference in semantics and compatibility withthe standard api.
Quoted 21 lines
Quoted 4 lines
so far i've noted the following
* we will not provide the non-explicit apis.
+1
Quoted 2 lines
* we will make no attempt to support operate on struct/union atomics with our apis.
+1
Quoted 11 lines
* we will mirror the standard api potentially in the
rte_namespace to
- reference the standard api documentation.
- assume compatible semantics (sans exceptions from first 2 points).my vote is to remove 'potentially' from the last point above for reasons previously discussed in postings to the mail thread.
thanks all for the discussion, i'll send up a patch removing non-explicit apis for viewing.
ty
Re: [PATCH] eal: introduce atomics abstraction
Quoted 135 lines · Honnappa Nagarahalli
<snip>
Quoted 133 lines · Honnappa Nagarahalli
Quoted 85 lines
<snip>
Quoted 83 lines
Quoted 61 lines
Quoted 61 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
For environments where stdatomics are not supported, we could
have a
Quoted 2 lines
Quoted 2 lines
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 2 lines
Quoted 2 lines
_explicitAPIs). This allows the code to use stdatomics APIs andwhen we move
Quoted 2 lines
Quoted 2 lines
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 3 lines
Quoted 3 lines
repo.
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 11 lines
Quoted 11 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manualhttps://www.gnu.org/software/libc/manual/html_node/Reserved-
Names.htmlin effect the header, the names and in some instances namespaces
introduced
Quoted 2 lines
Quoted 2 lines
are reserved by the implementation. there are several reasons in
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were introduced?
i.e. it should not apply if the compiler does not support stdatomics.
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 3 lines
Quoted 3 lines
manual that explain the justification for these reservations and if
if we think
Quoted 4 lines
Quoted 4 lines
about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX
standard
Quoted 1 line
Quoted 1 line
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 2 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time.
i.e. basically the model of any dpdk-dev package on any linux distribution.Quoted 8 lines
Quoted 5 lines
if dpdk is built without real stdatomic types but the application has to interoperate with a different kit or library that does they would be forced to dance around dpdk with their own version of a shim to hide our faked up stdatomics.
So basically, if we want a binary DPDK distribution to be compatible with a
separate application build environment, they both have to implement atomics the same way, i.e. agree on the ABI for atomics.
Quoted 5 lines
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application build
environment to support C11 stdatomics.
Quoted 6 lines
2. Provide our own DPDK atomics library.
(As mentioned by Tyler, the third option - using C11 stdatomics inside DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
I strongly want atomics to be available for use across inline and compiled
code; i.e. it must be possible for both compiled DPDK functions and inline functions to perform atomic transactions on the same atomic variable.
i consider it a mandatory requirement. i don't see practically how we could withdraw existing use and even if we had clean way i don't see why we would want to. so this item is defintely settled if you were
concerned.
Quoted 4 lines
I think I agree here.
Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
So either we upgrade the DPDK build requirements to support C11 (including
the optional stdatomics), or we provide our own DPDK atomics.
i think the issue of requiring a toolchain conformant to a specific standard is a separate matter because any adoption of C11 standard atomics is a potential abi break from the current use of intrinsics.
I am not sure why you are calling it as ABI break. Referring to [1], I just see
wrappers around intrinsics (though [2] does not use the intrinsics).
Quoted 6 lines
[1]
https://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/stdatomic.h
[2]
https://github.com/llvm-mirror/clang/blob/master/lib/Headers/stdatomic
.hit's a potential abi break because atomic types are not the same types as their corresponding integer types etc.. (or at least are not guaranteed to be by all implementations of c as an abstract language).
ISO/IEC 9899:2011
6.2.5 (27)
Further, there is the_Atomicqualifier. The presence of the_Atomicqualifier designates an atomic type. The size, representation, and alignment of an atomic type need not be the same as those of the corresponding unqualified type.7.17.6 (3)
NOTE The representation of atomic integer types need not have the same size as their corresponding regular types. They should have the same size
whenever
possible, as it eases effort required to port existing code.
Quoted 7 lines
Quoted 6 lines
i use the term `potential abi break' with intent because for me to assert in absolute terms i would have to evaluate the implementation of every current and potential future compilers atomic vs non-atomic types. this as i'm sure you understand is not practical, it would also defeat the purpose of moving to a standard. therefore i rely on the specification prescribed by the standard not the detail of a specific implementation.
Can we say that the platforms 'supported' by DPDK today do not have this problem? Any future platforms that will come to DPDK have to evaluate this.
sadly i don't think we can. i believe in an earlier post i linked a bug filed on gcc that shows that clang / gcc were producing different layout than the equivalent non-atomic type.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
the abstraction (whatever namespace it resides) allows the existing toolchain/platform combinations to maintain compatibility by defaulting to current non-standard intrinsics.
How about using the intrinsics (
__atomic_xxx) name space for abstraction?This covers the GCC and Clang compilers.
i haven't investigated fully but there are usages of these intrinsics that indicate there may be undesirable difference between clang and gcc versions. the hint is there seems to be conditionally compiled code under __clang__ when using some __atomic's.
for the purpose of this discussion clang just tries to look like gcc so i don't regard them as being different compilers for the purpose of this discussion.
Quoted 7 lines
Quoted 5 lines
the namespace starting with
__is also reserved for the implementation. this is why compilers gcc/clang/msvc place name their intrinsic and builtin functions starting with __ to explicitly avoid collision with the application namespace.Agreed. But, here we are considering '
__atomic_' specifically (i.e. not just '__')
i don't understand the confusion __atomic is within the __ namespace that is reserved.
let me ask this another way, what benefit do you see to trying to overlap with the standard namespace? the only benefit i can see is that at some point in the future it avoids having to perform a mechanical change to eventually retire the abstraction once all platform/toolchains support standard atomics. i.e. basically s/rte_atomic/atomic/g
is there another benefit i'm missing?
Quoted 8 lines
Quoted 8 lines
ISO/IEC 9899:2011
7.1.3 (1)
All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
Quoted 8 lines
Quoted 7 lines
...Quoted 1 line
If there is another platform that uses the same name space for something
else, I think DPDK should not be supporting that platform.
that's effectively a statement excluding windows platform and all non-gcc compilers from ever supporting dpdk.
Apologies, I did not understand your comment on windows platform. Do you mean to say a compiler for windows platform uses '
__atomic_xxx' name space to provide some other functionality (and hence it would get excluded)?
i mean dpdk can never fully be supported without msvc except for statically linked builds which are niche and limit it too severely for many consumers to practically use dpdk. there are also many application developers who would like to integrate dpdk but can't and telling them their only choice is to re-port their entire application to clang isn't feasible.
i can see no technical reason why we should be excluding a major compiler in broad use if it is capable of building dpdk. msvc arguably has some of the most sophisticated security features in the industry and the use of those features is mandated by many of the customers who might deploy dpdk applications on windows.
Quoted 8 lines
Clang supports these intrinsics. I am not sure about the merit of supporting other non-gcc compilers. May be a topic Techboard discussion.
Quoted 4 lines
Quoted 2 lines
What problems do you see?
i'm fairly certain at least one other compiler uses the
__atomicnamespace butDo you mean
__atomicnamespace is used for some other purpose?
Quoted 7 lines
Quoted 5 lines
it would take me time to check, the most notable potential issue that comes to mind is if such an intrinsic with the same name is provided in a different implementation and has either regressive code generation or different semantics it would be bad because it is intrinsic you can't just hack around it with #undef
__atomicto shim in a semantically correct version.I do not think we should worry about regressive code generation problem. It should be fixed by that compiler. Different semantics is something we need to worry about. It would be good to find out more about a compiler that does this.
again, this is about portability it's about potential not that we can find an example.
Quoted 11 lines
Quoted 10 lines
how about this, is there another possible namespace you might suggest that conforms or doesn't conflict with the the rules defined in ISO/IEC 9899:2011 7.1.3 i think if there were that would satisfy all of my concerns related to namespaces.
keep in mind the point of moving to a standard is to achieve portability so if we do things that will regress us back to being dependent on an implementation we haven't succeeded. that's all i'm trying to guarantee here.
Agree. We are trying to solve a problem that is temporary. I am trying to keep the problem scope narrow which might help us push to adopt the standard sooner.
i do wish we could just target the standard but unless we are willing to draw a line and say no more non std=c11 and also we potentially break the abi we are talking years. i don't think it is reasonable to block progress for years, so i'm offering a transitional path. it's an evolution over time that we have to manage.
Quoted 44 lines
Quoted 44 lines
i feel like we are really close on this discussion, if we can just iron this issue out we can probably get going on the actual changes.
thanks for the consideration.
Quoted 7 lines
Quoted 7 lines
once in place it provides an opportunity to introduce new toolchain/platform combinations and enables an opt-in capability to use stdatomics on existing toolchain/platform combinations subject to community discussion on how/if/when.
Quoted 8 lines
Quoted 8 lines
it would be good to get more participants into the discussion so i'll cc techboard for some attention. i feel like the only area that isn't decided is to do or not do this in
rte_namespace.i'm strongly in favor of
rte_namespace after discussion, mainly due to to disadvantages of trying to overlap with the standard namespace while not providing a compatible api/abi and because it provides clear disambiguation of that difference in semantics and compatibility withthe standard api.
Quoted 21 lines
Quoted 4 lines
so far i've noted the following
* we will not provide the non-explicit apis.
+1
Quoted 2 lines
* we will make no attempt to support operate on struct/union atomics with our apis.
+1
Quoted 11 lines
* we will mirror the standard api potentially in the
rte_namespace to
- reference the standard api documentation.
- assume compatible semantics (sans exceptions from first 2 points).my vote is to remove 'potentially' from the last point above for reasons previously discussed in postings to the mail thread.
thanks all for the discussion, i'll send up a patch removing non-explicit apis for viewing.
ty
RE: [PATCH] eal: introduce atomics abstraction
Hi Tyler,
Few more comments inline. Let us continue to make progress, I will add this topic for Techboard discussion for 22nd Feb.
Quoted 166 lines
-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Friday, February 10, 2023 2:30 PM
To: Honnappa Nagarahalli <[email protected]>
Cc: Morten Brørup <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; nd <[email protected]>; [email protected]
Subject: Re: [PATCH] eal: introduce atomics abstractionQuoted 34 lines · Honnappa Nagarahalli
<snip>
Quoted 32 lines · Honnappa Nagarahalli
Quoted 31 lines
<snip>
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
For environments where stdatomics are not supported, we could
have a
Quoted 2 lines
Quoted 2 lines
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 2 lines
Quoted 2 lines
_explicitAPIs). This allows the code to use stdatomics APIs andwhen we move
Quoted 2 lines
Quoted 2 lines
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 4 lines
Quoted 4 lines
repo.
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 10 lines
Quoted 10 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manualhttps://www.gnu.org/software/libc/manual/html_node/Reser
ved-
Names.htmlQuoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
in effect the header, the names and in some instances namespaces
introduced
Quoted 2 lines
Quoted 2 lines
are reserved by the implementation. there are several reasons in
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were
introduced?
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 29 lines
Quoted 29 lines
i.e. it should not apply if the compiler does not support stdatomics.
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 3 lines
Quoted 3 lines
manual that explain the justification for these
reservations and ifif we think
Quoted 4 lines
Quoted 4 lines
about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX
standard
Quoted 2 lines
Quoted 2 lines
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 3 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time.
i.e. basically the model of any dpdk-dev package on any linux distribution.Quoted 8 lines
Quoted 5 lines
if dpdk is built without real stdatomic types but the application has to interoperate with a different kit or library that does they would be forced to dance around dpdk with their own version of a shim to hide our faked up stdatomics.
So basically, if we want a binary DPDK distribution to be compatible with a
separate application build environment, they both have to implement atomics the same way, i.e. agree on the ABI for atomics.
Quoted 5 lines
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application build
environment to support C11 stdatomics.
Quoted 7 lines
2. Provide our own DPDK atomics library.
(As mentioned by Tyler, the third option - using C11 stdatomics inside DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
I strongly want atomics to be available for use across inline and compiled
code; i.e. it must be possible for both compiled DPDK functions and inline functions to perform atomic transactions on the same
atomic variable.
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
i consider it a mandatory requirement. i don't see practically how we could withdraw existing use and even if we had clean way i don't see why we would want to. so this item is defintely settled if you were
concerned.
Quoted 4 lines
I think I agree here.
Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
So either we upgrade the DPDK build requirements to support C11 (including
the optional stdatomics), or we provide our own DPDK atomics.
i think the issue of requiring a toolchain conformant to a specific standard is a separate matter because any adoption of C11 standard atomics is a potential abi break from the current use of
intrinsics.
Quoted 16 lines
Quoted 16 lines
Quoted 2 lines
I am not sure why you are calling it as ABI break. Referring to [1], I just see
wrappers around intrinsics (though [2] does not use the intrinsics).
Quoted 8 lines
[1]
https://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/stdatomic.h
[2]
https://github.com/llvm-mirror/clang/blob/master/lib/Headers/stdat
omic
.hit's a potential abi break because atomic types are not the same types as their corresponding integer types etc.. (or at least are not guaranteed to be by all implementations of c as an abstract language).
Quoted 5 lines
Quoted 5 lines
ISO/IEC 9899:2011
6.2.5 (27)
Further, there is the_Atomicqualifier. The presence of the_Atomicqualifier designates an atomic type. The size, representation, andalignment
Quoted 5 lines
Quoted 5 lines
of an atomic type need not be the same as those of the corresponding unqualified type.
7.17.6 (3)
NOTE The representation of atomic integer types need not have thesame size
Quoted 10 lines
Quoted 10 lines
as their corresponding regular types. They should have the same
size whenever
possible, as it eases effort required to port existing code.i use the term `potential abi break' with intent because for me to assert in absolute terms i would have to evaluate the implementation of every current and potential future compilers atomic vs non-atomic types. this as i'm sure you understand is not practical, it would also defeat the purpose of moving to a standard. therefore i rely on the specification prescribed by the standard not the detail of a specific
Quoted 7 lines
implementation.
Quoted 1 line
Can we say that the platforms 'supported' by DPDK today do not have this
problem? Any future platforms that will come to DPDK have to evaluate this.
sadly i don't think we can. i believe in an earlier post i linked a bug filed on gcc that shows that clang / gcc were producing different layout than the equivalent non-atomic type.
I looked at that bug again, it is to do with structure.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
the abstraction (whatever namespace it resides) allows the existing toolchain/platform combinations to maintain compatibility by defaulting to current non-standard intrinsics.
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
How about using the intrinsics (
__atomic_xxx) name space forabstraction?
Quoted 1 line
Quoted 1 line
This covers the GCC and Clang compilers.
i haven't investigated fully but there are usages of these intrinsics that indicate there may be undesirable difference between clang and gcc versions. the hint is there seems to be conditionally compiled code under
__clang__when using some __atomic's.
I sent an RFC to address this [1]. I think the size specific intrinsics are not necessary.
[1] http://patches.dpdk.org/project/dpdk/patch/[email protected]/
Quoted 10 lines
for the purpose of this discussion clang just tries to look like gcc so i don't regard them as being different compilers for the purpose of this discussion.
Quoted 5 lines
Quoted 5 lines
the namespace starting with
__is also reserved for the implementation. this is why compilers gcc/clang/msvc place name their intrinsic and builtin functions starting with __ to explicitly avoid collision with the application namespace.
Quoted 5 lines
Quoted 2 lines
Agreed. But, here we are considering '
__atomic_' specifically (i.e. not just '__')i don't understand the confusion
__atomicis within the __ namespace that is reserved.
What I mean is, we are not formulating a policy/rule to allow for any name space that starts with '__'.
Quoted 8 lines
let me ask this another way, what benefit do you see to trying to overlap with the standard namespace? the only benefit i can see is that at some point in the future it avoids having to perform a mechanical change to eventually retire the abstraction once all platform/toolchains support standard atomics. i.e. basically s/rte_atomic/atomic/g
is there another benefit i'm missing?
The abstraction you have proposed solves the problem for the long term. The proposed abstraction stops us from thinking about moving to stdatomics.
IMO, the problem is short term. Using the __atomic_ name space does not have any practical issues with the platforms DPDK supports (unless msvc has a problem with this, more questions below).
Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
ISO/IEC 9899:2011 7.1.3 (1) All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use. ...Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
If there is another platform that uses the same name space for something
else, I think DPDK should not be supporting that platform.
that's effectively a statement excluding windows platform and all non-gcc compilers from ever supporting dpdk.
Apologies, I did not understand your comment on windows platform. Do
you mean to say a compiler for windows platform uses '
__atomic_xxx' name space to provide some other functionality (and hence it would get excluded)?i mean dpdk can never fully be supported without msvc except for statically linked builds which are niche and limit it too severely for many consumers to practically use dpdk. there are also many application developers who would like to integrate dpdk but can't and telling them their only choice is to re-port their entire application to clang isn't feasible.
Quoted 5 lines
i can see no technical reason why we should be excluding a major compiler in broad use if it is capable of building dpdk. msvc arguably has some of the most sophisticated security features in the industry and the use of those features is mandated by many of the customers who might deploy dpdk applications on windows.
I did not mean DPDK should not support msvc (may be my sentence below was misunderstood). Does msvc provide '__atomic_xxx' intrinsics?
Quoted 38 lines
Quoted 2 lines
Clang supports these intrinsics. I am not sure about the merit of supporting
other non-gcc compilers. May be a topic Techboard discussion.
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
What problems do you see?
i'm fairly certain at least one other compiler uses the
__atomicnamespace butDo you mean
__atomicnamespace is used for some other purpose?Quoted 5 lines
it would take me time to check, the most notable potential issue that comes to mind is if such an intrinsic with the same name is provided in a different implementation and has either regressive code generation or different semantics it would be bad because it is intrinsic you can't just hack around it with #undef
__atomicto shim in asemantically correct version.
Quoted 1 line
I do not think we should worry about regressive code generation problem. It
should be fixed by that compiler.
Quoted 1 line
Different semantics is something we need to worry about. It would be good
to find out more about a compiler that does this.
again, this is about portability it's about potential not that we can find an example.
Quoted 11 lines
Quoted 11 lines
how about this, is there another possible namespace you might suggest that conforms or doesn't conflict with the the rules defined in ISO/IEC 9899:2011
7.1.3 i think if there were that would satisfy all of my concerns related to namespaces.keep in mind the point of moving to a standard is to achieve portability so if we do things that will regress us back to being dependent on an implementation we haven't succeeded. that's all i'm
trying to guarantee here.
Quoted 1 line
Agree. We are trying to solve a problem that is temporary. I am trying to
Quoted 8 lines
keep the problem scope narrow which might help us push to adopt the standard sooner.
i do wish we could just target the standard but unless we are willing to draw a line and say no more non std=c11 and also we potentially break the abi we are talking years. i don't think it is reasonable to block progress for years, so i'm offering a transitional path. it's an evolution over time that we have to manage.
Apologies if I am sounding like I am blocking progress. Rest assured, we will find a way. It is just about which solution we are going to pick. Also, is there are any information on how long before we move to C11?
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
i feel like we are really close on this discussion, if we can just iron this issue out we can probably get going on the actual changes.
thanks for the consideration.
Quoted 11 lines
Quoted 11 lines
once in place it provides an opportunity to introduce new toolchain/platform combinations and enables an opt-in capability to use stdatomics on existing toolchain/platform combinations subject to community discussion on how/if/when.
it would be good to get more participants into the discussion so i'll cc techboard for some attention. i feel like the only area that isn't decided is to do or not do this in
rte_namespace.Quoted 5 lines
Quoted 5 lines
i'm strongly in favor of
rte_namespace after discussion, mainly due to to disadvantages of trying to overlap with the standard namespace while not providing a compatible api/abi and because it provides clear disambiguation of that difference in semantics and compatibility withthe standard api.
Quoted 21 lines
Quoted 4 lines
so far i've noted the following
* we will not provide the non-explicit apis.
+1
Quoted 2 lines
* we will make no attempt to support operate on struct/union atomics with our apis.
+1
Quoted 11 lines
* we will mirror the standard api potentially in the
rte_namespace to
- reference the standard api documentation.
- assume compatible semantics (sans exceptions from first 2 points).my vote is to remove 'potentially' from the last point above for reasons previously discussed in postings to the mail thread.
thanks all for the discussion, i'll send up a patch removing non-explicit apis for viewing.
ty
Re: [PATCH] eal: introduce atomics abstraction
There is a thread discussing a change to the standard [1] but I have not seen anything explicit yet about moving to C11. I am personally in favor of making the jump to C11 now as part of the 23.x branch and provided my thoughts in the linked thread (what other projects using DPDK have as minimum compiler requirements, CentOS 7 EOL dates).
Is the long term plan to backport this change set to the existing LTS release or is this meant to be something introduced for use in 23.x and going forward? I think I was (probably naively) assuming this would be a new feature in the 23.x going forward only.
[1] http://mails.dpdk.org/archives/dev/2023-February/262188.html
Quoted 407 lines · Honnappa Nagarahalli
Hi Tyler,
Few more comments inline. Let us continue to make progress, I will
add this topic for Techboard discussion for 22nd Feb.Quoted 45 lines
-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Friday, February 10, 2023 2:30 PM
To: Honnappa Nagarahalli <[email protected]>
Cc: Morten Brørup <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; nd <[email protected]>; [email protected]
Subject: Re: [PATCH] eal: introduce atomics abstractionQuoted 34 lines · Honnappa Nagarahalli
<snip>
Quoted 32 lines · Honnappa Nagarahalli
Quoted 31 lines
<snip>
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
For environments where stdatomics are not supported, we could
have a
Quoted 2 lines
Quoted 2 lines
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 2 lines
Quoted 2 lines
_explicitAPIs). This allows the code to use stdatomics APIs andwhen we move
Quoted 2 lines
Quoted 2 lines
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 4 lines
Quoted 4 lines
repo.
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 10 lines
Quoted 10 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manualhttps://www.gnu.org/software/libc/manual/html_node/Reser
ved-
Names.htmlQuoted 9 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
in effect the header, the names and in some instances namespaces
introduced
Quoted 2 lines
Quoted 2 lines
are reserved by the implementation. there are several reasons in
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were
introduced?
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i.e. it should not apply if the compiler does not support
stdatomics.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 3 lines
Quoted 3 lines
manual that explain the justification for these
reservations and ifif we think
Quoted 1 line
Quoted 1 line
about ODR and ABI compatibility we can conceive of
others.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 3 lines
Quoted 3 lines
i'll also remark that the inter-mingling of names from the POSIX
standard
Quoted 2 lines
Quoted 2 lines
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 3 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time.
i.e. basically the model of any dpdk-dev package on any linux distribution.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
if dpdk is built without real stdatomic types but the application has to interoperate with a different kit or library that does they would be forced to dance around dpdk with their own version of a shim to hide our faked up
stdatomics.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
So basically, if we want a binary DPDK distribution to be compatible with a
separate application build environment, they both have to implement atomics the same way, i.e. agree on the ABI for
atomics.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application build
environment to support C11 stdatomics.
Quoted 7 lines
2. Provide our own DPDK atomics library.
(As mentioned by Tyler, the third option - using C11 stdatomics inside DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
Quoted 22 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
I strongly want atomics to be available for use across inline and compiled
code; i.e. it must be possible for both compiled DPDK functions and inline functions to perform atomic transactions on the same
atomic variable.
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
i consider it a mandatory requirement. i don't see practically how we could withdraw existing use and even if we had clean way i don't see why we would want to. so this item is defintely settled if you were
concerned.
Quoted 11 lines
I think I agree here.
Quoted 9 lines
Quoted 4 lines
So either we upgrade the DPDK build requirements to support C11 (including
the optional stdatomics), or we provide our own DPDK atomics.
i think the issue of requiring a toolchain conformant to a specific standard is a separate matter because any adoption of C11 standard atomics is a potential abi break from the current
use of
Quoted 16 lines
intrinsics.
Quoted 15 lines
Quoted 15 lines
Quoted 2 lines
I am not sure why you are calling it as ABI break. Referring to [1], I just see
wrappers around intrinsics (though [2] does not use the intrinsics).
Quoted 8 lines
[1]
https://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/stdatomic.h
[2]
https://github.com/llvm-mirror/clang/blob/master/lib/Headers/stdat
omic
.hit's a potential abi break because atomic types are not the same types as their corresponding integer types etc.. (or at least are not guaranteed to be by all implementations of c as an abstract
language).
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
ISO/IEC 9899:2011 6.2.5 (27) Further, there is the _Atomic qualifier. The presence of the
_AtomicQuoted 1 line
Quoted 1 line
Quoted 1 line
qualifier designates an atomic type. The size, representation,
and
Quoted 2 lines
alignment
Quoted 1 line
Quoted 1 line
of an atomic type need not be the same as those of the
corresponding
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
unqualified type.
7.17.6 (3)
NOTE The representation of atomic integer types need not have thesame size
Quoted 10 lines
Quoted 10 lines
as their corresponding regular types. They should have the same
size whenever
possible, as it eases effort required to port existing code.i use the term `potential abi break' with intent because for me to assert in absolute terms i would have to evaluate the implementation of every current and potential future compilers atomic vs non-atomic types. this as i'm sure you understand is not practical, it would also defeat the purpose of moving to a standard. therefore i rely on the specification prescribed by the standard not the detail of a
specific
Quoted 2 lines
implementation.
Quoted 1 line
Can we say that the platforms 'supported' by DPDK today do not have
this
Quoted 1 line
problem? Any future platforms that will come to DPDK have to evaluate
this.
Quoted 2 lines
sadly i don't think we can. i believe in an earlier post i linked a bug
filed on
Quoted 2 lines
gcc that shows that clang / gcc were producing different layout than the equivalent non-atomic type.
I looked at that bug again, it is to do with structure.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
the abstraction (whatever namespace it resides) allows the existing toolchain/platform combinations to maintain compatibility by defaulting to current non-standard intrinsics.
How about using the intrinsics (
__atomic_xxx) name space forabstraction?
Quoted 1 line
Quoted 1 line
This covers the GCC and Clang compilers.
i haven't investigated fully but there are usages of these intrinsics
that
Quoted 1 line
indicate there may be undesirable difference between clang and gcc
versions.
Quoted 2 lines
the hint is there seems to be conditionally compiled code under
__clang__when using some __atomic's.I sent an RFC to address this [1]. I think the size specific intrinsics are not necessary.
[1]
http://patches.dpdk.org/project/dpdk/patch/[email protected]/Quoted 2 lines
for the purpose of this discussion clang just tries to look like gcc so
i don't
Quoted 1 line
regard them as being different compilers for the purpose of this
discussion.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
the namespace starting with
__is also reserved for theimplementation.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
this is why compilers gcc/clang/msvc place name their intrinsic and builtin functions starting with __ to explicitly avoid collision with the application namespace.
Agreed. But, here we are considering '
__atomic_' specifically (i.e. not just '__')i don't understand the confusion
__atomicis within the __ namespacethat is
Quoted 1 line
reserved.
What I mean is, we are not formulating a policy/rule to allow for any name space that starts with '__'.
Quoted 2 lines
let me ask this another way, what benefit do you see to trying to
overlap with
Quoted 1 line
the standard namespace? the only benefit i can see is that at some point
in
Quoted 2 lines
the future it avoids having to perform a mechanical change to eventually retire the abstraction once all platform/toolchains support standard
atomics.
Quoted 3 lines
i.e. basically s/rte_atomic/atomic/g
is there another benefit i'm missing?
The abstraction you have proposed solves the problem for the long term. The proposed abstraction stops us from thinking about moving to stdatomics. IMO, the problem is short term. Using the
__atomic_name space does not have any practical issues with the platforms DPDK supports (unless msvc has a problem with this, more questions below).Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
ISO/IEC 9899:2011 7.1.3 (1) All identifiers that begin with an underscore and either anuppercase
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
letter or another underscore are always reserved for any use.
...
Quoted 2 lines
If there is another platform that uses the same name space for something
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
else, I think DPDK should not be supporting that platform.
that's effectively a statement excluding windows platform and all non-gcc compilers from ever supporting dpdk.
Apologies, I did not understand your comment on windows platform. Do
you mean to say a compiler for windows platform uses '
__atomic_xxx' name space to provide some other functionality (and hence it would getexcluded)?
Quoted 2 lines
i mean dpdk can never fully be supported without msvc except for
statically
Quoted 1 line
linked builds which are niche and limit it too severely for many
consumers to
Quoted 1 line
practically use dpdk. there are also many application developers who
would
Quoted 1 line
like to integrate dpdk but can't and telling them their only choice is
to re-port
Quoted 3 lines
their entire application to clang isn't feasible.
i can see no technical reason why we should be excluding a major
compiler in
Quoted 1 line
broad use if it is capable of building dpdk. msvc arguably has some of
the
Quoted 3 lines
most sophisticated security features in the industry and the use of those features is mandated by many of the customers who might deploy dpdk applications on windows.
I did not mean DPDK should not support msvc (may be my sentence below was misunderstood).
Does msvc provide '__atomic_xxx' intrinsics?Quoted 2 lines
Quoted 2 lines
Clang supports these intrinsics. I am not sure about the merit of
supporting
Quoted 14 lines
other non-gcc compilers. May be a topic Techboard discussion.
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
What problems do you see?
i'm fairly certain at least one other compiler uses the
__atomicnamespace butDo you mean
__atomicnamespace is used for some other purpose?Quoted 5 lines
it would take me time to check, the most notable potential issue that comes to mind is if such an intrinsic with the same name is provided in a different implementation and has either regressive code generation or different semantics it would be bad because it is intrinsic you can't just hack around it with #undef
__atomicto shimin a
Quoted 2 lines
semantically correct version.
Quoted 1 line
I do not think we should worry about regressive code generation
problem. It
Quoted 2 lines
should be fixed by that compiler.
Quoted 1 line
Different semantics is something we need to worry about. It would be
good
Quoted 3 lines
to find out more about a compiler that does this.
again, this is about portability it's about potential not that we can
find an
Quoted 10 lines
example.
Quoted 8 lines
Quoted 8 lines
how about this, is there another possible namespace you might suggest that conforms or doesn't conflict with the the rules defined in ISO/IEC 9899:2011
7.1.3 i think if there were that would satisfy all of my concerns related to namespaces.Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
keep in mind the point of moving to a standard is to achieve portability so if we do things that will regress us back to being dependent on an implementation we haven't succeeded. that's all i'm
trying to guarantee here.
Quoted 1 line
Agree. We are trying to solve a problem that is temporary. I am trying
to
Quoted 4 lines
keep the problem scope narrow which might help us push to adopt the standard sooner.
i do wish we could just target the standard but unless we are willing to
draw a
Quoted 2 lines
line and say no more non std=c11 and also we potentially break the abi we are talking years. i don't think it is reasonable to block progress for
years, so
Quoted 1 line
i'm offering a transitional path. it's an evolution over time that we
have to
Quoted 1 line
manage.
Apologies if I am sounding like I am blocking progress. Rest assured, we will find a way. It is just about which solution we are going to pick. Also, is there are any information on how long before we move to C11?
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
i feel like we are really close on this discussion, if we can just iron this issue out we can probably get going on the actual changes.
thanks for the consideration.
Quoted 16 lines
Quoted 16 lines
once in place it provides an opportunity to introduce new toolchain/platform combinations and enables an opt-in capability to use stdatomics on existing toolchain/platform combinations subject to community discussion on how/if/when.
it would be good to get more participants into the discussion so i'll cc techboard for some attention. i feel like the only area that isn't decided is to do or not do this in
rte_namespace.i'm strongly in favor of
rte_namespace after discussion, mainly due to to disadvantages of trying to overlap with the standard namespace while not providing a compatible api/abi and because it provides clear disambiguation of that difference in semantics and compatibility withQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
the standard api.
Quoted 7 lines
Quoted 4 lines
so far i've noted the following
* we will not provide the non-explicit apis.
+1
Quoted 1 line
* we will make no attempt to support operate on struct/union
atomics
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
with our apis.
+1
Quoted 1 line
* we will mirror the standard api potentially in the
rte_namespace to
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
- reference the standard api documentation.
- assume compatible semantics (sans exceptions from first 2points).
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
my vote is to remove 'potentially' from the last point above for reasons previously discussed in postings to the mail thread.
thanks all for the discussion, i'll send up a patch removing non-explicit apis for viewing.
ty
Re: [PATCH] eal: introduce atomics abstraction
Quoted 11 lines · Ben Magistro
There is a thread discussing a change to the standard [1] but I have not seen anything explicit yet about moving to C11. I am personally in favor of making the jump to C11 now as part of the 23.x branch and provided my thoughts in the linked thread (what other projects using DPDK have as minimum compiler requirements, CentOS 7 EOL dates). Is the long term plan to backport this change set to the existing LTS release or is this meant to be something introduced for use in 23.x and going forward? I think I was (probably naively) assuming this would be a new feature in the 23.x going forward only.
[1] [1]http://mails.dpdk.org/archives/dev/2023-February/262188.html
We don't bump requirements for older LTS releases, so any change to minimum required versions would only be for the 23.x series releases.
/Bruce
Re: [PATCH] eal: introduce atomics abstraction
Quoted 9 lines · Bruce Richardson
Quoted 2 lines · Ben Magistro
There is a thread discussing a change to the standard [1] but I have not seen anything explicit yet about moving to C11. I am personally
in
Quoted 5 lines
favor of making the jump to C11 now as part of the 23.x branch and provided my thoughts in the linked thread (what other projects using DPDK have as minimum compiler requirements, CentOS 7 EOL dates). Is the long term plan to backport this change set to the existing LTS release or is this meant to be something introduced for use in 23.x
Quoted 8 lines
and
Quoted 1 line
going forward? I think I was (probably naively) assuming this would
be
Quoted 3 lines
a new feature in the 23.x going forward only.
[1] [1]http://mails.dpdk.org/archives/dev/2023-February/262188.htmlWe don't bump requirements for older LTS releases, so any change to minimum required versions would only be for the 23.x series releases
I meant the atomics change set, I should have been clearer in that question, my apologies. If the atomic work is planned to be backported, the question of if/when the C11 standard would be adopted seems less relevant since it would need to be supported for DPDK versions that do not have the C11 standard requirement too.
RE: [PATCH] eal: introduce atomics abstraction
Hi Ben,
Only bug fixes are backported to LTS. Not even new NIC drivers are backported.
Reference: https://doc.dpdk.org/guides/contributing/stable.html#what-changes-should-be-backported <https://doc.dpdk.org/guides/contributing/stable.html#what-changes-should-be-backported>
-Morten
From: Ben Magistro [mailto:[email protected]]
Sent: Monday, 13 February 2023 17.47
On Mon, Feb 13, 2023 at 10:55 AM Bruce Richardson <[email protected]> wrote:
On Mon, Feb 13, 2023 at 10:28:40AM -0500, Ben Magistro wrote:
> There is a thread discussing a change to the standard [1] but I have
> not seen anything explicit yet about moving to C11. I am personally in
> favor of making the jump to C11 now as part of the 23.x branch and
> provided my thoughts in the linked thread (what other projects using
> DPDK have as minimum compiler requirements, CentOS 7 EOL dates).
> Is the long term plan to backport this change set to the existing LTS
> release or is this meant to be something introduced for use in 23.x and
> going forward? I think I was (probably naively) assuming this would be
> a new feature in the 23.x going forward only.
> [1] [1]http://mails.dpdk.org/archives/dev/2023-February/262188.html
>
We don't bump requirements for older LTS releases, so any change to minimum required versions would only be for the 23.x series releases
I meant the atomics change set, I should have been clearer in that question, my apologies. If the atomic work is planned to be backported, the question of if/when the C11 standard would be adopted seems less relevant since it would need to be supported for DPDK versions that do not have the C11 standard requirement too.
Re: [PATCH] eal: introduce atomics abstraction
In reply to Honnappa NagarahalliQuoted 169 lines · Honnappa Nagarahalli
Hi Tyler,
Few more comments inline. Let us continue to make progress, I will add this topic for Techboard discussion for 22nd Feb.Quoted 166 lines
-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Friday, February 10, 2023 2:30 PM
To: Honnappa Nagarahalli <[email protected]>
Cc: Morten Brørup <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; nd <[email protected]>; [email protected]
Subject: Re: [PATCH] eal: introduce atomics abstractionQuoted 34 lines · Honnappa Nagarahalli
<snip>
Quoted 32 lines · Honnappa Nagarahalli
Quoted 31 lines
<snip>
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
For environments where stdatomics are not supported, we could
have a
Quoted 2 lines
Quoted 2 lines
stdatomic.hin DPDK implementing the same APIs (we have to supportonly
Quoted 2 lines
Quoted 2 lines
_explicitAPIs). This allows the code to use stdatomics APIs andwhen we move
Quoted 2 lines
Quoted 2 lines
to minimum supported standard C11, we just need to get rid of the
file in DPDK
Quoted 4 lines
Quoted 4 lines
repo.
my concern with this is that if we provide a
stdatomic.horintroduce names
Quoted 10 lines
Quoted 10 lines
from
stdatomic.hit's a violation of the C standard.references:
* ISO/IEC 9899:2011 sections 7.1.2, 7.1.3.
* GNU libc manualhttps://www.gnu.org/software/libc/manual/html_node/Reser
ved-
Names.htmlQuoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
in effect the header, the names and in some instances namespaces
introduced
Quoted 2 lines
Quoted 2 lines
are reserved by the implementation. there are several reasons in
the GNU libc
Quoted 1 line
Wouldn't this apply only after the particular APIs were
introduced?
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 29 lines
Quoted 29 lines
i.e. it should not apply if the compiler does not support stdatomics.
yeah, i agree they're being a bit wishy washy in the wording, but i'm not convinced glibc folks are documenting this as permissive guidance against.
Quoted 3 lines
Quoted 3 lines
manual that explain the justification for these
reservations and ifif we think
Quoted 4 lines
Quoted 4 lines
about ODR and ABI compatibility we can conceive of others.
i'll also remark that the inter-mingling of names from the POSIX
standard
Quoted 2 lines
Quoted 2 lines
implicitly exposed as a part of the EAL public API has been
problematic for
Quoted 3 lines
Quoted 1 line
portability.
These should be exposed as EAL APIs only when compiled with a
compiler that does not support stdatomics.
you don't necessarily compile dpdk, the application or its other dynamically linked dependencies with the same compiler at the same time.
i.e. basically the model of any dpdk-dev package on any linux distribution.Quoted 8 lines
Quoted 5 lines
if dpdk is built without real stdatomic types but the application has to interoperate with a different kit or library that does they would be forced to dance around dpdk with their own version of a shim to hide our faked up stdatomics.
So basically, if we want a binary DPDK distribution to be compatible with a
separate application build environment, they both have to implement atomics the same way, i.e. agree on the ABI for atomics.
Quoted 5 lines
Summing up, this leaves us with only two realistic options:
1. Go all in on C11 stdatomics, also requiring the application build
environment to support C11 stdatomics.
Quoted 7 lines
2. Provide our own DPDK atomics library.
(As mentioned by Tyler, the third option - using C11 stdatomics inside DPDK, and requiring a build environment without C11 stdatomics to implement a shim - is not realistic!)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
I strongly want atomics to be available for use across inline and compiled
code; i.e. it must be possible for both compiled DPDK functions and inline functions to perform atomic transactions on the same
atomic variable.
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
i consider it a mandatory requirement. i don't see practically how we could withdraw existing use and even if we had clean way i don't see why we would want to. so this item is defintely settled if you were
concerned.
Quoted 4 lines
I think I agree here.
Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
So either we upgrade the DPDK build requirements to support C11 (including
the optional stdatomics), or we provide our own DPDK atomics.
i think the issue of requiring a toolchain conformant to a specific standard is a separate matter because any adoption of C11 standard atomics is a potential abi break from the current use of
intrinsics.
Quoted 16 lines
Quoted 16 lines
Quoted 2 lines
I am not sure why you are calling it as ABI break. Referring to [1], I just see
wrappers around intrinsics (though [2] does not use the intrinsics).
Quoted 8 lines
[1]
https://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/stdatomic.h
[2]
https://github.com/llvm-mirror/clang/blob/master/lib/Headers/stdat
omic
.hit's a potential abi break because atomic types are not the same types as their corresponding integer types etc.. (or at least are not guaranteed to be by all implementations of c as an abstract language).
Quoted 5 lines
Quoted 5 lines
ISO/IEC 9899:2011
6.2.5 (27)
Further, there is the_Atomicqualifier. The presence of the_Atomicqualifier designates an atomic type. The size, representation, andalignment
Quoted 5 lines
Quoted 5 lines
of an atomic type need not be the same as those of the corresponding unqualified type.
7.17.6 (3)
NOTE The representation of atomic integer types need not have thesame size
Quoted 10 lines
Quoted 10 lines
as their corresponding regular types. They should have the same
size whenever
possible, as it eases effort required to port existing code.i use the term `potential abi break' with intent because for me to assert in absolute terms i would have to evaluate the implementation of every current and potential future compilers atomic vs non-atomic types. this as i'm sure you understand is not practical, it would also defeat the purpose of moving to a standard. therefore i rely on the specification prescribed by the standard not the detail of a specific
Quoted 8 lines
Quoted 7 lines
implementation.
Quoted 1 line
Can we say that the platforms 'supported' by DPDK today do not have this
problem? Any future platforms that will come to DPDK have to evaluate this.
sadly i don't think we can. i believe in an earlier post i linked a bug filed on gcc that shows that clang / gcc were producing different layout than the equivalent non-atomic type.
I looked at that bug again, it is to do with structure.
just to be clear, you're saying you aren't concerned because we don't have in our public api struct objects to which we apply atomic operations?
if that guarantee is absolute and stays true in our public api then i am satisfied and we can drop the issue.
hypothetically if we make this assumption are you proposing that all platform/toolchain combinations that support std=c11 and optional stdatomic should adopt them as default on?
there are other implications to doing this, let's dig into the details at the next technical board meeting.
Quoted 12 lines
Quoted 12 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
the abstraction (whatever namespace it resides) allows the existing toolchain/platform combinations to maintain compatibility by defaulting to current non-standard intrinsics.
How about using the intrinsics (
__atomic_xxx) name space forabstraction?
Quoted 1 line
Quoted 1 line
This covers the GCC and Clang compilers.
Quoted 7 lines
Quoted 4 lines
i haven't investigated fully but there are usages of these intrinsics that indicate there may be undesirable difference between clang and gcc versions. the hint is there seems to be conditionally compiled code under
__clang__when using some __atomic's.I sent an RFC to address this [1]. I think the size specific intrinsics are not necessary.
[1] http://patches.dpdk.org/project/dpdk/patch/[email protected]/
yep, looks good to me. i acked the change.
thank you.
Quoted 11 lines
Quoted 11 lines
for the purpose of this discussion clang just tries to look like gcc so i don't regard them as being different compilers for the purpose of this discussion.
Quoted 5 lines
Quoted 5 lines
the namespace starting with
__is also reserved for the implementation. this is why compilers gcc/clang/msvc place name their intrinsic and builtin functions starting with __ to explicitly avoid collision with the application namespace.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
Agreed. But, here we are considering '
__atomic_' specifically (i.e. not just '__')i don't understand the confusion
__atomicis within the __ namespace that is reserved.What I mean is, we are not formulating a policy/rule to allow for any name space that starts with '__'.
understood, but we appear to be trying to formulate a policy allowing a name within that space which is reserved by the standard for and claimed by gcc.
anyway, let's discuss further at the meeting.
Quoted 10 lines
Quoted 9 lines
let me ask this another way, what benefit do you see to trying to overlap with the standard namespace? the only benefit i can see is that at some point in the future it avoids having to perform a mechanical change to eventually retire the abstraction once all platform/toolchains support standard atomics. i.e. basically s/rte_atomic/atomic/g
is there another benefit i'm missing?
The abstraction you have proposed solves the problem for the long term. The proposed abstraction stops us from thinking about moving to stdatomics.
i think this is where you've got me a bit confused. i'd like to understand how it stops us thinking about moving to stdatomics.
Quoted 1 line
IMO, the problem is short term. Using the
__atomic_name space does not have any practical issues with the platforms DPDK supports (unless msvc has a problem with this, more questions below).
oh, sorry for not answering this previously. msvc (and as it happens clang) both use __c11_atomic_xxx as a namespace. i'm only aware of gcc and potentially compilers that try to look like gcc using __atomic_xxxx.
so if you're asking if that selection would interfere with msvc, it wouldn't. i'm only concerned with mingling in a namespace that gcc has claimed.
Quoted 28 lines
Quoted 28 lines
Quoted 12 lines
Quoted 12 lines
ISO/IEC 9899:2011 7.1.3 (1) All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use. ...Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
If there is another platform that uses the same name space for something
else, I think DPDK should not be supporting that platform.
that's effectively a statement excluding windows platform and all non-gcc compilers from ever supporting dpdk.
Apologies, I did not understand your comment on windows platform. Do
you mean to say a compiler for windows platform uses '
__atomic_xxx' name space to provide some other functionality (and hence it would get excluded)?i mean dpdk can never fully be supported without msvc except for statically linked builds which are niche and limit it too severely for many consumers to practically use dpdk. there are also many application developers who would like to integrate dpdk but can't and telling them their only choice is to re-port their entire application to clang isn't feasible.
Quoted 7 lines
Quoted 5 lines
i can see no technical reason why we should be excluding a major compiler in broad use if it is capable of building dpdk. msvc arguably has some of the most sophisticated security features in the industry and the use of those features is mandated by many of the customers who might deploy dpdk applications on windows.
I did not mean DPDK should not support msvc (may be my sentence below was misunderstood). Does msvc provide '
__atomic_xxx' intrinsics?
msvc provides stdatomic (behind stdatomic there are intrinsics)
Quoted 42 lines
Quoted 42 lines
Quoted 3 lines
Clang supports these intrinsics. I am not sure about the merit of supporting
other non-gcc compilers. May be a topic Techboard discussion.
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
What problems do you see?
i'm fairly certain at least one other compiler uses the
__atomicnamespace butDo you mean
__atomicnamespace is used for some other purpose?Quoted 5 lines
it would take me time to check, the most notable potential issue that comes to mind is if such an intrinsic with the same name is provided in a different implementation and has either regressive code generation or different semantics it would be bad because it is intrinsic you can't just hack around it with #undef
__atomicto shim in asemantically correct version.
Quoted 1 line
I do not think we should worry about regressive code generation problem. It
should be fixed by that compiler.
Quoted 1 line
Different semantics is something we need to worry about. It would be good
to find out more about a compiler that does this.
again, this is about portability it's about potential not that we can find an example.
Quoted 11 lines
Quoted 11 lines
how about this, is there another possible namespace you might suggest that conforms or doesn't conflict with the the rules defined in ISO/IEC 9899:2011
7.1.3 i think if there were that would satisfy all of my concerns related to namespaces.keep in mind the point of moving to a standard is to achieve portability so if we do things that will regress us back to being dependent on an implementation we haven't succeeded. that's all i'm
trying to guarantee here.
Quoted 1 line
Agree. We are trying to solve a problem that is temporary. I am trying to
keep the problem scope narrow which might help us push to adopt the standard sooner.
Quoted 6 lines
Quoted 5 lines
i do wish we could just target the standard but unless we are willing to draw a line and say no more non std=c11 and also we potentially break the abi we are talking years. i don't think it is reasonable to block progress for years, so i'm offering a transitional path. it's an evolution over time that we have to manage.
Apologies if I am sounding like I am blocking progress. Rest assured, we will find a way. It is just about which solution we are going to pick.
no problems, i really appreciate any help.
Quoted 1 line
Also, is there are any information on how long before we move to C11?
we need to clear all long term compatibility promises for gcc/linux platforms that don't support -std=c11 and implement stdatomic option. the last discussion was that it was years i believe.
Bruce has a patch series and another thread going talking about moving to -std=c99 which is good but of course doesn't get us to std=c99.
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
i feel like we are really close on this discussion, if we can just iron this issue out we can probably get going on the actual changes.
thanks for the consideration.
Quoted 11 lines
Quoted 11 lines
once in place it provides an opportunity to introduce new toolchain/platform combinations and enables an opt-in capability to use stdatomics on existing toolchain/platform combinations subject to community discussion on how/if/when.
it would be good to get more participants into the discussion so i'll cc techboard for some attention. i feel like the only area that isn't decided is to do or not do this in
rte_namespace.Quoted 5 lines
Quoted 5 lines
i'm strongly in favor of
rte_namespace after discussion, mainly due to to disadvantages of trying to overlap with the standard namespace while not providing a compatible api/abi and because it provides clear disambiguation of that difference in semantics and compatibility withthe standard api.
Quoted 21 lines
Quoted 4 lines
so far i've noted the following
* we will not provide the non-explicit apis.
+1
Quoted 2 lines
* we will make no attempt to support operate on struct/union atomics with our apis.
+1
Quoted 11 lines
* we will mirror the standard api potentially in the
rte_namespace to
- reference the standard api documentation.
- assume compatible semantics (sans exceptions from first 2 points).my vote is to remove 'potentially' from the last point above for reasons previously discussed in postings to the mail thread.
thanks all for the discussion, i'll send up a patch removing non-explicit apis for viewing.
ty
hi folks,
just raising this to the top of mailboxes to call for reviewers. it's going to be a lot of work by the time it's done so your feedback is gretly appreciated.
thanks!
Quoted 27 lines · Tyler Retzlaff
Introduce an abstraction for compiler specific atomics and a meson option to allow standard C11 atomics use.
Note, this series does not attempt to convert to the use of the abstraction it only introduces it as per the plan discussed here.
http://mails.dpdk.org/archives/dev/2023-January/258693.htmldevtools checkatches warnings are expected as we intend no functional change with this series. Subsequent series will address the use of
__sync_xxxbuiltins warning.Tyler Retzlaff (1):
eal: introduce atomics abstractionconfig/meson.build | 11 +++ lib/eal/arm/include/rte_atomic_32.h | 6 +- lib/eal/arm/include/rte_atomic_64.h | 6 +- lib/eal/include/generic/rte_atomic.h | 156 ++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 +- lib/eal/ppc/include/rte_atomic.h | 6 +- lib/eal/riscv/include/rte_atomic.h | 6 +- lib/eal/x86/include/rte_atomic.h | 8 +- meson_options.txt | 2 + 9 files changed, 199 insertions(+), 8 deletions(-)Signature · 1 line
1.8.3.1
PATCH v2 1/1 eal: abstract compiler atomics
In reply to Tyler RetzlaffIntroduce an abstraction for compiler specific atomics and a meson option to allow standard C11 atomics use.
Note, this series does not attempt to convert to the use of the abstraction it only introduces it as per the plan discussed here.
http://mails.dpdk.org/archives/dev/2023-January/258693.html
devtools checkatches warnings are expected as we intend no functional change with this series. Subsequent series will address the use of __sync_xxx builtins warning.
v2:
* remove non-explicit rte_atomic_xxx macros.
Tyler Retzlaff (1):
eal: introduce atomics abstraction
config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/1 eal: introduce atomics abstraction
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)
config/meson.build +11 -0
@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') +else + add_project_arguments('-std=c11', language: 'c') +endif +endif + # enable extra warnings and disable any unwanted warnings # -Wall is added by default at warning level 1, and -Wextra # at warning level 2 (DPDK default)
lib/eal/arm/include/rte_atomic_32.h +5 -1
@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cplusplus
lib/eal/arm/include/rte_atomic_64.h +5 -1
@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations -------------------------*/
lib/eal/include/generic/rte_atomic.h +95 -1
108 lines not on this page · raw message
lib/eal/loongarch/include/rte_atomic.h +5 -1
@@ -35,9 +35,13 @@#define rte_io_rmb () rte_mb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cplusplus
lib/eal/ppc/include/rte_atomic.h +5 -1
@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/
lib/eal/riscv/include/rte_atomic.h +5 -1
@@ -40,9 +40,13 @@#define rte_io_rmb () asm volatile("fence ir, ir" : : : "memory") static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cplusplus
lib/eal/x86/include/rte_atomic.h +6 -2
@@ -87,12 +87,16 @@* used instead. */ static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { -if (memorder == __ATOMIC_SEQ_CST) +if (memorder == rte_memory_order_seq_cst)rte_smp_mb (); else +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/
meson_options.txt +2 -0
@@ -46,6 +46,8 @@ option('mbuf_refcnt_atomic', type: 'boolean', value: true, description: 'Atomically access the mbuf refcnt.') option('platform', type: 'string', value: 'native', description: 'Platform to build, either "native", "generic" or a SoC. Please refer to the Linux build guide for more information.') +option('enable_stdatomics', type: 'boolean', value: false, description: + 'enable use of standard C11 atomics.') option('enable_trace_fp', type: 'boolean', value: false, description: 'enable fast path trace points.') option('tests', type: 'boolean', value: true, description:
Signature · 1 line
1.8.3.1
RE: [PATCH v2] eal: introduce atomics abstraction
Quoted 8 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 8 February 2023 22.44Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>---
Looks good. A few minor suggestions about implementation only.
With or without suggested modifications,
Quoted 86 lines
config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +11
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') +else + add_project_arguments('-std=c11', language: 'c') +endif +endif + # enable extra warnings and disable any unwanted warnings # -Wall is added by default at warning level 1, and -Wextra # at warning level 2 (DPDK default)lib/eal/arm/include/rte_atomic_32.h +5
-1@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/arm/include/rte_atomic_64.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations ----------------- --------*/ lib/eal/include/generic/rte_atomic.h +2
-0@@ -110,6 +110,100 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS +
lib/eal/include/generic/rte_atomic.h line 124
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +9
-0+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ <201112L || defined(__STDC_NO_ATOMICS__) +#error compiler does not support C11 standard atomics +#else +#include <stdatomic.h> +#endif + +#define __rte_atomic _Atomic + +typedef int rte_memory_order ;
I would prefer enum for rte_memory_order:
typedef enum {
rte_memory_order_relaxed = memory_order_relaxed, rte_memory_order_consume = memory_order_consume, rte_memory_order_acquire = memory_order_acquire, rte_memory_order_release = memory_order_release, rte_memory_order_acq_rel = memory_order_acq_rel, rte_memory_order_seq_cst = memory_order_seq_cst
} rte_memory_order;
Quoted 44 lines
lib/eal/include/generic/rte_atomic.h +21
-0+ +#define rte_memory_order_relaxed memory_order_relaxed +#define rte_memory_order_consume memory_order_consume +#define rte_memory_order_acquire memory_order_acquire +#define rte_memory_order_release memory_order_release +#define rte_memory_order_acq_rel memory_order_acq_rel +#define rte_memory_order_seq_cst memory_order_seq_cst + +#define rte_atomic_store_explicit (obj, desired, order) \ + atomic_store_explicit(obj, desired, order) + +#define rte_atomic_load_explicit (obj, order) \ + atomic_load_explicit(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + atomic_exchange_explicit(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit (obj, expected, desired, success, fail) \ + atomic_compare_exchange_strong_explicit(obj, expected, desired, success, fail) + +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h +1
-0+ atomic_compare_exchange_weak_explicit(obj, expected, desired,success, fail)
lib/eal/include/generic/rte_atomic.h +18
-0+ +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + atomic_fetch_add_explicit(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + atomic_fetch_sub_explicit(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + atomic_fetch_or_explicit(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + atomic_fetch_xor_explicit(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + atomic_fetch_and_explicit(obj, arg, order) + +#else +
lib/eal/include/generic/rte_atomic.h line 173
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +10
-0+#define __rte_atomic + +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed __ATOMIC_RELAXED +#define rte_memory_order_consume __ATOMIC_CONSUME +#define rte_memory_order_acquire __ATOMIC_ACQUIRE +#define rte_memory_order_release __ATOMIC_RELEASE +#define rte_memory_order_acq_rel __ATOMIC_ACQ_REL +#define rte_memory_order_seq_cst __ATOMIC_SEQ_CST
Prefer enum for rte_memory_order:
typedef enum {
rte_memory_order_relaxed = __ATOMIC_RELAXED,
rte_memory_order_consume = __ATOMIC_CONSUME,
rte_memory_order_acquire = __ATOMIC_ACQUIRE,
rte_memory_order_release = __ATOMIC_RELEASE,
rte_memory_order_acq_rel = __ATOMIC_ACQ_REL,
rte_memory_order_seq_cst = __ATOMIC_SEQ_CST
} rte_memory_order;
Quoted 13 lines
lib/eal/include/generic/rte_atomic.h +11
-0+ +#define rte_atomic_store_explicit (obj, desired, order) \ + __atomic_store_n(obj, desired, order) + +#define rte_atomic_load_explicit (obj, order) \ + __atomic_load_n(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + __atomic_exchange_n(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h +1
-0+ __atomic_compare_exchange_n(obj, expected, desired, 0, success,
Quoted 1 line
fail)
The type of the "weak" parameter to __atomic_compare_exchange_n() is bool, not int, so use "false" instead of 0. There is probably no practical difference, so I'll leave it up to you.
You might need to include <stdbool.h> for this... I haven't checked.
Quoted 5 lines
lib/eal/include/generic/rte_atomic.h +2
-0+ +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h +1
-0+ __atomic_compare_exchange_n(obj, expected, desired, 1, success,fail)
Same as above: Use "true" instead of 1.
Quoted 137 lines
lib/eal/include/generic/rte_atomic.h +18
-0+ +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + __atomic_fetch_add(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + __atomic_fetch_sub(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + __atomic_fetch_or(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + __atomic_fetch_xor(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + __atomic_fetch_and(obj, arg, order) + +#endif +/** * Compiler barrier. * @@ -123,7 +217,7 @@/** * Synchronization fence between threads based on the specified memory order.
*/lib/eal/include/generic/rte_atomic.h +1
-2-static inline void rte_atomic_thread_fence (int memorder); +static inline void rte_atomic_thread_fence (rte_memory_order memorder);/*------------------------- 16 bit atomic operations ----------------- --------*/ lib/eal/loongarch/include/rte_atomic.h +5
-1@@ -35,9 +35,13 @@#define rte_io_rmb () rte_mb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/ppc/include/rte_atomic.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations ----------------- --------*/ lib/eal/riscv/include/rte_atomic.h +5
-1@@ -40,9 +40,13 @@#define rte_io_rmb () asm volatile("fence ir, ir" : : : "memory") static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/x86/include/rte_atomic.h +6
-3@@ -87,12 +87,16 @@* used instead. */ static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { -if (memorder == __ATOMIC_SEQ_CST) +if (memorder == rte_memory_order_seq_cst)rte_smp_mb (); else +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations ----------------- --------*/ meson_options.txt +0
-0@@ -46,6 +46,8 @@ option('mbuf_refcnt_atomic', type: 'boolean', value:true, description:
'Atomically access the mbuf refcnt.')
option('platform', type: 'string', value: 'native', description:
'Platform to build, either "native", "generic" or a SoC. Please
refer to the Linux build guide for more information.') +option('enable_stdatomics', type: 'boolean', value: false, description:
+ 'enable use of standard C11 atomics.')
option('enable_trace_fp', type: 'boolean', value: false, description:
'enable fast path trace points.')
option('tests', type: 'boolean', value: true, description:
--
1.8.3.1
Re: [PATCH v2] eal: introduce atomics abstraction
Quoted 115 lines · Morten Brørup
Quoted 8 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 8 February 2023 22.44Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>---
Looks good. A few minor suggestions about implementation only.
With or without suggested modifications,
Acked-by Morten Brørup <[email protected]>Quoted 86 lines
config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +11
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') +else + add_project_arguments('-std=c11', language: 'c') +endif +endif + # enable extra warnings and disable any unwanted warnings # -Wall is added by default at warning level 1, and -Wextra # at warning level 2 (DPDK default)lib/eal/arm/include/rte_atomic_32.h +5
-1@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/arm/include/rte_atomic_64.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations ----------------- --------*/ lib/eal/include/generic/rte_atomic.h +2
-0@@ -110,6 +110,100 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS +lib/eal/include/generic/rte_atomic.h line 124
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +9
-0+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ <201112L || defined(__STDC_NO_ATOMICS__) +#error compiler does not support C11 standard atomics +#else +#include <stdatomic.h> +#endif + +#define __rte_atomic _Atomic + +typedef int rte_memory_order ;I would prefer enum for
rte_memory_order:
Quoted 8 lines
typedef enum {
rte_memory_order_relaxed=memory_order_relaxed,rte_memory_order_consume=memory_order_consume,rte_memory_order_acquire=memory_order_acquire,rte_memory_order_release=memory_order_release,rte_memory_order_acq_rel=memory_order_acq_rel,rte_memory_order_seq_cst=memory_order_seq_cst
}rte_memory_order;
the reason for not using enum type is abi related. the c standard has this little gem.
ISO/IEC 9899:2011
6.7.2.2 (4)
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, 128) but shall be capable of representing the values of all the members of the enumeration.
128) An implementation may delay the choice of which integer type until all enumeration constants have been seen.
so i'm just being overly protective of maintaining the forward compatibility of the abi.
probably i'm being super unnecessarily cautious in this case since i think in practice even if an implementation chose sizeof(char) i doubt very much that enough enumerated values would get added to this enumeration within the lifetime of the API to suddenly cause the compiler to choose > sizeof(char).
incidentally this is also why you can't forward declare enums in c.
Quoted 84 lines
Quoted 45 lines
lib/eal/include/generic/rte_atomic.h +21
-0+ +#define rte_memory_order_relaxed memory_order_relaxed +#define rte_memory_order_consume memory_order_consume +#define rte_memory_order_acquire memory_order_acquire +#define rte_memory_order_release memory_order_release +#define rte_memory_order_acq_rel memory_order_acq_rel +#define rte_memory_order_seq_cst memory_order_seq_cst + +#define rte_atomic_store_explicit (obj, desired, order) \ + atomic_store_explicit(obj, desired, order) + +#define rte_atomic_load_explicit (obj, order) \ + atomic_load_explicit(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + atomic_exchange_explicit(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit (obj, expected, desired, success, fail) \ + atomic_compare_exchange_strong_explicit(obj, expected, desired, success, fail) + +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h +1
-0+ atomic_compare_exchange_weak_explicit(obj, expected, desired,success, fail)
lib/eal/include/generic/rte_atomic.h +18
-0+ +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + atomic_fetch_add_explicit(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + atomic_fetch_sub_explicit(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + atomic_fetch_or_explicit(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + atomic_fetch_xor_explicit(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + atomic_fetch_and_explicit(obj, arg, order) + +#else +lib/eal/include/generic/rte_atomic.h line 173
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +10
-0+#define __rte_atomic + +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed __ATOMIC_RELAXED +#define rte_memory_order_consume __ATOMIC_CONSUME +#define rte_memory_order_acquire __ATOMIC_ACQUIRE +#define rte_memory_order_release __ATOMIC_RELEASE +#define rte_memory_order_acq_rel __ATOMIC_ACQ_REL +#define rte_memory_order_seq_cst __ATOMIC_SEQ_CSTPrefer enum for
rte_memory_order:typedef enum {
rte_memory_order_relaxed=__ATOMIC_RELAXED,
rte_memory_order_consume=__ATOMIC_CONSUME,
rte_memory_order_acquire=__ATOMIC_ACQUIRE,
rte_memory_order_release=__ATOMIC_RELEASE,
rte_memory_order_acq_rel=__ATOMIC_ACQ_REL,
rte_memory_order_seq_cst=__ATOMIC_SEQ_CST
}rte_memory_order;Quoted 13 lines
lib/eal/include/generic/rte_atomic.h +11
-0+ +#define rte_atomic_store_explicit (obj, desired, order) \ + __atomic_store_n(obj, desired, order) + +#define rte_atomic_load_explicit (obj, order) \ + __atomic_load_n(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + __atomic_exchange_n(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h +1
-0+ __atomic_compare_exchange_n(obj, expected, desired, 0, success,Quoted 1 line
fail)
The type of the "weak" parameter to
__atomic_compare_exchange_n()is bool, not int, so use "false" instead of 0. There is probably no practical difference, so I'll leave it up to you.
Quoted 1 line
You might need to include <
stdbool.h> for this... I haven't checked.
strictly speaking you are correct the intrinsic does take bool according to documentation.
ISO/IEC 9899:2011
7.18 Boolean type and values <stdbool.h>
(1) The header <stdbool.h> defines four macros.
(2) The macro bool expands to _Bool.
(3) The remaining three macros are suitable for use in #if preprocessing directives. They are true' which expands to the integer constant 1, false' which expands to the integer constant 0, and __bool_true_false_are_defined which expands to the integer constant 1.
so i could include the header, to expand a macro which expands to integer constant 0 or 1 as appropriate for weak vs strong. do you think i should? (serious question) if you answer yes, i'll make the change.
Quoted 146 lines
Quoted 6 lines
lib/eal/include/generic/rte_atomic.h +2
-0+ +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h +1
-0+ __atomic_compare_exchange_n(obj, expected, desired, 1, success,fail)
Same as above: Use "true" instead of 1.
Quoted 137 lines
lib/eal/include/generic/rte_atomic.h +18
-0+ +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + __atomic_fetch_add(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + __atomic_fetch_sub(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + __atomic_fetch_or(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + __atomic_fetch_xor(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + __atomic_fetch_and(obj, arg, order) + +#endif +/** * Compiler barrier. * @@ -123,7 +217,7 @@/** * Synchronization fence between threads based on the specified memory order.
*/lib/eal/include/generic/rte_atomic.h +1
-2-static inline void rte_atomic_thread_fence (int memorder); +static inline void rte_atomic_thread_fence (rte_memory_order memorder);/*------------------------- 16 bit atomic operations ----------------- --------*/ lib/eal/loongarch/include/rte_atomic.h +5
-1@@ -35,9 +35,13 @@#define rte_io_rmb () rte_mb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/ppc/include/rte_atomic.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations ----------------- --------*/ lib/eal/riscv/include/rte_atomic.h +5
-1@@ -40,9 +40,13 @@#define rte_io_rmb () asm volatile("fence ir, ir" : : : "memory") static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/x86/include/rte_atomic.h +6
-3@@ -87,12 +87,16 @@* used instead. */ static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { -if (memorder == __ATOMIC_SEQ_CST) +if (memorder == rte_memory_order_seq_cst)rte_smp_mb (); else +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations ----------------- --------*/ meson_options.txt +0
-0@@ -46,6 +46,8 @@ option('mbuf_refcnt_atomic', type: 'boolean', value:true, description:
'Atomically access the mbuf refcnt.')
option('platform', type: 'string', value: 'native', description:
'Platform to build, either "native", "generic" or a SoC. Please
refer to the Linux build guide for more information.') +option('enable_stdatomics', type: 'boolean', value: false, description:
+ 'enable use of standard C11 atomics.')
option('enable_trace_fp', type: 'boolean', value: false, description:
'enable fast path trace points.')
option('tests', type: 'boolean', value: true, description:
--
1.8.3.1
RE: [PATCH v2] eal: introduce atomics abstraction
Quoted 20 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Thursday, 9 February 2023 19.15Quoted 4 lines · Morten Brørup
Quoted 4 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 8 February 2023 22.44Introduce atomics abstraction that permits optional use of standard
C11
Quoted 1 line
Quoted 1 line
atomics when meson is provided the new enable_stdatomics=true
option.
Quoted 9 lines
Quoted 3 lines
Signed-off-by Tyler Retzlaff <[email protected]>---
Looks good. A few minor suggestions about implementation only.
With or without suggested modifications,
Acked-by Morten Brørup <[email protected]>
[...]
Quoted 53 lines
Quoted 24 lines
Quoted 11 lines
lib/eal/include/generic/rte_atomic.h +2
-0@@ -110,6 +110,100 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS +lib/eal/include/generic/rte_atomic.h line 124
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +9
-0+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ <201112L || defined(__STDC_NO_ATOMICS__) +#error compiler does not support C11 standard atomics +#else +#include <stdatomic.h> +#endif + +#define __rte_atomic _Atomic + +typedef int rte_memory_order ;I would prefer enum for
rte_memory_order:Quoted 8 lines
typedef enum {
rte_memory_order_relaxed=memory_order_relaxed,rte_memory_order_consume=memory_order_consume,rte_memory_order_acquire=memory_order_acquire,rte_memory_order_release=memory_order_release,rte_memory_order_acq_rel=memory_order_acq_rel,rte_memory_order_seq_cst=memory_order_seq_cst
}rte_memory_order;the reason for not using enum type is abi related. the c standard has this little gem.
ISO/IEC 9899:2011 6.7.2.2 (4) Each enumerated type shall be compatible with char, a signedinteger
type, or an unsigned integer type. The choice of type is implementation-defined, 128) but shall be capable of representing
the
values of all the members of the enumeration.128) An implementation may delay the choice of which integer type
until
all enumeration constants have been seen.so i'm just being overly protective of maintaining the forward compatibility of the abi.
Quoted 8 lines
probably i'm being super unnecessarily cautious in this case since i think
in practice even if an implementation chose sizeof(char) i doubt very much
that enough enumerated values would get added to this enumeration within
the lifetime of the API to suddenly cause the compiler to choose > sizeof(char).
I am under the impression that compilers usually instantiate enum as int, and you can make it use a smaller size by decorating it with the "packed" attribute - I have benefited from that in the past.
The only risk I am effectively trying to avoid is someone calling an rte_atomic() function with "order" being another value than one of these values. Probably not ever going to happen.
Your solution also addresses an academic risk (of the compiler using another type than int for the enum), which will have unwanted side effects - especially if the "order" parameter to the rte_atomic() functions becomes char instead of int.
I can now conclude that your proposed type (int) is stronger/safer than the type (enum) I suggested. So please keep what you have.
Quoted 3 lines
incidentally this is also why you can't forward declare enums in c.
[...]
Quoted 17 lines
Quoted 6 lines
Quoted 4 lines
+#define
rte_atomic_compare_exchange_strong_explicit(obj, expected, desired, success, fail)\lib/eal/include/generic/rte_atomic.h +1
-0+ __atomic_compare_exchange_n(obj, expected, desired, 0, success,fail)
The type of the "weak" parameter to
__atomic_compare_exchange_n()isbool, not int, so use "false" instead of 0. There is probably no practical difference, so I'll leave it up to you.
Quoted 2 lines
You might need to include <
stdbool.h> for this... I haven't checked.strictly speaking you are correct the intrinsic does take bool according
to documentation.ISO/IEC 9899:2011
Quoted 10 lines
7.18 Boolean type and values <
stdbool.h>
(1) The header <stdbool.h> defines four macros.
(2) The macro bool expands to_Bool.
(3) The remaining three macros are suitable for use in #if
preprocessing
directives. They are `true' which expands to the integer constant
1,
`false' which expands to the integer constant 0, and__bool_true_false_are_definedwhich expands to the integer
constant 1.
Thank you for this reference. I wasn't aware that the two boolean values explicitly expanded to those two integer constants. I had never thought about it, but simply assumed that the constant "true" had the same meaning as "not false", like "if (123)" evaluates "123" as true.
So I learned something new today.
Quoted 4 lines
so i could include the header, to expand a macro which expands to integer constant 0 or 1 as appropriate for weak vs strong. do you think i should? (serious question) if you answer yes, i'll make the change.
Then no. Please keep the 1's and 0's.
Re: [PATCH v2] eal: introduce atomics abstraction
Quoted 85 lines · Morten Brørup
Quoted 20 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Thursday, 9 February 2023 19.15Quoted 4 lines · Morten Brørup
Quoted 4 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 8 February 2023 22.44Introduce atomics abstraction that permits optional use of standard
C11
Quoted 1 line
Quoted 1 line
atomics when meson is provided the new enable_stdatomics=true
option.
Quoted 9 lines
Quoted 3 lines
Signed-off-by Tyler Retzlaff <[email protected]>---
Looks good. A few minor suggestions about implementation only.
With or without suggested modifications,
Acked-by Morten Brørup <[email protected]>[...]
Quoted 53 lines
Quoted 24 lines
Quoted 11 lines
lib/eal/include/generic/rte_atomic.h +2
-0@@ -110,6 +110,100 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS +lib/eal/include/generic/rte_atomic.h line 124
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +9
-0+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ <201112L || defined(__STDC_NO_ATOMICS__) +#error compiler does not support C11 standard atomics +#else +#include <stdatomic.h> +#endif + +#define __rte_atomic _Atomic + +typedef int rte_memory_order ;I would prefer enum for
rte_memory_order:Quoted 8 lines
typedef enum {
rte_memory_order_relaxed=memory_order_relaxed,rte_memory_order_consume=memory_order_consume,rte_memory_order_acquire=memory_order_acquire,rte_memory_order_release=memory_order_release,rte_memory_order_acq_rel=memory_order_acq_rel,rte_memory_order_seq_cst=memory_order_seq_cst
}rte_memory_order;the reason for not using enum type is abi related. the c standard has this little gem.
ISO/IEC 9899:2011 6.7.2.2 (4) Each enumerated type shall be compatible with char, a signedinteger
type, or an unsigned integer type. The choice of type is implementation-defined, 128) but shall be capable of representing
the
values of all the members of the enumeration.128) An implementation may delay the choice of which integer type
until
all enumeration constants have been seen.so i'm just being overly protective of maintaining the forward compatibility of the abi.
Quoted 8 lines
probably i'm being super unnecessarily cautious in this case since i think
in practice even if an implementation chose sizeof(char) i doubt very much
that enough enumerated values would get added to this enumeration within
the lifetime of the API to suddenly cause the compiler to choose > sizeof(char).
Quoted 1 line
I am under the impression that compilers usually instantiate enum as int, and you can make it use a smaller size by decorating it with the "packed" attribute - I have benefited from that in the past.
generally i think most implementations choose int as a default but i think there is potential for char to get used if the compiler is asked to optimize for size. not a likely optimization preference when using dpdk.
Quoted 43 lines
The only risk I am effectively trying to avoid is someone calling an
rte_atomic()function with "order" being another value than one of these values. Probably not ever going to happen.Your solution also addresses an academic risk (of the compiler using another type than int for the enum), which will have unwanted side effects - especially if the "order" parameter to the
rte_atomic()functions becomes char instead of int.I can now conclude that your proposed type (int) is stronger/safer than the type (enum) I suggested. So please keep what you have.
Quoted 3 lines
incidentally this is also
[...]
Quoted 17 lines
Quoted 6 lines
Quoted 4 lines
+#define
rte_atomic_compare_exchange_strong_explicit(obj, expected, desired, success, fail)\lib/eal/include/generic/rte_atomic.h +1
-0+ __atomic_compare_exchange_n(obj, expected, desired, 0, success,fail)
The type of the "weak" parameter to
__atomic_compare_exchange_n()isbool, not int, so use "false" instead of 0. There is probably no practical difference, so I'll leave it up to you.
Quoted 2 lines
You might need to include <
stdbool.h> for this... I haven't checked.strictly speaking you are correct the intrinsic does take bool according
to documentation.ISO/IEC 9899:2011
Quoted 10 lines
7.18 Boolean type and values <
stdbool.h>
(1) The header <stdbool.h> defines four macros.
(2) The macro bool expands to_Bool.
(3) The remaining three macros are suitable for use in #if
preprocessing
directives. They are `true' which expands to the integer constant
1,
`false' which expands to the integer constant 0, and__bool_true_false_are_definedwhich expands to the integer
constant 1.Thank you for this reference. I wasn't aware that the two boolean values explicitly expanded to those two integer constants. I had never thought about it, but simply assumed that the constant "true" had the same meaning as "not false", like "if (123)" evaluates "123" as true.
Quoted 8 lines
So I learned something new today.
Quoted 4 lines
so i could include the header, to expand a macro which expands to integer constant 0 or 1 as appropriate for weak vs strong. do you think i should? (serious question) if you answer yes, i'll make the change.
Then no. Please keep the 1's and 0's.
thanks! will leave it as is.
Re: [PATCH v2] eal: introduce atomics abstraction
In reply to Morten BrørupQuoted 181 lines · Morten Brørup
Quoted 8 lines
From: Tyler Retzlaff [mailto:[email protected]]
Sent: Wednesday, 8 February 2023 22.44Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>---
Looks good. A few minor suggestions about implementation only.
With or without suggested modifications,
Acked-by Morten Brørup <[email protected]>Quoted 86 lines
config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +11
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') +else + add_project_arguments('-std=c11', language: 'c') +endif +endif + # enable extra warnings and disable any unwanted warnings # -Wall is added by default at warning level 1, and -Wextra # at warning level 2 (DPDK default)lib/eal/arm/include/rte_atomic_32.h +5
-1@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/arm/include/rte_atomic_64.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations ----------------- --------*/ lib/eal/include/generic/rte_atomic.h +2
-0@@ -110,6 +110,100 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS +lib/eal/include/generic/rte_atomic.h line 124
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +9
-0+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ <201112L || defined(__STDC_NO_ATOMICS__) +#error compiler does not support C11 standard atomics +#else +#include <stdatomic.h> +#endif + +#define __rte_atomic _Atomic + +typedef int rte_memory_order ;I would prefer enum for
rte_memory_order:typedef enum {
rte_memory_order_relaxed=memory_order_relaxed,rte_memory_order_consume=memory_order_consume,rte_memory_order_acquire=memory_order_acquire,rte_memory_order_release=memory_order_release,rte_memory_order_acq_rel=memory_order_acq_rel,rte_memory_order_seq_cst=memory_order_seq_cst
}rte_memory_order;Quoted 44 lines
lib/eal/include/generic/rte_atomic.h +21
-0+ +#define rte_memory_order_relaxed memory_order_relaxed +#define rte_memory_order_consume memory_order_consume +#define rte_memory_order_acquire memory_order_acquire +#define rte_memory_order_release memory_order_release +#define rte_memory_order_acq_rel memory_order_acq_rel +#define rte_memory_order_seq_cst memory_order_seq_cst + +#define rte_atomic_store_explicit (obj, desired, order) \ + atomic_store_explicit(obj, desired, order) + +#define rte_atomic_load_explicit (obj, order) \ + atomic_load_explicit(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + atomic_exchange_explicit(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit (obj, expected, desired, success, fail) \ + atomic_compare_exchange_strong_explicit(obj, expected, desired, success, fail) + +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h +1
-0+ atomic_compare_exchange_weak_explicit(obj, expected, desired,success, fail)
lib/eal/include/generic/rte_atomic.h +18
-0+ +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + atomic_fetch_add_explicit(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + atomic_fetch_sub_explicit(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + atomic_fetch_or_explicit(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + atomic_fetch_xor_explicit(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + atomic_fetch_and_explicit(obj, arg, order) + +#else +lib/eal/include/generic/rte_atomic.h line 173
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +10
-0+#define __rte_atomic + +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed __ATOMIC_RELAXED +#define rte_memory_order_consume __ATOMIC_CONSUME +#define rte_memory_order_acquire __ATOMIC_ACQUIRE +#define rte_memory_order_release __ATOMIC_RELEASE +#define rte_memory_order_acq_rel __ATOMIC_ACQ_REL +#define rte_memory_order_seq_cst __ATOMIC_SEQ_CSTPrefer enum for
rte_memory_order:
Quoted 9 lines
typedef enum {
rte_memory_order_relaxed=__ATOMIC_RELAXED,
rte_memory_order_consume=__ATOMIC_CONSUME,
rte_memory_order_acquire=__ATOMIC_ACQUIRE,
rte_memory_order_release=__ATOMIC_RELEASE,
rte_memory_order_acq_rel=__ATOMIC_ACQ_REL,
rte_memory_order_seq_cst=__ATOMIC_SEQ_CST
}rte_memory_order;
Minus the typedef, I would suggest.
The DPDK coding conventions calls for enum values to be upper case.
Quoted 165 lines
Quoted 13 lines
lib/eal/include/generic/rte_atomic.h +11
-0+ +#define rte_atomic_store_explicit (obj, desired, order) \ + __atomic_store_n(obj, desired, order) + +#define rte_atomic_load_explicit (obj, order) \ + __atomic_load_n(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + __atomic_exchange_n(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h +1
-0+ __atomic_compare_exchange_n(obj, expected, desired, 0, success,Quoted 1 line
fail)
The type of the "weak" parameter to
__atomic_compare_exchange_n()is bool, not int, so use "false" instead of 0. There is probably no practical difference, so I'll leave it up to you.You might need to include <
stdbool.h> for this... I haven't checked.Quoted 5 lines
lib/eal/include/generic/rte_atomic.h +2
-0+ +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h +1
-0+ __atomic_compare_exchange_n(obj, expected, desired, 1, success,fail)
Same as above: Use "true" instead of 1.
Quoted 137 lines
lib/eal/include/generic/rte_atomic.h +18
-0+ +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + __atomic_fetch_add(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + __atomic_fetch_sub(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + __atomic_fetch_or(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + __atomic_fetch_xor(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + __atomic_fetch_and(obj, arg, order) + +#endif +/** * Compiler barrier. * @@ -123,7 +217,7 @@/** * Synchronization fence between threads based on the specified memory order.
*/lib/eal/include/generic/rte_atomic.h +1
-2-static inline void rte_atomic_thread_fence (int memorder); +static inline void rte_atomic_thread_fence (rte_memory_order memorder);/*------------------------- 16 bit atomic operations ----------------- --------*/ lib/eal/loongarch/include/rte_atomic.h +5
-1@@ -35,9 +35,13 @@#define rte_io_rmb () rte_mb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/ppc/include/rte_atomic.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations ----------------- --------*/ lib/eal/riscv/include/rte_atomic.h +5
-1@@ -40,9 +40,13 @@#define rte_io_rmb () asm volatile("fence ir, ir" : : : "memory") static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/x86/include/rte_atomic.h +6
-3@@ -87,12 +87,16 @@* used instead. */ static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { -if (memorder == __ATOMIC_SEQ_CST) +if (memorder == rte_memory_order_seq_cst)rte_smp_mb (); else +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations ----------------- --------*/ meson_options.txt +0
-0@@ -46,6 +46,8 @@ option('mbuf_refcnt_atomic', type: 'boolean', value:true, description:
'Atomically access the mbuf refcnt.')
option('platform', type: 'string', value: 'native', description:
'Platform to build, either "native", "generic" or a SoC. Please
refer to the Linux build guide for more information.') +option('enable_stdatomics', type: 'boolean', value: false, description:
+ 'enable use of standard C11 atomics.')
option('enable_trace_fp', type: 'boolean', value: false, description:
'enable fast path trace points.')
option('tests', type: 'boolean', value: true, description:
--
1.8.3.1
Re: [PATCH v2] eal: introduce atomics abstraction
In reply to Tyler RetzlaffQuoted 21 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +0
-0
config/meson.build endif · line 263
Quoted 9 lines
config/meson.build +6
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c')
Is there a reason for using gnu11 on gcc and clang, rather than limiting ourselves to proper c11 support?
/Bruce
Re: [PATCH v2] eal: introduce atomics abstraction
Quoted 25 lines · Bruce Richardson
Quoted 24 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +0
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c')
Quoted 10 lines
config/meson.build endif · line 263
Quoted 6 lines
config/meson.build +6
-0+stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c')Is there a reason for using gnu11 on gcc and clang, rather than limiting ourselves to proper c11 support?
+1 to stick to c11 standard instead of relying compiler extensions
Re: [PATCH v2] eal: introduce atomics abstraction
Quoted 37 lines · Ferruh Yigit
Quoted 25 lines · Bruce Richardson
Quoted 24 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +0
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c')Quoted 10 lines
config/meson.build endif · line 263
Quoted 6 lines
config/meson.build +6
-0+stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c')Is there a reason for using gnu11 on gcc and clang, rather than limiting ourselves to proper c11 support?
Quoted 1 line
+1 to stick to c11 standard instead of relying compiler extensions
the extensions are already in use. enabling -std=c11 causes warnings about the extensions to start being emitted.
but since i feel encouraged here, i think i will interpret your request as let's limit the scope of enablement of extensions to where they are already used instead of enabling them over the whole build.
i will submit a new revision patch to get rid of -std=gnu11 here.
thanks!
Re: [PATCH v2] eal: introduce atomics abstraction
Quoted 38 lines · Tyler Retzlaff
Quoted 37 lines · Ferruh Yigit
Quoted 35 lines · Bruce Richardson
Quoted 21 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +0
-0config/meson.build endif · line 263
Quoted 9 lines
config/meson.build +6
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c')Is there a reason for using gnu11 on gcc and clang, rather than limiting ourselves to proper c11 support?
Quoted 5 lines
Quoted 1 line
+1 to stick to c11 standard instead of relying compiler extensions
the extensions are already in use. enabling -std=c11 causes warnings about the extensions to start being emitted.
There is '__extension__' keyword (RTE_STD_C11) which is already used in many places, can it help to remove the warnings? If it helps we can use it, which helps to document where compiler extensions used in the code.
Quoted 7 lines
but since i feel encouraged here, i think i will interpret your request as let's limit the scope of enablement of extensions to where they are already used instead of enabling them over the whole build.
i will submit a new revision patch to get rid of -std=gnu11 here.
thanks!
Re: [PATCH v2] eal: introduce atomics abstraction
Quoted 41 lines · Ferruh Yigit
Quoted 40 lines · Tyler Retzlaff
Quoted 38 lines · Ferruh Yigit
Quoted 25 lines · Bruce Richardson
Quoted 24 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +0
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c')Quoted 10 lines
config/meson.build endif · line 263
Quoted 6 lines
config/meson.build +6
-0+stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c')Is there a reason for using gnu11 on gcc and clang, rather than limiting ourselves to proper c11 support?
+1 to stick to c11 standard instead of relying compiler extensions
Quoted 7 lines
Quoted 3 lines
the extensions are already in use. enabling -std=c11 causes warnings about the extensions to start being emitted.
There is '
__extension__' keyword (RTE_STD_C11) which is already used in many places, can it help to remove the warnings? If it helps we can use it, which helps to document where compiler extensions used in the code.
yeah, that macro name kind of makes no sense when you realize it expands to __extension__ because a lot of places is it use isn't about an extension for something from a standard header. sometimes it's used to just annotate regular old gcc extensions/syntax.
i vaguely recall that the actual warning is for a missing declaration of an extern function or something (presumably because it comes from glibc) but not using -std=gnu11 or the macro dance didn't make the prototype visible in the stdxxx.h header.
so i don't think __extension__ would actually be a good way to suppress that warning and even if it did i'm trying to reduce code that carries __extension__ to improve portability anyway.
i'll submit a new version of the patch series fixing it but without the -std=gnu11 it's really the right thing to do.
ty
Quoted 8 lines
Quoted 8 lines
but since i feel encouraged here, i think i will interpret your request as let's limit the scope of enablement of extensions to where they are already used instead of enabling them over the whole build.
i will submit a new revision patch to get rid of -std=gnu11 here.
thanks!
Re: [PATCH v2] eal: introduce atomics abstraction
In reply to Bruce RichardsonQuoted 25 lines · Bruce Richardson
Quoted 24 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +0
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c')
Quoted 9 lines
config/meson.build endif · line 263
Quoted 6 lines
config/meson.build +6
-0+stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c')Is there a reason for using gnu11 on gcc and clang, rather than limiting ourselves to proper c11 support?
there is code using posix extensions, there are two ways to use them without emitting warnings.
1. -std=gnu11 (to get C11 with GNU extensions)
-- or --
2. -std=c11 and then in the source files consuming the C11 GNU extensions do some dance with various GNUC macros before including various stdxxx.h headers to enable the extensions for the translation unit.
i vaguely recall that if you try to do a test build with -std=c11 over the whole tree with meson --werror it will highlight the exact code i'm talking about.
selfishly i'd be happy to see (2) done and potentially eliminate the use of the extensions, but i didn't want to be disruptive as a part of this change.
Quoted 2 lines
/Bruce
Re: [PATCH v2] eal: introduce atomics abstraction
Quoted 48 lines · Tyler Retzlaff
Quoted 25 lines · Bruce Richardson
Quoted 24 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +0
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c')Quoted 9 lines
config/meson.build endif · line 263
Quoted 6 lines
config/meson.build +6
-0+stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c')Is there a reason for using gnu11 on gcc and clang, rather than limiting ourselves to proper c11 support?
there is code using posix extensions, there are two ways to use them without emitting warnings.
1. -std=gnu11 (to get C11 with GNU extensions)
-- or --
2. -std=c11 and then in the source files consuming the C11 GNU extensions do some dance with various GNUC macros before including various
stdxxx.hheaders to enable the extensions for the translation unit.
Quoted 8 lines
i vaguely recall that if you try to do a test build with -std=c11 over the whole tree with meson --werror it will highlight the exact code i'm talking about.
selfishly i'd be happy to see (2) done and potentially eliminate the use of the extensions, but i didn't want to be disruptive as a part of this change.
Some of the GNU extensions are useful, and have no equivalent in C11.
Statement expressions is one example that comes to mind.
I think you can get such code through GCC even with -std=c11, but not if combined with -pedantic.
Re: [PATCH v2] eal: introduce atomics abstraction
In reply to Tyler RetzlaffQuoted 3 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Terminology nitpicking: I don't think these functions provide any abstraction at all. They are just wrappers.
Quoted 90 lines
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +11
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') +else + add_project_arguments('-std=c11', language: 'c') +endif +endif + # enable extra warnings and disable any unwanted warnings # -Wall is added by default at warning level 1, and -Wextra # at warning level 2 (DPDK default)lib/eal/arm/include/rte_atomic_32.h +5
-1@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/arm/include/rte_atomic_64.h +5
-1@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations -------------------------*/ lib/eal/include/generic/rte_atomic.h +9
-0@@ -110,6 +110,100 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ <201112L || defined(__STDC_NO_ATOMICS__) +#error compiler does not support C11 standard atomics +#else +#include <stdatomic.h> +#endif + +#define __rte_atomic _Atomic
lib/eal/include/generic/rte_atomic.h line 131
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +10
-0+ +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed memory_order_relaxed +#define rte_memory_order_consume memory_order_consume +#define rte_memory_order_acquire memory_order_acquire +#define rte_memory_order_release memory_order_release +#define rte_memory_order_acq_rel memory_order_acq_rel +#define rte_memory_order_seq_cst memory_order_seq_cst +
Would this be better of as an enum, rather than a typedef? If typedef, it should have the "_t" postfix. Also, the #define should be all-caps.
lib/eal/include/generic/rte_atomic.h line 134
Quoted 3 lines
lib/eal/include/generic/rte_atomic.h +3
-0+#define rte_atomic_store_explicit (obj, desired, order) \ + atomic_store_explicit(obj, desired, order) +
Drop "explicit" from all the names. It's just noise. Also, the memory orders have very long names.
We haven't even move all DPDK code over from the old API, to using GCC C11 built-ins, and now we are switching to a new API?
Quoted 177 lines
lib/eal/include/generic/rte_atomic.h +73
-1+#define rte_atomic_load_explicit (obj, order) \ + atomic_load_explicit(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + atomic_exchange_explicit(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit (obj, expected, desired, success, fail) \ + atomic_compare_exchange_strong_explicit(obj, expected, desired, success, fail) + +#define rte_atomic_compare_exchange_weak_explicit (obj, expected, desired, success, fail) \ + atomic_compare_exchange_weak_explicit(obj, expected, desired, success, fail) + +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + atomic_fetch_add_explicit(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + atomic_fetch_sub_explicit(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + atomic_fetch_or_explicit(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + atomic_fetch_xor_explicit(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + atomic_fetch_and_explicit(obj, arg, order) + +#else + +#define __rte_atomic + +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed __ATOMIC_RELAXED +#define rte_memory_order_consume __ATOMIC_CONSUME +#define rte_memory_order_acquire __ATOMIC_ACQUIRE +#define rte_memory_order_release __ATOMIC_RELEASE +#define rte_memory_order_acq_rel __ATOMIC_ACQ_REL +#define rte_memory_order_seq_cst __ATOMIC_SEQ_CST + +#define rte_atomic_store_explicit (obj, desired, order) \ + __atomic_store_n(obj, desired, order) + +#define rte_atomic_load_explicit (obj, order) \ + __atomic_load_n(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + __atomic_exchange_n(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit (obj, expected, desired, success, fail) \ + __atomic_compare_exchange_n(obj, expected, desired, 0, success, fail) + +#define rte_atomic_compare_exchange_weak_explicit (obj, expected, desired, success, fail) \ + __atomic_compare_exchange_n(obj, expected, desired, 1, success, fail) + +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + __atomic_fetch_add(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + __atomic_fetch_sub(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + __atomic_fetch_or(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + __atomic_fetch_xor(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + __atomic_fetch_and(obj, arg, order) + +#endif +/** * Compiler barrier. * @@ -123,7 +217,7 @@/** * Synchronization fence between threads based on the specified memory order. */ -static inline void rte_atomic_thread_fence (int memorder); +static inline void rte_atomic_thread_fence (rte_memory_order memorder);/*------------------------- 16 bit atomic operations -------------------------*/ lib/eal/loongarch/include/rte_atomic.h +5
-1@@ -35,9 +35,13 @@#define rte_io_rmb () rte_mb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/ppc/include/rte_atomic.h +5
-1@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/ lib/eal/riscv/include/rte_atomic.h +5
-1@@ -40,9 +40,13 @@#define rte_io_rmb () asm volatile("fence ir, ir" : : : "memory") static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/x86/include/rte_atomic.h +6
-2@@ -87,12 +87,16 @@* used instead. */ static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { -if (memorder == __ATOMIC_SEQ_CST) +if (memorder == rte_memory_order_seq_cst)rte_smp_mb (); else +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/ meson_options.txt +2
-0@@ -46,6 +46,8 @@ option('mbuf_refcnt_atomic', type: 'boolean', value: true, description: 'Atomically access the mbuf refcnt.') option('platform', type: 'string', value: 'native', description: 'Platform to build, either "native", "generic" or a SoC. Please refer to the Linux build guide for more information.') +option('enable_stdatomics', type: 'boolean', value: false, description: + 'enable use of standard C11 atomics.') option('enable_trace_fp', type: 'boolean', value: false, description: 'enable fast path trace points.') option('tests', type: 'boolean', value: true, description:
RE: [PATCH v2] eal: introduce atomics abstraction
Quoted 11 lines
-----Original Message-----
From: Mattias Rönnblom <[email protected]>
Sent: Monday, April 3, 2023 4:12 PM
To: Tyler Retzlaff <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v2] eal: introduce atomics abstraction
Quoted 7 lines
Quoted 3 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Terminology nitpicking: I don't think these functions provide any abstraction at all. They are just wrappers.
This patch should be deprecated. As per the decision at Techboard, we will move to using atomic APIs from stdatomics.h
Quoted 310 lines
Quoted 7 lines
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96+++++++++++++++++++++++++++++++++-
Quoted 83 lines
lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build index renamed from config/meson.build +0
-026f3168..25dd628 100644
config/meson.build +8
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') else + add_project_arguments('-std=c11', language: 'c') endif endif + # enable extra warnings and disable any unwanted warnings # -Wall is added by default at warning level 1, and -Wextra # at warning level 2 (DPDK default)lib/eal/arm/include/rte_atomic_32.h +5
-1@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/arm/include/rte_atomic_64.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations -------------------------*/ diff --git
a/lib/eal/include/generic/rte_atomic.hb/lib/eal/include/generic/rte_atomic.h
index f5c49a9..392d928 100644lib/eal/include/generic/rte_atomic.h +7
-0@@ -110,6 +110,100 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || +defined(__STDC_NO_ATOMICS__) #error compiler does not support C11 +standard atomics #else #include <stdatomic.h> #endif + +#define __rte_atomic _Atomiclib/eal/include/generic/rte_atomic.h line 129
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +10
-0+ +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed memory_order_relaxed #define +rte_memory_order_consume memory_order_consume #define +rte_memory_order_acquire memory_order_acquire #define +rte_memory_order_release memory_order_release #define +rte_memory_order_acq_rel memory_order_acq_rel #define +rte_memory_order_seq_cst memory_order_seq_cst +Would this be better of as an enum, rather than a typedef? If typedef, it should have the "_t" postfix. Also, the #define should be all-caps.
lib/eal/include/generic/rte_atomic.h line 134
Quoted 3 lines
lib/eal/include/generic/rte_atomic.h +3
-0+#define rte_atomic_store_explicit (obj, desired, order) \ + atomic_store_explicit(obj, desired, order) +Drop "explicit" from all the names. It's just noise. Also, the memory orders have very long names.
We haven't even move all DPDK code over from the old API, to using GCC C11 built-ins, and now we are switching to a new API?
lib/eal/include/generic/rte_atomic.h
Quoted 7 lines
lib/eal/include/generic/rte_atomic.h +7
-0+#define rte_atomic_load_explicit (obj, order) \ + atomic_load_explicit(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + atomic_exchange_explicit(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h line 143
Quoted 4 lines
lib/eal/include/generic/rte_atomic.h +4
-0+atomic_compare_exchange_strong_explicit (obj, expected, desired, +success, fail) + +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
Quoted 31 lines
lib/eal/include/generic/rte_atomic.h +31
-0+atomic_compare_exchange_weak_explicit (obj, expected, desired, +success, fail) + +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + atomic_fetch_add_explicit(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + atomic_fetch_sub_explicit(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + atomic_fetch_or_explicit(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + atomic_fetch_xor_explicit(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + atomic_fetch_and_explicit(obj, arg, order) + +#else + +#define __rte_atomic + +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed __ATOMIC_RELAXED #define +rte_memory_order_consume __ATOMIC_CONSUME #define +rte_memory_order_acquire __ATOMIC_ACQUIRE #define +rte_memory_order_release __ATOMIC_RELEASE #define +rte_memory_order_acq_rel __ATOMIC_ACQ_REL #define +rte_memory_order_seq_cst __ATOMIC_SEQ_CST +lib/eal/include/generic/rte_atomic.h
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +10
-0+#define rte_atomic_store_explicit (obj, desired, order) \ + __atomic_store_n(obj, desired, order) + +#define rte_atomic_load_explicit (obj, order) \ + __atomic_load_n(obj, order) + +#define rte_atomic_exchange_explicit (obj, desired, order) \ + __atomic_exchange_n(obj, desired, order) + +#define rte_atomic_compare_exchange_strong_explicit(obj, expected,desired, success, fail) \
lib/eal/include/generic/rte_atomic.h line 188
Quoted 4 lines
lib/eal/include/generic/rte_atomic.h +4
-0+__atomic_compare_exchange_n (obj, expected, desired,0 , success, +fail) + +#define rte_atomic_compare_exchange_weak_explicit(obj, expected,desired, success, fail) \
Quoted 24 lines
lib/eal/include/generic/rte_atomic.h +20
-0+__atomic_compare_exchange_n (obj, expected, desired,1 , success, +fail) + +#define rte_atomic_fetch_add_explicit (obj, arg, order) \ + __atomic_fetch_add(obj, arg, order) + +#define rte_atomic_fetch_sub_explicit (obj, arg, order) \ + __atomic_fetch_sub(obj, arg, order) + +#define rte_atomic_fetch_or_explicit (obj, arg, order) \ + __atomic_fetch_or(obj, arg, order) + +#define rte_atomic_fetch_xor_explicit (obj, arg, order) \ + __atomic_fetch_xor(obj, arg, order) + +#define rte_atomic_fetch_and_explicit (obj, arg, order) \ + __atomic_fetch_and(obj, arg, order) + +#endif +/** * Compiler barrier. * lib/eal/include/generic/rte_atomic.h line 218
Quoted 2 lines
lib/eal/include/generic/rte_atomic.h +0
-0@@ -123,7 +217,7 @@/** * Synchronization fence between threads based on the specified memory order.
meson_options.txt option('mbuf_refcnt_atomic', type: 'boolean', value:
Quoted 98 lines
lib/eal/include/generic/rte_atomic.h +2
-2*/ -static inline void rte_atomic_thread_fence (int memorder); +static inline void rte_atomic_thread_fence (rte_memory_order +memorder);/*------------------------- 16 bit atomic operations -------------------------*/ lib/eal/loongarch/include/rte_atomic.h +5
-1@@ -35,9 +35,13 @@#define rte_io_rmb () rte_mb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/ppc/include/rte_atomic.h +5
-2@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/ diff --git
a/lib/eal/riscv/include/rte_atomic.hb/lib/eal/riscv/include/rte_atomic.h
index 4b4633c..3c203a9 100644lib/eal/riscv/include/rte_atomic.h +5
-1@@ -40,9 +40,13 @@#define rte_io_rmb () asm volatile("fence ir, ir" : : : "memory") static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/x86/include/rte_atomic.h +6
-3@@ -87,12 +87,16 @@* used instead. */ static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { -if (memorder == __ATOMIC_SEQ_CST) +if (memorder == rte_memory_order_seq_cst)rte_smp_mb (); else +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------- 16 bit atomic operations -------------------------*/ diff --git a/meson_options.txt
b/meson_options.txtindex 0852849..acbcbb8 100644meson_options.txt +0
-0@@ -46,6 +46,8 @@ option('mbuf_refcnt_atomic', type: 'boolean', value:true, description:
Quoted 9 lines
meson_options.txt +2
-0'Atomically access the mbuf refcnt.') option('platform', type: 'string', value: 'native', description: 'Platform to build, either "native", "generic" or a SoC. Please refer to the Linux build guide for more information.') +option('enable_stdatomics', type: 'boolean', value: false, description: + 'enable use of standard C11 atomics.') option('enable_trace_fp', type: 'boolean', value: false, description: 'enable fast path trace points.')option('tests', type: 'boolean', value: true, description:
Re: [PATCH v2] eal: introduce atomics abstraction
In reply to Mattias RönnblomQuoted 113 lines · Mattias Rönnblom
Quoted 3 lines · Tyler Retzlaff
Introduce atomics abstraction that permits optional use of standard C11 atomics when meson is provided the new enable_stdatomics=true option.
Terminology nitpicking: I don't think these functions provide any abstraction at all. They are just wrappers.
Quoted 83 lines
Signed-off-by Tyler Retzlaff <[email protected]>--- config/meson.build | 11 ++++ lib/eal/arm/include/rte_atomic_32.h | 6 ++- lib/eal/arm/include/rte_atomic_64.h | 6 ++- lib/eal/include/generic/rte_atomic.h | 96 +++++++++++++++++++++++++++++++++- lib/eal/loongarch/include/rte_atomic.h | 6 ++- lib/eal/ppc/include/rte_atomic.h | 6 ++- lib/eal/riscv/include/rte_atomic.h | 6 ++- lib/eal/x86/include/rte_atomic.h | 8 ++- meson_options.txt | 2 + 9 files changed, 139 insertions(+), 8 deletions(-)config/meson.build +11
-0@@ -255,6 +255,17 @@ endif # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') +stdc_atomics_enabled = get_option('enable_stdatomics') +dpdk_conf.set('RTE_STDC_ATOMICS', stdc_atomics_enabled) + +if stdc_atomics_enabled +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments('-std=gnu11', language: 'c') +else + add_project_arguments('-std=c11', language: 'c') +endif +endif + # enable extra warnings and disable any unwanted warnings # -Wall is added by default at warning level 1, and -Wextra # at warning level 2 (DPDK default)lib/eal/arm/include/rte_atomic_32.h +5
-1@@ -34,9 +34,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }#ifdef __cpluspluslib/eal/arm/include/rte_atomic_64.h +5
-1@@ -38,9 +38,13 @@#define rte_io_rmb () rte_rmb() static __rte_always_inline void -rte_atomic_thread_fence (int memorder) +rte_atomic_thread_fence (rte_memory_order memorder) { +#ifdef RTE_STDC_ATOMICS +atomic_thread_fence (memorder); +#else __atomic_thread_fence (memorder); +#endif }/*------------------------ 128 bit atomic operations -------------------------*/ lib/eal/include/generic/rte_atomic.h +9
-0@@ -110,6 +110,100 @@#endif /* __DOXYGEN__ */ +#ifdef RTE_STDC_ATOMICS + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ <201112L || defined(__STDC_NO_ATOMICS__) +#error compiler does not support C11 standard atomics +#else +#include <stdatomic.h> +#endif + +#define __rte_atomic _Atomiclib/eal/include/generic/rte_atomic.h line 129
Quoted 10 lines
lib/eal/include/generic/rte_atomic.h +10
-0+ +typedef int rte_memory_order ; + +#define rte_memory_order_relaxed memory_order_relaxed +#define rte_memory_order_consume memory_order_consume +#define rte_memory_order_acquire memory_order_acquire +#define rte_memory_order_release memory_order_release +#define rte_memory_order_acq_rel memory_order_acq_rel +#define rte_memory_order_seq_cst memory_order_seq_cst +Would this be better of as an enum, rather than a typedef? If typedef, it should have the "_t" postfix. Also, the #define should be all-caps.
lib/eal/include/generic/rte_atomic.h line 134
Quoted 3 lines
lib/eal/include/generic/rte_atomic.h +3
-0+#define rte_atomic_store_explicit (obj, desired, order) \ + atomic_store_explicit(obj, desired, order) +Drop "explicit" from all the names. It's just noise. Also, the memory orders have very long names.
Quoted 2 lines
We haven't even move all DPDK code over from the old API, to using GCC C11 built-ins, and now we are switching to a new API?
This series has been marked obsolete/abandoned. As per technical board DPDK will move straight to standard C atomics without transitioning with these macros.
Thanks
Quoted 2 lines · Tyler Retzlaff
Introduce an abstraction for compiler specific atomics and a meson option to allow standard C11 atomics use.
notice, this patch series is being withdrawn as it is no longer needed.
as per technical board meeting this morning we will work toward supporting msvc and use of standard atomics.
in the next few days i'll document in the roadmap a basic plan for enabling msvc as a supported compiler.
* post 23.03 release we will begin patch submission for msvc changes (but not atomics).
* post 23.07 release we will begin patch submission for use of standard atomics from C11.
* starting 23.11 release C11 conformant toolchain including standard atomics support will be a minimum requirement for dpdk.
thank you everyone who contributed to the conversation, it's fantastic to have a path forward.
ty
Quoted 17 lines
-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Wednesday, February 22, 2023 12:10 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v2] eal: abstract compiler atomicsQuoted 2 lines · Tyler Retzlaff
Introduce an abstraction for compiler specific atomics and a meson option to allow standard C11 atomics use.
notice, this patch series is being withdrawn as it is no longer needed.
Quoted 8 lines
as per technical board meeting this morning we will work toward supporting msvc and use of standard atomics.
in the next few days i'll document in the roadmap a basic plan for enabling msvc as a supported compiler.
* post 23.03 release we will begin patch submission for msvc changes (but not atomics).
My understanding of the discussion is slightly different. Please see below
Quoted 3 lines
* post 23.07 release we will begin patch submission for use of standard atomics from C11.
We want to merge the standard atomics patch immediately after 23.07 release. This means, the patches need to be reviewed/tested/ready-to-merge by 12 July 2023 (as per current planning for 23.07). So, the patch submission needs to happen earlier.
Quoted 8 lines
* starting 23.11 release C11 conformant toolchain including standard atomics support will be a minimum requirement for dpdk.
thank you everyone who contributed to the conversation, it's fantastic to have a path forward.
ty
Quoted 23 lines · Honnappa Nagarahalli
Quoted 23 lines
-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Wednesday, February 22, 2023 12:10 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v2] eal: abstract compiler atomicsQuoted 2 lines · Tyler Retzlaff
Introduce an abstraction for compiler specific atomics and a meson option to allow standard C11 atomics use.
notice, this patch series is being withdrawn as it is no longer needed.
as per technical board meeting this morning we will work toward supporting msvc and use of standard atomics.
in the next few days i'll document in the roadmap a basic plan for enabling msvc as a supported compiler.
Quoted 8 lines
Quoted 2 lines
* post 23.03 release we will begin patch submission for msvc changes (but not atomics).
My understanding of the discussion is slightly different. Please see below
Quoted 3 lines
* post 23.07 release we will begin patch submission for use of standard atomics from C11.
We want to merge the standard atomics patch immediately after 23.07 release. This means, the patches need to be reviewed/tested/ready-to-merge by 12 July 2023 (as per current planning for 23.07). So, the patch submission needs to happen earlier.
yes, my wording is poor here. i really meant to say can be merged as soon as 23.07 is released which as you note implies we want to review prior to that release.
Quoted 9 lines
Quoted 9 lines
* starting 23.11 release C11 conformant toolchain including standard atomics support will be a minimum requirement for dpdk.
thank you everyone who contributed to the conversation, it's fantastic to have a path forward.
ty