Skip to contentSkip to conversation

use WFE for locks and ring on aarch64

RFC Superseded Gavin Hu 11 participants 168 messages Jun 30, 2019 – Jan 17, 2020 2 messages not in the archive Page 1 of 2

Subsystems (2)
lore
Share & tools
lore

Gavin Hu

author
#0 lore raw

cover use WFE for locks and ring on aarch64

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_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.

Gavin Hu (5):
eal: add the APIs to wait until equal
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update on aarch64
spinlock: use wfe to reduce contention on aarch64
config: add WFE config entry for aarch64

 config/arm/meson.build                             |   1 +
 config/common_armv8a_linux                         |   6 +
 .../common/include/arch/arm/rte_pause_64.h         | 143 +++++++++++++++++++++
 .../common/include/arch/arm/rte_spinlock.h         |  25 ++++
 lib/librte_eal/common/include/generic/rte_pause.h  |  20 +++
 .../common/include/generic/rte_spinlock.h          |   2 +-
 .../common/include/generic/rte_ticketlock.h        |   4 +-
 lib/librte_ring/rte_ring_c11_mem.h                 |   5 +-
 lib/librte_ring/rte_ring_generic.h                 |   4 +-
 9 files changed, 203 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

RFC 1/5 eal: add the APIs to wait until equal

The rte_wait_until_equal_xxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
 .../common/include/arch/arm/rte_pause_64.h         | 143 +++++++++++++++++++++
 lib/librte_eal/common/include/generic/rte_pause.h  |  20 +++
 2 files changed, 163 insertions(+)
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +143 -0
index 93895d3..0095da6 100644
@@ -17,6 +17,149 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_USE_WFE
+#define rte_wait_until_equal_relaxed(addr, expected) do {\
+		typeof(*addr) tmp;  \
+		if (__builtin_constant_p((expected))) \
+			do { \
+				if (sizeof(*(addr)) == 16)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 32)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 64)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %x0, %1\n"  \
+						"cmp	%x0, %x2\n"  \
+						"bne	1b\n"  \
+						: "=&r" (tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory"); \
+			} while (0); \
+		else \
+			do { \
+				if (sizeof(*(addr)) == 16)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 32)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 64)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %x0, %1\n"  \
+						"cmp	%x0, %x2\n"  \
+						"bne	1b\n"  \
+						: "=&r" (tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+		} while (0); \
+} while (0)
+
+#define rte_wait_until_equal_acquire(addr, expected) do {\
+		typeof(*addr) tmp;  \
+		if (__builtin_constant_p((expected))) \
+			do { \
+				if (sizeof(*(addr)) == 16)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldaxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 32)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldaxr  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 64)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldaxr  %x0, %1\n"  \
+						"cmp	%x0, %x2\n"  \
+						"bne	1b\n"  \
+						: "=&r" (tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory"); \
+			} while (0); \
+		else \
+			do { \
+				if (sizeof(*(addr)) == 16)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldaxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 32)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldaxr  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 64)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldaxr  %x0, %1\n"  \
+						"cmp	%x0, %x2\n"  \
+						"bne	1b\n"  \
+						: "=&r" (tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+		} while (0); \
+} while (0)
+
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +20 -0
index 52bd4db..c115b61 100644
@@ -20,4 +20,24 @@
  */
 static inline void rte_pause(void);
 
+#if !defined(RTE_USE_WFE)
+#define rte_wait_until_equal_relaxed(addr, expected) do {\
+		rte_pause();	\
+	} while (*(addr) != (expected))
+
+#ifdef RTE_USE_C11_MEM_MODEL
+#define rte_wait_until_equal_acquire(addr, expected) do {\
+		rte_pause();	\
+	} while (__atomic_load_n((addr), __ATOMIC_ACQUIRE) != (expected))
+#else
+#define rte_wait_until_equal_acquire(addr, expected) do {\
+		do {\
+			rte_pause(); \
+		} while (*(addr) != (expected)); \
+		rte_smp_rmb(); \
+	} while (0)
+#endif
+#endif
+
+
 #endif /* _RTE_PAUSE_H_ */
Signature · 1 line
2.7.4
#2 lore raw

Re: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

Quoted 60 lines · On Mon, 1 Jul 2019 00:21:12 +0800 Gavin Hu <[email protected]> wrote:
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +60 -0
+#ifdef RTE_USE_WFE
+#define rte_wait_until_equal_relaxed(addr, expected) do {\
+		typeof(*addr) tmp;  \
+		if (__builtin_constant_p((expected))) \
+			do { \
+				if (sizeof(*(addr)) == 16)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 32)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 64)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %x0, %1\n"  \
+						"cmp	%x0, %x2\n"  \
+						"bne	1b\n"  \
+						: "=&r" (tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory"); \
+			} while (0); \
+		else \
+			do { \
+				if (sizeof(*(addr)) == 16)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 32)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 64)\
+					asm volatile(  \

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 89

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %x0, %1\n"  \
+						"cmp	%x0, %x2\n"  \
+						"bne	1b\n"  \
+						: "=&r" (tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+		} while (0); \
+} while (0)

That is a hot mess.
Macro's are harder to maintain and offer no benefit over inline functions.

#3 lore raw

Re: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

Hi Stephen,

Quoted 78 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, July 1, 2019 4:28 AM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>
Subject: Re: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

Quoted 65 lines · On Mon, 1 Jul 2019 00:21:12 +0800 Gavin Hu <[email protected]> wrote:
(quoted diff) +65 -0
+#ifdef RTE_USE_WFE
+#define rte_wait_until_equal_relaxed(addr, expected) do {\
+		typeof(*addr) tmp;  \
+		if (__builtin_constant_p((expected))) \
+			do { \
+				if (sizeof(*(addr)) == 16)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 32)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 64)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %x0, %1\n"  \
+						"cmp	%x0, %x2\n"  \
+						"bne	1b\n"  \
+						: "=&r" (tmp)  \
+						: "Q"(*addr), "i"(expected)  \
+						: "cc", "memory"); \
+			} while (0); \
+		else \
+			do { \
+				if (sizeof(*(addr)) == 16)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 32)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+				else if (sizeof(*(addr)) == 64)\
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxr  %x0, %1\n"  \
+						"cmp	%x0, %x2\n"  \
+						"bne	1b\n"  \
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+						: "=&r" (tmp)  \
+						: "Q"(*addr), "r"(expected)  \
+						: "cc", "memory");  \
+		} while (0); \
+} while (0)

That is a hot mess.
Macro's are harder to maintain and offer no benefit over inline functions.

During our internal review, I ever used C11 _Generic to generalize the API to take different types of arguments. That makes the API look much simpler and better, but it poses a hard requirement for C11 and gcc 4.9+. That means, Gaetan's patch, as shown below, has to be reverted, otherwise there are compiling errors.
https://gcc.gnu.org/wiki/C11Status

$ git show ea7726a6
commit ea7726a6ee4b2b63313c4a198522a8dcea70c13d
Author: Gaetan Rivet <[email protected]>
Date:   Thu Jul 20 14:27:53 2017 +0200

net/failsafe: fix build on FreeBSD 10 with GCC 4.8

drivers/net/failsafe/Makefile +1 -1
index 32aaaa2..d516d36 100644
@@ -50,7 +50,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_FAILSAFE) += failsafe_flow.c
 # No exported include files
 
 # Basic CFLAGS:
-CFLAGS += -std=c11 -Wextra
+CFLAGS += -std=gnu99 -Wextra
#4 lore raw

Re: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

01/07/2019 09:16, Gavin Hu (Arm Technology China):

Quoted 5 lines

From: Stephen Hemminger <[email protected]>

Quoted 4 lines
Quoted 2 lines · Gavin Hu
(quoted diff) +2 -0
+#ifdef RTE_USE_WFE
+#define rte_wait_until_equal_relaxed(addr, expected) do {\

[...]

Quoted 4 lines
Quoted 2 lines

That is a hot mess.
Macro's are harder to maintain and offer no benefit over inline functions.

During our internal review, I ever used C11 _Generic to generalize the API to take different types of arguments.

Gavin, the question is about macros versus functions. Please, could you convert it into an inline function?

#5 lore raw

Re: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

Hi Thomas,

Quoted 18 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Monday, July 1, 2019 3:43 PM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: Stephen Hemminger <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

01/07/2019 09:16, Gavin Hu (Arm Technology China):

Quoted 5 lines

From: Stephen Hemminger <[email protected]>

Quoted 4 lines
Quoted 2 lines · Gavin Hu
(quoted diff) +2 -0
+#ifdef RTE_USE_WFE
+#define rte_wait_until_equal_relaxed(addr, expected) do {\

[...]

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

That is a hot mess.
Macro's are harder to maintain and offer no benefit over inline functions.

During our internal review, I ever used C11 _Generic to generalize the API

to take different types of arguments.

Gavin, the question is about macros versus functions. Please, could you convert it into an inline function?

Sure, I will do it in next version.

#6 lore raw

Re: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

In reply to Gavin Hu

Hi Gavin,

Quoted 39 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Gavin Hu
Sent: Sunday, June 30, 2019 9:51 PM
To: [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

The rte_wait_until_equal_xxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
.../common/include/arch/arm/rte_pause_64.h | 143
+++++++++++++++++++++
lib/librte_eal/common/include/generic/rte_pause.h | 20 +++

2 files changed, 163 insertions(+)
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
index 93895d3..0095da6 100644
@@ -17,6 +17,149 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_USE_WFE
+#define rte_wait_until_equal_relaxed(addr, expected) do {\
+		typeof(*addr) tmp;  \
+		if (__builtin_constant_p((expected))) \
+			do { \
+				if (sizeof(*(addr)) == 16)\

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 35

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +9 -0
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr),
 "i"(expected)  \
+						: "cc", "memory");  \

Can we have early exit here i.e. instead of going directly to wfe can we first check the condition and then fallthrough? Something like:

		asm volatile("	ldxrh	%w0 %1	\n"
			        "    cmp	%w0 %w2	\n"
			        "	b.eq  	2:		\n"
			        "1: wfe			\n"
			        "    ldxrh	%w0, %1	\n"  
			        "    cmp	%w0, %w2	\n"  
			        "    b.ne	1b		\n"  
			        "2:				\n"
			        :::);

Regards,
Pavan.

#7 lore raw

Re: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

Hi Pavan,

Quoted 74 lines

-----Original Message-----
From: Pavan Nikhilesh Bhagavatula <[email protected]>
Sent: Monday, July 1, 2019 5:59 PM
To: Gavin Hu (Arm Technology China) <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>
Subject: RE: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

Hi Gavin,

Quoted 39 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Gavin Hu
Sent: Sunday, June 30, 2019 9:51 PM
To: [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [dpdk-dev] [RFC 1/5] eal: add the APIs to wait until equal

The rte_wait_until_equal_xxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
.../common/include/arch/arm/rte_pause_64.h | 143
+++++++++++++++++++++
lib/librte_eal/common/include/generic/rte_pause.h | 20 +++

2 files changed, 163 insertions(+)
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
index 93895d3..0095da6 100644
@@ -17,6 +17,149 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_USE_WFE
+#define rte_wait_until_equal_relaxed(addr, expected) do {\
+		typeof(*addr) tmp;  \
+		if (__builtin_constant_p((expected))) \
+			do { \
+				if (sizeof(*(addr)) == 16)\

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 35

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +9 -0
+					asm volatile(  \
+						"sevl\n"  \
+						"1:	 wfe\n"  \
+						"ldxrh  %w0, %1\n"  \
+						"cmp	%w0, %w2\n"  \
+						"bne	1b\n"  \
+						: "=&r"(tmp)  \
+						: "Q"(*addr),
 "i"(expected)  \
+						: "cc", "memory");  \

Can we have early exit here i.e. instead of going directly to wfe can we first check the condition and then fallthrough?
Something like:

		asm volatile("	ldxrh	%w0 %1	\n"
			        "    cmp	%w0 %w2	\n"
			        "	b.eq  	2:		\n"
			        "1: wfe			\n"
			        "    ldxrh	%w0, %1	\n"
			        "    cmp	%w0, %w2	\n"
			        "    b.ne	1b		\n"
			        "2:				\n"
			        :::);
Quoted 2 lines

Regards,
Pavan.

Ok, I will do it in next version.

author
#8 lore raw

RFC 2/5 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

While using ticket lock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running ticketlock_autotest on ThunderX2, with different numbers of cores and depths of rings, 3%~8% performance gains were measured.

---
 lib/librte_eal/common/include/generic/rte_ticketlock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/generic/rte_ticketlock.h +2 -2
index 191146f..6820f01 100644
@@ -64,8 +64,8 @@ static inline __rte_experimental 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();
+	if (__atomic_load_n(&tl->s.current, __ATOMIC_ACQUIRE) != me)
+		rte_wait_until_equal_acquire(&tl->s.current, me);
 }
 
 /**
Signature · 1 line
2.7.4
author
#9 lore raw

RFC 3/5 ring: use wfe to wait for ring tail update on aarch64

In reply to Gavin Hu

Instead of polling for tail to be updated, use wfe instruction.

50%~70% performance gain was measured by running ring_perf_autotest on ThunderX2.

---
 lib/librte_ring/rte_ring_c11_mem.h | 5 +++--
 lib/librte_ring/rte_ring_generic.h | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring_c11_mem.h +3 -2
index 0fb73a3..f1de79c 100644
@@ -2,6 +2,7 @@
  *
  * Copyright (c) 2017,2018 HXT-semitech Corporation.
  * Copyright (c) 2007-2009 Kip Macy [email protected]
+ * Copyright (c) 2019 Arm Limited
  * All rights reserved.
  * Derived from FreeBSD's bufring.h
  * Used as BSD-3 Licensed with permission from Kip Macy.
@@ -21,8 +22,8 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		if (unlikely(ht->tail != old_val))
+			rte_wait_until_equal_relaxed(&ht->tail, old_val);
 
 	__atomic_store_n(&ht->tail, new_val, __ATOMIC_RELEASE);
 }
lib/librte_ring/rte_ring_generic.h +2 -2
index 953cdbb..bb0dce0 100644
@@ -23,8 +23,8 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		if (unlikely(ht->tail != old_val))
+			rte_wait_until_equal_relaxed(&ht->tail, old_val);
 
 	ht->tail = new_val;
 }
Signature · 1 line
2.7.4
author
#10 lore raw

RFC 4/5 spinlock: use wfe to reduce contention on aarch64

In reply to Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

20% performance gain was measured by running spinlock_autotest on 14 isolated cores of ThunderX2.

---
 .../common/include/arch/arm/rte_spinlock.h         | 25 ++++++++++++++++++++++
 .../common/include/generic/rte_spinlock.h          |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +25 -0
index 1a6916b..b7e8521 100644
@@ -16,6 +16,31 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#if defined(RTE_USE_WFE) && defined(RTE_ARCH_ARM64)
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+	unsigned int tmp;
+	/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"sevl\n"
+		"1:	 wfe\n"
+		"2:	 ldaxr   %w0, %1\n"
+		"cbnz   %w0, 1b\n"
+		"stxr   %w0, %w2, %1\n"
+		"cbnz   %w0, 2b\n"
+		: "=&r" (tmp), "+Q"(sl->locked)
+		: "r" (1)
+		: "cc", "memory");
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
 	return 0;
lib/librte_eal/common/include/generic/rte_spinlock.h +1 -1
index 87ae7a4..cf4f15b 100644
@@ -57,7 +57,7 @@ rte_spinlock_init(rte_spinlock_t *sl)
 static inline void
 rte_spinlock_lock(rte_spinlock_t *sl);
 
-#ifdef RTE_FORCE_INTRINSICS
+#if defined(RTE_FORCE_INTRINSICS) && !defined(RTE_USE_WFE)
 static inline void
 rte_spinlock_lock(rte_spinlock_t *sl)
 {
Signature · 1 line
2.7.4
author
#11 lore raw

RFC 5/5 config: add WFE config entry for aarch64

In reply to Gavin Hu

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default. It can be enabled selectively based on the performance benchmarking.

---
 config/arm/meson.build     | 1 +
 config/common_armv8a_linux | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build +1 -0
index 6fa06a1..939d60e 100644
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa, machine_args_generic]
 impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]
 
 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
+dpdk_conf.set('RTE_USE_WFE', 0)
 
 if not dpdk_conf.get('RTE_ARCH_64')
 	dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
config/common_armv8a_linux +6 -0
index 72091de..ae87a87 100644
@@ -12,6 +12,12 @@ CONFIG_RTE_ARCH_64=y
 
 CONFIG_RTE_FORCE_INTRINSICS=y
 
+# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs,
+# calling these APIs put the cores enter low power state while waiting
+# for the memory address to be become equal to the expected value.
+# This is supported only by aarch64.
+CONFIG_RTE_USE_WFE=n
+
 # Maximum available cache line size in arm64 implementations.
 # Setting to maximum available cache line size in generic config
 # to address minimum DMA alignment across all arm64 implementations.
Signature · 1 line
2.7.4
#12 lore raw
In reply to Gavin Hu
Quoted 23 lines · On Mon, 1 Jul 2019 00:21:11 +0800 Gavin Hu <[email protected]> wrote:

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_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.

Quoted 5 lines

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.

How does this work if process is preempted?

#13 lore raw

Hi Stephen,

Quoted 37 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, July 1, 2019 4:30 AM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>
Subject: Re: [dpdk-dev] [RFC 0/5] use WFE for locks and ring on aarch64

Quoted 10 lines · On Mon, 1 Jul 2019 00:21:11 +0800 Gavin Hu <[email protected]> wrote:

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.

Quoted 7 lines

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

Quoted 6 lines

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.

Quoted 8 lines
Quoted 4 lines

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

Quoted 1 line

target platforms.

How does this work if process is preempted?

WFE won't prevent pre-emption from the kernel as that is down to a timer/re-scheduling interrupt.
Software using the WFE mechanism must tolerate spurious wake-up events, including timer/re-scheduling interrupts, so a re-check of the condition upon exit of WFE is needed to be in place(this is already included in the patch)

author
#14 lore raw

v2 cover use WFE for locks and ring on aarch64

In reply to Gavin Hu

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_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.

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):
eal: add the APIs to wait until equal
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update on aarch64
spinlock: use wfe to reduce contention on aarch64
config: add WFE config entry for aarch64

 config/arm/meson.build                             |   1 +
 config/common_armv8a_linux                         |   6 ++
 .../common/include/arch/arm/rte_atomic_64.h        |   4 +
 .../common/include/arch/arm/rte_pause_64.h         | 106 +++++++++++++++++++++
 .../common/include/arch/arm/rte_spinlock.h         |  25 +++++
 lib/librte_eal/common/include/generic/rte_pause.h  |  39 +++++++-
 .../common/include/generic/rte_spinlock.h          |   2 +-
 .../common/include/generic/rte_ticketlock.h        |   3 +-
 lib/librte_ring/rte_ring_c11_mem.h                 |   4 +-
 lib/librte_ring/rte_ring_generic.h                 |   3 +-
 10 files changed, 185 insertions(+), 8 deletions(-)
Signature · 1 line
2.7.4
author
#15 lore raw

RFC v2 1/5 eal: add the APIs to wait until equal

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
 .../common/include/arch/arm/rte_atomic_64.h        |   4 +
 .../common/include/arch/arm/rte_pause_64.h         | 106 +++++++++++++++++++++
 lib/librte_eal/common/include/generic/rte_pause.h  |  39 +++++++-
 3 files changed, 148 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_atomic_64.h +4 -0
index 97060e4..8d742c6 100644
@@ -15,8 +15,12 @@ extern "C" {
 
 #include "generic/rte_atomic.h"
 
+#ifndef dsb
 #define dsb(opt) asm volatile("dsb " #opt : : : "memory")
+#endif
+#ifndef dmb
 #define dmb(opt) asm volatile("dmb " #opt : : : "memory")
+#endif
 
 #define rte_mb() dsb(sy)
 
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +106 -0

112 lines not on this page · raw message

lib/librte_eal/common/include/generic/rte_pause.h +38 -1
index 52bd4db..8f5f025 100644
@@ -4,7 +4,6 @@
 
 #ifndef _RTE_PAUSE_H_
 #define _RTE_PAUSE_H_
-
 /**
  * @file
  *
@@ -12,6 +11,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +23,38 @@
  */
 static inline void rte_pause(void);
 
+#if !defined(RTE_USE_WFE)
+#ifdef RTE_USE_C11_MEM_MODEL
+#define __rte_wait_until_equal(addr, expected, memorder) do {\
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause();\
+} while (0)
+#else
+#define __rte_wait_until_equal(addr, expected, memorder) do {\
+	while (*addr != expected)\
+		rte_pause();\
+	if (memorder != __ATOMIC_RELAXED)\
+		rte_smp_rmb();\
+} while (0)
+#endif
+
+static __rte_always_inline void
+rte_wait_until_equal16(volatile uint16_t *addr, uint16_t expected, int memorder)
+{
+	__rte_wait_until_equal(addr, expected, memorder);
+}
+
+static __rte_always_inline void
+rte_wait_until_equal32(volatile uint32_t *addr, uint32_t expected, int memorder)
+{
+	__rte_wait_until_equal(addr, expected, memorder);
+}
+
+static __rte_always_inline void
+rte_wait_until_equal64(volatile uint64_t *addr, uint64_t expected, int memorder)
+{
+	__rte_wait_until_equal(addr, expected, memorder);
+}
+#endif /* RTE_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
Signature · 1 line
2.7.4
Acked-by on v2 1/5
#16 lore raw

Re: [dpdk-dev] [EXT] [RFC v2 1/5] eal: add the APIs to wait until equal

Quoted 16 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Gavin Hu
Sent: Wednesday, July 3, 2019 2:29 PM
To: [email protected]
Cc: [email protected]
Subject: [EXT] [dpdk-dev] [RFC v2 1/5] eal: add the APIs to wait until equal

External Email

----------------------------------------------------------------------
The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

Quoted 5 lines
Quoted 7 lines

---
.../common/include/arch/arm/rte_atomic_64.h | 4 +
.../common/include/arch/arm/rte_pause_64.h | 106
+++++++++++++++++++++
lib/librte_eal/common/include/generic/rte_pause.h | 39 +++++++-

3 files changed, 148 insertions(+), 1 deletion(-)
author
#17 lore raw

RFC v2 2/5 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

While using ticket lock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running ticketlock_autotest on ThunderX2, with different numbers of cores and depths of rings, 3%~8% performance gains were measured.

---
 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
index 191146f..8fa1f62 100644
@@ -64,8 +64,7 @@ static inline __rte_experimental 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_equal16(&tl->s.current, me, __ATOMIC_ACQUIRE);
 }
 
 /**
Signature · 1 line
2.7.4
Tested-by on v2 2/5
#18 lore raw

Re: [dpdk-dev] [RFC v2 2/5] ticketlock: use new API to reduce contention on aarch64

Quoted 10 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Gavin Hu
Sent: Wednesday, July 3, 2019 2:29 PM
To: [email protected]
Cc: [email protected]
Subject: [dpdk-dev] [RFC v2 2/5] ticketlock: use new API to reduce contention on aarch64

Quoted 6 lines

While using ticket lock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running ticketlock_autotest on ThunderX2, with different numbers of cores
and depths of rings, 3%~8% performance gains were measured.

Tested on octeontx2 board.

Quoted 3 lines
Quoted 24 lines

---
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
index 191146f..8fa1f62 100644
@@ -64,8 +64,7 @@ static inline __rte_experimental 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_equal16(&tl->s.current, me,
 __ATOMIC_ACQUIRE);

}

/**
--
2.7.4

author
#19 lore raw

RFC v2 3/5 ring: use wfe to wait for ring tail update on aarch64

In reply to Gavin Hu

Instead of polling for tail to be updated, use wfe instruction.

---
 lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
 lib/librte_ring/rte_ring_generic.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring_c11_mem.h +2 -2
index 0fb73a3..037811e 100644
@@ -2,6 +2,7 @@
  *
  * Copyright (c) 2017,2018 HXT-semitech Corporation.
  * Copyright (c) 2007-2009 Kip Macy [email protected]
+ * Copyright (c) 2019 Arm Limited
  * All rights reserved.
  * Derived from FreeBSD's bufring.h
  * Used as BSD-3 Licensed with permission from Kip Macy.
@@ -21,8 +22,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal32(&ht->tail, old_val, __ATOMIC_RELAXED);
 
 	__atomic_store_n(&ht->tail, new_val, __ATOMIC_RELEASE);
 }
lib/librte_ring/rte_ring_generic.h +1 -2
index 953cdbb..570765c 100644
@@ -23,8 +23,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal32(&ht->tail, old_val, __ATOMIC_RELAXED);
 
 	ht->tail = new_val;
 }
Signature · 1 line
2.7.4
author
#20 lore raw

RFC v2 4/5 spinlock: use wfe to reduce contention on aarch64

In reply to Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

5~10% performance gain was measured by running spinlock_autotest on 14 isolated cores of ThunderX2.

---
 .../common/include/arch/arm/rte_spinlock.h         | 25 ++++++++++++++++++++++
 .../common/include/generic/rte_spinlock.h          |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +25 -0
index 1a6916b..f25d17f 100644
@@ -16,6 +16,31 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#if defined(RTE_USE_WFE) && defined(RTE_ARCH_ARM64)
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+	unsigned int tmp;
+	/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"sevl\n"
+		"1:	wfe\n"
+		"2:	ldaxr %w[tmp], %w[locked]\n"
+		"cbnz   %w[tmp], 1b\n"
+		"stxr   %w[tmp], %w[one], %w[locked]\n"
+		"cbnz   %w[tmp], 2b\n"
+		: [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+		: [one] "r" (1)
+		: "cc", "memory");
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
 	return 0;
lib/librte_eal/common/include/generic/rte_spinlock.h +1 -1
index 87ae7a4..cf4f15b 100644
@@ -57,7 +57,7 @@ rte_spinlock_init(rte_spinlock_t *sl)
 static inline void
 rte_spinlock_lock(rte_spinlock_t *sl);
 
-#ifdef RTE_FORCE_INTRINSICS
+#if defined(RTE_FORCE_INTRINSICS) && !defined(RTE_USE_WFE)
 static inline void
 rte_spinlock_lock(rte_spinlock_t *sl)
 {
Signature · 1 line
2.7.4
Tested-by on v2 4/5
#21 lore raw

Re: [dpdk-dev] [RFC v2 4/5] spinlock: use wfe to reduce contention on aarch64

Quoted 10 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Gavin Hu
Sent: Wednesday, July 3, 2019 2:29 PM
To: [email protected]
Cc: [email protected]
Subject: [dpdk-dev] [RFC v2 4/5] spinlock: use wfe to reduce contention on aarch64

Quoted 6 lines

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

5~10% performance gain was measured by running spinlock_autotest on
14 isolated cores of ThunderX2.

Tested on octeontx2 board.

Quoted 7 lines
Quoted 61 lines

---
.../common/include/arch/arm/rte_spinlock.h | 25
++++++++++++++++++++++
.../common/include/generic/rte_spinlock.h | 2 +-

2 files changed, 26 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +1 -0
index 1a6916b..f25d17f 100644
@@ -16,6 +16,31 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV

is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */

