DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v1 0/2] Use WFE for spinlock and ring
@ 2020-04-24  7:07 Gavin Hu
  2020-04-24  7:07 ` [dpdk-dev] [PATCH v1 1/2] spinlock: use wfe to reduce contention on aarch64 Gavin Hu
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Gavin Hu @ 2020-04-24  7:07 UTC (permalink / raw)
  To: dev
  Cc: nd, david.marchand, thomas, jerinj, Honnappa.Nagarahalli,
	Ruifeng.Wang, Phil.Yang, Joyce.Kong

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

Use the API for the rte spinlock and ring implementations.

[1] http://patches.dpdk.org/cover/62703/

Gavin Hu (2):
  spinlock: use wfe to reduce contention on aarch64
  ring: use wfe to wait for ring tail update on aarch64

 lib/librte_eal/include/generic/rte_spinlock.h | 5 ++---
 lib/librte_ring/rte_ring_c11_mem.h            | 4 ++--
 lib/librte_ring/rte_ring_generic.h            | 3 +--
 3 files changed, 5 insertions(+), 7 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v1 1/2] spinlock: use wfe to reduce contention on aarch64
  2020-04-24  7:07 [dpdk-dev] [PATCH v1 0/2] Use WFE for spinlock and ring Gavin Hu
@ 2020-04-24  7:07 ` Gavin Hu
  2020-04-24  7:07 ` [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update " Gavin Hu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Gavin Hu @ 2020-04-24  7:07 UTC (permalink / raw)
  To: dev
  Cc: nd, david.marchand, thomas, jerinj, Honnappa.Nagarahalli,
	Ruifeng.Wang, Phil.Yang, Joyce.Kong

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.

Signed-off-by: Gavin Hu <gavin.hu@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Steve Capper <steve.capper@arm.com>
Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Tested-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 lib/librte_eal/include/generic/rte_spinlock.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/include/generic/rte_spinlock.h b/lib/librte_eal/include/generic/rte_spinlock.h
index 87ae7a4f1..5cc123247 100644
--- a/lib/librte_eal/include/generic/rte_spinlock.h
+++ b/lib/librte_eal/include/generic/rte_spinlock.h
@@ -28,7 +28,7 @@
  * The rte_spinlock_t type.
  */
 typedef struct {
-	volatile int locked; /**< lock status 0 = unlocked, 1 = locked */
+	volatile uint32_t locked; /**< lock status 0 = unlocked, 1 = locked */
 } rte_spinlock_t;
 
 /**
@@ -65,8 +65,7 @@ rte_spinlock_lock(rte_spinlock_t *sl)
 
 	while (!__atomic_compare_exchange_n(&sl->locked, &exp, 1, 0,
 				__ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {
-		while (__atomic_load_n(&sl->locked, __ATOMIC_RELAXED))
-			rte_pause();
+		rte_wait_until_equal_32(&sl->locked, 0, __ATOMIC_RELAXED);
 		exp = 0;
 	}
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update on aarch64
  2020-04-24  7:07 [dpdk-dev] [PATCH v1 0/2] Use WFE for spinlock and ring Gavin Hu
  2020-04-24  7:07 ` [dpdk-dev] [PATCH v1 1/2] spinlock: use wfe to reduce contention on aarch64 Gavin Hu
