use WFE for locks and ring on aarch64
Subsystems (2)
PATCH v10 5/5 event/opdl: use new API to save cycles on aarch64
In reply to Gavin HuUse the new API to wait in low power state instead of continuous polling to save CPU cycles and power.
--- drivers/event/opdl/Makefile | 1 + drivers/event/opdl/meson.build | 1 + drivers/event/opdl/opdl_ring.c | 5 ++--- 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/event/opdl/Makefile +1 -0
@@ -9,6 +9,7 @@ LIB = librte_pmd_opdl_event.a # build flags CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # for older GCC versions, allow us to initialize an event using # designated initializers. ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
drivers/event/opdl/meson.build +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Luca Boccassi <[email protected]> +allow_experimental_apis = true sources = files( 'opdl_evdev.c', 'opdl_evdev_init.c',
drivers/event/opdl/opdl_ring.c +2 -3
@@ -16,6 +16,7 @@#include <rte_memcpy.h> #include <rte_memory.h> #include <rte_memzone.h> +#include <rte_atomic.h> #include "opdl_ring.h" #include "opdl_log.h"
@@ -474,9 +475,7 @@ opdl_ring_input_multithread(struct opdl_ring *t, const void *entries,/* If another thread started inputting before this one, but hasn't * finished, we need to wait for it to complete to update the tail. */ -while (unlikely (__atomic_load_n (&s->shared.tail, __ATOMIC_ACQUIRE) != - old_head)) -rte_pause (); +rte_wait_until_equal_32 (&s->shared.tail, old_head, __ATOMIC_ACQUIRE);__atomic_store_n (&s->shared.tail, old_head + num_entries, __ATOMIC_RELEASE);
Signature · 1 line
2.7.4
v11 cover use WFE for aarch64
In reply to Gavin HuV11:
-add rte_ prefix to the __atomic_load_ex_x funtions(Ananyev Konstantin)
-define the above rte_atomic_load_ex_x funtions even if not RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED for future non-wfe usages(Ananyev Konstantin) -use the above functions for arm specific rte_wait_until_equal_x functions(Ananyev Konstantin)
-simplify the generic implementation by immersing "if" into "while"(Ananyev Konstantin)
V10:
- move arm specific stuff to arch/arm/rte_pause_64.h(Ananyev Konstantin)
V9:
- fix a weblink broken (David Marchand)
- define rte_wfe and rte_sev() (Ananyev Konstantin)
- explicitly define three function APIs instead of marcos (Ananyev Konstantin)
- incorporate common rte_wfe and rte_sev into the generic rte_spinlock (David Marchand)
- define arch neutral RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED (Ananyev Konstantin)
- define rte_load_ex_16/32/64 functions to use load-exclusive instruction for aarch64, which is required for wake up of WFE
- drop the rte_spinlock patch from this series, as the it calls this experimental API and it is widely included by a lot of components each requires the ALLOW_EXPERIMENRAL_API for the Makefile and meson.build, leave it to future after the experimental is removed. V8:
- simplify dmb definition to use io barriers (David Marchand)
- define wfe() and sev() macros and use them inside normal C code (Ananyev Konstantin)
- pass memorder as parameter, not to incorporate it into function name, less functions, similar to C11 atomic intrinsics (Ananyev Konstantin)
- remove mandating RTE_FORCE_INTRINSICS in arm spinlock implementation(David Marchand)
- undef __WAIT_UNTIL_EQUAL after use (David Marchand)
- add experimental tag and warning (David Marchand)
- add the limitation of using WFE instruction in the commit log (David Marchand)
- tweak the use of RTE_FORCE_INSTRINSICS(still mandatory for aarch64) and RTE_ARM_USE_WFE for spinlock (David Marchand)
- drop the rte_ring patch from this series, as the rte_ring.h calls this API and it is widely included by a lot of components each requires the ALLOW_EXPERIMENRAL_API for the Makefile and meson.build, leave it to future after the experimental is removed. V7:
- fix the checkpatch LONG_LINE_COMMENT issue
V6:
- squash the RTE_ARM_USE_WFE configuration entry patch into the new API patch
- move the new configuration to the end of EAL
- add doxygen comments to reflect the relaxed and acquire semantics
- correct the meson configuration
V5:
- add doxygen comments for the new APIs
- spinlock early exit without wfe if the spinlock not taken by others.
- add two patches on top for opdl and thunderx
V4:
- rename the config as CONFIG_RTE_ARM_USE_WFE to indicate it applys to arm only
- introduce a macro for assembly Skelton to reduce the duplication of code
- add one patch for nxp fslmc to address a compiling error
V3:
- Convert RFCs to patches
V2:
- Use inline functions instead of marcos
- Add load and compare in the beginning of the APIs
- Fix some style errors in asm inline
V1:
- Add the new APIs and use it for ring and locks
Gavin Hu (5):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
ticketlock: use new API to reduce contention on aarch64 net/thunderx: use new API to save cycles on aarch64 event/opdl: use new API to save cycles on aarch64
config/arm/meson.build | 1 + config/common_base | 5 + drivers/bus/fslmc/mc/fsl_mc_sys.h | 8 +- drivers/event/opdl/Makefile | 1 + drivers/event/opdl/meson.build | 1 + drivers/event/opdl/opdl_ring.c | 5 +- drivers/net/thunderx/Makefile | 1 + drivers/net/thunderx/meson.build | 1 + drivers/net/thunderx/nicvf_rxtx.c | 3 +- .../common/include/arch/arm/rte_pause_64.h | 188 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_pause.h | 99 +++++++++++ .../common/include/generic/rte_ticketlock.h | 3 +- 12 files changed, 304 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
PATCH v11 1/5 bus/fslmc: fix the conflicting dmb function
There are two definitions conflicting each other, for more details, refer to [1].
include/rte_atomic_64.h:19: error: "dmb" redefined [-Werror] drivers/bus/fslmc/mc/fsl_mc_sys.h:36: note: this is the location of the previous definition
#define dmb() {__asm__ __volatile__("" : : : "memory"); }
The fix is to reuse the EAL definition to avoid conflicts.
[1] http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF0@
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u
--- drivers/bus/fslmc/mc/fsl_mc_sys.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/bus/fslmc/mc/fsl_mc_sys.h +3 -5
@@ -31,12 +31,10 @@ struct fsl_mc_io {#include <errno.h> #include <sys/uio.h> #include <linux/byteorder/little_endian.h> +#include <rte_atomic.h> -#ifndef dmb -#define dmb () {__asm__ __volatile__("" : : : "memory"); } -#endif -#define __iormb () dmb() -#define __iowmb () dmb() +#define __iormb () rte_io_rmb() +#define __iowmb () rte_io_wmb()#define __arch_getq (a) (*(volatile uint64_t *)(a))#define __arch_putq (v, a) (*(volatile uint64_t *)(a) = (v))#define __arch_putq32 (v, a) (*(volatile uint32_t *)(a) = (v))
Signature · 1 line
2.7.4
PATCH v11 2/5 eal: add the APIs to wait until equal
In reply to Gavin HuThe rte_wait_until_equal_xx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.
Add the RTE_ARM_USE_WFE configuration entry for aarch64, disabled by default. When it is enabled, the above APIs will call WFE instruction to save CPU cycles and power.
From a VM, when calling this API on aarch64, it may trap in and out to release vCPUs whereas cause high exit latency. Since kernel 4.18.20 an adaptive trapping mechanism is introduced to balance the latency and workload.
--- config/arm/meson.build | 1 + config/common_base | 5 + .../common/include/arch/arm/rte_pause_64.h | 188 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_pause.h | 99 +++++++++++ 4 files changed, 293 insertions(+)
config/arm/meson.build +1 -0
@@ -26,6 +26,7 @@ flags_common_default = [ ['RTE_LIBRTE_AVP_PMD', false], ['RTE_SCHED_VECTOR', false], + ['RTE_ARM_USE_WFE', false], ] flags_generic = [
config/common_base +5 -0
@@ -111,6 +111,11 @@ CONFIG_RTE_MAX_VFIO_CONTAINERS=64 CONFIG_RTE_MALLOC_DEBUG=n CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n CONFIG_RTE_USE_LIBBSD=n +# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs, +# calling these APIs put the cores in low power state while waiting +# for the memory address to become equal to the expected value. +# This is supported only by aarch64. +CONFIG_RTE_ARM_USE_WFE=n # # Recognize/ignore the AVX/AVX512 CPU flags for performance/power testing.
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +188 -0
205 lines not on this page · raw message
lib/librte_eal/common/include/generic/rte_pause.h +99 -0
114 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [dpdk-dev] [PATCH v11 2/5] eal: add the APIs to wait until equal
On Sun, Oct 27, 2019 at 1:53 PM Gavin Hu <[email protected]> wrote:
[snip]
Quoted 4 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +0
-0
[snip]
Quoted 27 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +23
-0@@ -17,6 +23,188 @@ static inline void rte_pause(void) asmvolatile ("yield" :::"memory" ); } +/** +* Send an event to quit WFE. +*/ +static inline void rte_sevl (void ); + +/** +* Put processor into low power WFE(Wait For Event) state +*/ +static inline void rte_wfe (void ); + +#ifdef RTE_ARM_USE_WFE +static inline void rte_sevl (void ) +{ + asmvolatile ("sevl" : : :"memory" ); +} + +static inline void rte_wfe (void ) +{ + asmvolatile ("wfe" : : :"memory" ); +} +#else +static inline void rte_sevl (void ) +{
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 58
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+} +static inline void rte_wfe (void ) +{ +rte_pause (); +} +#endif + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice
experimental?
Just complaining on the principle, you missed the __rte_experimental in such a case.
But this API is a no go for me, see below.
Quoted 5 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +5
-0+* +* Atomic exclusive load from addr, it returns the 16-bit content of *addr +* while making it 'monitored',when it is written by someone else, the +* 'monitored' state is cleared and a event is generated implicitly to exit +* WFE.
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 73
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+* +* @param addr +* A pointer to the memory location. +* @param memorder +* The valid memory order variants are __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. +* These map to C++11 memory orders with the same names, see the C++11 standard +* the GCC wiki on atomic synchronization for detailed definitions. +*/ +static __rte_always_inline uint16_t +rte_atomic_load_ex_16 (volatile uint16_t *addr,int memorder);
This API does not make sense for anything but arm, so this prefix is not good.
On arm, when RTE_ARM_USE_WFE is undefined, why would you need it? A non exclusive load is enough since you don't want to use wfe.
[snip]
Quoted 57 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +57
-0+ +static __rte_always_inline uint16_t +rte_atomic_load_ex_16 (volatile uint16_t *addr,int memorder) +{ +uint16_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxrh %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxrh %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} + +static __rte_always_inline uint32_t +rte_atomic_load_ex_32 (volatile uint32_t *addr,int memorder) +{ +uint32_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxr %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxr %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} + +static __rte_always_inline uint64_t +rte_atomic_load_ex_64 (volatile uint64_t *addr,int memorder) +{ +uint64_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxr %x[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxr %x[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +}
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 178
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+ +#ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder) +{ +if (__atomic_load_n (addr, memorder) != expected) { +rte_sevl (); + do { + rte_wfe();
We are in the RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED case. rte_wfe() is always asm volatile("wfe" : : : "memory");
Quoted 5 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +5
-0+ }while (rte_atomic_load_ex_16 (addr, memorder) != expected); + } +} + +static __rte_always_inline void
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 193
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, +int memorder) +{ + if (__atomic_load_n(addr, memorder) != expected) { +rte_sevl (); +do { +rte_wfe (); + }while (__atomic_load_n (addr, memorder) != expected); + } +}
The while() should be with an exclusive load.
I will submit a v12 with those comments addressed so that we move forward for rc2.
But it won't make it in rc1, sorry.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v11 2/5] eal: add the APIs to wait until equal
Hi david,
Quoted 65 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Monday, October 28, 2019 4:50 AM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: dev <[email protected]>; nd <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; Stephen Hemminger <[email protected]>; [email protected]; [email protected]; Pavan Nikhilesh <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang (Arm Technology China) <[email protected]>; Phil Yang (Arm Technology China) <[email protected]>; Steve Capper <[email protected]>
Subject: Re: [PATCH v11 2/5] eal: add the APIs to wait until equalOn Sun, Oct 27, 2019 at 1:53 PM Gavin Hu <[email protected]> wrote:
[snip]
Review
Quoted 1 line
(quoted diff) +0
-0
b/lib/librte_eal/common/include/arch/arm/rte_pause_64.hQuoted 3 lines
index 93895d3..1680d7a 100644
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +0
-0[snip]
Quoted 27 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +23
-0@@ -17,6 +23,188 @@ static inline void rte_pause(void) asmvolatile ("yield" :::"memory" ); } +/** +* Send an event to quit WFE. +*/ +static inline void rte_sevl (void ); + +/** +* Put processor into low power WFE(Wait For Event) state +*/ +static inline void rte_wfe (void ); + +#ifdef RTE_ARM_USE_WFE +static inline void rte_sevl (void ) +{ + asmvolatile ("sevl" : : :"memory" ); +} + +static inline void rte_wfe (void ) +{ + asmvolatile ("wfe" : : :"memory" ); +} +#else +static inline void rte_sevl (void ) +{lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 58
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+} +static inline void rte_wfe (void ) +{ +rte_pause (); +} +#endif + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice
Quoted 4 lines
experimental?
Just complaining on the principle, you missed the__rte_experimentalin such a case.
But this API is a no go for me, see below.
Got it, thanks!
Quoted 12 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)
Quoted 11 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+* +* Atomic exclusive load from addr, it returns the 16-bit content of *addr +* while making it 'monitored',when it is written by someone else, the +* 'monitored' state is cleared and a event is generated implicitly to exit +* WFE. +* +* @param addr +* A pointer to the memory location. +* @param memorder +* The valid memory order variants are __ATOMIC_ACQUIRE and
__ATOMIC_RELAXED.
Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 69
Quoted 1 line
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1
-0+* These map to C++11 memory orders with the same names, see the C++11 standard
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 73
Quoted 4 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +4
-0+* the GCC wiki on atomic synchronization for detailed definitions. +*/ +static __rte_always_inline uint16_t +rte_atomic_load_ex_16 (volatile uint16_t *addr,int memorder);This API does not make sense for anything but arm, so this prefix is not good.
Yes, we can change back to __ atomic_load_ex_16?
Quoted 3 lines
On arm, when
RTE_ARM_USE_WFEis undefined, why would you need it? A non exclusive load is enough since you don't want to use wfe.
We can move it inside #ifdef RTE_ARM_USE_WFE .. #endif.
Quoted 84 lines
[snip]
Quoted 57 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +57
-0+ +static __rte_always_inline uint16_t +rte_atomic_load_ex_16 (volatile uint16_t *addr,int memorder) +{ +uint16_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxrh %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxrh %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} + +static __rte_always_inline uint32_t +rte_atomic_load_ex_32 (volatile uint32_t *addr,int memorder) +{ +uint32_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxr %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxr %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} + +static __rte_always_inline uint64_t +rte_atomic_load_ex_64 (volatile uint64_t *addr,int memorder) +{ +uint64_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxr %x[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxr %x[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +}lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 178
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+ +#ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder) +{ +if (__atomic_load_n (addr, memorder) != expected) { +rte_sevl (); + do { + rte_wfe();We are in the
RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINEDcase.rte_wfe()is always asmvolatile("wfe" : : : "memory");Quoted 9 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +9
-0+ }while (rte_atomic_load_ex_16 (addr, memorder) != expected); + } +} + +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder) +{ +if (__atomic_load_n (addr, memorder) != expected) {
Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 193
Quoted 6 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6
-0+rte_sevl (); +do { +rte_wfe (); + }while (__atomic_load_n (addr, memorder) != expected); + } +}The
while()should be with an exclusive load.
Sorry for this explicit error.
Quoted 5 lines
I will submit a v12 with those comments addressed so that we move forward for rc2.
But it won't make it in rc1, sorry.
I will do it if you prefer, otherwise thanks!
Quoted 4 lines
--
David Marchand
Re: [dpdk-dev] [PATCH v11 2/5] eal: add the APIs to wait until equal
In reply to Gavin HuQuoted 239 lines
The
rte_wait_until_equal_xxAPIs abstract the functionality of 'polling for a memory location to become equal to a given value'.Add the
RTE_ARM_USE_WFEconfiguration entry for aarch64, disabled by default. When it is enabled, the above APIs will call WFE instruction to save CPU cycles and power.From a VM, when calling this API on aarch64, it may trap in and out to release vCPUs whereas cause high exit latency. Since kernel 4.18.20 an adaptive trapping mechanism is introduced to balance the latency and workload.
Signed-off-by Gavin Hu <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Steve Capper <[email protected]>Reviewed-by Ola Liljedahl <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>Reviewed-by Phil Yang <[email protected]>Acked-by Pavan Nikhilesh <[email protected]>Acked-by Jerin Jacob <[email protected]>--- config/arm/meson.build | 1 + config/common_base | 5 + .../common/include/arch/arm/rte_pause_64.h | 188 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_pause.h | 99 +++++++++++ 4 files changed, 293 insertions(+)config/arm/meson.build +1
-0@@ -26,6 +26,7 @@ flags_common_default = [ ['RTE_LIBRTE_AVP_PMD', false], ['RTE_SCHED_VECTOR', false], + ['RTE_ARM_USE_WFE', false], ] flags_generic = [config/common_base +5
-0@@ -111,6 +111,11 @@ CONFIG_RTE_MAX_VFIO_CONTAINERS=64 CONFIG_RTE_MALLOC_DEBUG=n CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n CONFIG_RTE_USE_LIBBSD=n +# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs, +# calling these APIs put the cores in low power state while waiting +# for the memory address to become equal to the expected value. +# This is supported only by aarch64. +CONFIG_RTE_ARM_USE_WFE=n # # Recognize/ignore the AVX/AVX512 CPU flags for performance/power testing.lib/librte_eal/common/include/arch/arm/rte_pause_64.h +162
-0@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2017 Cavium, Inc +* Copyright(c) 2019 Arm Limited */ #ifndef _RTE_PAUSE_ARM64_H_@@ -10,6 +11,11 @@ extern "C" {#endif #include <rte_common.h> + +#ifdef RTE_ARM_USE_WFE +#define RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +#endif +#include "generic/rte_pause.h" static inline void rte_pause (void )@@ -17,6 +23,188 @@ static inline void rte_pause(void) asmvolatile ("yield" :::"memory" ); } +/** +* Send an event to quit WFE. +*/ +static inline void rte_sevl (void ); + +/** +* Put processor into low power WFE(Wait For Event) state +*/ +static inline void rte_wfe (void ); + +#ifdef RTE_ARM_USE_WFE +static inline void rte_sevl (void ) +{ + asmvolatile ("sevl" : : :"memory" ); +} + +static inline void rte_wfe (void ) +{ + asmvolatile ("wfe" : : :"memory" ); +} +#else +static inline void rte_sevl (void ) +{ +} +static inline void rte_wfe (void ) +{ +rte_pause (); +} +#endif + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Atomic exclusive load from addr, it returns the 16-bit content of *addr +* while making it 'monitored',when it is written by someone else, the +* 'monitored' state is cleared and a event is generated implicitly to exit +* WFE. +* +* @param addr +* A pointer to the memory location. +* @param memorder +* The valid memory order variants are __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. +* These map to C++11 memory orders with the same names, see the C++11 standard +* the GCC wiki on atomic synchronization for detailed definitions. +*/ +static __rte_always_inline uint16_t +rte_atomic_load_ex_16 (volatile uint16_t *addr,int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Atomic exclusive load from addr, it returns the 32-bit content of *addr +* while making it 'monitored',when it is written by someone else, the +* 'monitored' state is cleared and a event is generated implicitly to exit +* WFE. +* +* @param addr +* A pointer to the memory location. +* @param memorder +* The valid memory order variants are __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. +* These map to C++11 memory orders with the same names, see the C++11 standard +* the GCC wiki on atomic synchronization for detailed definitions. +*/ +static __rte_always_inline uint32_t +rte_atomic_load_ex_32 (volatile uint32_t *addr,int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Atomic exclusive load from addr, it returns the 64-bit content of *addr +* while making it 'monitored',when it is written by someone else, the +* 'monitored' state is cleared and a event is generated implicitly to exit +* WFE. +* +* @param addr +* A pointer to the memory location. +* @param memorder +* The valid memory order variants are __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. +* These map to C++11 memory orders with the same names, see the C++11 standard +* the GCC wiki on atomic synchronization for detailed definitions. +*/ +static __rte_always_inline uint64_t +rte_atomic_load_ex_64 (volatile uint64_t *addr,int memorder); + +static __rte_always_inline uint16_t +rte_atomic_load_ex_16 (volatile uint16_t *addr,int memorder) +{ +uint16_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxrh %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxrh %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} + +static __rte_always_inline uint32_t +rte_atomic_load_ex_32 (volatile uint32_t *addr,int memorder) +{ +uint32_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxr %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxr %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} + +static __rte_always_inline uint64_t +rte_atomic_load_ex_64 (volatile uint64_t *addr,int memorder) +{ +uint64_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxr %x[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxr %x[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} + +#ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder) +{ +if (__atomic_load_n (addr, memorder) != expected) { +rte_sevl (); +do { +rte_wfe (); + }while (rte_atomic_load_ex_16 (addr, memorder) != expected); + } +}
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 191
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+ +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder) +{ +if (__atomic_load_n (addr, memorder) != expected) { +rte_sevl (); +do { +rte_wfe (); + }while (__atomic_load_n (addr, memorder) != expected);
Here and in _64, shouldn't it be:rte_atomic_load_ex_..
?
Quoted 142 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +16
-0+ } +} + +static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder) +{ +if (__atomic_load_n (addr, memorder) != expected) { +rte_sevl (); +do { +rte_wfe (); + }while (__atomic_load_n (addr, memorder) != expected); + } +} +#endif + #ifdef __cplusplus }#endif lib/librte_eal/common/include/generic/rte_pause.h +99
-1@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2017 Cavium, Inc +* Copyright(c) 2019 Arm Limited */ #ifndef _RTE_PAUSE_H_@@ -12,6 +13,12 @@* */ +#include <stdint.h> +#include <rte_common.h> +#include <rte_atomic.h> +#include <rte_compat.h> +#include <assert.h> +/** * Pause CPU execution for a short while * @@ -20,4 +27,96 @@*/ static inline void rte_pause (void ); +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Wait for *addr to be updated with a 16-bit expected value, with a relaxed +* memory ordering model meaning the loads around this API can be reordered. +* +* @param addr +* A pointer to the memory location. +* @param expected +* A 16-bit expected value to be in the memory location. +* @param memorder +* Two different memory orders that can be specified: +* __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to +* C++11 memory orders with the same names, see the C++11 standard or +* the GCC wiki on atomic synchronization for detailed definition. +*/ +__rte_experimental +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Wait for *addr to be updated with a 32-bit expected value, with a relaxed +* memory ordering model meaning the loads around this API can be reordered. +* +* @param addr +* A pointer to the memory location. +* @param expected +* A 32-bit expected value to be in the memory location. +* @param memorder +* Two different memory orders that can be specified: +* __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to +* C++11 memory orders with the same names, see the C++11 standard or +* the GCC wiki on atomic synchronization for detailed definition. +*/ +__rte_experimental +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Wait for *addr to be updated with a 64-bit expected value, with a relaxed +* memory ordering model meaning the loads around this API can be reordered. +* +* @param addr +* A pointer to the memory location. +* @param expected +* A 64-bit expected value to be in the memory location. +* @param memorder +* Two different memory orders that can be specified: +* __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to +* C++11 memory orders with the same names, see the C++11 standard or +* the GCC wiki on atomic synchronization for detailed definition. +*/ +__rte_experimental +static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder); + +#ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder) +{ +while (__atomic_load_n (addr, memorder) != expected) +rte_pause (); +} + +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder) +{ +while (__atomic_load_n (addr, memorder) != expected) +rte_pause (); +} + +static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder) +{ +while (__atomic_load_n (addr, memorder) != expected) +rte_pause (); +} +#endif +#endif /* _RTE_PAUSE_H_ */ --2.7.4
Re: [dpdk-dev] [PATCH v11 2/5] eal: add the APIs to wait until equal
Hi Konstantin,
Quoted 262 lines
-----Original Message-----
From: Ananyev, Konstantin <[email protected]>
Sent: Monday, October 28, 2019 6:20 AM
To: Gavin Hu (Arm Technology China) <[email protected]>; [email protected]
Cc: nd <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang (Arm Technology China) <[email protected]>; Phil Yang (Arm Technology China) <[email protected]>; Steve Capper <[email protected]>
Subject: RE: [PATCH v11 2/5] eal: add the APIs to wait until equalQuoted 20 lines
The
rte_wait_until_equal_xxAPIs abstract the functionality of 'polling for a memory location to become equal to a given value'.Add the
RTE_ARM_USE_WFEconfiguration entry for aarch64, disabled by default. When it is enabled, the above APIs will call WFE instruction to save CPU cycles and power.From a VM, when calling this API on aarch64, it may trap in and out to release vCPUs whereas cause high exit latency. Since kernel 4.18.20 an adaptive trapping mechanism is introduced to balance the latency and workload.
Signed-off-by Gavin Hu <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Steve Capper <[email protected]>Reviewed-by Ola Liljedahl <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>Reviewed-by Phil Yang <[email protected]>Acked-by Pavan Nikhilesh <[email protected]>Acked-by Jerin Jacob <[email protected]>Quoted 4 lines
--- config/arm/meson.build | 1 + config/common_base | 5 + .../common/include/arch/arm/rte_pause_64.h | 188+++++++++++++++++++++
Quoted 21 lines
lib/librte_eal/common/include/generic/rte_pause.h | 99 +++++++++++ 4 files changed, 293 insertions(+)config/arm/meson.build +1
-0@@ -26,6 +26,7 @@ flags_common_default = [ ['RTE_LIBRTE_AVP_PMD', false], ['RTE_SCHED_VECTOR', false], + ['RTE_ARM_USE_WFE', false], ] flags_generic = [config/common_base +0
-0@@ -111,6 +111,11 @@ CONFIG_RTE_MAX_VFIO_CONTAINERS=64 CONFIG_RTE_MALLOC_DEBUG=nconfig/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64 · line 121
Quoted 10 lines
config/common_base +5
-0CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n CONFIG_RTE_USE_LIBBSD=n +# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs, +# calling these APIs put the cores in low power state while waiting +# for the memory address to become equal to the expected value. +# This is supported only by aarch64. +CONFIG_RTE_ARM_USE_WFE=n # # Recognize/ignore the AVX/AVX512 CPU flags for performance/powertesting.
Review
Quoted 1 line
(quoted diff) +0
-0
b/lib/librte_eal/common/include/arch/arm/rte_pause_64.hQuoted 49 lines
index 93895d3..1680d7a 100644
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +29
-0@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2017 Cavium, Inc +* Copyright(c) 2019 Arm Limited */ #ifndef _RTE_PAUSE_ARM64_H_@@ -10,6 +11,11 @@ extern "C" {#endif #include <rte_common.h> + +#ifdef RTE_ARM_USE_WFE +#define RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +#endif +#include "generic/rte_pause.h" static inline void rte_pause (void )@@ -17,6 +23,188 @@ static inline void rte_pause(void) asmvolatile ("yield" :::"memory" ); } +/** +* Send an event to quit WFE. +*/ +static inline void rte_sevl (void ); + +/** +* Put processor into low power WFE(Wait For Event) state +*/ +static inline void rte_wfe (void ); + +#ifdef RTE_ARM_USE_WFE +static inline void rte_sevl (void ) +{ + asmvolatile ("sevl" : : :"memory" ); +} + +static inline void rte_wfe (void ) +{ + asmvolatile ("wfe" : : :"memory" ); +} +#else +static inline void rte_sevl (void ) +{lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 58
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+} +static inline void rte_wfe (void ) +{ +rte_pause (); +} +#endif + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+* +* Atomic exclusive load from addr, it returns the 16-bit content of *addr +* while making it 'monitored',when it is written by someone else, the +* 'monitored' state is cleared and a event is generated implicitly to exit +* WFE. +* +* @param addr +* A pointer to the memory location. +* @param memorder +* The valid memory order variants are __ATOMIC_ACQUIRE and
__ATOMIC_RELAXED.lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 69
Quoted 1 line
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1
-0+* These map to C++11 memory orders with the same names, see the C++11 standard
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)
Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +8
-0+* the GCC wiki on atomic synchronization for detailed definitions. +*/ +static __rte_always_inline uint16_t +rte_atomic_load_ex_16 (volatile uint16_t *addr,int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+* +* Atomic exclusive load from addr, it returns the 32-bit content of *addr +* while making it 'monitored',when it is written by someone else, the +* 'monitored' state is cleared and a event is generated implicitly to exit +* WFE. +* +* @param addr +* A pointer to the memory location. +* @param memorder +* The valid memory order variants are __ATOMIC_ACQUIRE and
__ATOMIC_RELAXED.lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 88
Quoted 1 line
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1
-0+* These map to C++11 memory orders with the same names, see the C++11 standard
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)
Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +8
-0+* the GCC wiki on atomic synchronization for detailed definitions. +*/ +static __rte_always_inline uint32_t +rte_atomic_load_ex_32 (volatile uint32_t *addr,int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+* +* Atomic exclusive load from addr, it returns the 64-bit content of *addr +* while making it 'monitored',when it is written by someone else, the +* 'monitored' state is cleared and a event is generated implicitly to exit +* WFE. +* +* @param addr +* A pointer to the memory location. +* @param memorder +* The valid memory order variants are __ATOMIC_ACQUIRE and
__ATOMIC_RELAXED.lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 107
Quoted 1 line
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1
-0+* These map to C++11 memory orders with the same names, see the C++11 standard
Quoted 62 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +62
-0+* the GCC wiki on atomic synchronization for detailed definitions. +*/ +static __rte_always_inline uint64_t +rte_atomic_load_ex_64 (volatile uint64_t *addr,int memorder); + +static __rte_always_inline uint16_t +rte_atomic_load_ex_16 (volatile uint16_t *addr,int memorder) +{ +uint16_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxrh %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxrh %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} + +static __rte_always_inline uint32_t +rte_atomic_load_ex_32 (volatile uint32_t *addr,int memorder) +{ +uint32_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxr %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxr %w[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} + +static __rte_always_inline uint64_t +rte_atomic_load_ex_64 (volatile uint64_t *addr,int memorder) +{ +uint64_t tmp; +assert ((memorder == __ATOMIC_ACQUIRE) + || (memorder == __ATOMIC_RELAXED)); +if (memorder == __ATOMIC_ACQUIRE) + asmvolatile ("ldaxr %x[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +else if (memorder == __ATOMIC_RELAXED) + asmvolatile ("ldxr %x[tmp], [%x[addr]]" + : [tmp]"=&r" (tmp) + : [addr]"r" (addr) + :"memory" ); +return tmp; +} +lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+#ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder) +{ +if (__atomic_load_n (addr, memorder) != expected) { +rte_sevl (); + do { + rte_wfe(); + } while (rte_atomic_load_ex_16(addr, memorder) !=expected);
Quoted 15 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 191
Quoted 12 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +12
-0+ } +} + +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder) +{ +if (__atomic_load_n (addr, memorder) != expected) { +rte_sevl (); +do { +rte_wfe (); + }while (__atomic_load_n (addr, memorder) != expected);Here and in _64, shouldn't it be:
rte_atomic_load_ex_..
Thanks for spotting this error, David also spotted it. Sorry for that.
Quoted 150 lines
Review
Quoted 21 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +16
-0+ } +} + +static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder) +{ +if (__atomic_load_n (addr, memorder) != expected) { +rte_sevl (); +do { +rte_wfe (); + }while (__atomic_load_n (addr, memorder) != expected); + } +} +#endif + #ifdef __cplusplus }#endif (quoted diff) +0
-0
b/lib/librte_eal/common/include/generic/rte_pause.hQuoted 24 lines
index 52bd4db..9d42e32 100644
lib/librte_eal/common/include/generic/rte_pause.h +7
-0@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2017 Cavium, Inc +* Copyright(c) 2019 Arm Limited */ #ifndef _RTE_PAUSE_H_@@ -12,6 +13,12 @@* */ +#include <stdint.h> +#include <rte_common.h> +#include <rte_atomic.h> +#include <rte_compat.h> +#include <assert.h> +/** * Pause CPU execution for a short while * lib/librte_eal/common/include/generic/rte_pause.h line 32
Quoted 6 lines
lib/librte_eal/common/include/generic/rte_pause.h +3
-0@@ -20,4 +27,96 @@*/ static inline void rte_pause (void ); +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice
lib/librte_eal/common/include/generic/rte_pause.h
Quoted 3 lines
lib/librte_eal/common/include/generic/rte_pause.h +3
-0+* +* Wait for *addr to be updated with a 16-bit expected value, with a relaxed +* memory ordering model meaning the loads around this API can be reordered.
Quoted 9 lines
lib/librte_eal/common/include/generic/rte_pause.h +9
-0+* +* @param addr +* A pointer to the memory location. +* @param expected +* A 16-bit expected value to be in the memory location. +* @param memorder +* Two different memory orders that can be specified: +* __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to +* C++11 memory orders with the same names, see the C++11 standard or lib/librte_eal/common/include/generic/rte_pause.h
Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10
-0+* the GCC wiki on atomic synchronization for detailed definition. +*/ +__rte_experimental +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice
lib/librte_eal/common/include/generic/rte_pause.h
Quoted 3 lines
lib/librte_eal/common/include/generic/rte_pause.h +3
-0+* +* Wait for *addr to be updated with a 32-bit expected value, with a relaxed +* memory ordering model meaning the loads around this API can be reordered.
Quoted 9 lines
lib/librte_eal/common/include/generic/rte_pause.h +9
-0+* +* @param addr +* A pointer to the memory location. +* @param expected +* A 32-bit expected value to be in the memory location. +* @param memorder +* Two different memory orders that can be specified: +* __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to +* C++11 memory orders with the same names, see the C++11 standard or lib/librte_eal/common/include/generic/rte_pause.h
Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10
-0+* the GCC wiki on atomic synchronization for detailed definition. +*/ +__rte_experimental +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice
lib/librte_eal/common/include/generic/rte_pause.h
Quoted 3 lines
lib/librte_eal/common/include/generic/rte_pause.h +3
-0+* +* Wait for *addr to be updated with a 64-bit expected value, with a relaxed +* memory ordering model meaning the loads around this API can be reordered.
Quoted 45 lines
lib/librte_eal/common/include/generic/rte_pause.h +42
-1+* +* @param addr +* A pointer to the memory location. +* @param expected +* A 64-bit expected value to be in the memory location. +* @param memorder +* Two different memory orders that can be specified: +* __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to +* C++11 memory orders with the same names, see the C++11 standard or +* the GCC wiki on atomic synchronization for detailed definition. +*/ +__rte_experimental +static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder); + +#ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder) +{ +while (__atomic_load_n (addr, memorder) != expected) +rte_pause (); +} + +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder) +{ +while (__atomic_load_n (addr, memorder) != expected) +rte_pause (); +} + +static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder) +{ +while (__atomic_load_n (addr, memorder) != expected) +rte_pause (); +} +#endif +#endif /* _RTE_PAUSE_H_ */ --2.7.4
PATCH v11 3/5 ticketlock: use new API to reduce contention on aarch64
In reply to Gavin HuWhile using ticket lock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.
Running ticketlock_autotest on ThunderX2, Ampere eMAG80, and Arm N1SDP[1], there were variances between runs, but no notable performance gain or degradation were seen with and without this patch.
[1] https://community.arm.com/developer/tools-software/oss-platforms/w/\
docs/440/neoverse-n1-sdp
--- lib/librte_eal/common/include/generic/rte_ticketlock.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/librte_eal/common/include/generic/rte_ticketlock.h +1 -2
@@ -66,8 +66,7 @@ static inline void rte_ticketlock_lock(rte_ticketlock_t *tl) {uint16_t me =__atomic_fetch_add (&tl->s.next,1 , __ATOMIC_RELAXED); -while (__atomic_load_n (&tl->s.current, __ATOMIC_ACQUIRE) != me) -rte_pause (); +rte_wait_until_equal_16 (&tl->s.current, me, __ATOMIC_ACQUIRE); }/**
Signature · 1 line
2.7.4
PATCH v11 4/5 net/thunderx: use new API to save cycles on aarch64
In reply to Gavin HuUse the new API to wait in low power state instead of continuous polling to save CPU cycles and power.
--- drivers/net/thunderx/Makefile | 1 + drivers/net/thunderx/meson.build | 1 + drivers/net/thunderx/nicvf_rxtx.c | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/thunderx/Makefile +1 -0
@@ -10,6 +10,7 @@ include $(RTE_SDK)/mk/rte.vars.mk LIB = librte_pmd_thunderx_nicvf.a CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDLIBS += -lm LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
drivers/net/thunderx/meson.build +1 -0
@@ -4,6 +4,7 @@ subdir('base') objs = [base_objs] +allow_experimental_apis = true sources = files('nicvf_rxtx.c', 'nicvf_ethdev.c', 'nicvf_svf.c'
drivers/net/thunderx/nicvf_rxtx.c +1 -2
@@ -385,8 +385,7 @@ nicvf_fill_rbdr(struct nicvf_rxq *rxq, int to_fill) ltail++; } -while (__atomic_load_n (&rbdr->tail, __ATOMIC_RELAXED) != next_tail) -rte_pause (); +rte_wait_until_equal_32 (&rbdr->tail, next_tail, __ATOMIC_RELAXED);__atomic_store_n (&rbdr->tail, ltail, __ATOMIC_RELEASE);nicvf_addr_write (door, to_fill);
Signature · 1 line
2.7.4
PATCH v11 5/5 event/opdl: use new API to save cycles on aarch64
In reply to Gavin HuUse the new API to wait in low power state instead of continuous polling to save CPU cycles and power.
--- drivers/event/opdl/Makefile | 1 + drivers/event/opdl/meson.build | 1 + drivers/event/opdl/opdl_ring.c | 5 ++--- 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/event/opdl/Makefile +1 -0
@@ -9,6 +9,7 @@ LIB = librte_pmd_opdl_event.a # build flags CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # for older GCC versions, allow us to initialize an event using # designated initializers. ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
drivers/event/opdl/meson.build +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Luca Boccassi <[email protected]> +allow_experimental_apis = true sources = files( 'opdl_evdev.c', 'opdl_evdev_init.c',
drivers/event/opdl/opdl_ring.c +2 -3
@@ -16,6 +16,7 @@#include <rte_memcpy.h> #include <rte_memory.h> #include <rte_memzone.h> +#include <rte_atomic.h> #include "opdl_ring.h" #include "opdl_log.h"
@@ -474,9 +475,7 @@ opdl_ring_input_multithread(struct opdl_ring *t, const void *entries,/* If another thread started inputting before this one, but hasn't * finished, we need to wait for it to complete to update the tail. */ -while (unlikely (__atomic_load_n (&s->shared.tail, __ATOMIC_ACQUIRE) != - old_head)) -rte_pause (); +rte_wait_until_equal_32 (&s->shared.tail, old_head, __ATOMIC_ACQUIRE);__atomic_store_n (&s->shared.tail, old_head + num_entries, __ATOMIC_RELEASE);
Signature · 1 line
2.7.4
v12 cover use WFE for aarch64
In reply to Gavin HuV12:
- remove the 'rte_' prefix from the arm specific functions (David Marchand)
- use the __atomic_load_ex_xx functions in arm specific implementations of APIS (David Marchand)
- remove the experimental warnings (David Marchand)
- tweak the macros working scope (David Marchand)
V11:
-add rte_ prefix to the __atomic_load_ex_x funtions(Ananyev Konstantin)
-define the above rte_atomic_load_ex_x funtions even if not RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED for future non-wfe usages(Ananyev Konstantin) -use the above functions for arm specific rte_wait_until_equal_x functions(Ananyev Konstantin)
-simplify the generic implementation by immersing "if" into "while"(Ananyev Konstantin)
V10:
- move arm specific stuff to arch/arm/rte_pause_64.h(Ananyev Konstantin)
V9:
- fix a weblink broken (David Marchand)
- define rte_wfe and rte_sev() (Ananyev Konstantin)
- explicitly define three function APIs instead of marcos (Ananyev Konstantin)
- incorporate common rte_wfe and rte_sev into the generic rte_spinlock (David Marchand)
- define arch neutral RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED (Ananyev Konstantin)
- define rte_load_ex_16/32/64 functions to use load-exclusive instruction for aarch64, which is required for wake up of WFE
- drop the rte_spinlock patch from this series, as the it calls this experimental API and it is widely included by a lot of components each requires the ALLOW_EXPERIMENRAL_API for the Makefile and meson.build, leave it to future after the experimental is removed. V8:
- simplify dmb definition to use io barriers (David Marchand)
- define wfe() and sev() macros and use them inside normal C code (Ananyev Konstantin)
- pass memorder as parameter, not to incorporate it into function name, less functions, similar to C11 atomic intrinsics (Ananyev Konstantin)
- remove mandating RTE_FORCE_INTRINSICS in arm spinlock implementation(David Marchand)
- undef __WAIT_UNTIL_EQUAL after use (David Marchand)
- add experimental tag and warning (David Marchand)
- add the limitation of using WFE instruction in the commit log (David Marchand)
- tweak the use of RTE_FORCE_INSTRINSICS(still mandatory for aarch64) and RTE_ARM_USE_WFE for spinlock (David Marchand)
- drop the rte_ring patch from this series, as the rte_ring.h calls this API and it is widely included by a lot of components each requires the ALLOW_EXPERIMENRAL_API for the Makefile and meson.build, leave it to future after the experimental is removed. V7:
- fix the checkpatch LONG_LINE_COMMENT issue
V6:
- squash the RTE_ARM_USE_WFE configuration entry patch into the new API patch
- move the new configuration to the end of EAL
- add doxygen comments to reflect the relaxed and acquire semantics
- correct the meson configuration
V5:
- add doxygen comments for the new APIs
- spinlock early exit without wfe if the spinlock not taken by others.
- add two patches on top for opdl and thunderx
V4:
- rename the config as CONFIG_RTE_ARM_USE_WFE to indicate it applys to arm only
- introduce a macro for assembly Skelton to reduce the duplication of code
- add one patch for nxp fslmc to address a compiling error
V3:
- Convert RFCs to patches
V2:
- Use inline functions instead of marcos
- Add load and compare in the beginning of the APIs
- Fix some style errors in asm inline
V1:
- Add the new APIs and use it for ring and locks
Gavin Hu (5):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
ticketlock: use new API to reduce contention on aarch64 net/thunderx: use new API to save cycles on aarch64 event/opdl: use new API to save cycles on aarch64
config/arm/meson.build | 1 + config/common_base | 5 + drivers/bus/fslmc/mc/fsl_mc_sys.h | 8 +- drivers/event/opdl/Makefile | 1 + drivers/event/opdl/meson.build | 1 + drivers/event/opdl/opdl_ring.c | 5 +- drivers/net/thunderx/Makefile | 1 + drivers/net/thunderx/meson.build | 1 + drivers/net/thunderx/nicvf_rxtx.c | 3 +- .../common/include/arch/arm/rte_pause_64.h | 165 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_pause.h | 99 +++++++++++++ .../common/include/generic/rte_ticketlock.h | 3 +- 12 files changed, 281 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
PATCH v12 1/5 bus/fslmc: fix the conflicting dmb function
There are two definitions conflicting each other, for more details, refer to [1].
include/rte_atomic_64.h:19: error: "dmb" redefined [-Werror] drivers/bus/fslmc/mc/fsl_mc_sys.h:36: note: this is the location of the previous definition
#define dmb() {__asm__ __volatile__("" : : : "memory"); }
The fix is to reuse the EAL definition to avoid conflicts.
[1] http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF0@
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u
--- drivers/bus/fslmc/mc/fsl_mc_sys.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/bus/fslmc/mc/fsl_mc_sys.h +3 -5
@@ -31,12 +31,10 @@ struct fsl_mc_io {#include <errno.h> #include <sys/uio.h> #include <linux/byteorder/little_endian.h> +#include <rte_atomic.h> -#ifndef dmb -#define dmb () {__asm__ __volatile__("" : : : "memory"); } -#endif -#define __iormb () dmb() -#define __iowmb () dmb() +#define __iormb () rte_io_rmb() +#define __iowmb () rte_io_wmb()#define __arch_getq (a) (*(volatile uint64_t *)(a))#define __arch_putq (v, a) (*(volatile uint64_t *)(a) = (v))#define __arch_putq32 (v, a) (*(volatile uint32_t *)(a) = (v))
Signature · 1 line
2.7.4
PATCH v12 2/5 eal: add the APIs to wait until equal
In reply to Gavin HuThe rte_wait_until_equal_xx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.
Add the RTE_ARM_USE_WFE configuration entry for aarch64, disabled by default. When it is enabled, the above APIs will call WFE instruction to save CPU cycles and power.
From a VM, when calling this API on aarch64, it may trap in and out to release vCPUs whereas cause high exit latency. Since kernel 4.18.20 an adaptive trapping mechanism is introduced to balance the latency and workload.
--- config/arm/meson.build | 1 + config/common_base | 5 + .../common/include/arch/arm/rte_pause_64.h | 165 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_pause.h | 99 +++++++++++++ 4 files changed, 270 insertions(+)
config/arm/meson.build +1 -0
@@ -26,6 +26,7 @@ flags_common_default = [ ['RTE_LIBRTE_AVP_PMD', false], ['RTE_SCHED_VECTOR', false], + ['RTE_ARM_USE_WFE', false], ] flags_generic = [
config/common_base +5 -0
@@ -110,6 +110,11 @@ CONFIG_RTE_MAX_VFIO_CONTAINERS=64 CONFIG_RTE_MALLOC_DEBUG=n CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n CONFIG_RTE_USE_LIBBSD=n +# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs, +# calling these APIs put the cores in low power state while waiting +# for the memory address to become equal to the expected value. +# This is supported only by aarch64. +CONFIG_RTE_ARM_USE_WFE=n # # Recognize/ignore the AVX/AVX512 CPU flags for performance/power testing.
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +165 -0
182 lines not on this page · raw message
lib/librte_eal/common/include/generic/rte_pause.h +99 -0
114 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [dpdk-dev] [PATCH v12 2/5] eal: add the APIs to wait until equal
Quoted 22 lines
The
rte_wait_until_equal_xxAPIs abstract the functionality of 'polling for a memory location to become equal to a given value'.Add the
RTE_ARM_USE_WFEconfiguration entry for aarch64, disabled by default. When it is enabled, the above APIs will call WFE instruction to save CPU cycles and power.From a VM, when calling this API on aarch64, it may trap in and out to release vCPUs whereas cause high exit latency. Since kernel 4.18.20 an adaptive trapping mechanism is introduced to balance the latency and workload.
Signed-off-by Gavin Hu <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Steve Capper <[email protected]>Reviewed-by Ola Liljedahl <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>Reviewed-by Phil Yang <[email protected]>Acked-by Pavan Nikhilesh <[email protected]>Acked-by Jerin Jacob <[email protected]>
Quoted 1 line
---
Quoted 1 line
2.7.4
PATCH v12 3/5 ticketlock: use new API to reduce contention on aarch64
In reply to Gavin HuWhile using ticket lock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.
Running ticketlock_autotest on ThunderX2, Ampere eMAG80, and Arm N1SDP[1], there were variances between runs, but no notable performance gain or degradation were seen with and without this patch.
[1] https://community.arm.com/developer/tools-software/oss-platforms/w/\
docs/440/neoverse-n1-sdp
--- lib/librte_eal/common/include/generic/rte_ticketlock.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/librte_eal/common/include/generic/rte_ticketlock.h +1 -2
@@ -66,8 +66,7 @@ static inline void rte_ticketlock_lock(rte_ticketlock_t *tl) {uint16_t me =__atomic_fetch_add (&tl->s.next,1 , __ATOMIC_RELAXED); -while (__atomic_load_n (&tl->s.current, __ATOMIC_ACQUIRE) != me) -rte_pause (); +rte_wait_until_equal_16 (&tl->s.current, me, __ATOMIC_ACQUIRE); }/**
Signature · 1 line
2.7.4
PATCH v12 4/5 net/thunderx: use new API to save cycles on aarch64
In reply to Gavin HuUse the new API to wait in low power state instead of continuous polling to save CPU cycles and power.
--- drivers/net/thunderx/Makefile | 1 + drivers/net/thunderx/meson.build | 1 + drivers/net/thunderx/nicvf_rxtx.c | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/thunderx/Makefile +1 -0
@@ -10,6 +10,7 @@ include $(RTE_SDK)/mk/rte.vars.mk LIB = librte_pmd_thunderx_nicvf.a CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDLIBS += -lm LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
drivers/net/thunderx/meson.build +1 -0
@@ -4,6 +4,7 @@ subdir('base') objs = [base_objs] +allow_experimental_apis = true sources = files('nicvf_rxtx.c', 'nicvf_ethdev.c', 'nicvf_svf.c'
drivers/net/thunderx/nicvf_rxtx.c +1 -2
@@ -385,8 +385,7 @@ nicvf_fill_rbdr(struct nicvf_rxq *rxq, int to_fill) ltail++; } -while (__atomic_load_n (&rbdr->tail, __ATOMIC_RELAXED) != next_tail) -rte_pause (); +rte_wait_until_equal_32 (&rbdr->tail, next_tail, __ATOMIC_RELAXED);__atomic_store_n (&rbdr->tail, ltail, __ATOMIC_RELEASE);nicvf_addr_write (door, to_fill);
Signature · 1 line
2.7.4
PATCH v12 5/5 event/opdl: use new API to save cycles on aarch64
In reply to Gavin HuUse the new API to wait in low power state instead of continuous polling to save CPU cycles and power.
--- drivers/event/opdl/Makefile | 1 + drivers/event/opdl/meson.build | 1 + drivers/event/opdl/opdl_ring.c | 5 ++--- 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/event/opdl/Makefile +1 -0
@@ -9,6 +9,7 @@ LIB = librte_pmd_opdl_event.a # build flags CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # for older GCC versions, allow us to initialize an event using # designated initializers. ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
drivers/event/opdl/meson.build +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Luca Boccassi <[email protected]> +allow_experimental_apis = true sources = files( 'opdl_evdev.c', 'opdl_evdev_init.c',
drivers/event/opdl/opdl_ring.c +2 -3
@@ -16,6 +16,7 @@#include <rte_memcpy.h> #include <rte_memory.h> #include <rte_memzone.h> +#include <rte_atomic.h> #include "opdl_ring.h" #include "opdl_log.h"
@@ -474,9 +475,7 @@ opdl_ring_input_multithread(struct opdl_ring *t, const void *entries,/* If another thread started inputting before this one, but hasn't * finished, we need to wait for it to complete to update the tail. */ -while (unlikely (__atomic_load_n (&s->shared.tail, __ATOMIC_ACQUIRE) != - old_head)) -rte_pause (); +rte_wait_until_equal_32 (&s->shared.tail, old_head, __ATOMIC_ACQUIRE);__atomic_store_n (&s->shared.tail, old_head + num_entries, __ATOMIC_RELEASE);
Signature · 1 line
2.7.4
v13 cover use WFE for aarch64
In reply to Gavin HuDPDK has multiple use cases where the core repeatedly polls a location in memory. This polling results in many cache and memory transactions.
Arm architecture provides WFE (Wait For Event) instruction, which allows the cpu core to enter a low power state until woken up by the update to the memory location being polled. Thus reducing the cache and memory transactions.
x86 has the PAUSE hint instruction to reduce such overhead.
The rte_wait_until_equal_xxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.
For non-Arm platforms, these APIs are just wrappers around do-while loop with rte_pause, so there are no performance differences.
For Arm platforms, use of WFE can be configured using CONFIG_RTE_USE_WFE option. It is disabled by default.
Currently, use of WFE is supported only for aarch64 platforms. armv7 platforms do support the WFE instruction, but they require explicit wake up events(sev) and are less performannt.
Testing shows that, performance varies across different platforms, with some showing degradation.
CONFIG_RTE_USE_WFE should be enabled depending on the performance on the target platforms.
V13:
- added release notes update,
- reworked arm implementation to avoid exporting inlines,
- added assert in generic implementation,
V12:
- remove the 'rte_' prefix from the arm specific functions (David Marchand)
- use the __atomic_load_ex_xx functions in arm specific implementations of APIS (David Marchand)
- remove the experimental warnings (David Marchand)
- tweak the macros working scope (David Marchand)
V11:
- add rte_ prefix to the __atomic_load_ex_x funtions (Ananyev Konstantin)
- define the above rte_atomic_load_ex_x funtions even if not RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED for future non-wfe usages (Ananyev Konstantin)
- use the above functions for arm specific rte_wait_until_equal_x functions (Ananyev Konstantin)
- simplify the generic implementation by immersing "if" into "while" (Ananyev Konstantin)
V10:
- move arm specific stuff to arch/arm/rte_pause_64.h (Ananyev Konstantin)
V9:
- fix a weblink broken (David Marchand)
- define rte_wfe and rte_sev() (Ananyev Konstantin)
- explicitly define three function APIs instead of marcos (Ananyev Konstantin)
- incorporate common rte_wfe and rte_sev into the generic rte_spinlock (David Marchand)
- define arch neutral RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED (Ananyev Konstantin)
- define rte_load_ex_16/32/64 functions to use load-exclusive instruction for aarch64, which is required for wake up of WFE
- drop the rte_spinlock patch from this series, as the it calls this experimental API and it is widely included by a lot of components each requires the ALLOW_EXPERIMENRAL_API for the Makefile and meson.build, leave it to future after the experimental is removed.
V8:
- simplify dmb definition to use io barriers (David Marchand)
- define wfe() and sev() macros and use them inside normal C code (Ananyev Konstantin)
- pass memorder as parameter, not to incorporate it into function name, less functions, similar to C11 atomic intrinsics (Ananyev Konstantin)
- remove mandating RTE_FORCE_INTRINSICS in arm spinlock implementation (David Marchand)
- undef __WAIT_UNTIL_EQUAL after use (David Marchand)
- add experimental tag and warning (David Marchand)
- add the limitation of using WFE instruction in the commit log (David Marchand)
- tweak the use of RTE_FORCE_INSTRINSICS (still mandatory for aarch64) and RTE_ARM_USE_WFE for spinlock (David Marchand)
- drop the rte_ring patch from this series, as the rte_ring.h calls this API and it is widely included by a lot of components each requires the ALLOW_EXPERIMENRAL_API for the Makefile and meson.build, leave it to future after the experimental is removed.
V7:
- fix the checkpatch LONG_LINE_COMMENT issue
V6:
- squash the RTE_ARM_USE_WFE configuration entry patch into the new API patch
- move the new configuration to the end of EAL
- add doxygen comments to reflect the relaxed and acquire semantics
- correct the meson configuration
V5:
- add doxygen comments for the new APIs
- spinlock early exit without wfe if the spinlock not taken by others.
- add two patches on top for opdl and thunderx
V4:
- rename the config as CONFIG_RTE_ARM_USE_WFE to indicate it applys to arm only
- introduce a macro for assembly Skelton to reduce the duplication of code
- add one patch for nxp fslmc to address a compiling error
V3:
- Convert RFCs to patches
V2:
- Use inline functions instead of marcos
- Add load and compare in the beginning of the APIs
- Fix some style errors in asm inline
V1:
- Add the new APIs and use it for ring and locks
Gavin Hu (5):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
ticketlock: use new API to reduce contention on aarch64 net/thunderx: use new API to save cycles on aarch64 event/opdl: use new API to save cycles on aarch64
config/arm/meson.build | 1 + config/common_base | 5 + doc/guides/rel_notes/release_19_11.rst | 5 + drivers/bus/fslmc/mc/fsl_mc_sys.h | 9 +- drivers/event/opdl/Makefile | 1 + drivers/event/opdl/meson.build | 1 + drivers/event/opdl/opdl_ring.c | 5 +- drivers/net/thunderx/Makefile | 1 + drivers/net/thunderx/meson.build | 1 + drivers/net/thunderx/nicvf_rxtx.c | 3 +- .../common/include/arch/arm/rte_pause_64.h | 133 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_pause.h | 105 ++++++++++++++++ .../common/include/generic/rte_ticketlock.h | 3 +- 13 files changed, 261 insertions(+), 12 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v13 1/5 bus/fslmc: fix the conflicting dmb function
From: Gavin Hu <[email protected]>
There are two definitions conflicting each other, for more details, refer to [1].
include/rte_atomic_64.h:19: error: "dmb" redefined [-Werror] drivers/bus/fslmc/mc/fsl_mc_sys.h:36: note: this is the location of the previous definition
#define dmb() {__asm__ __volatile__("" : : : "memory"); }
The fix is to reuse the EAL definition to avoid conflicts.
[1] http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF0@
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u
---
Changelog since v12:
- fixed Phil Yang mail address,
--- drivers/bus/fslmc/mc/fsl_mc_sys.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/bus/fslmc/mc/fsl_mc_sys.h +4 -5
@@ -32,11 +32,10 @@ struct fsl_mc_io {#include <sys/uio.h> #include <linux/byteorder/little_endian.h> -#ifndef dmb -#define dmb () {__asm__ __volatile__("" : : : "memory"); } -#endif -#define __iormb () dmb() -#define __iowmb () dmb() +#include <rte_atomic.h> + +#define __iormb () rte_io_rmb() +#define __iowmb () rte_io_wmb()#define __arch_getq (a) (*(volatile uint64_t *)(a))#define __arch_putq (v, a) (*(volatile uint64_t *)(a) = (v))#define __arch_putq32 (v, a) (*(volatile uint32_t *)(a) = (v))
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v13 1/5] bus/fslmc: fix the conflicting dmb function
In case there are more versions of the WFE patch, is it ok to merge this patch alone?. It will be one less patch to carry around. Thanks,
Honnappa
Quoted 61 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of David Marchand
Sent: Thursday, November 7, 2019 3:35 PM
To: [email protected]
Cc: nd <[email protected]>; [email protected]; Gavin Hu (Arm Technology China) <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [dpdk-dev] [PATCH v13 1/5] bus/fslmc: fix the conflicting dmb functionFrom: Gavin Hu <[email protected]>
There are two definitions conflicting each other, for more details, refer to [1].
include/rte_atomic_64.h:19: error: "dmb" redefined [-Werror]drivers/bus/fslmc/mc/fsl_mc_sys.h:36: note: this is the location of the previous definition #definedmb(){__asm____volatile__("" : : : "memory"); }The fix is to reuse the EAL definition to avoid conflicts.
[1]
http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF
0@
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#uFixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")Signed-off-by Gavin Hu <[email protected]>Reviewed-by Phil Yang <[email protected]>Acked-by Hemant Agrawal <[email protected]>---
Changelog since v12:
- fixed Phil Yang mail address,--- drivers/bus/fslmc/mc/fsl_mc_sys.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/bus/fslmc/mc/fsl_mc_sys.h +4
-5@@ -32,11 +32,10 @@ struct fsl_mc_io {#include <sys/uio.h> #include <linux/byteorder/little_endian.h> -#ifndef dmb -#define dmb () {__asm__ __volatile__("" : : : "memory"); } -#endif -#define __iormb () dmb() -#define __iowmb () dmb() +#include <rte_atomic.h> + +#define __iormb () rte_io_rmb() +#define __iowmb () rte_io_wmb()#define __arch_getq (a) (*(volatile uint64_t *)(a))#define __arch_putq (v, a) (*(volatile uint64_t *)(a) = (v))#define __arch_putq32 (v, a) (*(volatile uint32_t *)(a) = (v)) --1.8.3.1
PATCH v13 2/5 eal: add the APIs to wait until equal
In reply to David MarchandFrom: Gavin Hu <[email protected]>
The rte_wait_until_equal_xx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.
Add the RTE_ARM_USE_WFE configuration entry for aarch64, disabled by default. When it is enabled, the above APIs will call WFE instruction to save CPU cycles and power.
From a VM, when calling this API on aarch64, it may trap in and out to release vCPUs whereas cause high exit latency. Since kernel 4.18.20 an adaptive trapping mechanism is introduced to balance the latency and workload.
---
Changelog since v12:
- added release notes update,
- fixed function prototypes indent,
- reimplemented the arm implementation without exposing internal inline functions,
- added asserts in generic implementation,
--- config/arm/meson.build | 1 + config/common_base | 5 + doc/guides/rel_notes/release_19_11.rst | 5 + .../common/include/arch/arm/rte_pause_64.h | 133 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_pause.h | 105 ++++++++++++++++ 5 files changed, 249 insertions(+)
config/arm/meson.build +1 -0
@@ -26,6 +26,7 @@ flags_common_default = [ ['RTE_LIBRTE_AVP_PMD', false], ['RTE_SCHED_VECTOR', false], + ['RTE_ARM_USE_WFE', false], ] flags_generic = [
config/common_base +5 -0
@@ -110,6 +110,11 @@ CONFIG_RTE_MAX_VFIO_CONTAINERS=64 CONFIG_RTE_MALLOC_DEBUG=n CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n CONFIG_RTE_USE_LIBBSD=n +# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs, +# calling these APIs put the cores in low power state while waiting +# for the memory address to become equal to the expected value. +# This is supported only by aarch64. +CONFIG_RTE_ARM_USE_WFE=n # # Recognize/ignore the AVX/AVX512 CPU flags for performance/power testing.
doc/guides/rel_notes/release_19_11.rst +5 -0
@@ -65,6 +65,11 @@ New Features The lock-free stack implementation is enabled for aarch64 platforms. +* **Added Wait Until Equal API.** + + A new API has been added to wait for a memory location to be updated with a + 16-bit, 32-bit, 64-bit value. + * **Changed mempool allocation behaviour.** Objects are no longer across pages by default.
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +133 -0
150 lines not on this page · raw message
lib/librte_eal/common/include/generic/rte_pause.h +105 -0
120 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equal
Hi David,
Quoted 225 lines
From: Gavin Hu <[email protected]>
The
rte_wait_until_equal_xxAPIs abstract the functionality of 'polling for a memory location to become equal to a given value'.Add the
RTE_ARM_USE_WFEconfiguration entry for aarch64, disabled by default. When it is enabled, the above APIs will call WFE instruction to save CPU cycles and power.From a VM, when calling this API on aarch64, it may trap in and out to release vCPUs whereas cause high exit latency. Since kernel 4.18.20 an adaptive trapping mechanism is introduced to balance the latency and workload.
Signed-off-by Gavin Hu <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Steve Capper <[email protected]>Reviewed-by Ola Liljedahl <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>Reviewed-by Phil Yang <[email protected]>Acked-by Pavan Nikhilesh <[email protected]>Acked-by Jerin Jacob <[email protected]>Signed-off-by David Marchand <[email protected]>---
Changelog since v12:
- added release notes update,
- fixed function prototypes indent,
- reimplemented the arm implementation without exposing internal inline functions,
- added asserts in generic implementation,--- config/arm/meson.build | 1 + config/common_base | 5 + doc/guides/rel_notes/release_19_11.rst | 5 + .../common/include/arch/arm/rte_pause_64.h | 133 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_pause.h | 105 ++++++++++++++++ 5 files changed, 249 insertions(+)config/arm/meson.build +1
-0@@ -26,6 +26,7 @@ flags_common_default = [ ['RTE_LIBRTE_AVP_PMD', false], ['RTE_SCHED_VECTOR', false], + ['RTE_ARM_USE_WFE', false], ] flags_generic = [config/common_base +5
-0@@ -110,6 +110,11 @@ CONFIG_RTE_MAX_VFIO_CONTAINERS=64 CONFIG_RTE_MALLOC_DEBUG=n CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n CONFIG_RTE_USE_LIBBSD=n +# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs, +# calling these APIs put the cores in low power state while waiting +# for the memory address to become equal to the expected value. +# This is supported only by aarch64. +CONFIG_RTE_ARM_USE_WFE=n # # Recognize/ignore the AVX/AVX512 CPU flags for performance/power testing.doc/guides/rel_notes/release_19_11.rst +5
-0@@ -65,6 +65,11 @@ New Features The lock-free stack implementation is enabled for aarch64 platforms. +* **Added Wait Until Equal API.** + + A new API has been added to wait for a memory location to be updated with a + 16-bit, 32-bit, 64-bit value. + * **Changed mempool allocation behaviour.** Objects are no longer across pages by default.lib/librte_eal/common/include/arch/arm/rte_pause_64.h +120
-0@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2017 Cavium, Inc +* Copyright(c) 2019 Arm Limited */ #ifndef _RTE_PAUSE_ARM64_H_@@ -10,6 +11,11 @@ extern "C" {#endif #include <rte_common.h> + +#ifdef RTE_ARM_USE_WFE +#define RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +#endif +#include "generic/rte_pause.h" static inline void rte_pause (void )@@ -17,6 +23,133 @@ static inline void rte_pause(void) asmvolatile ("yield" :::"memory" ); } +#ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED + +/* Send an event to quit WFE. */ +#define __SEVL () { asm volatile("sevl" : : : "memory"); } + +/* Put processor into low power WFE(Wait For Event) state. */ +#define __WFE () { asm volatile("wfe" : : : "memory"); } + +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder) +{ +uint16_t value; + +assert (memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED); + +/* +* Atomic exclusive load from addr, it returns the 16-bit content of +* *addr while making it 'monitored',when it is written by someone +* else, the 'monitored' state is cleared and a event is generated +* implicitly to exit WFE. +*/ +#define __LOAD_EXC_16 (src, dst, memorder) { \ + if (memorder == __ATOMIC_RELAXED) { \ + asm volatile("ldxrh %w[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } else { \ + asm volatile("ldaxrh %w[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } } + + __LOAD_EXC_16(addr, value, memorder) +if (value != expected) { + __SEVL() +do { + __WFE() + __LOAD_EXC_16(addr, value, memorder) + }while (value != expected); + } +#undef __LOAD_EXC_16 +} + +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder) +{ +uint32_t value; + +assert (memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED); + +/* +* Atomic exclusive load from addr, it returns the 32-bit content of +* *addr while making it 'monitored',when it is written by someone +* else, the 'monitored' state is cleared and a event is generated +* implicitly to exit WFE. +*/ +#define __LOAD_EXC_32 (src, dst, memorder) { \ + if (memorder == __ATOMIC_RELAXED) { \ + asm volatile("ldxr %w[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } else { \ + asm volatile("ldaxr %w[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } } + + __LOAD_EXC_32(addr, value, memorder) +if (value != expected) { + __SEVL() +do { + __WFE() + __LOAD_EXC_32(addr, value, memorder) + }while (value != expected); + } +#undef __LOAD_EXC_32 +} + +static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder) +{ +uint64_t value; + +assert (memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED); + +/* +* Atomic exclusive load from addr, it returns the 64-bit content of +* *addr while making it 'monitored',when it is written by someone +* else, the 'monitored' state is cleared and a event is generated +* implicitly to exit WFE. +*/ +#define __LOAD_EXC_64 (src, dst, memorder) { \ + if (memorder == __ATOMIC_RELAXED) { \ + asm volatile("ldxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } else { \ + asm volatile("ldaxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } } + + __LOAD_EXC_64(addr, value, memorder) +if (value != expected) { +__SEVL ()
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 149
Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10
-0+do { + __WFE() + __LOAD_EXC_64(addr, value, memorder) + }while (value != expected); + } +} +#undef __LOAD_EXC_64 + +#undef __SEVL +#undef __WFE
Personally I don't see how these define/undef are better then inline functions... Again I suppose they might be re-used in future some other ARM specific low-level primitvies. My preference would be to keep them as inline function - much cleaner code. But as I don't develop for/use, I wouldn't insist and let you and arm guys to decide. Konstantin
Quoted 135 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +3
-0+ +#endif + #ifdef __cplusplus }#endif lib/librte_eal/common/include/generic/rte_pause.h +105
-1@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2017 Cavium, Inc +* Copyright(c) 2019 Arm Limited */ #ifndef _RTE_PAUSE_H_@@ -12,6 +13,12 @@* */ +#include <stdint.h> +#include <assert.h> +#include <rte_common.h> +#include <rte_atomic.h> +#include <rte_compat.h> +/** * Pause CPU execution for a short while * @@ -20,4 +27,102 @@*/ static inline void rte_pause (void ); +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Wait for *addr to be updated with a 16-bit expected value, with a relaxed +* memory ordering model meaning the loads around this API can be reordered. +* +* @param addr +* A pointer to the memory location. +* @param expected +* A 16-bit expected value to be in the memory location. +* @param memorder +* Two different memory orders that can be specified: +* __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to +* C++11 memory orders with the same names, see the C++11 standard or +* the GCC wiki on atomic synchronization for detailed definition. +*/ +__rte_experimental +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Wait for *addr to be updated with a 32-bit expected value, with a relaxed +* memory ordering model meaning the loads around this API can be reordered. +* +* @param addr +* A pointer to the memory location. +* @param expected +* A 32-bit expected value to be in the memory location. +* @param memorder +* Two different memory orders that can be specified: +* __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to +* C++11 memory orders with the same names, see the C++11 standard or +* the GCC wiki on atomic synchronization for detailed definition. +*/ +__rte_experimental +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Wait for *addr to be updated with a 64-bit expected value, with a relaxed +* memory ordering model meaning the loads around this API can be reordered. +* +* @param addr +* A pointer to the memory location. +* @param expected +* A 64-bit expected value to be in the memory location. +* @param memorder +* Two different memory orders that can be specified: +* __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to +* C++11 memory orders with the same names, see the C++11 standard or +* the GCC wiki on atomic synchronization for detailed definition. +*/ +__rte_experimental +static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder); + +#ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED +static __rte_always_inline void +rte_wait_until_equal_16 (volatile uint16_t *addr,uint16_t expected, +int memorder) +{ +assert (memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED); + +while (__atomic_load_n (addr, memorder) != expected) +rte_pause (); +} + +static __rte_always_inline void +rte_wait_until_equal_32 (volatile uint32_t *addr,uint32_t expected, +int memorder) +{ +assert (memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED); + +while (__atomic_load_n (addr, memorder) != expected) +rte_pause (); +} + +static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder) +{ +assert (memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED); + +while (__atomic_load_n (addr, memorder) != expected) +rte_pause (); +} +#endif +#endif /* _RTE_PAUSE_H_ */ --1.8.3.1
Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equal
08/11/2019 17:38, Ananyev, Konstantin:
Quoted 35 lines
Quoted 35 lines
From: Gavin Hu <[email protected]>
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +34
-0+static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder) +{ +uint64_t value; + +assert (memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED); + +/* +* Atomic exclusive load from addr, it returns the 64-bit content of +* *addr while making it 'monitored',when it is written by someone +* else, the 'monitored' state is cleared and a event is generated +* implicitly to exit WFE. +*/ +#define __LOAD_EXC_64 (src, dst, memorder) { \ + if (memorder == __ATOMIC_RELAXED) { \ + asm volatile("ldxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } else { \ + asm volatile("ldaxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } } + + __LOAD_EXC_64(addr, value, memorder) +if (value != expected) { + __SEVL() +do { + __WFE() + __LOAD_EXC_64(addr, value, memorder) + }while (value != expected);
Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 149
Quoted 6 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6
-0+ } +} +#undef __LOAD_EXC_64 + +#undef __SEVL +#undef __WFEPersonally I don't see how these define/undef are better then inline functions...
The benefit it to not pollute the API namespace
with some functions which are used only locally.
After using a macro, it disappears with #undef.
Quoted 1 line
Again I suppose they might be re-used in future some other ARM specific low-level primitvies.
Do this low-level routines _LOAD_EXC_ need to be exposed in EAL for re-use?
Quoted 2 lines
My preference would be to keep them as inline function - much cleaner code. But as I don't develop for/use, I wouldn't insist and let you and arm guys to decide.
Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equal
Quoted 56 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Friday, November 8, 2019 5:00 PM
To: Ananyev, Konstantin <[email protected]>
Cc: David Marchand <[email protected]>; [email protected]; [email protected]; Gavin Hu <[email protected]>; Mcnamara, John <[email protected]>; Kovacevic, Marko <[email protected]>; Jerin Jacob <[email protected]>; Jan Viktorin <[email protected]>
Subject: Re: [PATCH v13 2/5] eal: add the APIs to wait until equal08/11/2019 17:38, Ananyev, Konstantin:
Quoted 35 lines
Quoted 35 lines
From: Gavin Hu <[email protected]>
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +34
-0+static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder) +{ +uint64_t value; + +assert (memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED); + +/* +* Atomic exclusive load from addr, it returns the 64-bit content of +* *addr while making it 'monitored',when it is written by someone +* else, the 'monitored' state is cleared and a event is generated +* implicitly to exit WFE. +*/ +#define __LOAD_EXC_64 (src, dst, memorder) { \ + if (memorder == __ATOMIC_RELAXED) { \ + asm volatile("ldxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } else { \ + asm volatile("ldaxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } } + + __LOAD_EXC_64(addr, value, memorder) +if (value != expected) { + __SEVL() +do { + __WFE() + __LOAD_EXC_64(addr, value, memorder) + }while (value != expected);Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 149
Quoted 6 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6
-0+ } +} +#undef __LOAD_EXC_64 + +#undef __SEVL +#undef __WFEPersonally I don't see how these define/undef are better then inline functions...
Quoted 7 lines
The benefit it to not pollute the API namespace with some functions which are used only locally. After using a macro, it disappears with #undef.
Quoted 1 line
Again I suppose they might be re-used in future some other ARM specific low-level primitvies.
Do this low-level routines _LOAD_EXC_ need to be exposed in EAL for re-use?
About load_exc don't know for sure...
Though as I can see wfe/sevl are used here:
http://patchwork.dpdk.org/patch/61779/
Might be it is possible to reuse these functions/macros...
But again, I am not arm expert, would be interested to know what arm guys think.
Quoted 5 lines
Quoted 3 lines
My preference would be to keep them as inline function - much cleaner code. But as I don't develop for/use, I wouldn't insist and let you and arm guys to decide.
Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equal
Quoted 63 lines · Konstantin
Quoted 63 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Friday, November 8, 2019 5:00 PM
To: Ananyev, Konstantin <[email protected]>
Cc: David Marchand <[email protected]>; [email protected]; [email protected]; Gavin Hu <[email protected]>; Mcnamara, John <[email protected]>; Kovacevic, Marko <[email protected]>; Jerin Jacob <[email protected]>; Jan Viktorin <[email protected]>
Subject: Re: [PATCH v13 2/5] eal: add the APIs to wait until equal08/11/2019 17:38, Ananyev, Konstantin:
Quoted 35 lines
Quoted 35 lines
From: Gavin Hu <[email protected]>
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +34
-0+static __rte_always_inline void +rte_wait_until_equal_64 (volatile uint64_t *addr,uint64_t expected, +int memorder) +{ +uint64_t value; + +assert (memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED); + +/* +* Atomic exclusive load from addr, it returns the 64-bit content of +* *addr while making it 'monitored',when it is written by someone +* else, the 'monitored' state is cleared and a event is generated +* implicitly to exit WFE. +*/ +#define __LOAD_EXC_64 (src, dst, memorder) { \ + if (memorder == __ATOMIC_RELAXED) { \ + asm volatile("ldxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } else { \ + asm volatile("ldaxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } } + + __LOAD_EXC_64(addr, value, memorder) +if (value != expected) { + __SEVL() +do { + __WFE() + __LOAD_EXC_64(addr, value, memorder) + }while (value != expected);Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 149
Quoted 6 lines
+ }
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +5
-0+} +#undef __LOAD_EXC_64 + +#undef __SEVL +#undef __WFEPersonally I don't see how these define/undef are better then inline functions...
The benefit it to not pollute the API namespace with some functions which are used only locally. After using a macro, it disappears with #undef.
Quoted 1 line
Again I suppose they might be re-used in future some other ARM specific low-level primitvies.
Quoted 7 lines
Quoted 1 line
Do this low-level routines _LOAD_EXC_ need to be exposed in EAL for re-use?
About
load_excdon't know for sure...
Though as I can see wfe/sevl are used here:
http://patchwork.dpdk.org/patch/61779/
Might be it is possible to reuse these functions/macros...
But again, I am not arm expert, would be interested to know what arm guys think.
Considering WFE has a requirement on using load_exec on ARM so IMO, it makes sense to exposeload_exec in conjunction with wfe/sevl to use it properly.
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
My preference would be to keep them as inline function - much cleaner code. But as I don't develop for/use, I wouldn't insist and let you and arm guys to decide.
Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equal
Quoted 92 lines
-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Monday, November 11, 2019 1:12 PM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; David Marchand <[email protected]>; [email protected]; nd <[email protected]>; Gavin Hu (Arm Technology China) <[email protected]>; Mcnamara, John <[email protected]>; Kovacevic, Marko <[email protected]>; [email protected]; Jan Viktorin <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equalQuoted 8 lines · Konstantin
Quoted 8 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Friday, November 8, 2019 5:00 PM
To: Ananyev, Konstantin <[email protected]>
Cc: David Marchand <[email protected]>; [email protected];[email protected]; Gavin Hu <[email protected]>; Mcnamara, John
Quoted 1 line
Quoted 1 line
<[email protected]>; Kovacevic, Marko
<[email protected]>; Jerin Jacob <[email protected]>; Jan Viktorin
Quoted 4 lines
Quoted 4 lines
<[email protected]>
Subject: Re: [PATCH v13 2/5] eal: add the APIs to wait until equal08/11/2019 17:38, Ananyev, Konstantin:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)
Quoted 8 lines
From: Gavin Hu <[email protected]>
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +7
-0+static __rte_always_inline void +rte_wait_until_equal_64(volatile uint64_t *addr, uint64_t expected, + int memorder) +{ + uint64_t value; + + assert(memorder == __ATOMIC_ACQUIRE || memorder ==
__ATOMIC_RELAXED);Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +27
-0+ +/* +* Atomic exclusive load from addr, it returns the 64-bit content of +* *addr while making it 'monitored',when it is written by someone +* else, the 'monitored' state is cleared and a event is generated +* implicitly to exit WFE. +*/ +#define __LOAD_EXC_64 (src, dst, memorder) { \ + if (memorder == __ATOMIC_RELAXED) { \ + asm volatile("ldxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } else { \ + asm volatile("ldaxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } } + + __LOAD_EXC_64(addr, value, memorder) +if (value != expected) { + __SEVL() +do { + __WFE() + __LOAD_EXC_64(addr, value, memorder) + }while (value != expected);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 149
Quoted 6 lines
+ }
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +5
-0+} +#undef __LOAD_EXC_64 + +#undef __SEVL +#undef __WFEPersonally I don't see how these define/undef are better then inline
functions...
Quoted 6 lines
Quoted 6 lines
The benefit it to not pollute the API namespace with some functions which are used only locally. After using a macro, it disappears with #undef.
Quoted 1 line
Again I suppose they might be re-used in future some other ARM
specific low-level primitvies.
Quoted 2 lines
Quoted 2 lines
Do this low-level routines _LOAD_EXC_ need to be exposed in EAL for re-
use?
Quoted 6 lines
About
load_excdon't know for sure...
Though as I can see wfe/sevl are used here:
http://patchwork.dpdk.org/patch/61779/
Might be it is possible to reuse these functions/macros... But again, I am not arm expert, would be interested to know what arm
Quoted 6 lines
guys think.
Considering WFE has a requirement on using
load_execon ARM so IMO, it makes sense to exposeload_execin conjunction with wfe/sevl to use it properly.
Agree, WFE should have more use cases can be developed, not limited to the WAIT_UNTIL_EQUAL_XX APIs. Marvel's patch is an example. Sorry I don't have more use case so far, but Arm is evolving WFE, so I think more use cases are emerging. /Gavin
Quoted 11 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
My preference would be to keep them as inline function - much
cleaner code.
Quoted 1 line
Quoted 1 line
Quoted 1 line
But as I don't develop for/use, I wouldn't insist and let you and arm
guys to decide.
Quoted 3 lines
Quoted 2 lines
Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equal
<snip>
Quoted 71 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Subject: Re: [PATCH v13 2/5] eal: add the APIs to wait until equal
08/11/2019 17:38, Ananyev, Konstantin:
Quoted 3 lines
Review
Quoted 3 lines
From: Gavin Hu <[email protected]>
(quoted diff) +2
-0+static __rte_always_inline void +rte_wait_until_equal_64(volatile uint64_t *addr, uint64_texpected,
Quoted 64 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)
Quoted 5 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +5
-0+ int memorder) +{ + uint64_t value; + + assert(memorder == __ATOMIC_ACQUIRE || memorder ==
__ATOMIC_RELAXED);Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +29
-0+ +/* +* Atomic exclusive load from addr, it returns the 64-bit +content of +* *addr while making it 'monitored',when it is written by +someone +* else, the 'monitored' state is cleared and a event is +generated +* implicitly to exit WFE. +*/ +#define __LOAD_EXC_64 (src, dst, memorder) { \ + if (memorder == __ATOMIC_RELAXED) { \ + asm volatile("ldxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } else { \ + asm volatile("ldaxr %x[tmp], [%x[addr]]" \ + : [tmp] "=&r" (dst) \ + : [addr] "r"(src) \ + : "memory"); \ + } } + + __LOAD_EXC_64(addr, value, memorder) if (value != expected) +{ + __SEVL() + do { + __WFE() + __LOAD_EXC_64(addr, value, memorder)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 149
Quoted 5 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +5
-0+ }while (value != expected); } }#undef +__LOAD_EXC_64 + +#undef __SEVL +#undef __WFEPersonally I don't see how these define/undef are better then inline
functions...
Quoted 6 lines
Quoted 6 lines
The benefit it to not pollute the API namespace with some functions which are used only locally.
After using a macro, it disappears with #undef.Quoted 1 line
Again I suppose they might be re-used in future some other ARM
specific low-level primitvies.
Quoted 3 lines
Quoted 3 lines
Do this low-level routines _LOAD_EXC_ need to be exposed in EAL for re-
use?
Quoted 6 lines
About
load_excdon't know for sure...
Though as I can see wfe/sevl are used here:
http://patchwork.dpdk.org/patch/61779/
Might be it is possible to reuse these functions/macros... But again, I am not arm expert, would be interested to know what armguys think.
Quoted 8 lines
Quoted 3 lines
Considering WFE has a requirement on using
load_execon ARM so IMO, it makes sense to exposeload_execin conjunction with wfe/sevl to use it properly.Agree, WFE should have more use cases can be developed, not limited to the
WAIT_UNTIL_EQUAL_XXAPIs. Marvel's patch is an example.
Sorry I don't have more use case so far, but Arm is evolving WFE, so I think more use cases are emerging.
/Gavin
I think the focus of this patch is 'rte_wait_until_equal_xxx' APIs. I would say, this patch serves that purpose as we all agree on the definition of the APIs. The implementation of the API may be conservative, but I think it is alright as it does not bind us from changing it in the future. We can look at further use cases as and when they come.
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
My preference would be to keep them as inline function - much
cleaner code.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
But as I don't develop for/use, I wouldn't insist and let you and arm
guys to decide.
Quoted 3 lines
Quoted 2 lines
Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equal
Quoted 18 lines · Honnappa Nagarahalli
Quoted 18 lines
Quoted 18 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Again I suppose they might be re-used in future some other ARM
specific low-level primitvies.
Quoted 3 lines
Quoted 3 lines
Do this low-level routines _LOAD_EXC_ need to be exposed in EAL for re-
use?
Quoted 6 lines
About
load_excdon't know for sure...
Though as I can see wfe/sevl are used here:
http://patchwork.dpdk.org/patch/61779/
Might be it is possible to reuse these functions/macros... But again, I am not arm expert, would be interested to know what armguys think.
Considering WFE has a requirement on using
load_execon ARM so IMO, it makes sense to exposeload_execin conjunction with wfe/sevl to use it properly.
Quoted 7 lines
Quoted 5 lines
Agree, WFE should have more use cases can be developed, not limited to the
WAIT_UNTIL_EQUAL_XXAPIs. Marvel's patch is an example.
Sorry I don't have more use case so far, but Arm is evolving WFE, so I think more use cases are emerging.
/GavinI think the focus of this patch is '
rte_wait_until_equal_xxx' APIs. I would say, this patch serves that purpose as we all agree on the definition of the APIs. The implementation of the API may be conservative, but I think it is alright as it does not bind us from changing it in the future. We can look at further use cases as and when they come.
Sorry for being so long to work on this.
We discussed this in december with Honnappa.
The main point that transpired is that there is no other usecase for wfe/sevl/loadex block than the rte_wait_until_equal APIs.
I then intend to stick to the last version I sent, which only exposes these APIs and hides all the other details.
If we need to expose those blocks for new usecases, then we will rediscuss the APIs.
I will merge this series tomorrow so that it makes it into 20.02-rc1. If there are strong oppositions to my last changes, we can have followup patches on the implementation, the exposed APIs will be the same anyway.
Thanks.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equal
Quoted 54 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, January 17, 2020 5:38 AM
To: Honnappa Nagarahalli <[email protected]>
Cc: Gavin Hu <[email protected]>; Jerin Jacob <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; Mcnamara, John <[email protected]>; Kovacevic, Marko <[email protected]>; [email protected]; Jan Viktorin <[email protected]>; nd <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v13 2/5] eal: add the APIs to wait until equalQuoted 12 lines · Honnappa Nagarahalli
Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Again I suppose they might be re-used in future some other ARM
specific low-level primitvies.
Quoted 3 lines
Quoted 3 lines
Do this low-level routines _LOAD_EXC_ need to be exposed in EAL for re-
use?
Quoted 6 lines
About
load_excdon't know for sure...
Though as I can see wfe/sevl are used here:
http://patchwork.dpdk.org/patch/61779/
Might be it is possible to reuse these functions/macros... But again, I am not arm expert, would be interested to know what armQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
guys think.
Considering WFE has a requirement on using
load_execon ARM so IMO,it
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
makes sense to expose
load_execin conjunction with wfe/sevl to use it properly.Agree, WFE should have more use cases can be developed, not limited to
the
Quoted 5 lines
Quoted 4 lines
WAIT_UNTIL_EQUAL_XXAPIs. Marvel's patch is an example.
Sorry I don't have more use case so far, but Arm is evolving WFE, so I think more use cases are emerging.
/GavinI think the focus of this patch is '
rte_wait_until_equal_xxx' APIs. I would say,this patch serves that purpose as we all agree on the definition of the APIs.
Quoted 1 line
The implementation of the API may be conservative, but I think it is alright as
it does not bind us from changing it in the future. We can look at further use cases as and when they come.
Sorry for being so long to work on this.
We discussed this in december with Honnappa.
The main point that transpired is that there is no other usecase for wfe/sevl/loadex block than therte_wait_until_equalAPIs.I then intend to stick to the last version I sent, which only exposes these APIs and hides all the other details.
Quoted 7 lines
If we need to expose those blocks for new usecases, then we will rediscuss the APIs.
I will merge this series tomorrow so that it makes it into 20.02-rc1. If there are strong oppositions to my last changes, we can have followup patches on the implementation, the exposed APIs will be the same anyway.
Looks good to me, thanks!
/Gavin
Quoted 6 lines
Thanks.
--
David Marchand
PATCH v13 3/5 ticketlock: use new API to reduce contention on aarch64
In reply to David MarchandFrom: Gavin Hu <[email protected]>
While using ticket lock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.
Running ticketlock_autotest on ThunderX2, Ampere eMAG80, and Arm N1SDP[1], there were variances between runs, but no notable performance gain or degradation were seen with and without this patch.
[1] https://community.arm.com/developer/tools-software/oss-platforms/w/\
docs/440/neoverse-n1-sdp
--- lib/librte_eal/common/include/generic/rte_ticketlock.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/librte_eal/common/include/generic/rte_ticketlock.h +1 -2
@@ -66,8 +66,7 @@ static inline void rte_ticketlock_lock(rte_ticketlock_t *tl) {uint16_t me =__atomic_fetch_add (&tl->s.next,1 , __ATOMIC_RELAXED); -while (__atomic_load_n (&tl->s.current, __ATOMIC_ACQUIRE) != me) -rte_pause (); +rte_wait_until_equal_16 (&tl->s.current, me, __ATOMIC_ACQUIRE); }/**
Signature · 1 line
1.8.3.1
PATCH v13 4/5 net/thunderx: use new API to save cycles on aarch64
In reply to David MarchandFrom: Gavin Hu <[email protected]>
Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.
--- drivers/net/thunderx/Makefile | 1 + drivers/net/thunderx/meson.build | 1 + drivers/net/thunderx/nicvf_rxtx.c | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/thunderx/Makefile +1 -0
@@ -10,6 +10,7 @@ include $(RTE_SDK)/mk/rte.vars.mk LIB = librte_pmd_thunderx_nicvf.a CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDLIBS += -lm LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
drivers/net/thunderx/meson.build +1 -0
@@ -4,6 +4,7 @@ subdir('base') objs = [base_objs] +allow_experimental_apis = true sources = files('nicvf_rxtx.c', 'nicvf_ethdev.c', 'nicvf_svf.c'
drivers/net/thunderx/nicvf_rxtx.c +1 -2
@@ -385,8 +385,7 @@ nicvf_fill_rbdr(struct nicvf_rxq *rxq, int to_fill) ltail++; } -while (__atomic_load_n (&rbdr->tail, __ATOMIC_RELAXED) != next_tail) -rte_pause (); +rte_wait_until_equal_32 (&rbdr->tail, next_tail, __ATOMIC_RELAXED);__atomic_store_n (&rbdr->tail, ltail, __ATOMIC_RELEASE);nicvf_addr_write (door, to_fill);
Signature · 1 line
1.8.3.1
PATCH v13 5/5 event/opdl: use new API to save cycles on aarch64
In reply to David MarchandFrom: Gavin Hu <[email protected]>
Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.
--- drivers/event/opdl/Makefile | 1 + drivers/event/opdl/meson.build | 1 + drivers/event/opdl/opdl_ring.c | 5 ++--- 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/event/opdl/Makefile +1 -0
@@ -9,6 +9,7 @@ LIB = librte_pmd_opdl_event.a # build flags CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # for older GCC versions, allow us to initialize an event using # designated initializers. ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
drivers/event/opdl/meson.build +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Luca Boccassi <[email protected]> +allow_experimental_apis = true sources = files( 'opdl_evdev.c', 'opdl_evdev_init.c',
drivers/event/opdl/opdl_ring.c +2 -3
@@ -16,6 +16,7 @@#include <rte_memcpy.h> #include <rte_memory.h> #include <rte_memzone.h> +#include <rte_atomic.h> #include "opdl_ring.h" #include "opdl_log.h"
@@ -474,9 +475,7 @@ opdl_ring_input_multithread(struct opdl_ring *t, const void *entries,/* If another thread started inputting before this one, but hasn't * finished, we need to wait for it to complete to update the tail. */ -while (unlikely (__atomic_load_n (&s->shared.tail, __ATOMIC_ACQUIRE) != - old_head)) -rte_pause (); +rte_wait_until_equal_32 (&s->shared.tail, old_head, __ATOMIC_ACQUIRE);__atomic_store_n (&s->shared.tail, old_head + num_entries, __ATOMIC_RELEASE);
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v13 0/5] use WFE for aarch64
In reply to David MarchandQuoted 109 lines · David Marchand
DPDK has multiple use cases where the core repeatedly polls a location in memory. This polling results in many cache and memory transactions.
Arm architecture provides WFE (Wait For Event) instruction, which allows the cpu core to enter a low power state until woken up by the update to the memory location being polled. Thus reducing the cache and memory transactions.
x86 has the PAUSE hint instruction to reduce such overhead.
The
rte_wait_until_equal_xxxAPIs abstract the functionality of 'polling for a memory location to become equal to a given value'.For non-Arm platforms, these APIs are just wrappers around do-while loop with
rte_pause, so there are no performance differences.For Arm platforms, use of WFE can be configured using
CONFIG_RTE_USE_WFEoption. It is disabled by default.Currently, use of WFE is supported only for aarch64 platforms. armv7 platforms do support the WFE instruction, but they require explicit wake up events(sev) and are less performannt.
Testing shows that, performance varies across different platforms, with some showing degradation.
CONFIG_RTE_USE_WFEshould be enabled depending on the performance on the target platforms.V13:
- added release notes update,
- reworked arm implementation to avoid exporting inlines,
- added assert in generic implementation,V12:
- remove the 'rte_' prefix from the arm specific functions (David Marchand)
- use the__atomic_load_ex_xxfunctions in arm specific implementations of APIS (David Marchand)
- remove the experimental warnings (David Marchand)
- tweak the macros working scope (David Marchand)
V11:
- addrte_prefix to the__atomic_load_ex_xfuntions (Ananyev Konstantin)
- define the aboverte_atomic_load_ex_xfuntions even if notRTE_WAIT_UNTIL_EQUAL_ARCH_DEFINEDfor future non-wfe usages (Ananyev Konstantin)
- use the above functions for arm specificrte_wait_until_equal_xfunctions (Ananyev Konstantin)
- simplify the generic implementation by immersing "if" into "while" (Ananyev Konstantin)V10:
- move arm specific stuff toarch/arm/rte_pause_64.h(Ananyev Konstantin)V9:
- fix a weblink broken (David Marchand)
- definerte_wfeandrte_sev()(Ananyev Konstantin)
- explicitly define three function APIs instead of marcos (Ananyev Konstantin)
- incorporate commonrte_wfeandrte_sevinto the genericrte_spinlock(David Marchand)
- define arch neutralRTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED(Ananyev Konstantin)
- define rte_load_ex_16/32/64 functions to use load-exclusive instruction for aarch64, which is required for wake up of WFE
- drop therte_spinlockpatch from this series, as the it calls this experimental API and it is widely included by a lot of components each requires theALLOW_EXPERIMENRAL_APIfor theMakefileand meson.build, leave it to future after the experimental is removed.V8:
- simplify dmb definition to use io barriers (David Marchand)
- definewfe()andsev()macros and use them inside normal C code (Ananyev Konstantin)
- pass memorder as parameter, not to incorporate it into function name, less functions, similar to C11 atomic intrinsics (Ananyev Konstantin)
- remove mandatingRTE_FORCE_INTRINSICSin arm spinlock implementation (David Marchand)
- undef__WAIT_UNTIL_EQUALafter use (David Marchand)
- add experimental tag and warning (David Marchand)
- add the limitation of using WFE instruction in the commit log (David Marchand)
- tweak the use ofRTE_FORCE_INSTRINSICS(still mandatory for aarch64) andRTE_ARM_USE_WFEfor spinlock (David Marchand)
- drop therte_ringpatch from this series, as therte_ring.hcalls this API and it is widely included by a lot of components each requires theALLOW_EXPERIMENRAL_APIfor theMakefileand meson.build, leave it to future after the experimental is removed.V7:
- fix the checkpatchLONG_LINE_COMMENTissueV6:
- squash theRTE_ARM_USE_WFEconfiguration entry patch into the new API patch
- move the new configuration to the end of EAL
- add doxygen comments to reflect the relaxed and acquire semantics
- correct the meson configurationV5:
- add doxygen comments for the new APIs
- spinlock early exit without wfe if the spinlock not taken by others.
- add two patches on top for opdl and thunderxV4:
- rename the config asCONFIG_RTE_ARM_USE_WFEto indicate it applys to arm only
- introduce a macro for assembly Skelton to reduce the duplication of code
- add one patch for nxp fslmc to address a compiling errorV3:
- Convert RFCs to patches
Quoted 7 lines
V2:
- Use inline functions instead of marcos
- Add load and compare in the beginning of the APIs
- Fix some style errors in asm inlineV1:
- Add the new APIs and use it for ring and locks
Series applied.
Thanks.
Signature · 1 line
David Marchand