lib/librte_eal/common/include/arch/arm/rte_spinlock.h +6 -0
+#if defined(RTE_USE_WFE) && defined(RTE_ARCH_ARM64)
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+	unsigned int tmp;
+	/*

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.

lib/librte_eal/common/include/arch/arm/rte_spinlock.h +15 -0
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"sevl\n"
+		"1:	wfe\n"
+		"2:	ldaxr %w[tmp], %w[locked]\n"
+		"cbnz   %w[tmp], 1b\n"
+		"stxr   %w[tmp], %w[one], %w[locked]\n"
+		"cbnz   %w[tmp], 2b\n"
+		: [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+		: [one] "r" (1)
+		: "cc", "memory");
+}
+#endif
+

static inline int rte_tm_supported(void)

{
	return 0;
lib/librte_eal/common/include/generic/rte_spinlock.h +0 -0
index 87ae7a4..cf4f15b 100644
@@ -57,7 +57,7 @@ rte_spinlock_init(rte_spinlock_t *sl)

static inline void
rte_spinlock_lock(rte_spinlock_t *sl);

lib/librte_eal/common/include/generic/rte_spinlock.h +1 -1
-#ifdef RTE_FORCE_INTRINSICS
+#if defined(RTE_FORCE_INTRINSICS) && !defined(RTE_USE_WFE)

static inline void
rte_spinlock_lock(rte_spinlock_t *sl)
{
--
2.7.4

author
#22 lore raw

RFC v2 5/5 config: add WFE config entry for aarch64

In reply to Gavin Hu

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default. It can be enabled selectively based on the performance benchmarking.

---
 config/arm/meson.build     | 1 +
 config/common_armv8a_linux | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build +1 -0
index 6fa06a1..939d60e 100644
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa, machine_args_generic]
 impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]
 
 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
+dpdk_conf.set('RTE_USE_WFE', 0)
 
 if not dpdk_conf.get('RTE_ARCH_64')
 	dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
config/common_armv8a_linux +6 -0
index 72091de..ae87a87 100644
@@ -12,6 +12,12 @@ CONFIG_RTE_ARCH_64=y
 
 CONFIG_RTE_FORCE_INTRINSICS=y
 
+# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs,
+# calling these APIs put the cores enter low power state while waiting
+# for the memory address to be become equal to the expected value.
+# This is supported only by aarch64.
+CONFIG_RTE_USE_WFE=n
+
 # Maximum available cache line size in arm64 implementations.
 # Setting to maximum available cache line size in generic config
 # to address minimum DMA alignment across all arm64 implementations.
Signature · 1 line
2.7.4
Acked-by on v2 5/5
#23 lore raw

Re: [dpdk-dev] [RFC v2 5/5] config: add WFE config entry for aarch64

Quoted 10 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Gavin Hu
Sent: Wednesday, July 3, 2019 2:29 PM
To: [email protected]
Cc: [email protected]
Subject: [dpdk-dev] [RFC v2 5/5] config: add WFE config entry for aarch64

Quoted 8 lines

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default.
It can be enabled selectively based on the performance benchmarking.

Quoted 5 lines

---
config/arm/meson.build | 1 +
config/common_armv8a_linux | 6 ++++++

2 files changed, 7 insertions(+)
#24 lore raw

Re: [dpdk-dev] [RFC v2 5/5] config: add WFE config entry for aarch64

Hi Stephen,

Quoted 22 lines

-----Original Message-----
From: Pavan Nikhilesh Bhagavatula <[email protected]>
Sent: Saturday, July 20, 2019 3:03 PM
To: Gavin Hu (Arm Technology China) <[email protected]>; [email protected]
Cc: nd <[email protected]>
Subject: RE: [dpdk-dev] [RFC v2 5/5] config: add WFE config entry for aarch64

Quoted 12 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Gavin Hu
Sent: Wednesday, July 3, 2019 2:29 PM
To: [email protected]
Cc: [email protected]
Subject: [dpdk-dev] [RFC v2 5/5] config: add WFE config entry for aarch64

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default.
It can be enabled selectively based on the performance benchmarking.

Quoted 6 lines
Quoted 4 lines

Hi Stephen,
I just converted the RFCs to patches in V3, could you review your comments for RFCs were addressed? Thanks Pavan for review and testing!
Best regards,
Gavin

Quoted 6 lines
Quoted 6 lines

---
config/arm/meson.build | 1 +
config/common_armv8a_linux | 6 ++++++

2 files changed, 7 insertions(+)
author
#25 lore raw

v3 cover use WFE for locks and ring on aarch64

In reply to Gavin Hu

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_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.

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):
eal: add the APIs to wait until equal
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update on aarch64
spinlock: use wfe to reduce contention on aarch64
config: add WFE config entry for aarch64

 config/arm/meson.build                             |   1 +
 config/common_armv8a_linux                         |   6 ++
 .../common/include/arch/arm/rte_atomic_64.h        |   4 +
 .../common/include/arch/arm/rte_pause_64.h         | 106 +++++++++++++++++++++
 .../common/include/arch/arm/rte_spinlock.h         |  25 +++++
 lib/librte_eal/common/include/generic/rte_pause.h  |  39 +++++++-
 .../common/include/generic/rte_spinlock.h          |   2 +-
 .../common/include/generic/rte_ticketlock.h        |   3 +-
 lib/librte_ring/rte_ring_c11_mem.h                 |   4 +-
 lib/librte_ring/rte_ring_generic.h                 |   3 +-
 10 files changed, 185 insertions(+), 8 deletions(-)
Signature · 1 line
2.7.4
author
#26 lore raw

PATCH v3 1/5 eal: add the APIs to wait until equal

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
 .../common/include/arch/arm/rte_atomic_64.h        |   4 +
 .../common/include/arch/arm/rte_pause_64.h         | 106 +++++++++++++++++++++
 lib/librte_eal/common/include/generic/rte_pause.h  |  39 +++++++-
 3 files changed, 148 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_atomic_64.h +4 -0
index 97060e4..8d742c6 100644
@@ -15,8 +15,12 @@ extern "C" {
 
 #include "generic/rte_atomic.h"
 
+#ifndef dsb
 #define dsb(opt) asm volatile("dsb " #opt : : : "memory")
+#endif
+#ifndef dmb
 #define dmb(opt) asm volatile("dmb " #opt : : : "memory")
+#endif
 
 #define rte_mb() dsb(sy)
 
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +106 -0

112 lines not on this page · raw message

lib/librte_eal/common/include/generic/rte_pause.h +38 -1
index 52bd4db..8f5f025 100644
@@ -4,7 +4,6 @@
 
 #ifndef _RTE_PAUSE_H_
 #define _RTE_PAUSE_H_
-
 /**
  * @file
  *
@@ -12,6 +11,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +23,38 @@
  */
 static inline void rte_pause(void);
 
+#if !defined(RTE_USE_WFE)
+#ifdef RTE_USE_C11_MEM_MODEL
+#define __rte_wait_until_equal(addr, expected, memorder) do {\
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause();\
+} while (0)
+#else
+#define __rte_wait_until_equal(addr, expected, memorder) do {\
+	while (*addr != expected)\
+		rte_pause();\
+	if (memorder != __ATOMIC_RELAXED)\
+		rte_smp_rmb();\
+} while (0)
+#endif
+
+static __rte_always_inline void
+rte_wait_until_equal16(volatile uint16_t *addr, uint16_t expected, int memorder)
+{
+	__rte_wait_until_equal(addr, expected, memorder);
+}
+
+static __rte_always_inline void
+rte_wait_until_equal32(volatile uint32_t *addr, uint32_t expected, int memorder)
+{
+	__rte_wait_until_equal(addr, expected, memorder);
+}
+
+static __rte_always_inline void
+rte_wait_until_equal64(volatile uint64_t *addr, uint64_t expected, int memorder)
+{
+	__rte_wait_until_equal(addr, expected, memorder);
+}
+#endif /* RTE_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
Signature · 1 line
2.7.4
#27 lore raw

Re: [dpdk-dev] [EXT] [PATCH v3 1/5] eal: add the APIs to wait until equal

Quoted 32 lines

-----Original Message-----
From: Gavin Hu <[email protected]>
Sent: Tuesday, July 23, 2019 9:14 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Pavan Nikhilesh Bhagavatula <[email protected]>; [email protected]; [email protected]
Subject: [EXT] [PATCH v3 1/5] eal: add the APIs to wait until equal

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
 .../common/include/arch/arm/rte_atomic_64.h        |   4 +
 .../common/include/arch/arm/rte_pause_64.h         | 106
+++++++++++++++++++++
 lib/librte_eal/common/include/generic/rte_pause.h  |  39 +++++++-
 3 files changed, 148 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_atomic_64.h +0 -0
index 97060e4..8d742c6 100644