@ 2020-04-24  7:07 ` Gavin Hu
  2020-04-24 13:23   ` Ananyev, Konstantin
  2020-04-24 14:46   ` Honnappa Nagarahalli
  2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring Gavin Hu
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 16+ messages in thread
From: Gavin Hu @ 2020-04-24  7:07 UTC (permalink / raw)
  To: dev
  Cc: nd, david.marchand, thomas, jerinj, Honnappa.Nagarahalli,
	Ruifeng.Wang, Phil.Yang, Joyce.Kong

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

Signed-off-by: Gavin Hu <gavin.hu@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Steve Capper <steve.capper@arm.com>
Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
---
 lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
 lib/librte_ring/rte_ring_generic.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/lib/librte_ring/rte_ring_c11_mem.h b/lib/librte_ring/rte_ring_c11_mem.h
index 0fb73a337..764d8f186 100644
--- a/lib/librte_ring/rte_ring_c11_mem.h
+++ b/lib/librte_ring/rte_ring_c11_mem.h
@@ -2,6 +2,7 @@
  *
  * Copyright (c) 2017,2018 HXT-semitech Corporation.
  * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
+ * 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);
 }
diff --git a/lib/librte_ring/rte_ring_generic.h b/lib/librte_ring/rte_ring_generic.h
index 953cdbbd5..682852783 100644
--- a/lib/librte_ring/rte_ring_generic.h
+++ b/lib/librte_ring/rte_ring_generic.h
@@ -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;
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update on aarch64
  2020-04-24  7:07 ` [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update " Gavin Hu
@ 2020-04-24 13:23   ` Ananyev, Konstantin
  2020-04-26  8:41     ` Gavin Hu
  2020-04-24 14:46   ` Honnappa Nagarahalli
  1 sibling, 1 reply; 16+ messages in thread
From: Ananyev, Konstantin @ 2020-04-24 13:23 UTC (permalink / raw)
  To: Gavin Hu, dev
  Cc: nd, david.marchand, thomas, jerinj, Honnappa.Nagarahalli,
	Ruifeng.Wang, Phil.Yang, Joyce.Kong


> 
> Instead of polling for tail to be updated, use wfe instruction.
> 
> Signed-off-by: Gavin Hu <gavin.hu@arm.com>
> Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> Reviewed-by: Steve Capper <steve.capper@arm.com>
> Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> ---
>  lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
>  lib/librte_ring/rte_ring_generic.h | 3 +--
>  2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/librte_ring/rte_ring_c11_mem.h b/lib/librte_ring/rte_ring_c11_mem.h
> index 0fb73a337..764d8f186 100644
> --- a/lib/librte_ring/rte_ring_c11_mem.h
> +++ b/lib/librte_ring/rte_ring_c11_mem.h
> @@ -2,6 +2,7 @@
>   *
>   * Copyright (c) 2017,2018 HXT-semitech Corporation.
>   * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
> + * 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);
>  }
> diff --git a/lib/librte_ring/rte_ring_generic.h b/lib/librte_ring/rte_ring_generic.h
> index 953cdbbd5..682852783 100644
> --- a/lib/librte_ring/rte_ring_generic.h
> +++ b/lib/librte_ring/rte_ring_generic.h
> @@ -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);

./lib/librte_ring/rte_ring_generic.h:26:3: error: implicit declaration of function 'rte_wait_until_equal_relaxed_32'; did you mean 'rte_wait_until_equal_32'? [-Werror=implicit-function-declaration]
   rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


BTW, after patch #1 compilation fails also:
../lib/librte_eal/x86/include/rte_spinlock.h:125:24: error: pointer targets in passing argument 1 of 'rte_try_tm' differ in signedness [-Werror=pointer-sign]
  if (likely(rte_try_tm(&sl->locked)))
                        ^



> 
>  	ht->tail = new_val;
>  }
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update on aarch64
  2020-04-24  7:07 ` [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update " Gavin Hu
  2020-04-24 13:23   ` Ananyev, Konstantin
@ 2020-04-24 14:46   ` Honnappa Nagarahalli
  2020-04-26  8:33     ` Gavin Hu
  1 sibling, 1 reply; 16+ messages in thread
From: Honnappa Nagarahalli @ 2020-04-24 14:46 UTC (permalink / raw)
  To: Gavin Hu, dev
  Cc: nd, david.marchand, thomas, jerinj, Ruifeng Wang, Phil Yang,
	Joyce Kong, Honnappa Nagarahalli, nd

<snip>

Hi Gavin,
	There are other sync modes added to rte_ring library. Can you please extend this to other rte_pause() calls in the library?

Thanks,
Honnappa

> Subject: [PATCH v1 2/2] ring: use wfe to wait for ring tail update on aarch64
> 
> Instead of polling for tail to be updated, use wfe instruction.
> 
> Signed-off-by: Gavin Hu <gavin.hu@arm.com>
> Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> Reviewed-by: Steve Capper <steve.capper@arm.com>
> Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> ---
>  lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
> lib/librte_ring/rte_ring_generic.h | 3 +--
>  2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/librte_ring/rte_ring_c11_mem.h
> b/lib/librte_ring/rte_ring_c11_mem.h
> index 0fb73a337..764d8f186 100644
> --- a/lib/librte_ring/rte_ring_c11_mem.h
> +++ b/lib/librte_ring/rte_ring_c11_mem.h
> @@ -2,6 +2,7 @@
>   *
>   * Copyright (c) 2017,2018 HXT-semitech Corporation.
>   * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
> + * 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);  } diff --
> git a/lib/librte_ring/rte_ring_generic.h b/lib/librte_ring/rte_ring_generic.h
> index 953cdbbd5..682852783 100644
> --- a/lib/librte_ring/rte_ring_generic.h
> +++ b/lib/librte_ring/rte_ring_generic.h
> @@ -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;
>  }
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update on aarch64
  2020-04-24 14:46   ` Honnappa Nagarahalli
@ 2020-04-26  8:33     ` Gavin Hu
  0 siblings, 0 replies; 16+ messages in thread
From: Gavin Hu @ 2020-04-26  8:33 UTC (permalink / raw)
  To: Honnappa Nagarahalli, dev
  Cc: nd, david.marchand, thomas, jerinj, Ruifeng Wang, Phil Yang,
	Joyce Kong, nd, nd

Hi Honnappa,

> -----Original Message-----
> From: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>
> Sent: Friday, April 24, 2020 10:46 PM
> To: Gavin Hu <Gavin.Hu@arm.com>; dev@dpdk.org
> Cc: nd <nd@arm.com>; david.marchand@redhat.com;
> thomas@monjalon.net; jerinj@marvell.com; Ruifeng Wang
> <Ruifeng.Wang@arm.com>; Phil Yang <Phil.Yang@arm.com>; Joyce Kong
> <Joyce.Kong@arm.com>; Honnappa Nagarahalli
> <Honnappa.Nagarahalli@arm.com>; nd <nd@arm.com>
> Subject: RE: [PATCH v1 2/2] ring: use wfe to wait for ring tail update on
> aarch64
> 
> <snip>
> 
> Hi Gavin,
> 	There are other sync modes added to rte_ring library. Can you
> please extend this to other rte_pause() calls in the library?
I looked into the other two calls to rte_cause, they can't use the rte_wait_until_equal_XX APIs simply.
Maybe new APIs are required? 
Here is the 32-bit API for your reference:
rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, int memorder)
> 
> Thanks,
> Honnappa
> 
> > Subject: [PATCH v1 2/2] ring: use wfe to wait for ring tail update on
> aarch64
> >
> > Instead of polling for tail to be updated, use wfe instruction.
> >
> > Signed-off-by: Gavin Hu <gavin.hu@arm.com>
> > Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> > Reviewed-by: Steve Capper <steve.capper@arm.com>
> > Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
> > Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> > ---
> >  lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
> > lib/librte_ring/rte_ring_generic.h | 3 +--
> >  2 files changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/librte_ring/rte_ring_c11_mem.h
> > b/lib/librte_ring/rte_ring_c11_mem.h
> > index 0fb73a337..764d8f186 100644
> > --- a/lib/librte_ring/rte_ring_c11_mem.h
> > +++ b/lib/librte_ring/rte_ring_c11_mem.h
> > @@ -2,6 +2,7 @@
> >   *
> >   * Copyright (c) 2017,2018 HXT-semitech Corporation.
> >   * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
> > + * 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);  } diff --
> > git a/lib/librte_ring/rte_ring_generic.h b/lib/librte_ring/rte_ring_generic.h
> > index 953cdbbd5..682852783 100644
> > --- a/lib/librte_ring/rte_ring_generic.h
> > +++ b/lib/librte_ring/rte_ring_generic.h
> > @@ -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;
> >  }
> > --
> > 2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring
  2020-04-24  7:07 [dpdk-dev] [PATCH v1 0/2] Use WFE for spinlock and ring Gavin Hu
  2020-04-24  7:07 ` [dpdk-dev] [PATCH v1 1/2] spinlock: use wfe to reduce contention on aarch64 Gavin Hu
  2020-04-24  7:07 ` [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update " Gavin Hu
@ 2020-04-26  8:39 ` Gavin Hu
  2020-05-01  9:47   ` Ananyev, Konstantin
  2020-05-03 14:54   ` David Marchand
  2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 1/2] spinlock: use wfe to reduce contention on aarch64 Gavin Hu
  2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 2/2] ring: use wfe to wait for ring tail update " Gavin Hu
  4 siblings, 2 replies; 16+ messages in thread