lib/librte_eal/common/include/arch/arm/rte_atomic_64.h extern "C" { · line 23

Quoted 9 lines
lib/librte_eal/common/include/arch/arm/rte_atomic_64.h +4 -0
@@ -15,8 +15,12 @@ extern "C" {
 
 #include "generic/rte_atomic.h"
 
+#ifndef dsb
 #define dsb(opt) asm volatile("dsb " #opt : : : "memory")
+#endif
+#ifndef dmb
 #define dmb(opt) asm volatile("dmb " #opt : : : "memory")
+#endif

Is this change required? Please fix the root cause. I do see some build error too.

In file included from /home/jerin/dpdk.org/build/include/rte_pause_64.h:13,

                 from /home/jerin/dpdk.org/build/include/rte_pause.h:13,
                 from /home/jerin/dpdk.org/build/include/generic/rte_spinlock.h:25,
                 from /home/jerin/dpdk.org/build/include/rte_spinlock.h:17,
                 from /home/jerin/dpdk.org/drivers/bus/fslmc/mc/mc_sys.c:10:

/home/jerin/dpdk.org/build/include/generic/rte_pause.h: In function 'rte_wait_until_equal16':
/home/jerin/dpdk.org/build/include/generic/rte_pause.h:44:49: error: macro "dmb" passed 1 arguments, but takes just 0
44 | __rte_wait_until_equal(addr, expected, memorder);

Command to reproduce(gcc 9.1)

rm -rf build && unset RTE_KERNELDIR && make -j T=arm64-thunderx-linux-gcc CROSS=aarch64-linux-gnu- && sed -ri 's,(CONFIG_RTE_KNI_KMOD=)y,\1n,' build/.config && sed -ri 's,(CONFIG_RTE_LIBRTE_VHOST_NUMA=)y,\1n,' build/.config && sed -ri 's,(CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=)y,\1n,' build/.config && sed -ri 's,(CONFIG_RTE_EAL_IGB_UIO=)y,\1n,' build/.config && CC="ccache gcc" make -j test-build CROSS=aarch64-linux-gnu-

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 20

Quoted 13 lines
lib/librte_eal/common/include/arch/arm/rte_atomic_64.h +0 -0
 #define rte_mb() dsb(sy)
 
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
index 93895d3..1f7be0a 100644
@@ -17,6 +17,112 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_USE_WFE

Do we need it to be under RTE_USE_WFE? If there is no harm, no need to add Conditional compilation to detect build errors, especially config is disabled by default.

Quoted 90 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +90 -0
+/* Wait for *addr to be updated with expected value */ static
+__rte_always_inline void rte_wait_until_equal16(volatile uint16_t
+*addr, uint16_t expected, int memorder) {
+	uint16_t tmp;
+	if (memorder == __ATOMIC_RELAXED)
+		asm volatile(
+			"ldxrh	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldxrh	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+	else
+		asm volatile(
+			"ldaxrh %w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldaxrh	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+}
+
+static __rte_always_inline void
+rte_wait_until_equal32(volatile uint32_t *addr, uint32_t expected, int
+memorder) {
+	uint32_t tmp;
+	if (memorder == __ATOMIC_RELAXED)
+		asm volatile(
+			"ldxr	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldxr	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+	else
+		asm volatile(
+			"ldaxr  %w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldaxr  %w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+}
+
+static __rte_always_inline void
+rte_wait_until_equal64(volatile uint64_t *addr, uint64_t expected, int
+memorder) {
+	uint64_t tmp;
+	if (memorder == __ATOMIC_RELAXED)
+		asm volatile(
+			"ldxr	%x[tmp], %x[addr]\n"
+			"cmp	%x[tmp], %x[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldxr	%x[tmp], %x[addr]\n"
+			"cmp	%x[tmp], %x[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+	else
+		asm volatile(
+			"ldaxr  %x[tmp], %x[addr]\n"
+			"cmp	%x[tmp], %x[expected]\n"

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 121

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldaxr  %x[tmp], %x[addr]\n"
+			"cmp	%x[tmp], %x[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");

Duplication of code. Please introduce a macro for assembly Skelton. Something like

http://patches.dpdk.org/patch/56949/

Quoted 37 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +4 -0
+}
+
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +6 -1
index 52bd4db..8f5f025 100644
@@ -4,7 +4,6 @@
 
 #ifndef _RTE_PAUSE_H_
 #define _RTE_PAUSE_H_
-
 /**
  * @file
  *
@@ -12,6 +11,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +23,38 @@
  */
 static inline void rte_pause(void);
 
+#if !defined(RTE_USE_WFE)
+#ifdef RTE_USE_C11_MEM_MODEL

lib/librte_eal/common/include/generic/rte_pause.h line 37

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+#define __rte_wait_until_equal(addr, expected, memorder) do {\
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause();\
+} while (0)
+#else
+#define __rte_wait_until_equal(addr, expected, memorder) do {\
+	while (*addr != expected)\
+		rte_pause();\
+	if (memorder != __ATOMIC_RELAXED)\
+		rte_smp_rmb();\

Is this correct wrt all memorder?
If there is no specific gain on no C11 mem model, let have only C11 memmodel Aka remove RTE_USE_C11_MEM_MODEL

lib/librte_eal/common/include/generic/rte_pause.h line 40

Quoted 3 lines
lib/librte_eal/common/include/generic/rte_pause.h +3 -0
+} while (0)
+#endif
+

Spotted public API. Lets have prototype with very good documentation on the API details.

Quoted 19 lines
lib/librte_eal/common/include/generic/rte_pause.h +16 -1
+static __rte_always_inline void
+rte_wait_until_equal16(volatile uint16_t *addr, uint16_t expected, int
+memorder) {
+	__rte_wait_until_equal(addr, expected, memorder); }
+
+static __rte_always_inline void
+rte_wait_until_equal32(volatile uint32_t *addr, uint32_t expected, int
+memorder) {
+	__rte_wait_until_equal(addr, expected, memorder); }
+
+static __rte_always_inline void
+rte_wait_until_equal64(volatile uint64_t *addr, uint64_t expected, int
+memorder) {
+	__rte_wait_until_equal(addr, expected, memorder); } #endif /*
+RTE_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#28 lore raw

Re: [dpdk-dev] [EXT] [PATCH v3 1/5] eal: add the APIs to wait until equal

Hi Jerin,

Quoted 247 lines

-----Original Message-----
From: Jerin Jacob Kollanukkaran <[email protected]>
Sent: Wednesday, July 24, 2019 7:53 PM
To: Gavin Hu (Arm Technology China) <[email protected]>; [email protected]
Cc: nd <[email protected]>; [email protected]; [email protected]; Pavan Nikhilesh Bhagavatula <[email protected]>; Honnappa Nagarahalli <[email protected]>
Subject: RE: [EXT] [PATCH v3 1/5] eal: add the APIs to wait until equal

Quoted 32 lines

-----Original Message-----
From: Gavin Hu <[email protected]>
Sent: Tuesday, July 23, 2019 9:14 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Pavan Nikhilesh Bhagavatula <[email protected]>; [email protected]; [email protected]
Subject: [EXT] [PATCH v3 1/5] eal: add the APIs to wait until equal

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
 .../common/include/arch/arm/rte_atomic_64.h        |   4 +
 .../common/include/arch/arm/rte_pause_64.h         | 106
+++++++++++++++++++++
 lib/librte_eal/common/include/generic/rte_pause.h  |  39 +++++++-
 3 files changed, 148 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_atomic_64.h +0 -0
index 97060e4..8d742c6 100644

lib/librte_eal/common/include/arch/arm/rte_atomic_64.h extern "C" { · line 23

Quoted 9 lines
lib/librte_eal/common/include/arch/arm/rte_atomic_64.h +4 -0
@@ -15,8 +15,12 @@ extern "C" {
 
 #include "generic/rte_atomic.h"
 
+#ifndef dsb
 #define dsb(opt) asm volatile("dsb " #opt : : : "memory")
+#endif
+#ifndef dmb
 #define dmb(opt) asm volatile("dmb " #opt : : : "memory")
+#endif

Is this change required? Please fix the root cause. I do see some build error too.

In file included from /home/jerin/dpdk.org/build/include/rte_pause_64.h:13,
from /home/jerin/dpdk.org/build/include/rte_pause.h:13, from
/home/jerin/dpdk.org/build/include/generic/rte_spinlock.h:25,

                 from /home/jerin/dpdk.org/build/include/rte_spinlock.h:17,
                 from /home/jerin/dpdk.org/drivers/bus/fslmc/mc/mc_sys.c:10:

/home/jerin/dpdk.org/build/include/generic/rte_pause.h: In function 'rte_wait_until_equal16':
/home/jerin/dpdk.org/build/include/generic/rte_pause.h:44:49: error:
macro "dmb" passed 1 arguments, but takes just 0
44 | __rte_wait_until_equal(addr, expected, memorder);

Command to reproduce(gcc 9.1)

rm -rf build && unset RTE_KERNELDIR && make -j T=arm64-thunderx-linux- gcc CROSS=aarch64-linux-gnu- && sed -ri 's,(CONFIG_RTE_KNI_KMOD=)y,\1n,' build/.config && sed -ri 's,(CONFIG_RTE_LIBRTE_VHOST_NUMA=)y,\1n,' build/.config && sed -ri 's,(CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=)y,\1n,' build/.config && sed -ri 's,(CONFIG_RTE_EAL_IGB_UIO=)y,\1n,' build/.config && CC="ccache gcc" make -j test-build CROSS=aarch64-linux-gnu-

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 20

Quoted 13 lines
lib/librte_eal/common/include/arch/arm/rte_atomic_64.h +0 -0
 #define rte_mb() dsb(sy)
 
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
index 93895d3..1f7be0a 100644
@@ -17,6 +17,112 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_USE_WFE

Do we need it to be under RTE_USE_WFE? If there is no harm, no need to add
Conditional compilation to detect build errors, especially config is disabled by default.

Quoted 90 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +90 -0
+/* Wait for *addr to be updated with expected value */ static
+__rte_always_inline void rte_wait_until_equal16(volatile uint16_t
+*addr, uint16_t expected, int memorder) {
+	uint16_t tmp;
+	if (memorder == __ATOMIC_RELAXED)
+		asm volatile(
+			"ldxrh	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldxrh	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+	else
+		asm volatile(
+			"ldaxrh %w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldaxrh	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+}
+
+static __rte_always_inline void
+rte_wait_until_equal32(volatile uint32_t *addr, uint32_t expected, int
+memorder) {
+	uint32_t tmp;
+	if (memorder == __ATOMIC_RELAXED)
+		asm volatile(
+			"ldxr	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldxr	%w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+	else
+		asm volatile(
+			"ldaxr  %w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldaxr  %w[tmp], %w[addr]\n"
+			"cmp	%w[tmp], %w[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+}
+
+static __rte_always_inline void
+rte_wait_until_equal64(volatile uint64_t *addr, uint64_t expected, int
+memorder) {
+	uint64_t tmp;
+	if (memorder == __ATOMIC_RELAXED)
+		asm volatile(
+			"ldxr	%x[tmp], %x[addr]\n"
+			"cmp	%x[tmp], %x[expected]\n"
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldxr	%x[tmp], %x[addr]\n"
+			"cmp	%x[tmp], %x[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");
+	else
+		asm volatile(
+			"ldaxr  %x[tmp], %x[addr]\n"
+			"cmp	%x[tmp], %x[expected]\n"

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 121

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+			"b.eq	2f\n"
+			"sevl\n"
+			"1:	wfe\n"
+			"ldaxr  %x[tmp], %x[addr]\n"
+			"cmp	%x[tmp], %x[expected]\n"
+			"bne	1b\n"
+			"2:\n"
+			: [tmp] "=&r" (tmp)
+			: [addr] "Q"(*addr), [expected] "r"(expected)
+			: "cc", "memory");

Duplication of code. Please introduce a macro for assembly Skelton. Something like

http://patches.dpdk.org/patch/56949/

Quoted 44 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +4 -0
+}
+
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +13 -1
index 52bd4db..8f5f025 100644
@@ -4,7 +4,6 @@
 
 #ifndef _RTE_PAUSE_H_
 #define _RTE_PAUSE_H_
-
 /**
  * @file
  *
@@ -12,6 +11,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +23,38 @@
  */
 static inline void rte_pause(void);
 
+#if !defined(RTE_USE_WFE)
+#ifdef RTE_USE_C11_MEM_MODEL
+#define __rte_wait_until_equal(addr, expected, memorder) do {\
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause();\
+} while (0)
+#else
+#define __rte_wait_until_equal(addr, expected, memorder) do {\
+	while (*addr != expected)\
Quoted 8 lines

lib/librte_eal/common/include/generic/rte_pause.h line 37

Quoted 3 lines
lib/librte_eal/common/include/generic/rte_pause.h +3 -0
+		rte_pause();\
+	if (memorder != __ATOMIC_RELAXED)\
+		rte_smp_rmb();\

Is this correct wrt all memorder?
If there is no specific gain on no C11 mem model, let have only C11 memmodel
Aka remove RTE_USE_C11_MEM_MODEL

I am looking into all your comments(thanks!) and will submit a new version.

Quoted 28 lines

lib/librte_eal/common/include/generic/rte_pause.h line 40

Quoted 3 lines
lib/librte_eal/common/include/generic/rte_pause.h +3 -0
+} while (0)
+#endif
+

Spotted public API. Lets have prototype with very good documentation on the
API details.

Quoted 19 lines
lib/librte_eal/common/include/generic/rte_pause.h +16 -1
+static __rte_always_inline void
+rte_wait_until_equal16(volatile uint16_t *addr, uint16_t expected, int
+memorder) {
+	__rte_wait_until_equal(addr, expected, memorder); }
+
+static __rte_always_inline void
+rte_wait_until_equal32(volatile uint32_t *addr, uint32_t expected, int
+memorder) {
+	__rte_wait_until_equal(addr, expected, memorder); }
+
+static __rte_always_inline void
+rte_wait_until_equal64(volatile uint64_t *addr, uint64_t expected, int
+memorder) {
+	__rte_wait_until_equal(addr, expected, memorder); } #endif /*
+RTE_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

author
#29 lore raw

PATCH v3 2/5 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

While using ticket lock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running ticketlock_autotest on ThunderX2, with different numbers of cores and depths of rings, 3%~8% performance gains were measured.

---
 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
index d9bec87..f0821f2 100644
@@ -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_equal16(&tl->s.current, me, __ATOMIC_ACQUIRE);
 }
 
 /**
Signature · 1 line
2.7.4
author
#30 lore raw

PATCH v3 3/5 ring: use wfe to wait for ring tail update on aarch64

In reply to Gavin Hu

Instead of polling for tail to be updated, use wfe instruction.

---
 lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
 lib/librte_ring/rte_ring_generic.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring_c11_mem.h +2 -2
index 0fb73a3..037811e 100644
@@ -2,6 +2,7 @@
  *
  * Copyright (c) 2017,2018 HXT-semitech Corporation.
  * Copyright (c) 2007-2009 Kip Macy [email protected]
+ * Copyright (c) 2019 Arm Limited
  * All rights reserved.
  * Derived from FreeBSD's bufring.h
  * Used as BSD-3 Licensed with permission from Kip Macy.
@@ -21,8 +22,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal32(&ht->tail, old_val, __ATOMIC_RELAXED);
 
 	__atomic_store_n(&ht->tail, new_val, __ATOMIC_RELEASE);
 }
lib/librte_ring/rte_ring_generic.h +1 -2
index 953cdbb..570765c 100644
@@ -23,8 +23,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal32(&ht->tail, old_val, __ATOMIC_RELAXED);
 
 	ht->tail = new_val;
 }
Signature · 1 line
2.7.4
author
#31 lore raw

PATCH v3 4/5 spinlock: use wfe to reduce contention on aarch64

In reply to Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

5~10% performance gain was measured by running spinlock_autotest on 14 isolated cores of ThunderX2.

---
 .../common/include/arch/arm/rte_spinlock.h         | 25 ++++++++++++++++++++++
 .../common/include/generic/rte_spinlock.h          |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +25 -0
index 1a6916b..f25d17f 100644
@@ -16,6 +16,31 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#if defined(RTE_USE_WFE) && defined(RTE_ARCH_ARM64)
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+	unsigned int tmp;
+	/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"sevl\n"
+		"1:	wfe\n"
+		"2:	ldaxr %w[tmp], %w[locked]\n"
+		"cbnz   %w[tmp], 1b\n"
+		"stxr   %w[tmp], %w[one], %w[locked]\n"
+		"cbnz   %w[tmp], 2b\n"
+		: [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+		: [one] "r" (1)
+		: "cc", "memory");
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
 	return 0;
lib/librte_eal/common/include/generic/rte_spinlock.h +1 -1
index 87ae7a4..cf4f15b 100644
@@ -57,7 +57,7 @@ rte_spinlock_init(rte_spinlock_t *sl)
 static inline void
 rte_spinlock_lock(rte_spinlock_t *sl);
 
-#ifdef RTE_FORCE_INTRINSICS
+#if defined(RTE_FORCE_INTRINSICS) && !defined(RTE_USE_WFE)
 static inline void
 rte_spinlock_lock(rte_spinlock_t *sl)
 {
Signature · 1 line
2.7.4
#32 lore raw

Re: [dpdk-dev] [EXT] [PATCH v3 4/5] spinlock: use wfe to reduce contention on aarch64

Quoted 36 lines

-----Original Message-----
From: Gavin Hu <[email protected]>
Sent: Tuesday, July 23, 2019 9:14 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Pavan Nikhilesh Bhagavatula <[email protected]>; [email protected]; [email protected]
Subject: [EXT] [PATCH v3 4/5] spinlock: use wfe to reduce contention on aarch64

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

5~10% performance gain was measured by running spinlock_autotest on 14 isolated cores of ThunderX2.

---
 .../common/include/arch/arm/rte_spinlock.h         | 25
++++++++++++++++++++++
 .../common/include/generic/rte_spinlock.h          |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +0 -0
index 1a6916b..f25d17f 100644

lib/librte_eal/common/include/arch/arm/rte_spinlock.h extern "C" { · line 23

Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +5 -0
@@ -16,6 +16,31 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#if defined(RTE_USE_WFE) && defined(RTE_ARCH_ARM64) static inline

See below. Please avoid complicated conditional compilation logic for scalability and readability.

Quoted 27 lines

void

lib/librte_eal/common/include/arch/arm/rte_spinlock.h +18 -0
+rte_spinlock_lock(rte_spinlock_t *sl) {
+	unsigned int tmp;
+	/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"sevl\n"
+		"1:	wfe\n"
+		"2:	ldaxr %w[tmp], %w[locked]\n"
+		"cbnz   %w[tmp], 1b\n"
+		"stxr   %w[tmp], %w[one], %w[locked]\n"
+		"cbnz   %w[tmp], 2b\n"
+		: [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+		: [one] "r" (1)
+		: "cc", "memory");
+}
+#endif
+
 static inline int rte_tm_supported(void)  {
 	return 0;
lib/librte_eal/common/include/generic/rte_spinlock.h +0 -0
index 87ae7a4..cf4f15b 100644

lib/librte_eal/common/include/generic/rte_spinlock.h rte_spinlock_init(rte_spinlock_t *sl) static inline void · line 59

Quoted 4 lines
lib/librte_eal/common/include/generic/rte_spinlock.h +1 -1
@@ -57,7 +57,7 @@ rte_spinlock_init(rte_spinlock_t *sl)  static inline void
 rte_spinlock_lock(rte_spinlock_t *sl);
 
-#ifdef RTE_FORCE_INTRINSICS
+#if defined(RTE_FORCE_INTRINSICS) && !defined(RTE_USE_WFE)

I would like to avoid hacking around adjusting generic code to meet specific requirement. For example, if someone enables RTE_USE_WFE for armv7 it will break
And it will pain for the new architecture to use RTE_FORCE_INTRINSICS.

Looks like the time has come to disable RTE_FORCE_INTRINSICS for arm64.

Since this patch is targeted for next release. How about enable native Implementation for RTE_FORCE_INTRINSICS used code for arm64 like spinlock, ticketlock like x86. If you guys don't have the bandwidth to convert all blocks, let us know, we can collaborate and Marvell can take up some RTE_FORCE_INTRINSICS conversion for next release.

Quoted 5 lines
lib/librte_eal/common/include/generic/rte_spinlock.h +0 -1
 static inline void
 rte_spinlock_lock(rte_spinlock_t *sl)
 {
--

2.7.4

author
#33 lore raw

PATCH v3 5/5 config: add WFE config entry for aarch64

In reply to Gavin Hu

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default. It can be enabled selectively based on the performance benchmarking.

---
 config/arm/meson.build     | 1 +
 config/common_armv8a_linux | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build +1 -0
index 979018e..496813a 100644
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa, machine_args_generic]
 impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]
 
 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
+dpdk_conf.set('RTE_USE_WFE', 0)
 
 if not dpdk_conf.get('RTE_ARCH_64')
 	dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
config/common_armv8a_linux +6 -0
index 481712e..48c7ab5 100644
@@ -12,6 +12,12 @@ CONFIG_RTE_ARCH_64=y
 
 CONFIG_RTE_FORCE_INTRINSICS=y
 
+# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs,
+# calling these APIs put the cores enter low power state while waiting
+# for the memory address to be become equal to the expected value.
+# This is supported only by aarch64.
+CONFIG_RTE_USE_WFE=n
+
 # Maximum available cache line size in arm64 implementations.
 # Setting to maximum available cache line size in generic config
 # to address minimum DMA alignment across all arm64 implementations.
Signature · 1 line
2.7.4
#34 lore raw

Re: [dpdk-dev] [PATCH v3 5/5] config: add WFE config entry for aarch64

Quoted 32 lines · On Tue, 23 Jul 2019 23:43:46 +0800 Gavin Hu <[email protected]> wrote:

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default. It can be enabled selectively based on the performance benchmarking.

---
 config/arm/meson.build     | 1 +
 config/common_armv8a_linux | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build +1 -0
index 979018e..496813a 100644
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa, machine_args_generic]
 impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]
 
 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
+dpdk_conf.set('RTE_USE_WFE', 0)
 
 if not dpdk_conf.get('RTE_ARCH_64')
 	dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
config/common_armv8a_linux +0 -0
index 481712e..48c7ab5 100644
@@ -12,6 +12,12 @@ CONFIG_RTE_ARCH_64=y
 
 CONFIG_RTE_FORCE_INTRINSICS=y

config/common_armv8a_linux CONFIG_RTE_ARCH_64=y · line 23

Quoted 10 lines
config/common_armv8a_linux +6 -0
 
+# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs,
+# calling these APIs put the cores enter low power state while waiting
+# for the memory address to be become equal to the expected value.
+# This is supported only by aarch64.
+CONFIG_RTE_USE_WFE=n
+
 # Maximum available cache line size in arm64 implementations.
 # Setting to maximum available cache line size in generic config
 # to address minimum DMA alignment across all arm64 implementations.

Introducing config options is a maintenance nightmare. How are distributions supposed to ship a package? Does full regression test get done on both options?

The user should not be able to change this.

#35 lore raw

Re: [dpdk-dev] [PATCH v3 5/5] config: add WFE config entry for aarch64

Quoted 52 lines
Quoted 42 lines · On Tue, 23 Jul 2019 23:43:46 +0800 Gavin Hu <[email protected]> wrote:

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default. It can be enabled selectively based on the performance benchmarking.

---
 config/arm/meson.build     | 1 +
 config/common_armv8a_linux | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build index renamed from config/arm/meson.build +0 -0

979018e..496813a 100644

config/arm/meson.build +0 -0
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa,

machine_args_generic]
impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]

dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)

config/arm/meson.build +1 -0
+dpdk_conf.set('RTE_USE_WFE', 0)
 
 if not dpdk_conf.get('RTE_ARCH_64')
 	dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64) diff --git

a/config/common_armv8a_linux b/config/common_armv8a_linux index 481712e..48c7ab5 100644

config/common_armv8a_linux +6 -0
@@ -12,6 +12,12 @@ CONFIG_RTE_ARCH_64=y
 
 CONFIG_RTE_FORCE_INTRINSICS=y
 
+# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs,
+# calling these APIs put the cores enter low power state while
+waiting # for the memory address to be become equal to the expected value.
+# This is supported only by aarch64.
+CONFIG_RTE_USE_WFE=n
+
 # Maximum available cache line size in arm64 implementations.
 # Setting to maximum available cache line size in generic config  #
Quoted 1 line

to address minimum DMA alignment across all arm64 implementations.

Introducing config options is a maintenance nightmare. How are distributions supposed to ship a package? Does full regression test get done on both options?

Quoted 1 line

The user should not be able to change this.

Agree with these concerns here. In our tests, we are finding that this patch does not result in performance improvements on all micro-architectures. May be these micro-architectures will evolve in the future knowing that WFE is being used in DPDK. But at this point, it does not make sense to enable this by default. This means additional testing/regression with the flag enabled. We could add this to Travis build (Travis yml file).

Currently, this patch will address use cases where the target hardware/environment is known during compilation.

#36 lore raw

Re: [dpdk-dev] [PATCH v3 5/5] config: add WFE config entry for aarch64

Hi Stephen,

Quoted 72 lines

-----Original Message-----
From: Honnappa Nagarahalli <[email protected]>
Sent: Wednesday, July 24, 2019 3:10 AM
To: Stephen Hemminger <[email protected]>; Gavin Hu (Arm Technology China) <[email protected]>
Cc: [email protected]; nd <[email protected]>; [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v3 5/5] config: add WFE config entry for aarch64

Quoted 5 lines
Quoted 1 line · On Tue, 23 Jul 2019 23:43:46 +0800 Gavin Hu <[email protected]> wrote:

Add the RTE_USE_WFE configuration entry for aarch64, disabled by

default.

Quoted 31 lines
Quoted 31 lines

It can be enabled selectively based on the performance benchmarking.

---
 config/arm/meson.build     | 1 +
 config/common_armv8a_linux | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build index renamed from config/arm/meson.build +0 -0

979018e..496813a 100644

config/arm/meson.build +0 -0
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa,

machine_args_generic]
impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]

dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
+dpdk_conf.set('RTE_USE_WFE', 0)

if not dpdk_conf.get('RTE_ARCH_64') dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64) diff --git
a/config/common_armv8a_linux b/config/common_armv8a_linux index 481712e..48c7ab5 100644

config/common_armv8a_linux +0 -0
@@ -12,6 +12,12 @@ CONFIG_RTE_ARCH_64=y
 
Quoted 5 lines

config/common_armv8a_linux CONFIG_RTE_ARCH_64=y

Quoted 5 lines
config/common_armv8a_linux +3 -0
 CONFIG_RTE_FORCE_INTRINSICS=y
 
+# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs,
+# calling these APIs put the cores enter low power state while
+waiting # for the memory address to be become equal to the expected

value.

Quoted 11 lines
Quoted 6 lines
config/common_armv8a_linux +3 -0
+# This is supported only by aarch64.
+CONFIG_RTE_USE_WFE=n
+
 # Maximum available cache line size in arm64 implementations.
 # Setting to maximum available cache line size in generic config  #

to address minimum DMA alignment across all arm64 implementations.

Introducing config options is a maintenance nightmare. How are distributions supposed to ship a package? Does full regression test get done on both options?

Quoted 1 line

The user should not be able to change this.

Agree with these concerns here. In our tests, we are finding that this patch does not result in performance improvements on all micro-architectures. May be these micro-architectures will evolve in the future knowing that WFE is being used in DPDK. But at this point, it does not make sense to enable this by default. This means additional testing/regression with the flag enabled. We could add this to Travis build (Travis yml file).

Quoted 2 lines

Currently, this patch will address use cases where the target hardware/environment is known during compilation.

In our testing, like running testpmd and packet_ordering(for WFE ring benchmarking), it showed no improvements nor degradation in performance. For some micro-benchmarking, it showed slight improvements sometimes, no degradation were seen.
The added benefit of the patch set is power saving, but it is not a primary concern in DPDK and we are short of measurement ways to benchmark that.

#37 lore raw

Re: [dpdk-dev] [EXT] [PATCH v3 5/5] config: add WFE config entry for aarch64

In reply to Gavin Hu
Quoted 19 lines

-----Original Message-----
From: Gavin Hu <[email protected]>
Sent: Tuesday, July 23, 2019 9:14 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Pavan Nikhilesh Bhagavatula <[email protected]>; [email protected]; [email protected]
Subject: [EXT] [PATCH v3 5/5] config: add WFE config entry for aarch64

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default. It can be enabled selectively based on the performance benchmarking.

Review

Quoted 5 lines
(quoted diff) +5 -0
+# Use WFE instructions to implement the rte_wait_for_equal_xxx APIs, #
+calling these APIs put the cores enter low power state while waiting #
+for the memory address to be become equal to the expected value.
+# This is supported only by aarch64.
+CONFIG_RTE_USE_WFE=n

# If it specific for arm and none of the other architectures supports it then I would like to change the config as CONFIG_RTE_ARM_USE_WFE
# Even if it is disabled, have the =n entry in config/common_base to know all supported configs in DPDK in one place.
# Arrange all CONFIG_RTE_ARM_* together in config/common_base

#38 lore raw
In reply to Gavin Hu

Hi Gavin,
I think this should have been V1 (I mean, no versioning, just 'PATCH'), since it is converted to patch. I think we should be able to resend it as V1 and mark this V3 as 'superseded'.

Hi Thomas,
Please let us know if it is worth/helps fixing the version.

Thanks,
Honnappa

Quoted 71 lines

-----Original Message-----
From: Gavin Hu <[email protected]>
Sent: Tuesday, July 23, 2019 10:44 AM
To: [email protected]
Cc: nd <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; Gavin Hu (Arm Technology China) <[email protected]>
Subject: [PATCH v3 0/5] use WFE for locks and ring on aarch64

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_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.

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):
eal: add the APIs to wait until equal
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update on aarch64
spinlock: use wfe to reduce contention on aarch64
config: add WFE config entry for aarch64

 config/arm/meson.build                             |   1 +
 config/common_armv8a_linux                         |   6 ++
 .../common/include/arch/arm/rte_atomic_64.h        |   4 +
 .../common/include/arch/arm/rte_pause_64.h         | 106
+++++++++++++++++++++
 .../common/include/arch/arm/rte_spinlock.h         |  25 +++++
 lib/librte_eal/common/include/generic/rte_pause.h  |  39 +++++++-
 .../common/include/generic/rte_spinlock.h          |   2 +-
 .../common/include/generic/rte_ticketlock.h        |   3 +-
 lib/librte_ring/rte_ring_c11_mem.h                 |   4 +-
 lib/librte_ring/rte_ring_generic.h                 |   3 +-
 10 files changed, 185 insertions(+), 8 deletions(-)

--
2.7.4

#39 lore raw

23/07/2019 21:15, Honnappa Nagarahalli:

Quoted 5 lines

Hi Gavin,
I think this should have been V1 (I mean, no versioning, just 'PATCH'), since it is converted to patch. I think we should be able to resend it as V1 and mark this V3 as 'superseded'.

Hi Thomas,
Please let us know if it is worth/helps fixing the version.

I don't follow why it should be v1.

#40 lore raw
Quoted 11 lines

23/07/2019 21:15, Honnappa Nagarahalli:

Quoted 2 lines

Hi Gavin,
I think this should have been V1 (I mean, no versioning, just 'PATCH'),

since it is converted to patch. I think we should be able to resend it as V1 and mark this V3 as 'superseded'.

Quoted 3 lines

Hi Thomas,
Please let us know if it is worth/helps fixing the version.

I don't follow why it should be v1.

This patch series was a RFC (RFC V1 and RFC v2). It is converted to a patch, I thought it should start with V1.

Quoted 2 lines
#41 lore raw

24/07/2019 04:44, Honnappa Nagarahalli:

Quoted 6 lines
Quoted 6 lines

23/07/2019 21:15, Honnappa Nagarahalli:

Quoted 2 lines

Hi Gavin,
I think this should have been V1 (I mean, no versioning, just 'PATCH'),

since it is converted to patch. I think we should be able to resend it as V1 and mark this V3 as 'superseded'.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Hi Thomas,
Please let us know if it is worth/helps fixing the version.

I don't follow why it should be v1.

This patch series was a RFC (RFC V1 and RFC v2). It is converted to a patch, I thought it should start with V1.

No it can keep incrementing, it is OK and clear.

author
#42 lore raw

v4 cover use WFE for locks and ring on aarch64

In reply to Gavin Hu

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_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_ARM_USE_WFE should be enabled depending on the performance benchmarking on the target platforms. Power saving should be an bonus, but currenly we don't have ways to characterize that.

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 (6):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update on aarch64
spinlock: use wfe to reduce contention on aarch64
config: add WFE config entry for aarch64

 config/arm/meson.build                             |  1 +
 config/common_base                                 |  6 +++++
 drivers/bus/fslmc/mc/fsl_mc_sys.h                  | 10 +++++---
 drivers/bus/fslmc/mc/mc_sys.c                      |  3 +--
 .../common/include/arch/arm/rte_pause_64.h         | 30 ++++++++++++++++++++++
 .../common/include/arch/arm/rte_spinlock.h         | 25 ++++++++++++++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 26 ++++++++++++++++++-
 .../common/include/generic/rte_ticketlock.h        |  3 +--
 lib/librte_ring/rte_ring_c11_mem.h                 |  4 +--
 lib/librte_ring/rte_ring_generic.h                 |  3 +--
 10 files changed, 99 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
author
#43 lore raw

PATCH v4 1/6 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 include the spinlock.h file before the other header files, this is inline with the coding style[2] about the "header includes". The fix changes the function to take the argument for arm to be meaningful.

[1] http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF0@i
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u
[2] https://doc.dpdk.org/guides/contributing/coding_style.html

Fixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")
---
 drivers/bus/fslmc/mc/fsl_mc_sys.h | 10 +++++++---
 drivers/bus/fslmc/mc/mc_sys.c     |  3 +--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/bus/fslmc/mc/fsl_mc_sys.h +7 -3
index d0c7b39..fe9dc95 100644
@@ -33,10 +33,14 @@ struct fsl_mc_io {
 #include <linux/byteorder/little_endian.h>
 
 #ifndef dmb
-#define dmb() {__asm__ __volatile__("" : : : "memory"); }
+#ifdef RTE_ARCH_ARM64
+#define dmb(opt) {asm volatile("dmb " #opt : : : "memory"); }
+#else
+#define dmb(opt)
 #endif
-#define __iormb()	dmb()
-#define __iowmb()	dmb()
+#endif
+#define __iormb()	dmb(ld)
+#define __iowmb()	dmb(st)
 #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))
drivers/bus/fslmc/mc/mc_sys.c +1 -2
index efafdc3..22143ef 100644
@@ -4,11 +4,10 @@
  * Copyright 2017 NXP
  *
  */
+#include <rte_spinlock.h>
 #include <fsl_mc_sys.h>
 #include <fsl_mc_cmd.h>
 
-#include <rte_spinlock.h>
-
 /** User space framework uses MC Portal in shared mode. Following change
  * introduces lock in MC FLIB
  */
Signature · 1 line
2.7.4
author
#44 lore raw

PATCH v4 2/6 eal: add the APIs to wait until equal

In reply to Gavin Hu

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
 .../common/include/arch/arm/rte_pause_64.h         | 30 ++++++++++++++++++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 26 ++++++++++++++++++-
 2 files changed, 55 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +30 -0
index 93895d3..dabde17 100644
@@ -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +25 -1
index 52bd4db..4741f8a 100644
@@ -1,10 +1,10 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2017 Cavium, Inc
+ * Copyright(c) 2019 Arm Limited
  */
 
 #ifndef _RTE_PAUSE_H_
 #define _RTE_PAUSE_H_
-
 /**
  * @file
  *
@@ -12,6 +12,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +24,24 @@
  */
 static inline void rte_pause(void);
 
+#if !defined(RTE_ARM_USE_WFE)
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void	\
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+	type expected) \
+{ \
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
Signature · 1 line
2.7.4
#45 lore raw

Re: [dpdk-dev] [PATCH v4 2/6] eal: add the APIs to wait until equal

Quoted 50 lines · Gavin Hu

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
 .../common/include/arch/arm/rte_pause_64.h         | 30 ++++++++++++++++++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 26 ++++++++++++++++++-
 2 files changed, 55 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +20 -0
index 93895d3..dabde17 100644
@@ -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+       type tmp; \
+       asm volatile( \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "b.eq   2f\n" \
+               "sevl\n" \
+               "1:     wfe\n" \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "bne    1b\n" \
+               "2:\n" \
+               : [tmp] "=&r" (tmp) \
+               : [addr] "Q"(*addr), [expected] "r"(expected) \
+               : "cc", "memory"); \

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 49

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +8 -0
+}
 
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
 

This scheme doesn't allow to write Doxygen comments for the API Please change to some scheme where you can Doxygen comments for each API without code duplication. Something like

/**
* Doxygen comment
*/
rte_wait_until_equal_relaxed_16(..)

{
        __WAIT_UNTIL_EQUAL(..)
}
#46 lore raw

Re: [dpdk-dev] [PATCH v4 2/6] eal: add the APIs to wait until equal

Hi Jerin,

Quoted 66 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Wednesday, September 11, 2019 8:27 PM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: [email protected]; nd <[email protected]>; [email protected]; [email protected]; [email protected]; Pavan Nikhilesh <[email protected]>; Honnappa Nagarahalli <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v4 2/6] eal: add the APIs to wait until equal

Quoted 11 lines · Gavin Hu

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

Quoted 2 lines
---
 .../common/include/arch/arm/rte_pause_64.h         | 30

++++++++++++++++++++++

Quoted 1 line
 lib/librte_eal/common/include/generic/rte_pause.h  | 26

++++++++++++++++++-

Review

Quoted 3 lines
 2 files changed, 55 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 35 lines

index 93895d3..dabde17 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +21 -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+       type tmp; \
+       asm volatile( \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "b.eq   2f\n" \
+               "sevl\n" \
+               "1:     wfe\n" \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "bne    1b\n" \
+               "2:\n" \
+               : [tmp] "=&r" (tmp) \
+               : [addr] "Q"(*addr), [expected] "r"(expected) \
+               : "cc", "memory"); \
+}
 
Quoted 13 lines

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 +7 -0
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
 

This scheme doesn't allow to write Doxygen comments for the API Please change to some scheme where you can Doxygen comments for each API
without code duplication. Something like

Thanks for pointing out this, I will fix this in next version.

Quoted 8 lines

/**
* Doxygen comment
*/
rte_wait_until_equal_relaxed_16(..)

{
        __WAIT_UNTIL_EQUAL(..)
}

Following the other examples, just add some declarations of the APIs in the beginning of the file, with the Doxygen comments above can fix this problem. The implementations of the APIs do not need to change, please help review the v5 version.

author
#47 lore raw

PATCH v4 3/6 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

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
index d9bec87..232bbe9 100644
@@ -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_acquire_16(&tl->s.current, me);
 }
 
 /**
Signature · 1 line
2.7.4
author
#48 lore raw

PATCH v4 4/6 ring: use wfe to wait for ring tail update on aarch64

In reply to Gavin Hu

Instead of polling for tail to be updated, use wfe instruction.

---
 lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
 lib/librte_ring/rte_ring_generic.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring_c11_mem.h +2 -2
index 0fb73a3..764d8f1 100644
@@ -2,6 +2,7 @@
  *
  * Copyright (c) 2017,2018 HXT-semitech Corporation.
  * Copyright (c) 2007-2009 Kip Macy [email protected]
+ * Copyright (c) 2019 Arm Limited
  * All rights reserved.
  * Derived from FreeBSD's bufring.h
  * Used as BSD-3 Licensed with permission from Kip Macy.
@@ -21,8 +22,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
 
 	__atomic_store_n(&ht->tail, new_val, __ATOMIC_RELEASE);
 }
lib/librte_ring/rte_ring_generic.h +1 -2
index 953cdbb..6828527 100644
@@ -23,8 +23,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
 
 	ht->tail = new_val;
 }
Signature · 1 line
2.7.4
author
#49 lore raw

PATCH v4 5/6 spinlock: use wfe to reduce contention on aarch64

In reply to Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running the micro benchmarking and the testpmd and l3fwd traffic tests on ThunderX2, Ampere eMAG80 and Arm N1SDP, everything went well and no notable performance gain nor degradation was measured.

---
 .../common/include/arch/arm/rte_spinlock.h         | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +25 -0
index 1a6916b..7b8328e 100644
@@ -16,6 +16,31 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#ifndef RTE_FORCE_INTRINSICS
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+	unsigned int tmp;
+	/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"sevl\n"
+		"1:	wfe\n"
+		"2:	ldaxr %w[tmp], %w[locked]\n"
+		"cbnz   %w[tmp], 1b\n"
+		"stxr   %w[tmp], %w[one], %w[locked]\n"
+		"cbnz   %w[tmp], 2b\n"
+		: [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+		: [one] "r" (1)
+		: "cc", "memory");
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
 	return 0;
Signature · 1 line
2.7.4

A message that is not in the archive (sent off-list or not yet received): CY4PR1801MB1863AF9695BB10930E817D78DEB00@CY4PR1801MB1863.namprd18.prod.outlook.com

A message that is not in the archive (sent off-list or not yet received): VI1PR08MB5376BEBCC1FD1E03F0B8A8848FB00@VI1PR08MB5376.eurprd08.prod.outlook.com

#52 lore raw

Re: [dpdk-dev] [EXT] [PATCH v4 5/6] spinlock: use wfe to reduce contention on aarch64

Hi Jerin,

Add the offlist discussion with Pavan to facilitate the review for the spinlock patch(currently in v6). Thanks Pavan and Jerin for review.

Best Regards,
Gavin

Quoted 52 lines

-----Original Message-----
From: Gavin Hu (Arm Technology China)
Sent: Thursday, September 12, 2019 5:22 PM
To: Pavan Nikhilesh Bhagavatula <[email protected]>
Subject: RE: [EXT] [PATCH v4 5/6] spinlock: use wfe to reduce contention on aarch64

Hi Pavan,

Thanks for pointing this out, it was implemented in the API already. Spinlock did not use the API to save a comparison branch(loading 0 to a reg and compare against).

Anyway it is also a good idea to add it into this asm code.

Best Regards,
Gavin

Quoted 34 lines

-----Original Message-----
From: Pavan Nikhilesh Bhagavatula <[email protected]>
Sent: Thursday, September 12, 2019 4:45 PM
To: Gavin Hu (Arm Technology China) <[email protected]>
Subject: RE: [EXT] [PATCH v4 5/6] spinlock: use wfe to reduce contention on aarch64

Hi Gavin, (Offlist)

I there a reason why the below asm doesn't use early exit as discussed in
http://patches.dpdk.org/patch/55669/

Regards,
Pavan.

Quoted 19 lines
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +6 -0
+#ifndef RTE_FORCE_INTRINSICS
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+  unsigned int tmp;
+  /*

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.

lib/librte_eal/common/include/arch/arm/rte_spinlock.h +12 -0
+   * faqs/ka16809.html
+   */
+  asm volatile(
+          "sevl\n"
+          "1:     wfe\n"
+          "2:     ldaxr %w[tmp], %w[locked]\n"
+          "cbnz   %w[tmp], 1b\n"
+          "stxr   %w[tmp], %w[one], %w[locked]\n"
+          "cbnz   %w[tmp], 2b\n"
+          : [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+          : [one] "r" (1)
+          : "cc", "memory");
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +3 -0
+}
+#endif
+

static inline int rte_tm_supported(void)
{
return 0;
--
2.7.4

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

author
#53 lore raw

PATCH v4 6/6 config: add WFE config entry for aarch64

In reply to Gavin Hu

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default. It can be enabled selectively based on the performance benchmarking.

---
 config/arm/meson.build | 1 +
 config/common_base     | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build +1 -0
index 979018e..18ecd53 100644
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa, machine_args_generic]
 impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]
 
 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
+dpdk_conf.set('RTE_ARM_USE_WFE', 0)
 
 if not dpdk_conf.get('RTE_ARCH_64')
 	dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
config/common_base +6 -0
index 8ef75c2..d4cf974 100644
@@ -570,6 +570,12 @@ CONFIG_RTE_CRYPTO_MAX_DEVS=64
 CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO=n
 CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO_DEBUG=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
+
 #
 # Compile NXP CAAM JR crypto Driver
 #
Signature · 1 line
2.7.4
#54 lore raw
In reply to Gavin Hu

Hello guys,

This series got a lot of attention from ARM people and it seems ready for integration.
But I did not see comment from other architectures, could you have a look please?

Thanks.

Signature · 1 line
David Marchand
Quoted 67 lines · Gavin Hu

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_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_ARM_USE_WFE should be enabled depending on the performance benchmarking on the target platforms. Power saving should be an bonus, but currenly we don't have ways to characterize that.

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 (6):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update on aarch64
spinlock: use wfe to reduce contention on aarch64
config: add WFE config entry for aarch64

 config/arm/meson.build                             |  1 +
 config/common_base                                 |  6 +++++
 drivers/bus/fslmc/mc/fsl_mc_sys.h                  | 10 +++++---
 drivers/bus/fslmc/mc/mc_sys.c                      |  3 +--
 .../common/include/arch/arm/rte_pause_64.h         | 30 ++++++++++++++++++++++
 .../common/include/arch/arm/rte_spinlock.h         | 25 ++++++++++++++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 26 ++++++++++++++++++-
 .../common/include/generic/rte_ticketlock.h        |  3 +--
 lib/librte_ring/rte_ring_c11_mem.h                 |  4 +--
 lib/librte_ring/rte_ring_generic.h                 |  3 +--
 10 files changed, 99 insertions(+), 12 deletions(-)

--
2.7.4

#55 lore raw
Quoted 4 lines

This series got a lot of attention from ARM people and it seems ready for integration.
But I did not see comment from other architectures, could you have a look please?

I spent some time going through the Power ISA specification and the Linux code and didn't find an equivalent. Under Linux this looks like a __cmpwait_case_XX operation but that's only defined for arm64 and used in barrier operations.

Dave

author
#56 lore raw

v5 cover use WFE for aarch64

In reply to Gavin Hu

V5:
- add doxygen comments for the new APIs
- spinlock early exit without wfe if the spinlock not taken by others. 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

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_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_ARM_USE_WFE should be enabled depending on the performance benchmarking on the target platforms. Power saving should be an bonus, but currenly we don't have ways to characterize that.

Gavin Hu (8):
config: add WFE config entry for aarch64 bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
spinlock: use wfe to reduce contention on aarch64
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update 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                                 |   6 +
 drivers/bus/fslmc/mc/fsl_mc_sys.h                  |  10 +-
 drivers/bus/fslmc/mc/mc_sys.c                      |   3 +-
 drivers/event/opdl/opdl_ring.c                     |   5 +-
 drivers/net/thunderx/nicvf_rxtx.c                  |   3 +-
 .../common/include/arch/arm/rte_pause_64.h         |  30 +++++
 .../common/include/arch/arm/rte_spinlock.h         |  26 ++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 146 ++++++++++++++++++++-
 .../common/include/generic/rte_ticketlock.h        |   3 +-
 lib/librte_ring/rte_ring_c11_mem.h                 |   4 +-
 lib/librte_ring/rte_ring_generic.h                 |   3 +-
 12 files changed, 223 insertions(+), 17 deletions(-)
Signature · 1 line
2.7.4
author
#57 lore raw

PATCH v5 1/8 config: add WFE config entry for aarch64

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default. It can be enabled selectively based on the performance benchmarking.

---
 config/arm/meson.build | 1 +
 config/common_base     | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build +1 -0
index 979018e..18ecd53 100644
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa, machine_args_generic]
 impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]
 
 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
+dpdk_conf.set('RTE_ARM_USE_WFE', 0)
 
 if not dpdk_conf.get('RTE_ARCH_64')
 	dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
config/common_base +6 -0
index 8ef75c2..d4cf974 100644
@@ -570,6 +570,12 @@ CONFIG_RTE_CRYPTO_MAX_DEVS=64
 CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO=n
 CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO_DEBUG=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
+
 #
 # Compile NXP CAAM JR crypto Driver
 #
Signature · 1 line
2.7.4
#58 lore raw

Re: [dpdk-dev] [PATCH v5 1/8] config: add WFE config entry for aarch64

Quoted 2 lines · Gavin Hu

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default.

s/RTE_USE_WFE/RTE_ARM_USE_WFE

Quoted 7 lines

It can be enabled selectively based on the performance benchmarking.

Does it make sense to add the Reviewed-by without CCing the people?

I understand, There may be an internal review before sending out to mailing list, IMO, it better to give Reviewed-By in the mailing list. Not sure about general practice and other people view.

Quoted 23 lines
---
 config/arm/meson.build | 1 +
 config/common_base     | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build +1 -0
index 979018e..18ecd53 100644
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa, machine_args_generic]
 impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]
 
 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
+dpdk_conf.set('RTE_ARM_USE_WFE', 0)
 
 if not dpdk_conf.get('RTE_ARCH_64')
        dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
config/common_base +0 -0
index 8ef75c2..d4cf974 100644

config/common_base CONFIG_RTE_CRYPTO_MAX_DEVS=64 · line 577

Quoted 8 lines
config/common_base +5 -0
@@ -570,6 +570,12 @@ CONFIG_RTE_CRYPTO_MAX_DEVS=64
 CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO=n
 CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO_DEBUG=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

Since this comes as EAL config, IMO, it is better to move this to end of EAL section.
i.e move after CONFIG_RTE_USE_LIBBSD

And I think, we should squash this patch to "eal: add the APIs to wait until equall" as it single logical change.

Quoted 7 lines
config/common_base +1 -1
+
 #
 # Compile NXP CAAM JR crypto Driver
 #
--

2.7.4

#59 lore raw

Re: [dpdk-dev] [PATCH v5 1/8] config: add WFE config entry for aarch64

Hi Jerin,

Thanks for reviewing the series, my comments inline.

Quoted 11 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Thursday, September 12, 2019 11:49 PM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: [email protected]; nd <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Pavan Nikhilesh <[email protected]>; Honnappa Nagarahalli <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 1/8] config: add WFE config entry for aarch64

Quoted 5 lines
Quoted 2 lines · Gavin Hu

Add the RTE_USE_WFE configuration entry for aarch64, disabled by default.

s/RTE_USE_WFE/RTE_ARM_USE_WFE

Will fix in next version.

Quoted 10 lines
Quoted 8 lines

It can be enabled selectively based on the performance benchmarking.

Does it make sense to add the Reviewed-by without CCing the people?

I will cc all the internal reviewers for the future patches.

Quoted 4 lines

I understand, There may be an internal review before sending out to mailing list, IMO, it better to give Reviewed-By in the mailing list. Not sure about general practice and other people view.

If there is a guideline here, we will strictly follow it. Currently both ways are ok?

Quoted 29 lines

config/arm/meson.build impl_dpaa = ['NXP DPAA', flags_dpaa,

Quoted 13 lines
---
 config/arm/meson.build | 1 +
 config/common_base     | 6 ++++++
 2 files changed, 7 insertions(+)
config/arm/meson.build +0 -0
index 979018e..18ecd53 100644
@@ -116,6 +116,7 @@ impl_dpaa = ['NXP DPAA', flags_dpaa,

machine_args_generic]

Quoted 15 lines
config/arm/meson.build +1 -0
 impl_dpaa2 = ['NXP DPAA2', flags_dpaa2, machine_args_generic]
 
 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
+dpdk_conf.set('RTE_ARM_USE_WFE', 0)
 
 if not dpdk_conf.get('RTE_ARCH_64')
        dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
config/common_base +0 -0
index 8ef75c2..d4cf974 100644
@@ -570,6 +570,12 @@ CONFIG_RTE_CRYPTO_MAX_DEVS=64
 CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO=n
 CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO_DEBUG=n
 
Quoted 9 lines

config/common_base CONFIG_RTE_CRYPTO_MAX_DEVS=64 · line 577

Quoted 5 lines
config/common_base +5 -0
+# 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

Since this comes as EAL config, IMO, it is better to move this to end of EAL section.
i.e move after CONFIG_RTE_USE_LIBBSD

Will fix it in next version.

Quoted 2 lines

And I think, we should squash this patch to "eal: add the APIs to wait until equall" as it single logical change.

Will fix it in next version.

Quoted 8 lines
Quoted 8 lines
config/common_base +1 -1
+
 #
 # Compile NXP CAAM JR crypto Driver
 #
--

2.7.4

author
#60 lore raw

PATCH v5 2/8 bus/fslmc: fix the conflicting dmb function

In reply to Gavin Hu

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 include the spinlock.h file before the other header files, this is inline with the coding style[2] about the "header includes". The fix changes the function to take the argument for arm to be meaningful.

[1] http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF0@i
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u
[2] https://doc.dpdk.org/guides/contributing/coding_style.html

Fixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")
---
 drivers/bus/fslmc/mc/fsl_mc_sys.h | 10 +++++++---
 drivers/bus/fslmc/mc/mc_sys.c     |  3 +--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/bus/fslmc/mc/fsl_mc_sys.h +7 -3
index d0c7b39..fe9dc95 100644
@@ -33,10 +33,14 @@ struct fsl_mc_io {
 #include <linux/byteorder/little_endian.h>
 
 #ifndef dmb
-#define dmb() {__asm__ __volatile__("" : : : "memory"); }
+#ifdef RTE_ARCH_ARM64
+#define dmb(opt) {asm volatile("dmb " #opt : : : "memory"); }
+#else
+#define dmb(opt)
 #endif
-#define __iormb()	dmb()
-#define __iowmb()	dmb()
+#endif
+#define __iormb()	dmb(ld)
+#define __iowmb()	dmb(st)
 #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))
drivers/bus/fslmc/mc/mc_sys.c +1 -2
index efafdc3..22143ef 100644
@@ -4,11 +4,10 @@
  * Copyright 2017 NXP
  *
  */
+#include <rte_spinlock.h>
 #include <fsl_mc_sys.h>
 #include <fsl_mc_cmd.h>
 
-#include <rte_spinlock.h>
-
 /** User space framework uses MC Portal in shared mode. Following change
  * introduces lock in MC FLIB
  */
Signature · 1 line
2.7.4
author
#61 lore raw

PATCH v5 3/8 eal: add the APIs to wait until equal

In reply to Gavin Hu

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
 .../common/include/arch/arm/rte_pause_64.h         | 30 +++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 98 +++++++++++++++++++++-
 2 files changed, 127 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +30 -0
index 93895d3..dabde17 100644
@@ -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +97 -1

117 lines not on this page · raw message

Signature · 1 line
2.7.4
#62 lore raw

Re: [dpdk-dev] [PATCH v5 3/8] eal: add the APIs to wait until equal

Quoted 49 lines · Gavin Hu

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

---
 .../common/include/arch/arm/rte_pause_64.h         | 30 +++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 98 +++++++++++++++++++++-
 2 files changed, 127 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +19 -0
index 93895d3..dabde17 100644
@@ -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+       type tmp; \
+       asm volatile( \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "b.eq   2f\n" \
+               "sevl\n" \
+               "1:     wfe\n" \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "bne    1b\n" \
+               "2:\n" \
+               : [tmp] "=&r" (tmp) \
+               : [addr] "Q"(*addr), [expected] "r"(expected) \

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 48

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+               : "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif

Looks good.

Quoted 9 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +0 -0
index 52bd4db..dfa6a53 100644

lib/librte_eal/common/include/generic/rte_pause.h line 7

Quoted 8 lines
lib/librte_eal/common/include/generic/rte_pause.h +1 -1
@@ -1,10 +1,10 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2017 Cavium, Inc
+ * Copyright(c) 2019 Arm Limited
  */
 
 #ifndef _RTE_PAUSE_H_
 #define _RTE_PAUSE_H_
-

Unwanted change.

Quoted 15 lines
lib/librte_eal/common/include/generic/rte_pause.h +4 -0
 /**
  * @file
  *
@@ -12,6 +12,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *

lib/librte_eal/common/include/generic/rte_pause.h line 28

Quoted 5 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
@@ -20,4 +24,96 @@
  */
 static inline void rte_pause(void);
 
+/**
+ * Wait for *addr to be updated with expected value

IMO, We need to mention relaxed attribute also in the comment.

Quoted 14 lines
lib/librte_eal/common/include/generic/rte_pause.h +13 -0
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  An expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_16(volatile uint16_t *addr, uint16_t expected);
 
+
+/**
+ * Wait for *addr to be updated with expected value
+ *

lib/librte_eal/common/include/generic/rte_pause.h line 99

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  An expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_64(volatile uint64_t *addr, uint64_t expected);
+
+#if !defined(RTE_ARM_USE_WFE)

Looks like there is a side effect as meson's build/rte_build_config.h comes as below
#define RTE_ARM_USE_WFE 0

So actually it is defined.

Quoted 23 lines
lib/librte_eal/common/include/generic/rte_pause.h +19 -1
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void    \
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+       type expected) \
+{ \
+       while (__atomic_load_n(addr, memorder) != expected) \
+               rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#63 lore raw

Re: [dpdk-dev] [PATCH v5 3/8] eal: add the APIs to wait until equal

Hi Jerin,

Quoted 90 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Friday, September 13, 2019 12:12 AM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: [email protected]; nd <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Pavan Nikhilesh <[email protected]>; Honnappa Nagarahalli <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 3/8] eal: add the APIs to wait until equal

Quoted 11 lines · Gavin Hu

The rte_wait_until_equalxx APIs abstract the functionality of 'polling for a memory location to become equal to a given value'.

Quoted 3 lines
---
 .../common/include/arch/arm/rte_pause_64.h         | 30 +++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 98

+++++++++++++++++++++-

Review

Quoted 3 lines
 2 files changed, 127 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 32 lines

index 93895d3..dabde17 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +19 -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+       type tmp; \
+       asm volatile( \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "b.eq   2f\n" \
+               "sevl\n" \
+               "1:     wfe\n" \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "bne    1b\n" \
+               "2:\n" \
+               : [tmp] "=&r" (tmp) \
+               : [addr] "Q"(*addr), [expected] "r"(expected) \

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 48

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+               : "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif

Looks good.

Review

Quoted 5 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
+
 #ifdef __cplusplus
 }
 #endif
(quoted diff) +0 -0

b/lib/librte_eal/common/include/generic/rte_pause.h

Quoted 9 lines

index 52bd4db..dfa6a53 100644

lib/librte_eal/common/include/generic/rte_pause.h +1 -0
@@ -1,10 +1,10 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2017 Cavium, Inc
+ * Copyright(c) 2019 Arm Limited
  */
 
Quoted 5 lines

lib/librte_eal/common/include/generic/rte_pause.h line 7

Quoted 3 lines
lib/librte_eal/common/include/generic/rte_pause.h +0 -1
 #ifndef _RTE_PAUSE_H_
 #define _RTE_PAUSE_H_
-

Unwanted change.

Will fix it.

Quoted 19 lines
Quoted 19 lines
lib/librte_eal/common/include/generic/rte_pause.h +4 -0
 /**
  * @file
  *
@@ -12,6 +12,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +24,96 @@
  */
 static inline void rte_pause(void);
 
Quoted 4 lines

lib/librte_eal/common/include/generic/rte_pause.h line 28

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+/**
+ * Wait for *addr to be updated with expected value

IMO, We need to mention relaxed attribute also in the comment.

Will fix it.

Quoted 25 lines

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +9 -0
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  An expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_16(volatile uint16_t *addr, uint16_t

expected);

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 12 lines
lib/librte_eal/common/include/generic/rte_pause.h +12 -0
+
+/**
+ * Wait for *addr to be updated with expected value
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  An expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_64(volatile uint64_t *addr, uint64_t

expected);

Quoted 8 lines

lib/librte_eal/common/include/generic/rte_pause.h line 51

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+
+#if !defined(RTE_ARM_USE_WFE)

Looks like there is a side effect as meson's build/rte_build_config.h comes as below
#define RTE_ARM_USE_WFE 0

So actually it is defined.

Good catch, thanks, will fix it.

Quoted 24 lines
Quoted 24 lines
lib/librte_eal/common/include/generic/rte_pause.h +19 -1
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void    \
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+       type expected) \
+{ \
+       while (__atomic_load_n(addr, memorder) != expected) \
+               rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

author
#64 lore raw

PATCH v5 4/8 spinlock: use wfe to reduce contention on aarch64

In reply to Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running the micro benchmarking and the testpmd and l3fwd traffic tests on ThunderX2, Ampere eMAG80 and Arm N1SDP, everything went well and no notable performance gain nor degradation was measured.

---
 .../common/include/arch/arm/rte_spinlock.h         | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +26 -0
index 1a6916b..b61c055 100644
@@ -16,6 +16,32 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#ifndef RTE_FORCE_INTRINSICS
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+	unsigned int tmp;
+	/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"1:	ldaxr %w[tmp], %w[locked]\n"
+		"cbnz   %w[tmp], 2f\n"
+		"stxr   %w[tmp], %w[one], %w[locked]\n"
+		"cbnz   %w[tmp], 1b\n"
+		"ret\n"
+		"2:	sevl\n"
+		"wfe\n"
+		"jmp	1b\n"
+		: [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+		: [one] "r" (1)
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
 	return 0;
Signature · 1 line
2.7.4
author
#65 lore raw

PATCH v5 5/8 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

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
index d9bec87..232bbe9 100644
@@ -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_acquire_16(&tl->s.current, me);
 }
 
 /**
Signature · 1 line
2.7.4
Reviewed-by on v5 5/8
#66 lore raw

Re: [dpdk-dev] [PATCH v5 5/8] ticketlock: use new API to reduce contention on aarch64

Quoted 8 lines · Gavin Hu

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.

Quoted 7 lines

[1] https://community.arm.com/developer/tools-software/oss-platforms/w/\
docs/440/neoverse-n1-sdp

author
#67 lore raw

PATCH v5 6/8 ring: use wfe to wait for ring tail update on aarch64

In reply to Gavin Hu

Instead of polling for tail to be updated, use wfe instruction.

---
 lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
 lib/librte_ring/rte_ring_generic.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring_c11_mem.h +2 -2
index 0fb73a3..764d8f1 100644
@@ -2,6 +2,7 @@
  *
  * Copyright (c) 2017,2018 HXT-semitech Corporation.
  * Copyright (c) 2007-2009 Kip Macy [email protected]
+ * Copyright (c) 2019 Arm Limited
  * All rights reserved.
  * Derived from FreeBSD's bufring.h
  * Used as BSD-3 Licensed with permission from Kip Macy.
@@ -21,8 +22,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
 
 	__atomic_store_n(&ht->tail, new_val, __ATOMIC_RELEASE);
 }
lib/librte_ring/rte_ring_generic.h +1 -2
index 953cdbb..6828527 100644
@@ -23,8 +23,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
 
 	ht->tail = new_val;
 }
Signature · 1 line
2.7.4
author
#68 lore raw

PATCH v5 7/8 net/thunderx: use new API to save cycles on aarch64

In reply to Gavin Hu

Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.

---
 drivers/net/thunderx/nicvf_rxtx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/thunderx/nicvf_rxtx.c +1 -2
index 1c42874..16f34c6 100644
@@ -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_relaxed_32(&rbdr->tail, next_tail);
 
 	__atomic_store_n(&rbdr->tail, ltail, __ATOMIC_RELEASE);
 	nicvf_addr_write(door, to_fill);
Signature · 1 line
2.7.4
Acked-by on v5 7/8
#69 lore raw

Re: [dpdk-dev] [PATCH v5 7/8] net/thunderx: use new API to save cycles on aarch64

Quoted 6 lines · Gavin Hu

Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.

Quoted 21 lines
---
 drivers/net/thunderx/nicvf_rxtx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/thunderx/nicvf_rxtx.c +1 -3
index 1c42874..16f34c6 100644
@@ -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_relaxed_32(&rbdr->tail, next_tail);
 
        __atomic_store_n(&rbdr->tail, ltail, __ATOMIC_RELEASE);
        nicvf_addr_write(door, to_fill);
--

2.7.4

author
#70 lore raw

PATCH v5 8/8 event/opdl: use new API to save cycles on aarch64

In reply to Gavin Hu

Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.

---
 drivers/event/opdl/opdl_ring.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/event/opdl/opdl_ring.c +2 -3
index e8b29e2..f446fa3 100644
@@ -17,6 +17,7 @@
 #include <rte_memory.h>
 #include <rte_memzone.h>
 #include <rte_eal_memconfig.h>
+#include <rte_atomic.h>
 
 #include "opdl_ring.h"
 #include "opdl_log.h"
@@ -475,9 +476,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_acquire_32(&s->shared.tail, old_head);
 
 	__atomic_store_n(&s->shared.tail, old_head + num_entries,
 			__ATOMIC_RELEASE);
Signature · 1 line
2.7.4
Reviewed-by on v5 8/8
#71 lore raw

Re: [dpdk-dev] [PATCH v5 8/8] event/opdl: use new API to save cycles on aarch64

Quoted 6 lines · Gavin Hu

Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.

Quoted 30 lines
---
 drivers/event/opdl/opdl_ring.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/event/opdl/opdl_ring.c +2 -4
index e8b29e2..f446fa3 100644
@@ -17,6 +17,7 @@
 #include <rte_memory.h>
 #include <rte_memzone.h>
 #include <rte_eal_memconfig.h>
+#include <rte_atomic.h>
 
 #include "opdl_ring.h"
 #include "opdl_log.h"
@@ -475,9 +476,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_acquire_32(&s->shared.tail, old_head);
 
        __atomic_store_n(&s->shared.tail, old_head + num_entries,
                        __ATOMIC_RELEASE);
--

2.7.4

author
#72 lore raw

v6 cover use WFE for aarch64

In reply to Gavin Hu

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

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_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_ARM_USE_WFE should be enabled depending on the performance benchmarking on the target platforms. Power saving should be an bonus, but currenly we don't have ways to characterize that.

Gavin Hu (7):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
spinlock: use wfe to reduce contention on aarch64
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update 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                  |  10 +-
 drivers/bus/fslmc/mc/mc_sys.c                      |   3 +-
 drivers/event/opdl/opdl_ring.c                     |   5 +-
 drivers/net/thunderx/nicvf_rxtx.c                  |   3 +-
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 .../common/include/arch/arm/rte_spinlock.h         |  26 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 103 +++++++++++++++++++++
 .../common/include/generic/rte_ticketlock.h        |   3 +-
 lib/librte_ring/rte_ring_c11_mem.h                 |   4 +-
 lib/librte_ring/rte_ring_generic.h                 |   3 +-
 12 files changed, 180 insertions(+), 16 deletions(-)
Signature · 1 line
2.7.4
author
#73 lore raw

PATCH v6 1/7 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 include the spinlock.h file before the other header files, this is inline with the coding style[2] about the "header includes". The fix changes the function to take the argument for arm to be meaningful.

[1] http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF0@i
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u
[2] https://doc.dpdk.org/guides/contributing/coding_style.html

Fixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")
---
 drivers/bus/fslmc/mc/fsl_mc_sys.h | 10 +++++++---
 drivers/bus/fslmc/mc/mc_sys.c     |  3 +--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/bus/fslmc/mc/fsl_mc_sys.h +7 -3
index d0c7b39..fe9dc95 100644
@@ -33,10 +33,14 @@ struct fsl_mc_io {
 #include <linux/byteorder/little_endian.h>
 
 #ifndef dmb
-#define dmb() {__asm__ __volatile__("" : : : "memory"); }
+#ifdef RTE_ARCH_ARM64
+#define dmb(opt) {asm volatile("dmb " #opt : : : "memory"); }
+#else
+#define dmb(opt)
 #endif
-#define __iormb()	dmb()
-#define __iowmb()	dmb()
+#endif
+#define __iormb()	dmb(ld)
+#define __iowmb()	dmb(st)
 #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))
drivers/bus/fslmc/mc/mc_sys.c +1 -2
index efafdc3..22143ef 100644
@@ -4,11 +4,10 @@
  * Copyright 2017 NXP
  *
  */
+#include <rte_spinlock.h>
 #include <fsl_mc_sys.h>
 #include <fsl_mc_cmd.h>
 
-#include <rte_spinlock.h>
-
 /** User space framework uses MC Portal in shared mode. Following change
  * introduces lock in MC FLIB
  */
Signature · 1 line
2.7.4
author
#74 lore raw

PATCH v6 2/7 eal: add the APIs to wait until equal

In reply to Gavin Hu

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.

---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 103 +++++++++++++++++++++
 4 files changed, 139 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -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 +30 -0
index 93895d3..dabde17 100644
@@ -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +103 -0

118 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#75 lore raw

PATCH v6 3/7 spinlock: use wfe to reduce contention on aarch64

In reply to Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running the micro benchmarking and the testpmd and l3fwd traffic tests on ThunderX2, Ampere eMAG80 and Arm N1SDP, everything went well and no notable performance gain nor degradation was measured.

---
 .../common/include/arch/arm/rte_spinlock.h         | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +26 -0
index 1a6916b..b61c055 100644
@@ -16,6 +16,32 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#ifndef RTE_FORCE_INTRINSICS
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+	unsigned int tmp;
+	/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"1:	ldaxr %w[tmp], %w[locked]\n"
+		"cbnz   %w[tmp], 2f\n"
+		"stxr   %w[tmp], %w[one], %w[locked]\n"
+		"cbnz   %w[tmp], 1b\n"
+		"ret\n"
+		"2:	sevl\n"
+		"wfe\n"
+		"jmp	1b\n"
+		: [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+		: [one] "r" (1)
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
 	return 0;
Signature · 1 line
2.7.4
author
#76 lore raw

PATCH v6 4/7 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

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
index d9bec87..232bbe9 100644
@@ -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_acquire_16(&tl->s.current, me);
 }
 
 /**
Signature · 1 line
2.7.4
author
#77 lore raw

PATCH v6 5/7 ring: use wfe to wait for ring tail update on aarch64

In reply to Gavin Hu

Instead of polling for tail to be updated, use wfe instruction.

---
 lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
 lib/librte_ring/rte_ring_generic.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring_c11_mem.h +2 -2
index 0fb73a3..764d8f1 100644
@@ -2,6 +2,7 @@
  *
  * Copyright (c) 2017,2018 HXT-semitech Corporation.
  * Copyright (c) 2007-2009 Kip Macy [email protected]
+ * Copyright (c) 2019 Arm Limited
  * All rights reserved.
  * Derived from FreeBSD's bufring.h
  * Used as BSD-3 Licensed with permission from Kip Macy.
@@ -21,8 +22,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
 
 	__atomic_store_n(&ht->tail, new_val, __ATOMIC_RELEASE);
 }
lib/librte_ring/rte_ring_generic.h +1 -2
index 953cdbb..6828527 100644
@@ -23,8 +23,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
 
 	ht->tail = new_val;
 }
Signature · 1 line
2.7.4
author
#78 lore raw

PATCH v6 6/7 net/thunderx: use new API to save cycles on aarch64

In reply to Gavin Hu

Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.

---
 drivers/net/thunderx/nicvf_rxtx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/thunderx/nicvf_rxtx.c +1 -2
index 1c42874..16f34c6 100644
@@ -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_relaxed_32(&rbdr->tail, next_tail);
 
 	__atomic_store_n(&rbdr->tail, ltail, __ATOMIC_RELEASE);
 	nicvf_addr_write(door, to_fill);
Signature · 1 line
2.7.4
author
#79 lore raw

PATCH v6 7/7 event/opdl: use new API to save cycles on aarch64

In reply to Gavin Hu

Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.

---
 drivers/event/opdl/opdl_ring.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/event/opdl/opdl_ring.c +2 -3
index e8b29e2..f446fa3 100644
@@ -17,6 +17,7 @@
 #include <rte_memory.h>
 #include <rte_memzone.h>
 #include <rte_eal_memconfig.h>
+#include <rte_atomic.h>
 
 #include "opdl_ring.h"
 #include "opdl_log.h"
@@ -475,9 +476,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_acquire_32(&s->shared.tail, old_head);
 
 	__atomic_store_n(&s->shared.tail, old_head + num_entries,
 			__ATOMIC_RELEASE);
Signature · 1 line
2.7.4
Acked-by on the v6 series
#80 lore raw

Re: [dpdk-dev] [PATCH v6 0/7] use WFE for aarch64

In reply to Gavin Hu
Quoted 53 lines · Gavin Hu

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

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_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_ARM_USE_WFE should be enabled depending on the performance benchmarking on the target platforms. Power saving should be an bonus, but currenly we don't have ways to characterize that.

Quoted 8 lines

Gavin Hu (7):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
spinlock: use wfe to reduce contention on aarch64
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update on aarch64 net/thunderx: use new API to save cycles on aarch64 event/opdl: use new API to save cycles on aarch64

There is checkpatch failure.
### eal: add the APIs to wait until equal

WARNING:LONG_LINE_COMMENT: line over 80 characters
#123: FILE: lib/librte_eal/common/include/generic/rte_pause.h:29:
+ * Wait for *addr to be updated with a 16-bit expected value, with a relaxed memory

With checkpatch fixes:

#81 lore raw

Re: [dpdk-dev] [PATCH v6 0/7] use WFE for aarch64

Quoted 4 lines

There is checkpatch failure.
### eal: add the APIs to wait until equal

Quoted 8 lines

WARNING:LONG_LINE_COMMENT: line over 80 characters
#123: FILE: lib/librte_eal/common/include/generic/rte_pause.h:29:
+ * Wait for *addr to be updated with a 16-bit expected value, with a relaxed memory

With checkpatch fixes:

Thanks Jerin for review, sorry for this leakage, it was fixed in the new version(v7, already posted).

author
#82 lore raw

v7 cover use WFE for aarch64

In reply to Gavin Hu

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

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_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_ARM_USE_WFE should be enabled depending on the performance benchmarking on the target platforms. Power saving should be an bonus, but currenly we don't have ways to characterize that.

Gavin Hu (7):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
spinlock: use wfe to reduce contention on aarch64
ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update 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                  |  10 +-
 drivers/bus/fslmc/mc/mc_sys.c                      |   3 +-
 drivers/event/opdl/opdl_ring.c                     |   5 +-
 drivers/net/thunderx/nicvf_rxtx.c                  |   3 +-
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 .../common/include/arch/arm/rte_spinlock.h         |  26 +++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106 +++++++++++++++++++++
 .../common/include/generic/rte_ticketlock.h        |   3 +-
 lib/librte_ring/rte_ring_c11_mem.h                 |   4 +-
 lib/librte_ring/rte_ring_generic.h                 |   3 +-
 12 files changed, 183 insertions(+), 16 deletions(-)
Signature · 1 line
2.7.4
author
#83 lore raw

PATCH v7 1/7 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 include the spinlock.h file before the other header files, this is inline with the coding style[2] about the "header includes". The fix changes the function to take the argument for arm to be meaningful.

[1] http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF0@i
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u
[2] https://doc.dpdk.org/guides/contributing/coding_style.html

Fixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")
---
 drivers/bus/fslmc/mc/fsl_mc_sys.h | 10 +++++++---
 drivers/bus/fslmc/mc/mc_sys.c     |  3 +--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/bus/fslmc/mc/fsl_mc_sys.h +7 -3
index d0c7b39..fe9dc95 100644
@@ -33,10 +33,14 @@ struct fsl_mc_io {
 #include <linux/byteorder/little_endian.h>
 
 #ifndef dmb
-#define dmb() {__asm__ __volatile__("" : : : "memory"); }
+#ifdef RTE_ARCH_ARM64
+#define dmb(opt) {asm volatile("dmb " #opt : : : "memory"); }
+#else
+#define dmb(opt)
 #endif
-#define __iormb()	dmb()
-#define __iowmb()	dmb()
+#endif
+#define __iormb()	dmb(ld)
+#define __iowmb()	dmb(st)
 #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))
drivers/bus/fslmc/mc/mc_sys.c +1 -2
index efafdc3..22143ef 100644
@@ -4,11 +4,10 @@
  * Copyright 2017 NXP
  *
  */
+#include <rte_spinlock.h>
 #include <fsl_mc_sys.h>
 #include <fsl_mc_cmd.h>
 
-#include <rte_spinlock.h>
-
 /** User space framework uses MC Portal in shared mode. Following change
  * introduces lock in MC FLIB
  */
Signature · 1 line
2.7.4
#85 lore raw

Re: [dpdk-dev] [PATCH v7 1/7] bus/fslmc: fix the conflicting dmb function

In reply to Gavin Hu
Quoted 8 lines · Gavin Hu

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"); }

Interesting, this means that we have a leftover macro from the arm header that can pollute the namespace.

Anyway, this driver is not using the memory barrier api from the EAL.

How about simply fixing with?
#define __iormb() rte_io_rmb()
#define __iowmb() rte_io_wmb()

Quoted 8 lines

The fix is to include the spinlock.h file before the other header files, this is inline with the coding style[2] about the "header includes". The fix changes the function to take the argument for arm to be meaningful.

[1] http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF0@i
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u

This url is broken, there is a trailing i on the first line.

Quoted 7 lines

[2] https://doc.dpdk.org/guides/contributing/coding_style.html

Fixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")
Signature · 1 line
David Marchand
author
#86 lore raw

PATCH v7 2/7 eal: add the APIs to wait until equal

In reply to Gavin Hu

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.

---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106 +++++++++++++++++++++
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -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 +30 -0
index 93895d3..dabde17 100644
@@ -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +106 -0

121 lines not on this page · raw message

Signature · 1 line
2.7.4
Acked-by on v7 2/7
#87 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Quoted 8 lines · Gavin Hu

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.

Quoted 7 lines
#88 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

In reply to Gavin Hu

Hi Gavin,

Quoted 179 lines

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.

---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106 +++++++++++++++++++++
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -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 +30 -0
index 93895d3..dabde17 100644
@@ -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +61 -0
index 52bd4db..8906473 100644
@@ -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,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +25,105 @@
  */
 static inline void rte_pause(void);
 
+/**
+ * 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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_16(volatile uint16_t *addr, uint16_t expected);
+
+/**
+ * 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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_32(volatile uint32_t *addr, uint32_t expected);
+
+/**
+ * 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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_64(volatile uint64_t *addr, uint64_t expected);
+
+/**
+ * Wait for *addr to be updated with a 16-bit expected value, with an acquire
+ * memory ordering model meaning the loads after this API can't be observed
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 16-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_16(volatile uint16_t *addr, uint16_t expected);
+
+/**
+ * Wait for *addr to be updated with a 32-bit expected value, with an acquire
+ * memory ordering model meaning the loads after this API can't be observed

lib/librte_eal/common/include/generic/rte_pause.h line 93

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 32-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_32(volatile uint32_t *addr, uint32_t expected);

LGTM in general.
One stylish thing: wouldn't it be better to have an API like that:
rte_wait_until_equal_acquire_X(addr, expected, memory_order) ?

I.E. - pass memorder as parameter, not to incorporate it into function name? Less functions, plus user can specify order himself.
Plus looks similar to C11 atomic instrincts.

Quoted 38 lines
lib/librte_eal/common/include/generic/rte_pause.h +35 -1
+
+/**
+ * Wait for *addr to be updated with a 64-bit expected value, with an acquire
+ * memory ordering model meaning the loads after this API can't be observed
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_64(volatile uint64_t *addr, uint64_t expected);
+
+#if !defined(RTE_ARM_USE_WFE)
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void	\
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+	type expected) \
+{ \
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#89 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Quoted 224 lines

-----Original Message-----
From: Ananyev, Konstantin <[email protected]>
Sent: Thursday, October 17, 2019 9:15 PM
To: Gavin Hu (Arm Technology China) <[email protected]>; [email protected]
Cc: nd <[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: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Hi Gavin,

Quoted 15 lines

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.

Quoted 5 lines
---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106

+++++++++++++++++++++

Quoted 20 lines
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -111,6 +111,11 @@ CONFIG_RTE_MAX_VFIO_CONTAINERS=64
 CONFIG_RTE_MALLOC_DEBUG=n

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64 · line 121

Quoted 10 lines
config/common_base +5 -0
 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.

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Review

Quoted 47 lines

index 93895d3..dabde17 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +30 -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
(quoted diff) +0 -0

b/lib/librte_eal/common/include/generic/rte_pause.h

Quoted 22 lines

index 52bd4db..8906473 100644

lib/librte_eal/common/include/generic/rte_pause.h +5 -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,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *

lib/librte_eal/common/include/generic/rte_pause.h line 29

Quoted 5 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
@@ -20,4 +25,105 @@
  */
 static inline void rte_pause(void);
 
+/**
+ * Wait for *addr to be updated with a 16-bit expected value, with a

relaxed

lib/librte_eal/common/include/generic/rte_pause.h line 30

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

lib/librte_eal/common/include/generic/rte_pause.h

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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_16(volatile uint16_t *addr, uint16_t

expected);

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

lib/librte_eal/common/include/generic/rte_pause.h line 43

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

lib/librte_eal/common/include/generic/rte_pause.h

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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_32(volatile uint32_t *addr, uint32_t

expected);

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

lib/librte_eal/common/include/generic/rte_pause.h line 56

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

lib/librte_eal/common/include/generic/rte_pause.h

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 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_64(volatile uint64_t *addr, uint64_t

expected);

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 an

acquire

lib/librte_eal/common/include/generic/rte_pause.h line 69

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 16-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_16(volatile uint16_t *addr, uint16_t

expected);

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 an

acquire

lib/librte_eal/common/include/generic/rte_pause.h line 83

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 32-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_32(volatile uint32_t *addr, uint32_t

expected);

Quoted 9 lines

LGTM in general.
One stylish thing: wouldn't it be better to have an API like that:
rte_wait_until_equal_acquire_X(addr, expected, memory_order) ?

I.E. - pass memorder as parameter, not to incorporate it into function name? Less functions, plus user can specify order himself.
Plus looks similar to C11 atomic instrincts.

Thanks for your comment, will fix this in v8.

Quoted 41 lines

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 an

acquire

lib/librte_eal/common/include/generic/rte_pause.h line 97

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_64(volatile uint64_t *addr, uint64_t

expected);

Quoted 24 lines
lib/librte_eal/common/include/generic/rte_pause.h +21 -1
+
+#if !defined(RTE_ARM_USE_WFE)
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void	\
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+	type expected) \
+{ \
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#90 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

In reply to Gavin Hu
Quoted 7 lines · Gavin Hu

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.

- As discussed on irc, I would prefer we have two stages for this:
* first stage, an architecture announces it has its own implementation of this api, in such a case it defines RTE_ARCH_HAS_WFE in its arch/xxx/rte_pause.h header before including generic/rte_pause.h The default implementation with C11 is then skipped in the generic header.
* second stage, in the arm64 header, if RTE_ARM_USE_WFE is set in the configuration, then define RTE_ARCH_HAS_WFE

- Can you add a little description on the limitation of using WFE instruction in the commit log?

- This is a new api, should be marked experimental, even if inlined.

Small comments inline.

Quoted 75 lines
---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106 +++++++++++++++++++++
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -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 +18 -0
index 93895d3..dabde17 100644
@@ -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+       type tmp; \
+       asm volatile( \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "b.eq   2f\n" \
+               "sevl\n" \
+               "1:     wfe\n" \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "bne    1b\n" \
+               "2:\n" \
+               : [tmp] "=&r" (tmp) \

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 47

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+               : [addr] "Q"(*addr), [expected] "r"(expected) \
+               : "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)

Missing #undef __WAIT_UNTIL_EQUAL

Quoted 28 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +2 -0
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +5 -0
index 52bd4db..8906473 100644
@@ -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,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *

lib/librte_eal/common/include/generic/rte_pause.h line 28

Quoted 4 lines
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
@@ -20,4 +25,105 @@
  */
 static inline void rte_pause(void);
 
+/**

Missing warning on experimental api.

lib/librte_eal/common/include/generic/rte_pause.h line 36

Quoted 8 lines
lib/librte_eal/common/include/generic/rte_pause.h +8 -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.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 16-bit expected value to be in the memory location.
+ */

Missing experimental tag.
Saying this only once, please update declarations below, plus doxygen header.

Quoted 80 lines
lib/librte_eal/common/include/generic/rte_pause.h +80 -0
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_16(volatile uint16_t *addr, uint16_t expected);
+
+/**
+ * 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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_32(volatile uint32_t *addr, uint32_t expected);
+
+/**
+ * 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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_64(volatile uint64_t *addr, uint64_t expected);
+
+/**
+ * Wait for *addr to be updated with a 16-bit expected value, with an acquire
+ * memory ordering model meaning the loads after this API can't be observed
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 16-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_16(volatile uint16_t *addr, uint16_t expected);
+
+/**
+ * Wait for *addr to be updated with a 32-bit expected value, with an acquire
+ * memory ordering model meaning the loads after this API can't be observed
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 32-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_32(volatile uint32_t *addr, uint32_t expected);
+
+/**
+ * Wait for *addr to be updated with a 64-bit expected value, with an acquire
+ * memory ordering model meaning the loads after this API can't be observed
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_64(volatile uint64_t *addr, uint64_t expected);
+
+#if !defined(RTE_ARM_USE_WFE)
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void    \
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+       type expected) \
+{ \
+       while (__atomic_load_n(addr, memorder) != expected) \

lib/librte_eal/common/include/generic/rte_pause.h line 126

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+               rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)

#undef __WAIT_UNTIL_EQUAL

Quoted 6 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -1
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

Signature · 1 line
David Marchand
#91 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Hi David,

One comment about the experimental tag for the API inlined. /Gavin

Quoted 22 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Thursday, October 17, 2019 11:45 PM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: dev <[email protected]>; nd <[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: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Quoted 7 lines · Gavin Hu

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.

Quoted 8 lines

- As discussed on irc, I would prefer we have two stages for this:
* first stage, an architecture announces it has its own implementation of this api, in such a case it defines RTE_ARCH_HAS_WFE in its arch/xxx/rte_pause.h header before including generic/rte_pause.h The default implementation with C11 is then skipped in the generic
header.
* second stage, in the arm64 header, if RTE_ARM_USE_WFE is set in the configuration, then define RTE_ARCH_HAS_WFE

Will fix in v8

Quoted 2 lines

- Can you add a little description on the limitation of using WFE instruction in the commit log?

Will fix in v8

Quoted 2 lines

- This is a new api, should be marked experimental, even if inlined.

It is ok to add for the patches except the rte_ring, which called the API in the .h file, other than the .c file.
For the .h file is included by a lot of components, which require adding 'allowing_experimenal_apis = true' to the meson.build and makefile. I am worried adding too many of these changes is confusing. I may leave this patch out of the series if there is no decorous solutions. /Gavin

Quoted 85 lines

Small comments inline.

Quoted 8 lines
Quoted 5 lines
---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106

+++++++++++++++++++++

Quoted 20 lines
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -111,6 +111,11 @@ CONFIG_RTE_MAX_VFIO_CONTAINERS=64
 CONFIG_RTE_MALLOC_DEBUG=n

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64 · line 121

Quoted 10 lines
config/common_base +5 -0
 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.

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 35 lines

index 93895d3..dabde17 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +22 -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+       type tmp; \
+       asm volatile( \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "b.eq   2f\n" \
+               "sevl\n" \
+               "1:     wfe\n" \
+               #asm_op " %" #wide "[tmp], %[addr]\n" \
+               "cmp    %" #wide "[tmp], %" #wide "[expected]\n" \
+               "bne    1b\n" \
+               "2:\n" \
+               : [tmp] "=&r" (tmp) \
+               : [addr] "Q"(*addr), [expected] "r"(expected) \
+               : "cc", "memory"); \
+}
+/* Wait for *addr to be updated with expected value */
Quoted 8 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 47

Quoted 6 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)

Missing #undef __WAIT_UNTIL_EQUAL

Will fix in v8

Quoted 33 lines

Review

Quoted 7 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +2 -0
+#endif
+
 #ifdef __cplusplus
 }
 #endif
(quoted diff) +0 -0

b/lib/librte_eal/common/include/generic/rte_pause.h

Quoted 25 lines

index 52bd4db..8906473 100644

lib/librte_eal/common/include/generic/rte_pause.h +5 -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,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +25,105 @@
  */
 static inline void rte_pause(void);
 
Quoted 3 lines

lib/librte_eal/common/include/generic/rte_pause.h line 28

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+/**

Missing warning on experimental api.

Will add it in v8.

Quoted 12 lines

lib/librte_eal/common/include/generic/rte_pause.h line 29

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * Wait for *addr to be updated with a 16-bit expected value, with a

relaxed

lib/librte_eal/common/include/generic/rte_pause.h line 30

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

lib/librte_eal/common/include/generic/rte_pause.h line 36

Quoted 6 lines
lib/librte_eal/common/include/generic/rte_pause.h +6 -0
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 16-bit expected value to be in the memory location.
+ */
Quoted 3 lines

Missing experimental tag.
Saying this only once, please update declarations below, plus doxygen header.

Will fix all in v8.

Quoted 120 lines

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 4 lines
lib/librte_eal/common/include/generic/rte_pause.h +3 -0
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_16(volatile uint16_t *addr, uint16_t

expected);

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

lib/librte_eal/common/include/generic/rte_pause.h line 43

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

lib/librte_eal/common/include/generic/rte_pause.h

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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_32(volatile uint32_t *addr, uint32_t

expected);

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

lib/librte_eal/common/include/generic/rte_pause.h line 56

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

lib/librte_eal/common/include/generic/rte_pause.h

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 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_64(volatile uint64_t *addr, uint64_t

expected);

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 an

acquire

lib/librte_eal/common/include/generic/rte_pause.h line 69

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 16-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_16(volatile uint16_t *addr, uint16_t

expected);

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 an

acquire

lib/librte_eal/common/include/generic/rte_pause.h line 83

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 32-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_32(volatile uint32_t *addr, uint32_t

expected);

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 an

acquire

lib/librte_eal/common/include/generic/rte_pause.h line 97

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_64(volatile uint64_t *addr, uint64_t

expected);

Quoted 9 lines
lib/librte_eal/common/include/generic/rte_pause.h +9 -0
+
+#if !defined(RTE_ARM_USE_WFE)
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void    \
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+       type expected) \
+{ \
+       while (__atomic_load_n(addr, memorder) != expected) \

lib/librte_eal/common/include/generic/rte_pause.h line 126

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+               rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)

#undef __WAIT_UNTIL_EQUAL

Quoted 6 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -1
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

--
David Marchand

#92 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Quoted 6 lines · Gavin Hu (Arm Technology China)
Quoted 3 lines

-----Original Message-----
From: David Marchand <[email protected]>
- This is a new api, should be marked experimental, even if inlined.

It is ok to add for the patches except the rte_ring, which called the API in the .h file, other than the .c file.
For the .h file is included by a lot of components, which require adding 'allowing_experimenal_apis = true' to the meson.build and makefile. I am worried adding too many of these changes is confusing. I may leave this patch out of the series if there is no decorous solutions.

You can still keep the current code in the ring headers under a #ifndef ALLOW_EXPERIMENTAL_API banner and put the call to your new experimental api in the #else part of it.
Something like:

#ifndef ALLOW_EXPERIMENTAL_API
                while (unlikely(ht->tail != old_val))
                        rte_pause();
#else
                rte_wait_until_equal_relaxed_32(&ht->tail, old_val);

#endif

This way, if the application enables the experimental api, then the ring code will benefit from it, else it will rely on the current stable code.

Signature · 1 line
David Marchand
#93 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

In reply to Gavin Hu
Quoted 81 lines

Hi Gavin,

Quoted 77 lines

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.

---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106 +++++++++++++++++++++
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -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 +13 -0
index 93895d3..dabde17 100644
@@ -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
Quoted 8 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 40

Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +8 -0
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}

One more thought:
Why do you need to write asm code for the whole procedure? Why not to do like linux kernel:
define wfe() and sev() macros and use them inside normal C code?

#define sev() asm volatile("sev" : : : "memory")
#define wfe() asm volatile("wfe" : : : "memory")

Then:
rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, int memorder)