From: Gavin Hu @ 2020-04-26  8:39 UTC (permalink / raw)
  To: dev
  Cc: nd, david.marchand, thomas, jerinj, Honnappa.Nagarahalli,
	Ruifeng.Wang, Phil.Yang, Joyce.Kong

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

Use the API for the rte spinlock and ring implementations.

[1] http://patches.dpdk.org/cover/62703/

Gavin Hu (2):
  spinlock: use wfe to reduce contention on aarch64
  ring: use wfe to wait for ring tail update on aarch64

 lib/librte_eal/include/generic/rte_spinlock.h | 4 ++--
 lib/librte_ring/rte_ring_c11_mem.h            | 4 ++--
 lib/librte_ring/rte_ring_generic.h            | 3 +--
 3 files changed, 5 insertions(+), 6 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v2 1/2] spinlock: use wfe to reduce contention on aarch64
  2020-04-24  7:07 [dpdk-dev] [PATCH v1 0/2] Use WFE for spinlock and ring Gavin Hu
                   ` (2 preceding siblings ...)
  2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring Gavin Hu
@ 2020-04-26  8:39 ` Gavin Hu
  2020-04-28 12:22   ` Jerin Jacob
  2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 2/2] ring: use wfe to wait for ring tail update " Gavin Hu
  4 siblings, 1 reply; 16+ messages in thread
From: Gavin Hu @ 2020-04-26  8:39 UTC (permalink / raw)
  To: dev
  Cc: nd, david.marchand, thomas, jerinj, Honnappa.Nagarahalli,
	Ruifeng.Wang, Phil.Yang, Joyce.Kong

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.

Signed-off-by: Gavin Hu <gavin.hu@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Steve Capper <steve.capper@arm.com>
Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Tested-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 lib/librte_eal/include/generic/rte_spinlock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/include/generic/rte_spinlock.h b/lib/librte_eal/include/generic/rte_spinlock.h
index 87ae7a4f1..40fe49d5a 100644
--- a/lib/librte_eal/include/generic/rte_spinlock.h
+++ b/lib/librte_eal/include/generic/rte_spinlock.h
@@ -65,8 +65,8 @@ rte_spinlock_lock(rte_spinlock_t *sl)
 
 	while (!__atomic_compare_exchange_n(&sl->locked, &exp, 1, 0,
 				__ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {
-		while (__atomic_load_n(&sl->locked, __ATOMIC_RELAXED))
-			rte_pause();
+		rte_wait_until_equal_32((volatile uint32_t *)&sl->locked,
+			       0, __ATOMIC_RELAXED);
 		exp = 0;
 	}
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v2 2/2] ring: use wfe to wait for ring tail update on aarch64
  2020-04-24  7:07 [dpdk-dev] [PATCH v1 0/2] Use WFE for spinlock and ring Gavin Hu
                   ` (3 preceding siblings ...)
  2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 1/2] spinlock: use wfe to reduce contention on aarch64 Gavin Hu