{
     if (__atomic_load_n(addr, memorder) != expected) {
         sev();
         do {
             wfe();
         } while ((__atomic_load_n(addr, memorder) != expected);
     }
}

?

Quoted 153 lines
Quoted 94 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +9 -0
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +61 -0
index 52bd4db..8906473 100644
@@ -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,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +25,105 @@
  */
 static inline void rte_pause(void);
 
+/**
+ * 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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_16(volatile uint16_t *addr, uint16_t expected);
+
+/**
+ * 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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_32(volatile uint32_t *addr, uint32_t expected);
+
+/**
+ * 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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_64(volatile uint64_t *addr, uint64_t expected);
+
+/**
+ * Wait for *addr to be updated with a 16-bit expected value, with an acquire
+ * memory ordering model meaning the loads after this API can't be observed
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 16-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_16(volatile uint16_t *addr, uint16_t expected);
+
+/**
+ * Wait for *addr to be updated with a 32-bit expected value, with an acquire
+ * memory ordering model meaning the loads after this API can't be observed

lib/librte_eal/common/include/generic/rte_pause.h line 93

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 32-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_32(volatile uint32_t *addr, uint32_t expected);

LGTM in general.
One stylish thing: wouldn't it be better to have an API like that:
rte_wait_until_equal_acquire_X(addr, expected, memory_order) ?

I.E. - pass memorder as parameter, not to incorporate it into function name? Less functions, plus user can specify order himself.
Plus looks similar to C11 atomic instrincts.

Quoted 38 lines
lib/librte_eal/common/include/generic/rte_pause.h +35 -1
+
+/**
+ * Wait for *addr to be updated with a 64-bit expected value, with an acquire
+ * memory ordering model meaning the loads after this API can't be observed
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_64(volatile uint64_t *addr, uint64_t expected);
+
+#if !defined(RTE_ARM_USE_WFE)
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void	\
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+	type expected) \
+{ \
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#94 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Hi Konstantin,

Quoted 126 lines

-----Original Message-----
From: Ananyev, Konstantin <[email protected]>
Sent: Friday, October 18, 2019 12:44 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]; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang (Arm Technology China) <[email protected]>; Phil Yang (Arm Technology China) <[email protected]>; Steve Capper <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Quoted 23 lines

Hi Gavin,

Quoted 20 lines

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.

---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106

+++++++++++++++++++++

Quoted 28 lines
Quoted 28 lines
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -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
 
Quoted 2 lines

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64 · line 121

Quoted 2 lines
config/common_base +0 -0
 #
 # Recognize/ignore the AVX/AVX512 CPU flags for performance/power

testing.

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 26 lines
Quoted 26 lines

index 93895d3..dabde17 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +13 -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
Quoted 8 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 40

Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +8 -0
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}

One more thought:
Why do you need to write asm code for the whole procedure? Why not to do like linux kernel:
define wfe() and sev() macros and use them inside normal C code?

#define sev() asm volatile("sev" : : : "memory")
#define wfe() asm volatile("wfe" : : : "memory")

Then:
rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, int memorder)

{
     if (__atomic_load_n(addr, memorder) != expected) {
         sev();
         do {
             wfe();
         } while ((__atomic_load_n(addr, memorder) != expected);
     }
}
Quoted 1 line

?

A really good suggestion, I made corresponding changes to v8 already, but it missed a armv8 specific feature after internal discussion.
We call wfe to wait/sleep on the 'monitored' address, it will be waken up upon someone write to the monitor address, so before wfe, we have to call load-exclusive instruction to 'monitor'. __atomic_load_n - disassembled to "ldr" does not do so. We have to use "ldxrh" for relaxed mem ordering and "ldaxrh" for acquire ordering, in example of 16-bit.

Let me re-think coming back to the full assembly procedure or implementing a 'load-exclusive' function. What do you think? /Gavin

Quoted 173 lines
Quoted 5 lines
Quoted 5 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +5 -0
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
Quoted 8 lines

Review

Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +4 -0
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
(quoted diff) +0 -0

b/lib/librte_eal/common/include/generic/rte_pause.h

Quoted 25 lines
Quoted 25 lines

index 52bd4db..8906473 100644

lib/librte_eal/common/include/generic/rte_pause.h +5 -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,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +25,105 @@
  */
 static inline void rte_pause(void);
 
Quoted 2 lines

lib/librte_eal/common/include/generic/rte_pause.h line 29

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+/**
+ * Wait for *addr to be updated with a 16-bit expected value, with a

relaxed

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 30

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

Quoted 9 lines

lib/librte_eal/common/include/generic/rte_pause.h

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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_16(volatile uint16_t *addr, uint16_t

expected);

Quoted 3 lines

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

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 43

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

Quoted 9 lines

lib/librte_eal/common/include/generic/rte_pause.h

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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_32(volatile uint32_t *addr, uint32_t

expected);

Quoted 3 lines

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

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 56

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

Quoted 9 lines

lib/librte_eal/common/include/generic/rte_pause.h

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 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_64(volatile uint64_t *addr, uint64_t

expected);

Quoted 3 lines

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 an

acquire

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 69

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

Quoted 10 lines

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 16-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_16(volatile uint16_t *addr, uint16_t

expected);

Quoted 3 lines

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 an

acquire

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 83

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

Quoted 10 lines

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 32-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_32(volatile uint32_t *addr, uint32_t

expected);

Quoted 7 lines

LGTM in general.
One stylish thing: wouldn't it be better to have an API like that:
rte_wait_until_equal_acquire_X(addr, expected, memory_order) ?

I.E. - pass memorder as parameter, not to incorporate it into function

name?

Quoted 7 lines

Less functions, plus user can specify order himself. Plus looks similar to C11 atomic instrincts.

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 an

acquire

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 97

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

Quoted 10 lines

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_64(volatile uint64_t *addr, uint64_t

expected);

Quoted 24 lines
Quoted 24 lines
lib/librte_eal/common/include/generic/rte_pause.h +21 -1
+
+#if !defined(RTE_ARM_USE_WFE)
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void	\
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+	type expected) \
+{ \
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#95 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Hi Konstantin,

Quoted 153 lines

-----Original Message-----
From: Gavin Hu (Arm Technology China)
Sent: Thursday, October 24, 2019 12:20 AM
To: Ananyev, Konstantin <[email protected]>; [email protected]
Cc: nd <[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]>; nd <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Hi Konstantin,

Quoted 9 lines

-----Original Message-----
From: Ananyev, Konstantin <[email protected]>
Sent: Friday, October 18, 2019 12:44 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]; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang (Arm Technology

China)

Quoted 21 lines

<[email protected]>; Phil Yang (Arm Technology China) <[email protected]>; Steve Capper <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Quoted 16 lines

Hi Gavin,

Quoted 13 lines

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.

<[email protected]>

Quoted 96 lines
Quoted 7 lines
Quoted 7 lines
---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106

+++++++++++++++++++++

Quoted 28 lines
Quoted 28 lines
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -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
 
Quoted 2 lines

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64 · line 121

Quoted 2 lines
config/common_base +0 -0
 #
 # Recognize/ignore the AVX/AVX512 CPU flags for performance/power

testing.

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 26 lines
Quoted 26 lines

index 93895d3..dabde17 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +13 -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
Quoted 8 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 40

Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +8 -0
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}

One more thought:
Why do you need to write asm code for the whole procedure? Why not to do like linux kernel:
define wfe() and sev() macros and use them inside normal C code?

#define sev() asm volatile("sev" : : : "memory")
#define wfe() asm volatile("wfe" : : : "memory")

Then:
rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, int memorder)

{
     if (__atomic_load_n(addr, memorder) != expected) {
         sev();
         do {
             wfe();
         } while ((__atomic_load_n(addr, memorder) != expected);
     }
}
Quoted 1 line

?

A really good suggestion, I made corresponding changes to v8 already, but it missed a armv8 specific feature after internal discussion.
We call wfe to wait/sleep on the 'monitored' address, it will be waken up upon someone write to the monitor address, so before wfe, we have to call load-exclusive instruction to 'monitor'.
__atomic_load_n - disassembled to "ldr" does not do so. We have to use "ldxrh" for relaxed mem ordering and "ldaxrh" for acquire ordering, in example of 16-bit.

Quoted 3 lines

Let me re-think coming back to the full assembly procedure or implementing a 'load-exclusive' function. What do you think?
/Gavin

Forgot to mention, kernel uses wfe() without preceding load-exclusive instructions because:
1) it replies on the timer, to wake up, i.e. __delay()
2) explicit calling sev to send wake events, for all kinds of locks
3) IPI instructions.

Our patches can't count on these events, due to of lack of these events or performance impact. /Gavin

Quoted 174 lines
Quoted 174 lines
Quoted 14 lines

Review

Quoted 14 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +9 -0
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
(quoted diff) +0 -0

b/lib/librte_eal/common/include/generic/rte_pause.h

Quoted 25 lines
Quoted 25 lines

index 52bd4db..8906473 100644

lib/librte_eal/common/include/generic/rte_pause.h +5 -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,10 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +25,105 @@
  */
 static inline void rte_pause(void);
 
Quoted 2 lines

lib/librte_eal/common/include/generic/rte_pause.h line 29

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+/**
+ * Wait for *addr to be updated with a 16-bit expected value, with a

relaxed

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 30

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

Quoted 9 lines

lib/librte_eal/common/include/generic/rte_pause.h

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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_16(volatile uint16_t *addr, uint16_t

expected);

Quoted 3 lines

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

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 43

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

Quoted 9 lines

lib/librte_eal/common/include/generic/rte_pause.h

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.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_32(volatile uint32_t *addr, uint32_t

expected);

Quoted 3 lines

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

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 56

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

Quoted 9 lines

lib/librte_eal/common/include/generic/rte_pause.h

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 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_relaxed_64(volatile uint64_t *addr, uint64_t

expected);

Quoted 3 lines

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 an

acquire

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 69

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

Quoted 10 lines

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 16-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_16(volatile uint16_t *addr, uint16_t

expected);

Quoted 3 lines

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 an

acquire

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 83

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

Quoted 10 lines

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 32-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_32(volatile uint32_t *addr, uint32_t

expected);

Quoted 7 lines

LGTM in general.
One stylish thing: wouldn't it be better to have an API like that:
rte_wait_until_equal_acquire_X(addr, expected, memory_order) ?

I.E. - pass memorder as parameter, not to incorporate it into function

name?

Quoted 7 lines

Less functions, plus user can specify order himself. Plus looks similar to C11 atomic instrincts.

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 an

acquire

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 97

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads after this API can't be

observed

Quoted 10 lines

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ * before this API.
+ *
+ * @param addr
+ *  A pointer to the memory location.
+ * @param expected
+ *  A 64-bit expected value to be in the memory location.
+ */
+__rte_always_inline
+static void
+rte_wait_until_equal_acquire_64(volatile uint64_t *addr, uint64_t

expected);

Quoted 24 lines
Quoted 24 lines
lib/librte_eal/common/include/generic/rte_pause.h +21 -1
+
+#if !defined(RTE_ARM_USE_WFE)
+#define __WAIT_UNTIL_EQUAL(op_name, size, type, memorder) \
+__rte_always_inline \
+static void	\
+rte_wait_until_equal_##op_name##_##size(volatile type *addr, \
+	type expected) \
+{ \
+	while (__atomic_load_n(addr, memorder) != expected) \
+		rte_pause(); \
+}
+
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed, 16, uint16_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 16, uint16_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 32, uint32_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 32, uint32_t, __ATOMIC_ACQUIRE)
+__WAIT_UNTIL_EQUAL(relaxed, 64, uint64_t, __ATOMIC_RELAXED)
+__WAIT_UNTIL_EQUAL(acquire, 64, uint64_t, __ATOMIC_ACQUIRE)
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#96 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Hi Gavin,

Quoted 110 lines
Quoted 110 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

<[email protected]>

Quoted 97 lines
Quoted 7 lines
Quoted 7 lines
---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106

+++++++++++++++++++++

Quoted 28 lines
Quoted 28 lines
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index 8ef75c2..8861713 100644
@@ -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
 
Quoted 2 lines

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64 · line 121

Quoted 2 lines
config/common_base +0 -0
 #
 # Recognize/ignore the AVX/AVX512 CPU flags for performance/power

testing.

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 26 lines
Quoted 26 lines

index 93895d3..dabde17 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +13 -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type expected) \
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
Quoted 8 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 40

Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +8 -0
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n" \
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}

One more thought:
Why do you need to write asm code for the whole procedure? Why not to do like linux kernel:
define wfe() and sev() macros and use them inside normal C code?

#define sev() asm volatile("sev" : : : "memory")
#define wfe() asm volatile("wfe" : : : "memory")

Then:
rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, int memorder)

{
     if (__atomic_load_n(addr, memorder) != expected) {
         sev();
         do {
             wfe();
         } while ((__atomic_load_n(addr, memorder) != expected);
     }
}

?

Quoted 8 lines
Quoted 8 lines

A really good suggestion, I made corresponding changes to v8 already, but it missed a armv8 specific feature after internal discussion.
We call wfe to wait/sleep on the 'monitored' address, it will be waken up upon someone write to the monitor address, so before wfe, we have to call load-exclusive instruction to 'monitor'.
__atomic_load_n - disassembled to "ldr" does not do so. We have to use "ldxrh" for relaxed mem ordering and "ldaxrh" for acquire ordering, in example of 16-bit.

Didn't realize that, sorry for confusion caused...

Quoted 3 lines
Quoted 3 lines

Let me re-think coming back to the full assembly procedure or implementing a 'load-exclusive' function. What do you think?

After some thought I am leaning towards 'load-exclusive' function - Hopefully it would help you avoid ras asm here and in other places. What do you think?
Konstantin

Quoted 21 lines
Quoted 1 line

/Gavin

Forgot to mention, kernel uses wfe() without preceding load-exclusive instructions because:
1) it replies on the timer, to wake up, i.e. __delay()
2) explicit calling sev to send wake events, for all kinds of locks
3) IPI instructions.