@ 2020-04-26  8:39 ` Gavin Hu
  4 siblings, 0 replies; 16+ messages in thread
From: Gavin Hu @ 2020-04-26  8:39 UTC (permalink / raw)
  To: dev
  Cc: nd, david.marchand, thomas, jerinj, Honnappa.Nagarahalli,
	Ruifeng.Wang, Phil.Yang, Joyce.Kong

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

Signed-off-by: Gavin Hu <gavin.hu@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Steve Capper <steve.capper@arm.com>
Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
---
 lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
 lib/librte_ring/rte_ring_generic.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/lib/librte_ring/rte_ring_c11_mem.h b/lib/librte_ring/rte_ring_c11_mem.h
index 0fb73a337..b37ef5995 100644
--- a/lib/librte_ring/rte_ring_c11_mem.h
+++ b/lib/librte_ring/rte_ring_c11_mem.h
@@ -2,6 +2,7 @@
  *
  * Copyright (c) 2017,2018 HXT-semitech Corporation.
  * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
+ * 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_32(&ht->tail, old_val, __ATOMIC_RELAXED);
 
 	__atomic_store_n(&ht->tail, new_val, __ATOMIC_RELEASE);
 }
diff --git a/lib/librte_ring/rte_ring_generic.h b/lib/librte_ring/rte_ring_generic.h
index 953cdbbd5..afce89aec 100644
--- a/lib/librte_ring/rte_ring_generic.h
+++ b/lib/librte_ring/rte_ring_generic.h
@@ -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_32(&ht->tail, old_val, __ATOMIC_RELAXED);
 
 	ht->tail = new_val;
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update on aarch64
  2020-04-24 13:23   ` Ananyev, Konstantin