Our patches can't count on these events, due to of lack of these events or performance impact. /Gavin

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +9 -0
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
#97 lore raw

Re: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Hi Konstantin,

Quoted 143 lines

-----Original Message-----
From: Ananyev, Konstantin <[email protected]>
Sent: Thursday, October 24, 2019 6:21 PM
To: Gavin Hu (Arm Technology China) <[email protected]>; [email protected]
Cc: nd <[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]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v7 2/7] eal: add the APIs to wait until equal

Hi Gavin,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

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

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

by default. When it is enabled, the above APIs will call WFE

instruction

Quoted 29 lines
Quoted 29 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

to save CPU cycles and power.

<[email protected]>

Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  30 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 106

+++++++++++++++++++++

Quoted 13 lines
Quoted 13 lines
 4 files changed, 142 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -26,6 +26,7 @@ flags_common_default = [
 	['RTE_LIBRTE_AVP_PMD', false],
 
 	['RTE_SCHED_VECTOR', false],
+	['RTE_ARM_USE_WFE', false],
 ]
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

config/common_base

Quoted 6 lines
config/arm/meson.build +0 -0
 flags_generic = [
config/common_base +0 -0
index 8ef75c2..8861713 100644
@@ -111,6 +111,11 @@

CONFIG_RTE_MAX_VFIO_CONTAINERS=64

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64

Quoted 4 lines
config/common_base +1 -0
 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,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

config/common_base line 116

Quoted 2 lines
config/common_base +2 -0
+# calling these APIs put the cores in low power state while waiting
+# for the memory address to become equal to the expected

value.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64

Quoted 5 lines
config/common_base +2 -0
+# This is supported only by aarch64.
+CONFIG_RTE_ARM_USE_WFE=n
 
 #
 # Recognize/ignore the AVX/AVX512 CPU flags for

performance/power

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

testing.

Quoted 1 line
Quoted 1 line

diff --git

a/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 14 lines
Quoted 14 lines

index 93895d3..dabde17 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -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_
@@ -17,6 +18,35 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void)

Quoted 4 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +4 -0
+#ifdef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(name, asm_op, wide, type) \
+static __rte_always_inline void \
+rte_wait_until_equal_##name(volatile type * addr, type

expected) \

Quoted 5 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
+{ \
+	type tmp; \
+	asm volatile( \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n"

\

Quoted 5 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
+		"b.eq	2f\n" \
+		"sevl\n" \
+		"1:	wfe\n" \
+		#asm_op " %" #wide "[tmp], %[addr]\n" \
+		"cmp	%" #wide "[tmp], %" #wide "[expected]\n"

\

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 40

Quoted 6 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
+		"bne	1b\n" \
+		"2:\n" \
+		: [tmp] "=&r" (tmp) \
+		: [addr] "Q"(*addr), [expected] "r"(expected) \
+		: "cc", "memory"); \
+}

One more thought:
Why do you need to write asm code for the whole procedure? Why not to do like linux kernel:
define wfe() and sev() macros and use them inside normal C code?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

#define sev() asm volatile("sev" : : : "memory")
#define wfe() asm volatile("wfe" : : : "memory")

Then:
rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected,

int

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

memorder)

{
     if (__atomic_load_n(addr, memorder) != expected) {
         sev();
         do {
             wfe();
         } while ((__atomic_load_n(addr, memorder) != expected);
     }
}
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

?

A really good suggestion, I made corresponding changes to v8 already,

but it

Quoted 3 lines
Quoted 3 lines

missed a armv8 specific feature after internal discussion.
We call wfe to wait/sleep on the 'monitored' address, it will be waken up upon someone write to the monitor address, so before wfe, we have to

Quoted 8 lines

call

Quoted 2 lines
Quoted 2 lines

load-exclusive instruction to 'monitor'. __atomic_load_n - disassembled to "ldr" does not do so. We have to

use

Quoted 2 lines
Quoted 2 lines

"ldxrh" for relaxed mem ordering and "ldaxrh" for acquire ordering, in example of 16-bit.

Didn't realize that, sorry for confusion caused...

Your comments are really helpful! Although we missed this point, anyway it helped to make the patches in a better shape(I personally likes the new v9 more than v7 😊), really appreciate, thanks! /Gavin

Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

Let me re-think coming back to the full assembly procedure or

implementing

Quoted 1 line
Quoted 1 line

a 'load-exclusive' function. What do you think?

After some thought I am leaning towards 'load-exclusive' function - Hopefully it would help you avoid ras asm here and in other places. What do you think?
Konstantin

Yes, I implemented 'load-exclusive' function in v9, please have a review, thanks! Currently I did not make it 'rte_' as it is not used in other places than the rte_wait_until_equal APIs. Any more comments are welcome!
/Gavin

Quoted 24 lines
Quoted 3 lines
Quoted 2 lines

/Gavin

Forgot to mention, kernel uses wfe() without preceding load-exclusive

instructions because:

Quoted 5 lines

1) it replies on the timer, to wake up, i.e. __delay()
2) explicit calling sev to send wake events, for all kinds of locks
3) IPI instructions.

Our patches can't count on these events, due to of lack of these events or

performance impact.

Quoted 14 lines