@ 2020-04-26  8:41     ` Gavin Hu
  0 siblings, 0 replies; 16+ messages in thread
From: Gavin Hu @ 2020-04-26  8:41 UTC (permalink / raw)
  To: Ananyev, Konstantin, dev
  Cc: nd, david.marchand, thomas, jerinj, Honnappa Nagarahalli,
	Ruifeng Wang, Phil Yang, Joyce Kong, nd

Hi Konstantin,

> -----Original Message-----
> From: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Sent: Friday, April 24, 2020 9:24 PM
> To: Gavin Hu <Gavin.Hu@arm.com>; dev@dpdk.org
> Cc: nd <nd@arm.com>; david.marchand@redhat.com;
> thomas@monjalon.net; jerinj@marvell.com; Honnappa Nagarahalli
> <Honnappa.Nagarahalli@arm.com>; Ruifeng Wang
> <Ruifeng.Wang@arm.com>; Phil Yang <Phil.Yang@arm.com>; Joyce Kong
> <Joyce.Kong@arm.com>
> Subject: RE: [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail
> update on aarch64
> 
> 
> >
> > Instead of polling for tail to be updated, use wfe instruction.
> >
> > Signed-off-by: Gavin Hu <gavin.hu@arm.com>
> > Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> > Reviewed-by: Steve Capper <steve.capper@arm.com>
> > Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
> > Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> > ---
> >  lib/librte_ring/rte_ring_c11_mem.h | 4 ++--
> >  lib/librte_ring/rte_ring_generic.h | 3 +--
> >  2 files changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/librte_ring/rte_ring_c11_mem.h
> b/lib/librte_ring/rte_ring_c11_mem.h
> > index 0fb73a337..764d8f186 100644
> > --- a/lib/librte_ring/rte_ring_c11_mem.h
> > +++ b/lib/librte_ring/rte_ring_c11_mem.h
> > @@ -2,6 +2,7 @@
> >   *
> >   * Copyright (c) 2017,2018 HXT-semitech Corporation.
> >   * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
> > + * 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);
> >  }
> > diff --git a/lib/librte_ring/rte_ring_generic.h
> b/lib/librte_ring/rte_ring_generic.h
> > index 953cdbbd5..682852783 100644
> > --- a/lib/librte_ring/rte_ring_generic.h
> > +++ b/lib/librte_ring/rte_ring_generic.h
> > @@ -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);
> 
> ./lib/librte_ring/rte_ring_generic.h:26:3: error: implicit declaration of
> function 'rte_wait_until_equal_relaxed_32'; did you mean
> 'rte_wait_until_equal_32'? [-Werror=implicit-function-declaration]
>    rte_wait_until_equal_relaxed_32(&ht->tail, old_val);
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sorry for the leakage, fixed in v2.
> 
> BTW, after patch #1 compilation fails also:
> ../lib/librte_eal/x86/include/rte_spinlock.h:125:24: error: pointer targets in
> passing argument 1 of 'rte_try_tm' differ in signedness [-Werror=pointer-
> sign]
>   if (likely(rte_try_tm(&sl->locked)))
Fixed in v2, thanks!
>                         ^
> 
> 
> 
> >
> >  	ht->tail = new_val;
> >  }
> > --
> > 2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/2] spinlock: use wfe to reduce contention on aarch64
  2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 1/2] spinlock: use wfe to reduce contention on aarch64 Gavin Hu
@ 2020-04-28 12:22   ` Jerin Jacob
  0 siblings, 0 replies; 16+ messages in thread