/Gavin

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +9 -0
+/* Wait for *addr to be updated with expected value */
+__WAIT_UNTIL_EQUAL(relaxed_16, ldxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(acquire_16, ldaxrh, w, uint16_t)
+__WAIT_UNTIL_EQUAL(relaxed_32, ldxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(acquire_32, ldaxr, w, uint32_t)
+__WAIT_UNTIL_EQUAL(relaxed_64, ldxr, x, uint64_t)
+__WAIT_UNTIL_EQUAL(acquire_64, ldaxr, x, uint64_t)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
author
#98 lore raw

PATCH v7 3/7 spinlock: use wfe to reduce contention on aarch64

In reply to Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running the micro benchmarking and the testpmd and l3fwd traffic tests on ThunderX2, Ampere eMAG80 and Arm N1SDP, everything went well and no notable performance gain nor degradation was measured.

---
 .../common/include/arch/arm/rte_spinlock.h         | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +26 -0
index 1a6916b..b61c055 100644
@@ -16,6 +16,32 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#ifndef RTE_FORCE_INTRINSICS
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+	unsigned int tmp;
+	/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"1:	ldaxr %w[tmp], %w[locked]\n"
+		"cbnz   %w[tmp], 2f\n"
+		"stxr   %w[tmp], %w[one], %w[locked]\n"
+		"cbnz   %w[tmp], 1b\n"
+		"ret\n"
+		"2:	sevl\n"
+		"wfe\n"
+		"jmp	1b\n"
+		: [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+		: [one] "r" (1)
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
 	return 0;
Signature · 1 line
2.7.4
#99 lore raw

Re: [dpdk-dev] [PATCH v7 3/7] spinlock: use wfe to reduce contention on aarch64

Quoted 24 lines · Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running the micro benchmarking and the testpmd and l3fwd traffic tests on ThunderX2, Ampere eMAG80 and Arm N1SDP, everything went well and no notable performance gain nor degradation was measured.

---
 .../common/include/arch/arm/rte_spinlock.h         | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +0 -0
index 1a6916b..b61c055 100644

lib/librte_eal/common/include/arch/arm/rte_spinlock.h extern "C" { · line 23

Quoted 8 lines
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +5 -0
@@ -16,6 +16,32 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#ifndef RTE_FORCE_INTRINSICS

Earlier, in the same file, I can see:
https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/include/arch/arm/rte_spinlock.h?h=v19.08#n8

#ifndef RTE_FORCE_INTRINSICS
# error Platform must be built with CONFIG_RTE_FORCE_INTRINSICS #endif

IIUC, this is dead code.

Quoted 27 lines
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +21 -1
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+       unsigned int tmp;
+       /* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+        * faqs/ka16809.html
+        */
+       asm volatile(
+               "1:     ldaxr %w[tmp], %w[locked]\n"
+               "cbnz   %w[tmp], 2f\n"
+               "stxr   %w[tmp], %w[one], %w[locked]\n"
+               "cbnz   %w[tmp], 1b\n"
+               "ret\n"
+               "2:     sevl\n"
+               "wfe\n"
+               "jmp    1b\n"
+               : [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+               : [one] "r" (1)
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
        return 0;
--

2.7.4

Signature · 1 line
David Marchand
#100 lore raw

Re: [dpdk-dev] [PATCH v7 3/7] spinlock: use wfe to reduce contention on aarch64

Hi David,

Quoted 55 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, October 18, 2019 2:28 AM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: dev <[email protected]>; nd <[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: [dpdk-dev] [PATCH v7 3/7] spinlock: use wfe to reduce contention on aarch64

Quoted 6 lines · Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running the micro benchmarking and the testpmd and l3fwd traffic tests on ThunderX2, Ampere eMAG80 and Arm N1SDP, everything went well

and no

Quoted 11 lines

notable performance gain nor degradation was measured.

---
 .../common/include/arch/arm/rte_spinlock.h         | 26

++++++++++++++++++++++

Review

Quoted 3 lines
 1 file changed, 26 insertions(+)
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_spinlock.h

lib/librte_eal/common/include/arch/arm/rte_spinlock.h extern "C" { · line 23

Quoted 12 lines

index 1a6916b..b61c055 100644

lib/librte_eal/common/include/arch/arm/rte_spinlock.h +5 -0
@@ -16,6 +16,32 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#ifndef RTE_FORCE_INTRINSICS

Earlier, in the same file, I can see:
https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/include/arch/arm/rte
_spinlock.h?h=v19.08#n8

Quoted 5 lines

#ifndef RTE_FORCE_INTRINSICS
# error Platform must be built with CONFIG_RTE_FORCE_INTRINSICS #endif

IIUC, this is dead code.

Yes, will remove in next version.

Quoted 32 lines
Quoted 26 lines
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +21 -1
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+       unsigned int tmp;
+       /* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+        * faqs/ka16809.html
+        */
+       asm volatile(
+               "1:     ldaxr %w[tmp], %w[locked]\n"
+               "cbnz   %w[tmp], 2f\n"
+               "stxr   %w[tmp], %w[one], %w[locked]\n"
+               "cbnz   %w[tmp], 1b\n"
+               "ret\n"
+               "2:     sevl\n"
+               "wfe\n"
+               "jmp    1b\n"
+               : [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+               : [one] "r" (1)
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
        return 0;
--
Quoted 2 lines

2.7.4

--
David Marchand

#101 lore raw

Re: [dpdk-dev] [PATCH v7 3/7] spinlock: use wfe to reduce contention on aarch64

In reply to David Marchand

Hi David,

Quoted 56 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, October 18, 2019 2:28 AM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: dev <[email protected]>; nd <[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: [dpdk-dev] [PATCH v7 3/7] spinlock: use wfe to reduce contention on aarch64

Quoted 6 lines · Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running the micro benchmarking and the testpmd and l3fwd traffic tests on ThunderX2, Ampere eMAG80 and Arm N1SDP, everything went well

and no

Quoted 11 lines

notable performance gain nor degradation was measured.

---
 .../common/include/arch/arm/rte_spinlock.h         | 26

++++++++++++++++++++++

Review

Quoted 3 lines
 1 file changed, 26 insertions(+)
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_spinlock.h

lib/librte_eal/common/include/arch/arm/rte_spinlock.h extern "C" { · line 19

Quoted 8 lines

index 1a6916b..b61c055 100644

lib/librte_eal/common/include/arch/arm/rte_spinlock.h +1 -0
@@ -16,6 +16,32 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV

is

lib/librte_eal/common/include/arch/arm/rte_spinlock.h extern "C" { · line 23

Quoted 4 lines
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +4 -0
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#ifndef RTE_FORCE_INTRINSICS

Earlier, in the same file, I can see:
https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/include/arch/arm/r
te_spinlock.h?h=v19.08#n8

Quoted 5 lines

#ifndef RTE_FORCE_INTRINSICS
# error Platform must be built with CONFIG_RTE_FORCE_INTRINSICS #endif

IIUC, this is dead code.

This is not dead code, RTE_FORCE_INTRINSICS is still mandatory for aarch64 ad RTE_ARM_USE_WFE is optional currently.
Yes, as Jerin pointed out, we may make it optional also, like x86, but now it is still too earlier before WFE is mandatory, anyway it is in our plan. I will tweak a little bit for the two macros to reflect this logic in v8.
/Gavin

Quoted 32 lines
Quoted 26 lines
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +21 -1
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+       unsigned int tmp;
+       /* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+        * faqs/ka16809.html
+        */
+       asm volatile(
+               "1:     ldaxr %w[tmp], %w[locked]\n"
+               "cbnz   %w[tmp], 2f\n"
+               "stxr   %w[tmp], %w[one], %w[locked]\n"
+               "cbnz   %w[tmp], 1b\n"
+               "ret\n"
+               "2:     sevl\n"
+               "wfe\n"
+               "jmp    1b\n"
+               : [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+               : [one] "r" (1)
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
        return 0;
--
Quoted 2 lines

2.7.4

--
David Marchand

author
#102 lore raw

PATCH v7 4/7 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

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
index d9bec87..232bbe9 100644
@@ -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_acquire_16(&tl->s.current, me);
 }
 
 /**
Signature · 1 line
2.7.4
author
#103 lore raw

PATCH v7 5/7 ring: use wfe to wait for ring tail update on aarch64

In reply to Gavin Hu

Instead of polling for tail to be updated, use wfe instruction.

---
 lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
 lib/librte_ring/rte_ring_generic.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring_c11_mem.h +2 -2
index 0fb73a3..764d8f1 100644
@@ -2,6 +2,7 @@
  *
  * Copyright (c) 2017,2018 HXT-semitech Corporation.
  * Copyright (c) 2007-2009 Kip Macy [email protected]
+ * Copyright (c) 2019 Arm Limited
  * All rights reserved.
  * Derived from FreeBSD's bufring.h
  * Used as BSD-3 Licensed with permission from Kip Macy.
@@ -21,8 +22,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
 
 	__atomic_store_n(&ht->tail, new_val, __ATOMIC_RELEASE);
 }
lib/librte_ring/rte_ring_generic.h +1 -2
index 953cdbb..6828527 100644
@@ -23,8 +23,7 @@ update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val,
 	 * we need to wait for them to complete
 	 */
 	if (!single)
-		while (unlikely(ht->tail != old_val))
-			rte_pause();
+		rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
 
 	ht->tail = new_val;
 }
Signature · 1 line
2.7.4
author
#104 lore raw

PATCH v7 6/7 net/thunderx: use new API to save cycles on aarch64

In reply to Gavin Hu

Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.

---
 drivers/net/thunderx/nicvf_rxtx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/thunderx/nicvf_rxtx.c +1 -2
index 1c42874..16f34c6 100644
@@ -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_relaxed_32(&rbdr->tail, next_tail);
 
 	__atomic_store_n(&rbdr->tail, ltail, __ATOMIC_RELEASE);
 	nicvf_addr_write(door, to_fill);
Signature · 1 line
2.7.4
author
#105 lore raw

PATCH v7 7/7 event/opdl: use new API to save cycles on aarch64

In reply to Gavin Hu

Use the new API to wait in low power state instead of continuous polling to save CPU cycles and power.

---
 drivers/event/opdl/opdl_ring.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/event/opdl/opdl_ring.c +2 -3
index e8b29e2..f446fa3 100644
@@ -17,6 +17,7 @@
 #include <rte_memory.h>
 #include <rte_memzone.h>
 #include <rte_eal_memconfig.h>
+#include <rte_atomic.h>
 
 #include "opdl_ring.h"
 #include "opdl_log.h"
@@ -475,9 +476,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_acquire_32(&s->shared.tail, old_head);
 
 	__atomic_store_n(&s->shared.tail, old_head + num_entries,
 			__ATOMIC_RELEASE);
Signature · 1 line
2.7.4
#106 lore raw

Re: [dpdk-dev] [PATCH v7 0/7] use WFE for aarch64

In reply to Gavin Hu
Quoted 51 lines · Gavin Hu

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

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_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.

Quoted 8 lines

CONFIG_RTE_ARM_USE_WFE should be enabled depending on the performance benchmarking on the target platforms. Power saving should be an bonus, but currenly we don't have ways to characterize that.

Gavin Hu (7):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
spinlock: use wfe to reduce contention on aarch64

Sent comments on the 3 first patches, the rest looks good to me.

Quoted 4 lines

ticketlock: use new API to reduce contention on aarch64
ring: use wfe to wait for ring tail update on aarch64 net/thunderx: use new API to save cycles on aarch64 event/opdl: use new API to save cycles on aarch64

Thanks.

Signature · 1 line
David Marchand
author
#107 lore raw

v8 cover use WFE for aarch64

In reply to Gavin Hu

V8:
- 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

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_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_ARM_USE_WFE should be enabled depending on the performance benchmarking on the target platforms. Power saving should be an bonus, but currenly we don't have ways to characterize that.

Gavin Hu (6):
bus/fslmc: fix the conflicting dmb function
eal: add the APIs to wait until equal
spinlock: use wfe to reduce contention on aarch64
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         | 26 ++++++
 .../common/include/arch/arm/rte_spinlock.h         | 26 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 93 ++++++++++++++++++++++
 .../common/include/generic/rte_spinlock.h          |  2 +-
 .../common/include/generic/rte_ticketlock.h        |  3 +-
 14 files changed, 163 insertions(+), 13 deletions(-)
Signature · 1 line
2.7.4
author
#108 lore raw

PATCH v8 1/6 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@i
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u

Fixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")
---
 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
index d0c7b39..68ce38b 100644
@@ -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
#109 lore raw

Re: [dpdk-dev] [PATCH v8 1/6] bus/fslmc: fix the conflicting dmb function

Quoted 9 lines · Gavin Hu

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"); }

Quoted 4 lines

The fix is to reuse the EAL definition to avoid conflicts.

[1] http://inbox.dpdk.org/users/VI1PR08MB537631AB25F41B8880DCCA988FDF0@i
VI1PR08MB5376.eurprd08.prod.outlook.com/T/#u

This url is broken as reported previously.
I can fix when applying, but please take the time to fix basic issues like this when reported.

Quoted 7 lines
Fixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")

Was the last change on using EAL memory barrier properly seen by Hemant ? Just want to be sure he is ok.

Quoted 25 lines
---
 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 -6
index d0c7b39..68ce38b 100644
@@ -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))
--
Quoted 2 lines

2.7.4

--
David Marchand

author
#110 lore raw

PATCH v8 2/6 eal: add the APIs to wait until equal

In reply to Gavin Hu

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.

---
 config/arm/meson.build                             |  1 +
 config/common_base                                 |  5 ++
 .../common/include/arch/arm/rte_pause_64.h         | 26 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 93 ++++++++++++++++++++++
 4 files changed, 125 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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 +26 -0
index 93895d3..eb8f73e 100644
@@ -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_
@@ -17,6 +18,31 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define sev()	{ asm volatile("sev" : : : "memory") }
+#define wfe()	{ asm volatile("wfe" : : : "memory") }
+
+#define __WAIT_UNTIL_EQUAL(type, size, addr, expected, memorder) \
+__rte_experimental						\
+static __rte_always_inline void					\
+rte_wait_until_equal_##size(volatile type * addr, type expected,\
+int memorder)							\
+{								\
+	if (__atomic_load_n(addr, memorder) != expected) {	\
+		sev();							\
+		do {							\
+			wfe();						\
+		} while (__atomic_load_n(addr, memorder) != expected);	\
+	 }								\
+}
+__WAIT_UNTIL_EQUAL(uint16_t, 16, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint32_t, 32, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint64_t, 64, addr, expected, memorder)
+
+#undef __WAIT_UNTIL_EQUAL
+
+#endif /* RTE_ARM_USE_WFE */
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +93 -0

108 lines not on this page · raw message

Signature · 1 line
2.7.4
#111 lore raw

Re: [dpdk-dev] [PATCH v8 2/6] eal: add the APIs to wait until equal

Quoted 61 lines · Gavin Hu

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.

---
 config/arm/meson.build                             |  1 +
 config/common_base                                 |  5 ++
 .../common/include/arch/arm/rte_pause_64.h         | 26 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 93 ++++++++++++++++++++++
 4 files changed, 125 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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 +0 -0
index 93895d3..eb8f73e 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h line 4

Quoted 4 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2017 Cavium, Inc
+ * Copyright(c) 2019 Arm Limited
  */

Before including generic/rte_pause.h, put a check like:

#ifdef RTE_ARM_USE_WFE
#define RTE_ARCH_HAS_WFE
#endif

#include "generic/rte_pause.h"

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 26

Quoted 12 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
 #ifndef _RTE_PAUSE_ARM64_H_
@@ -17,6 +18,31 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define sev()  { asm volatile("sev" : : : "memory") }
+#define wfe()  { asm volatile("wfe" : : : "memory") }
+
+#define __WAIT_UNTIL_EQUAL(type, size, addr, expected, memorder) \
+__rte_experimental                                             \

The experimental tag is unnecessary here.
We only need it in the function prototype (in the generic header).

Quoted 6 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
+static __rte_always_inline void                                        \
+rte_wait_until_equal_##size(volatile type * addr, type expected,\
+int memorder)                                                  \
+{                                                              \
+       if (__atomic_load_n(addr, memorder) != expected) {      \
+               sev();                                                  \

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 42

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+               do {                                                    \
+                       wfe();                                          \
+               } while (__atomic_load_n(addr, memorder) != expected);  \
+        }                                                              \
+}
+__WAIT_UNTIL_EQUAL(uint16_t, 16, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint32_t, 32, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint64_t, 64, addr, expected, memorder)
+
+#undef __WAIT_UNTIL_EQUAL

Missing #undef on sev and wfe macros.

Quoted 89 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +3 -0
+
+#endif /* RTE_ARM_USE_WFE */
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +62 -0
index 52bd4db..80597a9 100644
@@ -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,11 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+#include <rte_compat.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +26,91 @@
  */
 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

lib/librte_eal/common/include/generic/rte_pause.h line 94

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ *  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);
+

Here, change this check to:

#ifndef RTE_ARCH_HAS_WFE

Quoted 23 lines
lib/librte_eal/common/include/generic/rte_pause.h +21 -1
+#ifndef RTE_ARM_USE_WFE
+#define __WAIT_UNTIL_EQUAL(type, size, addr, expected, memorder) \
+__rte_experimental \
+static __rte_always_inline void                                        \
+rte_wait_until_equal_##size(volatile type * addr, type expected,\
+int memorder)                                                  \
+{                                                              \
+       if (__atomic_load_n(addr, memorder) != expected) {      \
+               do {                                                    \
+                       rte_pause();                                    \
+               } while (__atomic_load_n(addr, memorder) != expected);  \
+       }                                                               \
+}
+__WAIT_UNTIL_EQUAL(uint16_t, 16, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint32_t, 32, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint64_t, 64, addr, expected, memorder)
+
+#undef __WAIT_UNTIL_EQUAL
+
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--
Quoted 2 lines

2.7.4

Thanks.

--
David Marchand

#112 lore raw

Re: [dpdk-dev] [PATCH v8 2/6] eal: add the APIs to wait until equal

Quoted 89 lines
Quoted 60 lines

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.

---
 config/arm/meson.build                             |  1 +
 config/common_base                                 |  5 ++
 .../common/include/arch/arm/rte_pause_64.h         | 26 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 93 ++++++++++++++++++++++
 4 files changed, 125 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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 +0 -0
index 93895d3..eb8f73e 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h line 4

Quoted 4 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2017 Cavium, Inc
+ * Copyright(c) 2019 Arm Limited
  */

Before including generic/rte_pause.h, put a check like:

#ifdef RTE_ARM_USE_WFE
#define RTE_ARCH_HAS_WFE
#endif

#include "generic/rte_pause.h"

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 26

Quoted 12 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
 #ifndef _RTE_PAUSE_ARM64_H_
@@ -17,6 +18,31 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define sev()  { asm volatile("sev" : : : "memory") }
+#define wfe()  { asm volatile("wfe" : : : "memory") }
+
+#define __WAIT_UNTIL_EQUAL(type, size, addr, expected, memorder) \
+__rte_experimental                                             \

The experimental tag is unnecessary here.
We only need it in the function prototype (in the generic header).

Quoted 16 lines
Quoted 6 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
+static __rte_always_inline void                                        \
+rte_wait_until_equal_##size(volatile type * addr, type expected,\
+int memorder)                                                  \
+{                                                              \
+       if (__atomic_load_n(addr, memorder) != expected) {      \
+               sev();                                                  \

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 42

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+               do {                                                    \
+                       wfe();                                          \
+               } while (__atomic_load_n(addr, memorder) != expected);  \
+        }                                                              \
+}
+__WAIT_UNTIL_EQUAL(uint16_t, 16, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint32_t, 32, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint64_t, 64, addr, expected, memorder)
+
+#undef __WAIT_UNTIL_EQUAL

Might be instead of defining/undefining these macros, just define explicitly these 3 functions?
Now they are really small, so I think it would be an easier/cleaner way. Yes, a bit of code duplication, but as I said they are really small now. Same thought about generic version.

Quoted 2 lines

Missing #undef on sev and wfe macros.

Actually should we undefine them?
Or should we add rte_ prefix (which is needed anyway I suppose)
and have them always defined?
Might be you can reuse them in other arm specific places too (spinlock, rwlock, etc.) Actually probably it is possible to make them either emiting a proper instructions or NOP, then you'll need RTE_ARM_USE_WFE only around these macros.

I.E

#ifdef RTE_ARM_USE_WFE
#define rte_sev() { asm volatile("sev" : : : "memory") } #define rte_wfe() { asm volatile("wfe" : : : "memory") } #else
static inline void rte_sev(void)
{
}
static inline void rte_wfe(void)

{
	rte_pause();
}

#endif

And then just one common version of _wait_ functios:

static __rte_always_inline void \
rte_wait_until_equal_32(volatile type * addr, type expected, int memorder)

{                                                              \
	if (__atomic_load_n(addr, memorder) != expected) {    
		rte_sev();
		do {
	                       rte_wfe();
	              } while (__atomic_load_n(addr, memorder) != expected);
	  } 
}
Quoted 104 lines
Quoted 91 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +3 -0
+
+#endif /* RTE_ARM_USE_WFE */
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +62 -0
index 52bd4db..80597a9 100644
@@ -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,11 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+#include <rte_compat.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +26,91 @@
  */
 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

lib/librte_eal/common/include/generic/rte_pause.h line 94

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+ *  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);
+

Here, change this check to:

Quoted 4 lines

#ifndef RTE_ARCH_HAS_WFE

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+#ifndef RTE_ARM_USE_WFE

Might be something arch neutral in name here?
RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED or so?

Quoted 29 lines
Quoted 22 lines
lib/librte_eal/common/include/generic/rte_pause.h +20 -1
+#define __WAIT_UNTIL_EQUAL(type, size, addr, expected, memorder) \
+__rte_experimental \
+static __rte_always_inline void                                        \
+rte_wait_until_equal_##size(volatile type * addr, type expected,\
+int memorder)                                                  \
+{                                                              \
+       if (__atomic_load_n(addr, memorder) != expected) {      \
+               do {                                                    \
+                       rte_pause();                                    \
+               } while (__atomic_load_n(addr, memorder) != expected);  \
+       }                                                               \
+}
+__WAIT_UNTIL_EQUAL(uint16_t, 16, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint32_t, 32, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint64_t, 64, addr, expected, memorder)
+
+#undef __WAIT_UNTIL_EQUAL
+
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--
Quoted 2 lines

2.7.4

Thanks.

--
David Marchand

#113 lore raw

Re: [dpdk-dev] [PATCH v8 2/6] eal: add the APIs to wait until equal

Quoted 104 lines · Konstantin
Quoted 104 lines
Quoted 61 lines

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.

---
 config/arm/meson.build                             |  1 +
 config/common_base                                 |  5 ++
 .../common/include/arch/arm/rte_pause_64.h         | 26 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 93 ++++++++++++++++++++++
 4 files changed, 125 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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 +0 -0
index 93895d3..eb8f73e 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h line 4

Quoted 4 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2017 Cavium, Inc
+ * Copyright(c) 2019 Arm Limited
  */

Before including generic/rte_pause.h, put a check like:

#ifdef RTE_ARM_USE_WFE
#define RTE_ARCH_HAS_WFE
#endif

#include "generic/rte_pause.h"

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 26

Quoted 12 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
 #ifndef _RTE_PAUSE_ARM64_H_
@@ -17,6 +18,31 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define sev()  { asm volatile("sev" : : : "memory") }
+#define wfe()  { asm volatile("wfe" : : : "memory") }
+
+#define __WAIT_UNTIL_EQUAL(type, size, addr, expected, memorder) \
+__rte_experimental                                             \

The experimental tag is unnecessary here.
We only need it in the function prototype (in the generic header).

Quoted 14 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +14 -0
+static __rte_always_inline void                                        \
+rte_wait_until_equal_##size(volatile type * addr, type expected,\
+int memorder)                                                  \
+{                                                              \
+       if (__atomic_load_n(addr, memorder) != expected) {      \
+               sev();                                                  \
+               do {                                                    \
+                       wfe();                                          \
+               } while (__atomic_load_n(addr, memorder) != expected);  \
+        }                                                              \
+}
+__WAIT_UNTIL_EQUAL(uint16_t, 16, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint32_t, 32, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint64_t, 64, addr, expected, memorder)
Quoted 8 lines
Quoted 2 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 42

Quoted 2 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +2 -0
+
+#undef __WAIT_UNTIL_EQUAL

Might be instead of defining/undefining these macros, just define explicitly these 3 functions?
Now they are really small, so I think it would be an easier/cleaner way. Yes, a bit of code duplication, but as I said they are really small now. Same thought about generic version.

I don't really like those macros defining inlines either. I am fine with this little duplication, so +1 from me.

Quoted 10 lines
Quoted 3 lines

Missing #undef on sev and wfe macros.

Actually should we undefine them?
Or should we add rte_ prefix (which is needed anyway I suppose)
and have them always defined?
Might be you can reuse them in other arm specific places too (spinlock, rwlock, etc.) Actually probably it is possible to make them either emiting a proper instructions or NOP, then you'll need RTE_ARM_USE_WFE only around these macros.

Interesting idea, but only if it gets used in this series. I don't want to see stuff that will not be used later.

Quoted 30 lines

I.E

#ifdef RTE_ARM_USE_WFE
#define rte_sev() { asm volatile("sev" : : : "memory") } #define rte_wfe() { asm volatile("wfe" : : : "memory") } #else
static inline void rte_sev(void)
{
}
static inline void rte_wfe(void)

{
        rte_pause();
}

#endif

And then just one common version of _wait_ functios:

static __rte_always_inline void \
rte_wait_until_equal_32(volatile type * addr, type expected, int memorder)

{                                                              \
        if (__atomic_load_n(addr, memorder) != expected) {
                rte_sev();
                do {
                               rte_wfe();
                      } while (__atomic_load_n(addr, memorder) != expected);
          }
}

[snip]

Quoted 9 lines
Quoted 6 lines

Here, change this check to:

#ifndef RTE_ARCH_HAS_WFE

Quoted 1 line

+#ifndef RTE_ARM_USE_WFE

Might be something arch neutral in name here?
RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED or so?

Yes, better than my suggestion.

Gavin, I noticed that you added a #ifndef ARM in the generic rte_spinlock.h header later in this series. Please, can you think of a way to avoid this? Maybe applying the same pattern to the spinlock?

Thanks.

--
David Marchand

#114 lore raw

Re: [dpdk-dev] [PATCH v8 2/6] eal: add the APIs to wait until equal

Quoted 198 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Tuesday, October 22, 2019 6:17 PM
To: Ananyev, Konstantin <[email protected]>
Cc: Gavin Hu (Arm Technology China) <[email protected]>; dev <[email protected]>; nd <[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: [dpdk-dev] [PATCH v8 2/6] eal: add the APIs to wait until equal

Quoted 13 lines · Konstantin
Quoted 13 lines
Quoted 13 lines

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.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

<[email protected]>

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
---
 config/arm/meson.build                             |  1 +
 config/common_base                                 |  5 ++
 .../common/include/arch/arm/rte_pause_64.h         | 26 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 93

++++++++++++++++++++++

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
 4 files changed, 125 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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
 
Quoted 2 lines
Quoted 2 lines

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64 · line 121

Quoted 2 lines
config/common_base +0 -0
 #
 # Recognize/ignore the AVX/AVX512 CPU flags for performance/power

testing.

Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 23 lines
Quoted 23 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h line 4

Quoted 8 lines

index 93895d3..eb8f73e 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2017 Cavium, Inc
+ * Copyright(c) 2019 Arm Limited
  */

Before including generic/rte_pause.h, put a check like:

#ifdef RTE_ARM_USE_WFE
#define RTE_ARCH_HAS_WFE
#endif

#include "generic/rte_pause.h"

Quoted 6 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +0 -0
 #ifndef _RTE_PAUSE_ARM64_H_
@@ -17,6 +18,31 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
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
+#ifdef RTE_ARM_USE_WFE
+#define sev()  { asm volatile("sev" : : : "memory") }
+#define wfe()  { asm volatile("wfe" : : : "memory") }
+
+#define __WAIT_UNTIL_EQUAL(type, size, addr, expected, memorder)

\

Quoted 19 lines
Quoted 19 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 26

Quoted 1 line
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
+__rte_experimental                                             \

The experimental tag is unnecessary here.
We only need it in the function prototype (in the generic header).

Quoted 14 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +14 -0
+static __rte_always_inline void                                        \
+rte_wait_until_equal_##size(volatile type * addr, type expected,\
+int memorder)                                                  \
+{                                                              \
+       if (__atomic_load_n(addr, memorder) != expected) {      \
+               sev();                                                  \
+               do {                                                    \
+                       wfe();                                          \
+               } while (__atomic_load_n(addr, memorder) != expected);  \
+        }                                                              \
+}
+__WAIT_UNTIL_EQUAL(uint16_t, 16, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint32_t, 32, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint64_t, 64, addr, expected, memorder)
Quoted 8 lines
Quoted 2 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 42

Quoted 2 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +2 -0
+
+#undef __WAIT_UNTIL_EQUAL

Might be instead of defining/undefining these macros, just define explicitly these 3 functions?
Now they are really small, so I think it would be an easier/cleaner way. Yes, a bit of code duplication, but as I said they are really small now. Same thought about generic version.

I don't really like those macros defining inlines either. I am fine with this little duplication, so +1 from me.

Quoted 8 lines
Quoted 3 lines

Missing #undef on sev and wfe macros.

Actually should we undefine them?
Or should we add rte_ prefix (which is needed anyway I suppose) and have them always defined?
Might be you can reuse them in other arm specific places too (spinlock,

rwlock, etc.)

Quoted 1 line

Actually probably it is possible to make them either emiting a proper

instructions or NOP,

Quoted 1 line

then you'll need RTE_ARM_USE_WFE only around these macros.

Interesting idea, but only if it gets used in this series. I don't want to see stuff that will not be used later.

Quoted 14 lines

I.E

#ifdef RTE_ARM_USE_WFE
#define rte_sev() { asm volatile("sev" : : : "memory") } #define rte_wfe() { asm volatile("wfe" : : : "memory") } #else
static inline void rte_sev(void)
{
}
static inline void rte_wfe(void)

{
        rte_pause();
}
Quoted 6 lines

#endif

And then just one common version of _wait_ functios:

static __rte_always_inline void \
rte_wait_until_equal_32(volatile type * addr, type expected, int

memorder)

Quoted 10 lines
{                                                              \
        if (__atomic_load_n(addr, memorder) != expected) {
                rte_sev();
                do {
                               rte_wfe();
                      } while (__atomic_load_n(addr, memorder) != expected);
          }
}

[snip]

Quoted 9 lines
Quoted 6 lines

Here, change this check to:

#ifndef RTE_ARCH_HAS_WFE

Quoted 1 line

+#ifndef RTE_ARM_USE_WFE

Might be something arch neutral in name here?
RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED or so?

Quoted 7 lines

Yes, better than my suggestion.

Gavin, I noticed that you added a #ifndef ARM in the generic rte_spinlock.h header later in this series. Please, can you think of a way to avoid this? Maybe applying the same pattern to the spinlock?

David, I will look into this and other comments, and fix them in v9, thanks for all your comments! /Gavin

Quoted 5 lines

Thanks.

--
David Marchand

#115 lore raw

Re: [dpdk-dev] [PATCH v8 2/6] eal: add the APIs to wait until equal

In reply to Ananyev, Konstantin
Quoted 121 lines

-----Original Message-----
From: Ananyev, Konstantin <[email protected]>
Sent: Tuesday, October 22, 2019 5:37 PM
To: David Marchand <[email protected]>; Gavin Hu (Arm Technology China) <[email protected]>
Cc: dev <[email protected]>; nd <[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: [dpdk-dev] [PATCH v8 2/6] eal: add the APIs to wait until equal

Quoted 12 lines
Quoted 12 lines

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.

Quoted 13 lines
Quoted 8 lines
Quoted 5 lines
---
 config/arm/meson.build                             |  1 +
 config/common_base                                 |  5 ++
 .../common/include/arch/arm/rte_pause_64.h         | 26 ++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 93

++++++++++++++++++++++

Quoted 28 lines
Quoted 28 lines
 4 files changed, 125 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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
 
Quoted 2 lines

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64 · line 121

Quoted 2 lines
config/common_base +0 -0
 #
 # Recognize/ignore the AVX/AVX512 CPU flags for performance/power

testing.

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 47 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h line 4

Quoted 8 lines

index 93895d3..eb8f73e 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +1 -0
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2017 Cavium, Inc
+ * Copyright(c) 2019 Arm Limited
  */

Before including generic/rte_pause.h, put a check like:

#ifdef RTE_ARM_USE_WFE
#define RTE_ARCH_HAS_WFE
#endif

#include "generic/rte_pause.h"

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 26

Quoted 12 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +6 -0
 #ifndef _RTE_PAUSE_ARM64_H_
@@ -17,6 +18,31 @@ static inline void rte_pause(void)
        asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_ARM_USE_WFE
+#define sev()  { asm volatile("sev" : : : "memory") }
+#define wfe()  { asm volatile("wfe" : : : "memory") }
+
+#define __WAIT_UNTIL_EQUAL(type, size, addr, expected, memorder) \
+__rte_experimental                                             \

The experimental tag is unnecessary here.
We only need it in the function prototype (in the generic header).

Quoted 14 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +14 -0
+static __rte_always_inline void                                        \
+rte_wait_until_equal_##size(volatile type * addr, type expected,\
+int memorder)                                                  \
+{                                                              \
+       if (__atomic_load_n(addr, memorder) != expected) {      \
+               sev();                                                  \
+               do {                                                    \
+                       wfe();                                          \
+               } while (__atomic_load_n(addr, memorder) != expected);  \
+        }                                                              \
+}
+__WAIT_UNTIL_EQUAL(uint16_t, 16, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint32_t, 32, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint64_t, 64, addr, expected, memorder)
Quoted 8 lines
Quoted 2 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 42

Quoted 2 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +2 -0
+
+#undef __WAIT_UNTIL_EQUAL

Might be instead of defining/undefining these macros, just define explicitly these 3 functions?
Now they are really small, so I think it would be an easier/cleaner way. Yes, a bit of code duplication, but as I said they are really small now. Same thought about generic version.

Ok, no problem, an alternative way to reduce duplication is to use _Generic( since gcc-4.9). As you said, now it is small, I will take your suggestion.

Quoted 22 lines
Quoted 2 lines

Missing #undef on sev and wfe macros.

Actually should we undefine them?
Or should we add rte_ prefix (which is needed anyway I suppose) and have them always defined?
Might be you can reuse them in other arm specific places too (spinlock, rwlock, etc.)
Actually probably it is possible to make them either emiting a proper instructions or NOP,
then you'll need RTE_ARM_USE_WFE only around these macros.

I.E

#ifdef RTE_ARM_USE_WFE
#define rte_sev() { asm volatile("sev" : : : "memory") } #define rte_wfe() { asm volatile("wfe" : : : "memory") } #else
static inline void rte_sev(void)
{
}
static inline void rte_wfe(void)

Quoted 6 lines
{
	rte_pause();
}

#endif

And then just one common version of _wait_ functios:

Good suggestion, will fix in v9.

Quoted 167 lines

static __rte_always_inline void \
rte_wait_until_equal_32(volatile type * addr, type expected, int memorder)

{                                                              \
	if (__atomic_load_n(addr, memorder) != expected) {
		rte_sev();
		do {
	                       rte_wfe();
	              } while (__atomic_load_n(addr, memorder) != expected);
	  }
}
Quoted 9 lines

Review

Quoted 9 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +3 -0
+
+#endif /* RTE_ARM_USE_WFE */
+
 #ifdef __cplusplus
 }
 #endif
(quoted diff) +0 -0

b/lib/librte_eal/common/include/generic/rte_pause.h

Quoted 26 lines
Quoted 26 lines

index 52bd4db..80597a9 100644

lib/librte_eal/common/include/generic/rte_pause.h +6 -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,11 @@
  *
  */
 
+#include <stdint.h>
+#include <rte_common.h>
+#include <rte_atomic.h>
+#include <rte_compat.h>
+
 /**
  * Pause CPU execution for a short while
  *
@@ -20,4 +26,91 @@
  */
 static inline void rte_pause(void);
 
Quoted 3 lines

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 3 lines
lib/librte_eal/common/include/generic/rte_pause.h +3 -0
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without

prior notice

Quoted 2 lines

lib/librte_eal/common/include/generic/rte_pause.h line 33

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+ *
+ * Wait for *addr to be updated with a 16-bit expected value, with a

relaxed

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 34

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

Quoted 9 lines

lib/librte_eal/common/include/generic/rte_pause.h

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

Quoted 10 lines

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

Quoted 2 lines

lib/librte_eal/common/include/generic/rte_pause.h line 55

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+ *
+ * Wait for *addr to be updated with a 32-bit expected value, with a

relaxed

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 56

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

Quoted 9 lines

lib/librte_eal/common/include/generic/rte_pause.h

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

Quoted 10 lines

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

Quoted 2 lines

lib/librte_eal/common/include/generic/rte_pause.h line 77

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+ *
+ * Wait for *addr to be updated with a 64-bit expected value, with a

relaxed

Quoted 1 line

lib/librte_eal/common/include/generic/rte_pause.h line 78

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

Quoted 9 lines

lib/librte_eal/common/include/generic/rte_pause.h

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 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

Quoted 10 lines

lib/librte_eal/common/include/generic/rte_pause.h line 94

Quoted 7 lines
lib/librte_eal/common/include/generic/rte_pause.h +7 -0
+ *  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);
+

Here, change this check to:

Quoted 4 lines

#ifndef RTE_ARCH_HAS_WFE

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+#ifndef RTE_ARM_USE_WFE

Might be something arch neutral in name here?
RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED or so?

Quoted 29 lines
Quoted 22 lines
lib/librte_eal/common/include/generic/rte_pause.h +20 -1
+#define __WAIT_UNTIL_EQUAL(type, size, addr, expected, memorder) \
+__rte_experimental \
+static __rte_always_inline void                                        \
+rte_wait_until_equal_##size(volatile type * addr, type expected,\
+int memorder)                                                  \
+{                                                              \
+       if (__atomic_load_n(addr, memorder) != expected) {      \
+               do {                                                    \
+                       rte_pause();                                    \
+               } while (__atomic_load_n(addr, memorder) != expected);  \
+       }                                                               \
+}
+__WAIT_UNTIL_EQUAL(uint16_t, 16, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint32_t, 32, addr, expected, memorder)
+__WAIT_UNTIL_EQUAL(uint64_t, 64, addr, expected, memorder)
+
+#undef __WAIT_UNTIL_EQUAL
+
+#endif /* RTE_ARM_USE_WFE */
+
 #endif /* _RTE_PAUSE_H_ */
--
Quoted 2 lines

2.7.4

Thanks.

--
David Marchand

author
#116 lore raw

PATCH v8 3/6 spinlock: use wfe to reduce contention on aarch64

In reply to Gavin Hu

In acquiring a spinlock, cores repeatedly poll the lock variable. This is replaced by rte_wait_until_equal API.

Running the micro benchmarking and the testpmd and l3fwd traffic tests on ThunderX2, Ampere eMAG80 and Arm N1SDP, everything went well and no notable performance gain nor degradation was measured.

---
 .../common/include/arch/arm/rte_spinlock.h         | 26 ++++++++++++++++++++++
 .../common/include/generic/rte_spinlock.h          |  2 +-
 2 files changed, 27 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/arch/arm/rte_spinlock.h +26 -0
index 1a6916b..c69bed1 100644
@@ -16,6 +16,32 @@ extern "C" {
 #include <rte_common.h>
 #include "generic/rte_spinlock.h"
 
+/* armv7a does support WFE, but an explicit wake-up signal using SEV is
+ * required (must be preceded by DSB to drain the store buffer) and
+ * this is less performant, so keep armv7a implementation unchanged.
+ */
+#ifdef RTE_ARM_USE_WFE
+static inline void
+rte_spinlock_lock(rte_spinlock_t *sl)
+{
+	unsigned int tmp;
+	/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.
+	 * faqs/ka16809.html
+	 */
+	asm volatile(
+		"1:	ldaxr %w[tmp], %w[locked]\n"
+		"cbnz   %w[tmp], 2f\n"
+		"stxr   %w[tmp], %w[one], %w[locked]\n"
+		"cbnz   %w[tmp], 1b\n"
+		"ret\n"
+		"2:	sevl\n"
+		"wfe\n"
+		"jmp	1b\n"
+		: [tmp] "=&r" (tmp), [locked] "+Q"(sl->locked)
+		: [one] "r" (1)
+}
+#endif
+
 static inline int rte_tm_supported(void)
 {
 	return 0;
lib/librte_eal/common/include/generic/rte_spinlock.h +1 -1
index 87ae7a4..cf57c72 100644
@@ -57,7 +57,7 @@ rte_spinlock_init(rte_spinlock_t *sl)
 static inline void
 rte_spinlock_lock(rte_spinlock_t *sl);
 
-#ifdef RTE_FORCE_INTRINSICS
+#if defined(RTE_FORCE_INTRINSICS) && !defined(RTE_ARM_USE_WFE)
 static inline void
 rte_spinlock_lock(rte_spinlock_t *sl)
 {
Signature · 1 line
2.7.4
author
#117 lore raw

PATCH v8 4/6 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

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
index d9bec87..c295ae7 100644
@@ -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
author
#118 lore raw

PATCH v8 5/6 net/thunderx: use new API to save cycles on aarch64

In reply to Gavin Hu

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
index e6bf497..9e0de10 100644
@@ -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
index 69819a9..23d9458 100644
@@ -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
index 1c42874..90a6098 100644
@@ -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
author
#119 lore raw

PATCH v8 6/6 event/opdl: use new API to save cycles on aarch64

In reply to Gavin Hu

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
index bf50a60..72ef07d 100644
@@ -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
index 1fe034e..e67b164 100644
@@ -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
index 06fb5b3..c8d19fe 100644
@@ -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
author
#120 lore raw

v9 cover use WFE for aarch64

In reply to Gavin Hu

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         |  70 +++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 217 +++++++++++++++++++++
 .../common/include/generic/rte_ticketlock.h        |   3 +-
 12 files changed, 304 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
author
#121 lore raw

PATCH v9 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

Fixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")
---
 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
index d0c7b39..68ce38b 100644
@@ -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
author
#122 lore raw

PATCH v9 2/5 eal: add the APIs to wait until equal

In reply to Gavin Hu

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.

---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  70 +++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 217 +++++++++++++++++++++
 4 files changed, 293 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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 +70 -0

81 lines not on this page · raw message

lib/librte_eal/common/include/generic/rte_pause.h +217 -0

232 lines not on this page · raw message

Signature · 1 line
2.7.4
#123 lore raw

Re: [dpdk-dev] [PATCH v9 2/5] eal: add the APIs to wait until equal

Hi Gavin,

Quoted 129 lines

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.

---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  70 +++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 217 +++++++++++++++++++++
 4 files changed, 293 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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 +60 -0
index 93895d3..7bc8efb 100644
@@ -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_
@@ -17,6 +18,75 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+static inline void rte_sevl(void)
+{
+	asm volatile("sevl" : : : "memory");
+}
+
+static inline void rte_wfe(void)
+{
+	asm volatile("wfe" : : : "memory");
+}
+
+static __rte_always_inline uint16_t
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder)
+{
+	uint16_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxrh %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxrh %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+
+static __rte_always_inline uint32_t
+__atomic_load_ex_32(volatile uint32_t *addr, int memorder)
+{
+	uint32_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxr %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxr %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+
+static __rte_always_inline uint64_t
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder)
+{
+	uint64_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxr %x[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 89

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxr %x[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+#endif
+

The function themselves seems good to me...
But I think it was some misunderstanding about code layout/placement.
I think arm specific functionsand defines need to be defined in arm specific headers only. But we still can have one instance of rte_wait_until_equal_* for arm.

To be more specific, I am talking about something like that here:

lib/librte_eal/common/include/generic/rte_pause.h:
...
#ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED static __rte_always_inline void
rte_wait_until_equal_32(volatile type * addr, type expected, int memorder) \

{				
	while (__atomic_load_n(addr, memorder) != expected) {
		rte_pause();					\
							\
}

....
#endif
...

lib/librte_eal/common/include/arch/arm/rte_pause_64.h:

...
#ifdef RTE_ARM_USE_WFE
#define RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
#endif
#include "generic/rte_pause.h"

...
#ifdef RTE_ARM_USE_WFE
static inline void rte_sevl(void)

{
	asm volatile("sevl" : : : "memory");
}
static inline void rte_wfe(void)
{
	asm volatile("wfe" : : : "memory");
}

#else
static inline void rte_sevl(void)
{
}
static inline void rte_wfe(void)

{
	rte_pause();
}

...

static __rte_always_inline void
rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, int memorder)

{
	if (__atomic_load_ex_32(addr, memorder) != expected) {
		rte_sevl();
		do {
			rte_wfe();
		} while (__atomic_load_ex_32(addr, memorder) != expected);
	}
}

#endif

Quoted 244 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +0 -0
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +217 -1
index 52bd4db..4db44f9 100644
@@ -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,214 @@
  */
 static inline void rte_pause(void);
 
+static inline void rte_sevl(void);
+static inline void rte_wfe(void);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Atomic load from addr, it returns the 16-bit content of *addr.
+ *
+ * @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
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Atomic load from addr, it returns the 32-bit content of *addr.
+ *
+ * @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
+__atomic_load_ex_32(volatile uint32_t *addr, int memorder);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Atomic load from addr, it returns the 64-bit content of *addr.
+ *
+ * @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
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder);
+
+/**
+ * @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);
+
+#ifdef RTE_ARM_USE_WFE
+#define RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+#endif
+
+#ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+static inline void rte_sevl(void)
+{
+}
+
+static inline void rte_wfe(void)
+{
+	rte_pause();
+}
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Atomic load from addr, it returns the 16-bit content of *addr.
+ *
+ * @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
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder)
+{
+	uint16_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	tmp = __atomic_load_n(addr, memorder);
+	return tmp;
+}
+
+static __rte_always_inline uint32_t
+__atomic_load_ex_32(volatile uint32_t *addr, int memorder)
+{
+	uint32_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	tmp = __atomic_load_n(addr, memorder);
+	return tmp;
+}
+
+static __rte_always_inline uint64_t
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder)
+{
+	uint64_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	tmp = __atomic_load_n(addr, memorder);
+	return tmp;
+}
+
+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 (__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_ex_32(addr, memorder) != expected) {
+		rte_sevl();
+		do {
+			rte_wfe();
+		} while (__atomic_load_ex_32(addr, memorder) != expected);
+	}
+}
+
+static __rte_always_inline void
+rte_wait_until_equal_64(volatile uint64_t *addr, uint64_t expected,
+int memorder)
+{
+	if (__atomic_load_ex_64(addr, memorder) != expected) {
+		rte_sevl();
+		do {
+			rte_wfe();
+		} while (__atomic_load_ex_64(addr, memorder) != expected);
+	}
+}
+#endif
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#124 lore raw

Re: [dpdk-dev] [PATCH v9 2/5] eal: add the APIs to wait until equal

Quoted 197 lines

Hi Gavin,

Quoted 129 lines

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.

---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  70 +++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 217 +++++++++++++++++++++
 4 files changed, 293 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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 +60 -0
index 93895d3..7bc8efb 100644
@@ -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_
@@ -17,6 +18,75 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+static inline void rte_sevl(void)
+{
+	asm volatile("sevl" : : : "memory");
+}
+
+static inline void rte_wfe(void)
+{
+	asm volatile("wfe" : : : "memory");
+}
+
+static __rte_always_inline uint16_t
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder)
+{
+	uint16_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxrh %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxrh %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+
+static __rte_always_inline uint32_t
+__atomic_load_ex_32(volatile uint32_t *addr, int memorder)
+{
+	uint32_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxr %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxr %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+
+static __rte_always_inline uint64_t
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder)
+{
+	uint64_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxr %x[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 89

Quoted 10 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +10 -0
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxr %x[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+#endif
+

The function themselves seems good to me...
But I think it was some misunderstanding about code layout/placement.
I think arm specific functionsand defines need to be defined in arm specific headers only. But we still can have one instance of rte_wait_until_equal_* for arm.

To be more specific, I am talking about something like that here:

lib/librte_eal/common/include/generic/rte_pause.h:
...
#ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED static __rte_always_inline void
rte_wait_until_equal_32(volatile type * addr, type expected, int memorder) \

{
	while (__atomic_load_n(addr, memorder) != expected) {
		rte_pause();					\
							\
}

....
#endif
...

lib/librte_eal/common/include/arch/arm/rte_pause_64.h:

...
#ifdef RTE_ARM_USE_WFE
#define RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
#endif
#include "generic/rte_pause.h"

...
#ifdef RTE_ARM_USE_WFE
static inline void rte_sevl(void)

{
	asm volatile("sevl" : : : "memory");
}
static inline void rte_wfe(void)
{
	asm volatile("wfe" : : : "memory");
}

#else
static inline void rte_sevl(void)
{
}
static inline void rte_wfe(void)

{
	rte_pause();
}

...

static __rte_always_inline void
rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, int memorder)

Quoted 8 lines
{
	if (__atomic_load_ex_32(addr, memorder) != expected) {
		rte_sevl();
		do {
			rte_wfe();
		} while (__atomic_load_ex_32(addr, memorder) != expected);
	}
}

One more nit (nearly forgot): I think it is better to have rte_ (or __rte__) prefix for all functions defined in public files, so: __rte_atomic_load_ex_32() or just rte_atomic_load_ex_32().

Quoted 248 lines

#endif

Quoted 244 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +0 -0
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/generic/rte_pause.h +217 -1
index 52bd4db..4db44f9 100644
@@ -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,214 @@
  */
 static inline void rte_pause(void);
 
+static inline void rte_sevl(void);
+static inline void rte_wfe(void);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Atomic load from addr, it returns the 16-bit content of *addr.
+ *
+ * @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
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Atomic load from addr, it returns the 32-bit content of *addr.
+ *
+ * @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
+__atomic_load_ex_32(volatile uint32_t *addr, int memorder);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Atomic load from addr, it returns the 64-bit content of *addr.
+ *
+ * @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
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder);
+
+/**
+ * @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);
+
+#ifdef RTE_ARM_USE_WFE
+#define RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+#endif
+
+#ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+static inline void rte_sevl(void)
+{
+}
+
+static inline void rte_wfe(void)
+{
+	rte_pause();
+}
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Atomic load from addr, it returns the 16-bit content of *addr.
+ *
+ * @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
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder)
+{
+	uint16_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	tmp = __atomic_load_n(addr, memorder);
+	return tmp;
+}
+
+static __rte_always_inline uint32_t
+__atomic_load_ex_32(volatile uint32_t *addr, int memorder)
+{
+	uint32_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	tmp = __atomic_load_n(addr, memorder);
+	return tmp;
+}
+
+static __rte_always_inline uint64_t
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder)
+{
+	uint64_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	tmp = __atomic_load_n(addr, memorder);
+	return tmp;
+}
+
+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 (__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_ex_32(addr, memorder) != expected) {
+		rte_sevl();
+		do {
+			rte_wfe();
+		} while (__atomic_load_ex_32(addr, memorder) != expected);
+	}
+}
+
+static __rte_always_inline void
+rte_wait_until_equal_64(volatile uint64_t *addr, uint64_t expected,
+int memorder)
+{
+	if (__atomic_load_ex_64(addr, memorder) != expected) {
+		rte_sevl();
+		do {
+			rte_wfe();
+		} while (__atomic_load_ex_64(addr, memorder) != expected);
+	}
+}
+#endif
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#125 lore raw

Re: [dpdk-dev] [PATCH v9 2/5] eal: add the APIs to wait until equal

In reply to Ananyev, Konstantin

Hi Konstantin,

Quoted 156 lines

-----Original Message-----
From: Ananyev, Konstantin <[email protected]>
Sent: Thursday, October 24, 2019 9:52 PM
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 v9 2/5] eal: add the APIs to wait until equal

Hi Gavin,

Quoted 20 lines

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.

Quoted 5 lines
---
 config/arm/meson.build                             |   1 +
 config/common_base                                 |   5 +
 .../common/include/arch/arm/rte_pause_64.h         |  70 +++++++
 lib/librte_eal/common/include/generic/rte_pause.h  | 217

+++++++++++++++++++++

Quoted 20 lines
 4 files changed, 293 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -111,6 +111,11 @@ CONFIG_RTE_MAX_VFIO_CONTAINERS=64
 CONFIG_RTE_MALLOC_DEBUG=n

config/common_base CONFIG_RTE_MAX_VFIO_CONTAINERS=64 · line 121

Quoted 10 lines
config/common_base +5 -0
 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.

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_eal/common/include/arch/arm/rte_pause_64.h

Quoted 81 lines

index 93895d3..7bc8efb 100644

lib/librte_eal/common/include/arch/arm/rte_pause_64.h +68 -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_
@@ -17,6 +18,75 @@ static inline void rte_pause(void)
 	asm volatile("yield" ::: "memory");
 }
 
+#ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+static inline void rte_sevl(void)
+{
+	asm volatile("sevl" : : : "memory");
+}
+
+static inline void rte_wfe(void)
+{
+	asm volatile("wfe" : : : "memory");
+}
+
+static __rte_always_inline uint16_t
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder)
+{
+	uint16_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxrh %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxrh %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+
+static __rte_always_inline uint32_t
+__atomic_load_ex_32(volatile uint32_t *addr, int memorder)
+{
+	uint32_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxr %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxr %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+
+static __rte_always_inline uint64_t
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder)
+{
+	uint64_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxr %x[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxr %x[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
Quoted 8 lines

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 89

Quoted 2 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +2 -0
+#endif
+

The function themselves seems good to me...
But I think it was some misunderstanding about code layout/placement. I think arm specific functionsand defines need to be defined in arm specific headers only.
But we still can have one instance of rte_wait_until_equal_* for arm.

I will move that part to arm specific headers.
/Gavin

Quoted 36 lines

To be more specific, I am talking about something like that here:

lib/librte_eal/common/include/generic/rte_pause.h:
...
#ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
static __rte_always_inline void rte_wait_until_equal_32(volatile type * addr, type expected, int memorder)

							\
{
	while (__atomic_load_n(addr, memorder) != expected) {
		rte_pause();					\
							\
}

....
#endif
...

lib/librte_eal/common/include/arch/arm/rte_pause_64.h:

...
#ifdef RTE_ARM_USE_WFE
#define RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
#endif
#include "generic/rte_pause.h"

...
#ifdef RTE_ARM_USE_WFE
static inline void rte_sevl(void)

{
	asm volatile("sevl" : : : "memory");
}
static inline void rte_wfe(void)
{
	asm volatile("wfe" : : : "memory");
}
Quoted 8 lines

#else
static inline void rte_sevl(void)
{
}
static inline void rte_wfe(void)

{
	rte_pause();
}

Should these arm specific APIs, including rte_load_ex_xxx APIs, be added the doxygen comments?
These APIs are arm specific, not intended to expose, but they are in the public files(arm specific headers be considered public?) /Gavin

Quoted 290 lines

...

static __rte_always_inline void rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, int memorder)

{
	if (__atomic_load_ex_32(addr, memorder) != expected) {
		rte_sevl();
		do {
			rte_wfe();
		} while (__atomic_load_ex_32(addr, memorder) !=
expected);
	}
}

#endif

Review

Quoted 4 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +0 -0
 #ifdef __cplusplus
 }
 #endif
(quoted diff) +0 -0

b/lib/librte_eal/common/include/generic/rte_pause.h

Quoted 24 lines

index 52bd4db..4db44f9 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 34

Quoted 8 lines
lib/librte_eal/common/include/generic/rte_pause.h +5 -0
@@ -20,4 +27,214 @@
  */
 static inline void rte_pause(void);
 
+static inline void rte_sevl(void);
+static inline void rte_wfe(void);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior

notice

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 7 lines
lib/librte_eal/common/include/generic/rte_pause.h +7 -0
+ *
+ * Atomic load from addr, it returns the 16-bit content of *addr.
+ *
+ * @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/generic/rte_pause.h line 42

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ *  These map to C++11 memory orders with the same names, see the

C++11 standard

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 8 lines
lib/librte_eal/common/include/generic/rte_pause.h +8 -0
+ *  the GCC wiki on atomic synchronization for detailed definitions.
+ */
+static __rte_always_inline uint16_t
+__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/generic/rte_pause.h

Quoted 7 lines
lib/librte_eal/common/include/generic/rte_pause.h +7 -0
+ *
+ * Atomic load from addr, it returns the 32-bit content of *addr.
+ *
+ * @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/generic/rte_pause.h line 58

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ *  These map to C++11 memory orders with the same names, see the

C++11 standard

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 8 lines
lib/librte_eal/common/include/generic/rte_pause.h +8 -0
+ *  the GCC wiki on atomic synchronization for detailed definitions.
+ */
+static __rte_always_inline uint32_t
+__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/generic/rte_pause.h

Quoted 7 lines
lib/librte_eal/common/include/generic/rte_pause.h +7 -0
+ *
+ * Atomic load from addr, it returns the 64-bit content of *addr.
+ *
+ * @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/generic/rte_pause.h line 74

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ *  These map to C++11 memory orders with the same names, see the

C++11 standard

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 8 lines
lib/librte_eal/common/include/generic/rte_pause.h +8 -0
+ *  the GCC wiki on atomic synchronization for detailed definitions.
+ */
+static __rte_always_inline uint64_t
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior

notice

lib/librte_eal/common/include/generic/rte_pause.h line 84

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+ *
+ * Wait for *addr to be updated with a 16-bit expected value, with a

relaxed

lib/librte_eal/common/include/generic/rte_pause.h line 85

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

lib/librte_eal/common/include/generic/rte_pause.h

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 line 106

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+ *
+ * Wait for *addr to be updated with a 32-bit expected value, with a

relaxed

lib/librte_eal/common/include/generic/rte_pause.h line 107

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

lib/librte_eal/common/include/generic/rte_pause.h

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 line 128

Quoted 2 lines
lib/librte_eal/common/include/generic/rte_pause.h +2 -0
+ *
+ * Wait for *addr to be updated with a 64-bit expected value, with a

relaxed

lib/librte_eal/common/include/generic/rte_pause.h line 129

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ * memory ordering model meaning the loads around this API can be

reordered.

lib/librte_eal/common/include/generic/rte_pause.h

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 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

Quoted 14 lines
lib/librte_eal/common/include/generic/rte_pause.h +14 -0
+ *  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);
+
+#ifdef RTE_ARM_USE_WFE
+#define RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+#endif
+
+#ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+static inline void rte_sevl(void)
+{

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+}
+
+static inline void rte_wfe(void)
+{
+	rte_pause();
+}
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior

notice

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 7 lines
lib/librte_eal/common/include/generic/rte_pause.h +7 -0
+ *
+ * Atomic load from addr, it returns the 16-bit content of *addr.
+ *
+ * @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/generic/rte_pause.h line 170

Quoted 1 line
lib/librte_eal/common/include/generic/rte_pause.h +1 -0
+ *  These map to C++11 memory orders with the same names, see the

C++11 standard

Quoted 31 lines
lib/librte_eal/common/include/generic/rte_pause.h +31 -0
+ *  the GCC wiki on atomic synchronization for detailed definitions.
+ */
+static __rte_always_inline uint16_t
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder)
+{
+	uint16_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	tmp = __atomic_load_n(addr, memorder);
+	return tmp;
+}
+
+static __rte_always_inline uint32_t
+__atomic_load_ex_32(volatile uint32_t *addr, int memorder)
+{
+	uint32_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	tmp = __atomic_load_n(addr, memorder);
+	return tmp;
+}
+
+static __rte_always_inline uint64_t
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder)
+{
+	uint64_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	tmp = __atomic_load_n(addr, memorder);
+	return tmp;
+}

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+
+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 (__atomic_load_ex_16(addr, memorder) !=

expected);

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 12 lines
lib/librte_eal/common/include/generic/rte_pause.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_ex_32(addr, memorder) != expected) {
+		rte_sevl();
+		do {
+			rte_wfe();
+		} while (__atomic_load_ex_32(addr, memorder) !=

expected);

lib/librte_eal/common/include/generic/rte_pause.h

Quoted 12 lines
lib/librte_eal/common/include/generic/rte_pause.h +12 -0
+	}
+}
+
+static __rte_always_inline void
+rte_wait_until_equal_64(volatile uint64_t *addr, uint64_t expected,
+int memorder)
+{
+	if (__atomic_load_ex_64(addr, memorder) != expected) {
+		rte_sevl();
+		do {
+			rte_wfe();
+		} while (__atomic_load_ex_64(addr, memorder) !=

expected);

Quoted 7 lines
lib/librte_eal/common/include/generic/rte_pause.h +4 -1
+	}
+}
+#endif
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

author
#126 lore raw

PATCH v9 3/5 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

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
index d9bec87..c295ae7 100644
@@ -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
author
#127 lore raw

PATCH v9 4/5 net/thunderx: use new API to save cycles on aarch64

In reply to Gavin Hu

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
index e6bf497..9e0de10 100644
@@ -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
index 69819a9..23d9458 100644
@@ -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
index 1c42874..90a6098 100644
@@ -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
author
#128 lore raw

PATCH v9 5/5 event/opdl: use new API to save cycles on aarch64

In reply to Gavin Hu

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
index bf50a60..72ef07d 100644
@@ -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
index 1fe034e..e67b164 100644
@@ -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
index 06fb5b3..c8d19fe 100644
@@ -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
author
#129 lore raw

v10 cover use WFE for aarch64

In reply to Gavin Hu

V10:
- move arm specific stuff to arch/arm/rte_pause_64.h
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  | 108 ++++++++++++
 .../common/include/generic/rte_ticketlock.h        |   3 +-
 12 files changed, 313 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
author
#130 lore raw

PATCH v10 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

Fixes 3af733ba8da8 ("bus/fslmc: introduce MC object functions")
---
 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
index d0c7b39..68ce38b 100644
@@ -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
author
#131 lore raw

PATCH v10 2/5 eal: add the APIs to wait until equal

In reply to Gavin Hu

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.

---
 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  | 108 ++++++++++++
 4 files changed, 302 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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 +108 -0

123 lines not on this page · raw message

Signature · 1 line
2.7.4
Acked-by on v10 2/5
#132 lore raw

Re: [dpdk-dev] [PATCH v10 2/5] eal: add the APIs to wait until equal

Hi Gavin,

Quoted 121 lines

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.

---
 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  | 108 ++++++++++++
 4 files changed, 302 insertions(+)
config/arm/meson.build +1 -0
index 979018e..b4b4cac 100644
@@ -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
index e843a21..c812156 100644
@@ -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 +45 -0
index 93895d3..dd37f72 100644
@@ -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)
 	asm volatile("yield" ::: "memory");
 }
 
+/**
+ * Send an event to exit 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)
+{
+	asm volatile("sevl" : : : "memory");
+}
+
+static inline void rte_wfe(void)
+{
+	asm volatile("wfe" : : : "memory");
+}
+#else
+static inline void rte_sevl(void)
+{
+}
+static inline void rte_wfe(void)
+{
+	rte_pause();
+}
+#endif
+
+#ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
+/**
+ * @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.

lib/librte_eal/common/include/arch/arm/rte_pause_64.h static inline void rte_pause(void) · line 74

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
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder);

I still think (as it is a public header) better to have all function names prefixed with rte_. Or if you consider them not to be used by user explicitly with __rte_
BTW, these _load_ex_ functions can be defined even if RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED, though don't know would be any other non-WFE usages for them.

Quoted 107 lines
lib/librte_eal/common/include/arch/arm/rte_pause_64.h +107 -0
+
+/**
+ * @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
+__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
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder);
+
+static __rte_always_inline uint16_t
+__atomic_load_ex_16(volatile uint16_t *addr, int memorder)
+{
+	uint16_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxrh %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxrh %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+
+static __rte_always_inline uint32_t
+__atomic_load_ex_32(volatile uint32_t *addr, int memorder)
+{
+	uint32_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxr %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxr %w[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+
+static __rte_always_inline uint64_t
+__atomic_load_ex_64(volatile uint64_t *addr, int memorder)
+{
+	uint64_t tmp;
+	assert((memorder == __ATOMIC_ACQUIRE)
+			|| (memorder == __ATOMIC_RELAXED));
+	if (memorder == __ATOMIC_ACQUIRE)
+		asm volatile("ldaxr %x[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	else if (memorder == __ATOMIC_RELAXED)
+		asm volatile("ldxr %x[tmp], [%x[addr]]"
+			: [tmp] "=&r" (tmp)
+			: [addr] "r"(addr)
+			: "memory");
+	return tmp;
+}
+
+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 (__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);

while (__atomic_load_ex_32(addr, memorder) != expected); ?
Same for 64 bit version

Quoted 113 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 +73 -0
index 52bd4db..9854455 100644
@@ -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,105 @@
  */
 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);
+

lib/librte_eal/common/include/generic/rte_pause.h line 105

Quoted 10 lines
lib/librte_eal/common/include/generic/rte_pause.h +10 -0
+#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)
+{
+	if (__atomic_load_n(addr, memorder) != expected) {
+		do {
+			rte_pause();
+		} while (__atomic_load_n(addr, memorder) != expected);
+	}

I think, these generic implementations could be just:
while (__atomic_load_n(addr, memorder) != expected)

	rte_pause();

Other than that:

Quoted 28 lines
lib/librte_eal/common/include/generic/rte_pause.h +25 -1
+}
+
+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) {
+		do {
+			rte_pause();
+		} while (__atomic_load_n(addr, memorder) != expected);
+	}
+}
+
+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) {
+		do {
+			rte_pause();
+		} while (__atomic_load_n(addr, memorder) != expected);
+	}
+}
+#endif
+
 #endif /* _RTE_PAUSE_H_ */
--

2.7.4

#133 lore raw

Re: [dpdk-dev] [PATCH v10 2/5] eal: add the APIs to wait until equal

Hi Konstantin,

I think all your comments are addressed in v11, you can have a check, thanks for your review and really appreciate. /Gavin

author
#134 lore raw

PATCH v10 3/5 ticketlock: use new API to reduce contention on aarch64

In reply to Gavin Hu

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
index d9bec87..c295ae7 100644
@@ -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
author
#135 lore raw

PATCH v10 4/5 net/thunderx: use new API to save cycles on aarch64

In reply to Gavin Hu

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
index e6bf497..9e0de10 100644
@@ -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
index 69819a9..23d9458 100644
@@ -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
index 1c42874..90a6098 100644
@@ -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