From: Jerin Jacob @ 2020-04-28 12:22 UTC (permalink / raw)
  To: Gavin Hu
  Cc: dpdk-dev, nd, David Marchand, Thomas Monjalon, Jerin Jacob,
	Honnappa Nagarahalli, Ruifeng Wang (Arm Technology China),
	Phil Yang, Joyce Kong

On Sun, Apr 26, 2020 at 2:09 PM Gavin Hu <gavin.hu@arm.com> wrote:
>
> 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.
>
> Signed-off-by: Gavin Hu <gavin.hu@arm.com>
> Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> Reviewed-by: Phil Yang <phil.yang@arm.com>
> Reviewed-by: Steve Capper <steve.capper@arm.com>
> Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> Tested-by: Pavan Nikhilesh <pbhagavatula@marvell.com>

Acked-by: Jerin Jacob <jerinj@marvell.com>


> ---
>  lib/librte_eal/include/generic/rte_spinlock.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_eal/include/generic/rte_spinlock.h b/lib/librte_eal/include/generic/rte_spinlock.h
> index 87ae7a4f1..40fe49d5a 100644
> --- a/lib/librte_eal/include/generic/rte_spinlock.h
> +++ b/lib/librte_eal/include/generic/rte_spinlock.h
> @@ -65,8 +65,8 @@ rte_spinlock_lock(rte_spinlock_t *sl)
>
>         while (!__atomic_compare_exchange_n(&sl->locked, &exp, 1, 0,
>                                 __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {
> -               while (__atomic_load_n(&sl->locked, __ATOMIC_RELAXED))
> -                       rte_pause();
> +               rte_wait_until_equal_32((volatile uint32_t *)&sl->locked,
> +                              0, __ATOMIC_RELAXED);
>                 exp = 0;
>         }
>  }
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring
  2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring Gavin Hu
@ 2020-05-01  9:47   ` Ananyev, Konstantin
  2020-05-03 14:54   ` David Marchand
  1 sibling, 0 replies; 16+ messages in thread
From: Ananyev, Konstantin @ 2020-05-01  9:47 UTC (permalink / raw)
  To: Gavin Hu, dev
  Cc: nd, david.marchand, thomas, jerinj, Honnappa.Nagarahalli,
	Ruifeng.Wang, Phil.Yang, Joyce.Kong

> 
> The rte_wait_until_equal_xxx APIs abstract the functionality of 'polling
> for a memory location to become equal to a given value'[1].
> 
> Use the API for the rte spinlock and ring implementations.
> 
> [1] http://patches.dpdk.org/cover/62703/
> 
> Gavin Hu (2):
>   spinlock: use wfe to reduce contention on aarch64
>   ring: use wfe to wait for ring tail update on aarch64
> 
>  lib/librte_eal/include/generic/rte_spinlock.h | 4 ++--
>  lib/librte_ring/rte_ring_c11_mem.h            | 4 ++--
>  lib/librte_ring/rte_ring_generic.h            | 3 +--
>  3 files changed, 5 insertions(+), 6 deletions(-)
> 

Series Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

> --
> 2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring
  2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring Gavin Hu
  2020-05-01  9:47   ` Ananyev, Konstantin
@ 2020-05-03 14:54   ` David Marchand
  2020-05-03 21:31     ` Honnappa Nagarahalli
  1 sibling, 1 reply; 16+ messages in thread
From: David Marchand @ 2020-05-03 14:54 UTC (permalink / raw)
  To: Gavin Hu
  Cc: dev, nd, Thomas Monjalon, Jerin Jacob Kollanukkaran,
	Honnappa Nagarahalli, Ruifeng Wang (Arm Technology China),
	Phil Yang, Joyce Kong, Ananyev, Konstantin

On Sun, Apr 26, 2020 at 10:39 AM Gavin Hu <gavin.hu@arm.com> wrote:
>
> The rte_wait_until_equal_xxx APIs abstract the functionality of 'polling
> for a memory location to become equal to a given value'[1].
>
> Use the API for the rte spinlock and ring implementations.
>
> [1] http://patches.dpdk.org/cover/62703/
>
> Gavin Hu (2):
>   spinlock: use wfe to reduce contention on aarch64
>   ring: use wfe to wait for ring tail update on aarch64

This would result in rte_ring and rte_spinlock APIs becoming
experimental and this breaks compilation for external applications
using stable ring and spinlock APIs.
IIRC, it was the reason why these patches were dropped with the
introduction of the rte_wait_until_equal_* API.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring
  2020-05-03 14:54   ` David Marchand
@ 2020-05-03 21:31     ` Honnappa Nagarahalli
  2020-09-25 14:30       ` David Marchand
  0 siblings, 1 reply; 16+ messages in thread
From: Honnappa Nagarahalli @ 2020-05-03 21:31 UTC (permalink / raw)
  To: David Marchand
  Cc: dev, nd, thomas, jerinj, Ruifeng Wang, Phil Yang, Joyce Kong,
	Ananyev, Konstantin, Honnappa Nagarahalli, nd, nd

<snip>

> Subject: Re: [PATCH v2 0/2] Use WFE for spinlock and ring
> 
> On Sun, Apr 26, 2020 at 10:39 AM Gavin Hu <gavin.hu@arm.com> wrote:
> >
> > The rte_wait_until_equal_xxx APIs abstract the functionality of
> > 'polling for a memory location to become equal to a given value'[1].
> >
> > Use the API for the rte spinlock and ring implementations.
> >
> > [1] http://patches.dpdk.org/cover/62703/
> >
> > Gavin Hu (2):
> >   spinlock: use wfe to reduce contention on aarch64
> >   ring: use wfe to wait for ring tail update on aarch64
> 
> This would result in rte_ring and rte_spinlock APIs becoming experimental
> and this breaks compilation for external applications using stable ring and
> spinlock APIs.
> IIRC, it was the reason why these patches were dropped with the introduction
> of the rte_wait_until_equal_* API.
Agreed, the rte_ring new sync modes are resulting in different use cases for these APIs. We need to take a relook at the APIs.

> 
> 
> --
> David Marchand


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring
  2020-05-03 21:31     ` Honnappa Nagarahalli
@ 2020-09-25 14:30       ` David Marchand
  2021-03-25 14:58         ` David Marchand
  0 siblings, 1 reply; 16+ messages in thread
From: David Marchand @ 2020-09-25 14:30 UTC (permalink / raw)
  To: Honnappa Nagarahalli
  Cc: dev, nd, thomas, jerinj, Ruifeng Wang, Phil Yang, Joyce Kong,
	Ananyev, Konstantin

Hello Honnappa,

On Sun, May 3, 2020 at 11:32 PM Honnappa Nagarahalli
<Honnappa.Nagarahalli@arm.com> wrote:
>
> <snip>
>
> > Subject: Re: [PATCH v2 0/2] Use WFE for spinlock and ring
> >
> > On Sun, Apr 26, 2020 at 10:39 AM Gavin Hu <gavin.hu@arm.com> wrote:
> > >
> > > The rte_wait_until_equal_xxx APIs abstract the functionality of
> > > 'polling for a memory location to become equal to a given value'[1].
> > >
> > > Use the API for the rte spinlock and ring implementations.
> > >
> > > [1] http://patches.dpdk.org/cover/62703/
> > >
> > > Gavin Hu (2):
> > >   spinlock: use wfe to reduce contention on aarch64
> > >   ring: use wfe to wait for ring tail update on aarch64
> >
> > This would result in rte_ring and rte_spinlock APIs becoming experimental
> > and this breaks compilation for external applications using stable ring and
> > spinlock APIs.
> > IIRC, it was the reason why these patches were dropped with the introduction
> > of the rte_wait_until_equal_* API.
> Agreed, the rte_ring new sync modes are resulting in different use cases for these APIs. We need to take a relook at the APIs.

Will we reconsider this series now that the wait until equal is going stable?


-- 
David Marchand


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring
  2020-09-25 14:30       ` David Marchand
@ 2021-03-25 14:58         ` David Marchand
  0 siblings, 0 replies; 16+ messages in thread
From: David Marchand @ 2021-03-25 14:58 UTC (permalink / raw)
  To: Honnappa Nagarahalli
  Cc: dev, nd, thomas, jerinj, Ruifeng Wang, Phil Yang, Joyce Kong,
	Ananyev, Konstantin

Hello,

On Fri, Sep 25, 2020 at 4:30 PM David Marchand
<david.marchand@redhat.com> wrote:
>
> Hello Honnappa,
>
> On Sun, May 3, 2020 at 11:32 PM Honnappa Nagarahalli
> <Honnappa.Nagarahalli@arm.com> wrote:
> >
> > <snip>
> >
> > > Subject: Re: [PATCH v2 0/2] Use WFE for spinlock and ring
> > >
> > > On Sun, Apr 26, 2020 at 10:39 AM Gavin Hu <gavin.hu@arm.com> wrote:
> > > >
> > > > The rte_wait_until_equal_xxx APIs abstract the functionality of
> > > > 'polling for a memory location to become equal to a given value'[1].
> > > >
> > > > Use the API for the rte spinlock and ring implementations.
> > > >
> > > > [1] http://patches.dpdk.org/cover/62703/
> > > >
> > > > Gavin Hu (2):
> > > >   spinlock: use wfe to reduce contention on aarch64
> > > >   ring: use wfe to wait for ring tail update on aarch64
> > >
> > > This would result in rte_ring and rte_spinlock APIs becoming experimental
> > > and this breaks compilation for external applications using stable ring and
> > > spinlock APIs.
> > > IIRC, it was the reason why these patches were dropped with the introduction
> > > of the rte_wait_until_equal_* API.
> > Agreed, the rte_ring new sync modes are resulting in different use cases for these APIs. We need to take a relook at the APIs.
>
> Will we reconsider this series now that the wait until equal is going stable?

Any update?
I suppose this would need some rebasing after the ring library changes.

Thanks.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-03-25 14:58 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24  7:07 [dpdk-dev] [PATCH v1 0/2] Use WFE for spinlock and ring Gavin Hu
2020-04-24  7:07 ` [dpdk-dev] [PATCH v1 1/2] spinlock: use wfe to reduce contention on aarch64 Gavin Hu
2020-04-24  7:07 ` [dpdk-dev] [PATCH v1 2/2] ring: use wfe to wait for ring tail update " Gavin Hu
2020-04-24 13:23   ` Ananyev, Konstantin
2020-04-26  8:41     ` Gavin Hu
2020-04-24 14:46   ` Honnappa Nagarahalli
2020-04-26  8:33     ` Gavin Hu
2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 0/2] Use WFE for spinlock and ring Gavin Hu
2020-05-01  9:47   ` Ananyev, Konstantin
2020-05-03 14:54   ` David Marchand
2020-05-03 21:31     ` Honnappa Nagarahalli
2020-09-25 14:30       ` David Marchand
2021-03-25 14:58         ` David Marchand
2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 1/2] spinlock: use wfe to reduce contention on aarch64 Gavin Hu
2020-04-28 12:22   ` Jerin Jacob
2020-04-26  8:39 ` [dpdk-dev] [PATCH v2 2/2] ring: use wfe to wait for ring tail update " Gavin Hu

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git