Skip to contentSkip to conversation

replace tight loop with wait until equal api

PATCH Superseded Feifei Wang 2 participants 11 messages Aug 25, 2021 – Oct 20, 2021

lore
Share & tools
lore
#0 lore raw

cover replace tight loop with wait until equal api

For dpdk/lib, directly use wait_until_equal API to replace tight loop.

Feifei Wang (2):
eal/common: use wait until equal API for tight loop
mcslock: use wait until equal API for tight loop

 lib/eal/common/eal_common_mcfg.c      | 3 +--
 lib/eal/include/generic/rte_mcslock.h | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 eal/common: use wait until equal API for tight loop

Instead of polling for mcfg->magic to be updated, use wait_until_equal API.

---
 lib/eal/common/eal_common_mcfg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/eal/common/eal_common_mcfg.c +1 -2
index c77ba97a9f..cf4a279905 100644
@@ -30,8 +30,7 @@ eal_mcfg_wait_complete(void)
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 
 	/* wait until shared mem_config finish initialising */
-	while (mcfg->magic != RTE_MAGIC)
-		rte_pause();
+	rte_wait_until_equal_32(&mcfg->magic, RTE_MAGIC, __ATOMIC_RELAXED);
 }
 
 int
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 mcslock: use wait until equal API for tight loop

In reply to Feifei Wang

Instead of polling for previous lock holder unlocking, use wait_until_equal API.

---
 lib/eal/include/generic/rte_mcslock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/eal/include/generic/rte_mcslock.h +2 -2
index 9f323bd2a2..c99343f22c 100644
@@ -84,8 +84,8 @@ rte_mcslock_lock(rte_mcslock_t **msl, rte_mcslock_t *me)
 	 * to spin on me->locked until the previous lock holder resets
 	 * the me->locked using mcslock_unlock().
 	 */
-	while (__atomic_load_n(&me->locked, __ATOMIC_ACQUIRE))
-		rte_pause();
+	rte_wait_until_equal_32((volatile uint32_t *)&me->locked,
+			0, __ATOMIC_ACQUIRE);
 }
 
 /**
Signature · 1 line
2.25.1
#3 lore raw

Re: [dpdk-dev] [PATCH v1 2/2] mcslock: use wait until equal API for tight loop

Quoted 15 lines · Feifei Wang

Instead of polling for previous lock holder unlocking, use wait_until_equal API.

---
 lib/eal/include/generic/rte_mcslock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/eal/include/generic/rte_mcslock.h +0 -0
index 9f323bd2a2..c99343f22c 100644

lib/eal/include/generic/rte_mcslock.h rte_mcslock_lock(rte_mcslock_t **msl, rte_mcslock_t *me) · line 88

Quoted 7 lines
lib/eal/include/generic/rte_mcslock.h +2 -2
@@ -84,8 +84,8 @@ rte_mcslock_lock(rte_mcslock_t **msl, rte_mcslock_t *me)
         * to spin on me->locked until the previous lock holder resets
         * the me->locked using mcslock_unlock().
         */
-       while (__atomic_load_n(&me->locked, __ATOMIC_ACQUIRE))
-               rte_pause();
+       rte_wait_until_equal_32((volatile uint32_t *)&me->locked,
+                       0, __ATOMIC_ACQUIRE);

Why do you need to cast as volatile?

Signature · 1 line
David Marchand
#4 lore raw

[dpdk-dev] 回复: [PATCH v1 2/2] mcslock: use wait until equal API for tight loop

Quoted 37 lines

-----邮件原件-----
发件人: dev <[email protected]> 代表 David Marchand
发送时间: Tuesday, October 19, 2021 7:10 PM
收件人: Feifei Wang <[email protected]>
抄送: Honnappa Nagarahalli <[email protected]>; dev <[email protected]>; nd <[email protected]>; Ruifeng Wang <[email protected]>
主题: Re: [dpdk-dev] [PATCH v1 2/2] mcslock: use wait until equal API for tight loop

lib/eal/include/generic/rte_mcslock.h rte_mcslock_lock(rte_mcslock_t **msl,

Quoted 16 lines · Feifei Wang

Instead of polling for previous lock holder unlocking, use wait_until_equal API.

---
 lib/eal/include/generic/rte_mcslock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/eal/include/generic/rte_mcslock.h +0 -0
index 9f323bd2a2..c99343f22c 100644
@@ -84,8 +84,8 @@ rte_mcslock_lock(rte_mcslock_t **msl,

rte_mcslock_t *me)

lib/eal/include/generic/rte_mcslock.h rte_mcslock_lock(rte_mcslock_t **msl, rte_mcslock_t *me) · line 88

Quoted 7 lines
lib/eal/include/generic/rte_mcslock.h +2 -2
         * to spin on me->locked until the previous lock holder resets
         * the me->locked using mcslock_unlock().
         */
-       while (__atomic_load_n(&me->locked, __ATOMIC_ACQUIRE))
-               rte_pause();
+       rte_wait_until_equal_32((volatile uint32_t *)&me->locked,
+                       0, __ATOMIC_ACQUIRE);
Quoted 1 line

Why do you need to cast as volatile?

Thanks for the comments.
This is firstly because rte_wait_until_equal API defines the variable as volatile. However, with your comment, I find 'me->lock' is not volatile. And by the test, I think you are right, it is necessary to add volatile here.

Quoted 4 lines

--
David Marchand

#5 lore raw

[dpdk-dev] 回复: [PATCH v1 2/2] mcslock: use wait until equal API for tight loop

Quoted 49 lines

-----邮件原件-----
发件人: Feifei Wang
发送时间: Wednesday, October 20, 2021 10:46 AM
收件人: David Marchand <[email protected]>
抄送: Honnappa Nagarahalli <[email protected]>; dev <[email protected]>; nd <[email protected]>; Ruifeng Wang <[email protected]>; nd <[email protected]>
主题: 回复: [dpdk-dev] [PATCH v1 2/2] mcslock: use wait until equal API for tight loop

Quoted 6 lines

-----邮件原件-----
发件人: dev <[email protected]> 代表 David Marchand 发送时间: Tuesday, October 19, 2021 7:10 PM
收件人: Feifei Wang <[email protected]>
抄送: Honnappa Nagarahalli <[email protected]>; dev <[email protected]>; nd <[email protected]>; Ruifeng Wang

<[email protected]>

Quoted 30 lines

主题: Re: [dpdk-dev] [PATCH v1 2/2] mcslock: use wait until equal API for tight loop

lib/eal/include/generic/rte_mcslock.h rte_mcslock_lock(rte_mcslock_t **msl,

Quoted 16 lines · Feifei Wang

Instead of polling for previous lock holder unlocking, use wait_until_equal API.

---
 lib/eal/include/generic/rte_mcslock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/eal/include/generic/rte_mcslock.h +0 -0
index 9f323bd2a2..c99343f22c 100644
@@ -84,8 +84,8 @@ rte_mcslock_lock(rte_mcslock_t **msl,

rte_mcslock_t *me)

Quoted 7 lines
lib/eal/include/generic/rte_mcslock.h +2 -2
         * to spin on me->locked until the previous lock holder resets
         * the me->locked using mcslock_unlock().
         */
-       while (__atomic_load_n(&me->locked, __ATOMIC_ACQUIRE))
-               rte_pause();
+       rte_wait_until_equal_32((volatile uint32_t *)&me->locked,
+                       0, __ATOMIC_ACQUIRE);
Quoted 5 lines
Quoted 1 line

Why do you need to cast as volatile?

Thanks for the comments.
This is firstly because rte_wait_until_equal API defines the variable as volatile. However, with your comment, I find 'me->lock' is not volatile. And by the test, I think you are right, it is necessary to add volatile here.

Sorry, correct the writing mistakes:
'It is unnecessary to add volatile here.'

Quoted 4 lines
Quoted 4 lines

--
David Marchand

#6 lore raw
In reply to Feifei Wang

Hi,

Would you please help review this patch series?
Thanks very much.

Best Regards
Feifei

Quoted 19 lines

-----邮件原件-----
发件人: Feifei Wang <[email protected]>
发送时间: Wednesday, August 25, 2021 4:01 PM
抄送: [email protected]; nd <[email protected]>; Feifei Wang <[email protected]>
主题: [PATCH v1 0/2] replace tight loop with wait until equal api

For dpdk/lib, directly use wait_until_equal API to replace tight loop.

Feifei Wang (2):
eal/common: use wait until equal API for tight loop
mcslock: use wait until equal API for tight loop

 lib/eal/common/eal_common_mcfg.c      | 3 +--
 lib/eal/include/generic/rte_mcslock.h | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

--
2.25.1

#7 lore raw

v2 cover replace tight loop with wait until equal api

In reply to Feifei Wang

For dpdk/lib, directly use wait_until_equal API to replace tight loop.

v2:
1. delete wrong 'volatile' in mcslock (David)

Feifei Wang (2):
eal/common: use wait until equal API for tight loop
mcslock: use wait until equal API for tight loop

 lib/eal/common/eal_common_mcfg.c      | 3 +--
 lib/eal/include/generic/rte_mcslock.h | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
#8 lore raw

PATCH v2 1/2 eal/common: use wait until equal API for tight loop

Instead of polling for mcfg->magic to be updated, use wait_until_equal API.

---
 lib/eal/common/eal_common_mcfg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/eal/common/eal_common_mcfg.c +1 -2
index c77ba97a9f..cf4a279905 100644
@@ -30,8 +30,7 @@ eal_mcfg_wait_complete(void)
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 
 	/* wait until shared mem_config finish initialising */
-	while (mcfg->magic != RTE_MAGIC)
-		rte_pause();
+	rte_wait_until_equal_32(&mcfg->magic, RTE_MAGIC, __ATOMIC_RELAXED);
 }
 
 int
Signature · 1 line
2.25.1
#9 lore raw

PATCH v2 2/2 mcslock: use wait until equal API for tight loop

In reply to Feifei Wang

Instead of polling for previous lock holder unlocking, use wait_until_equal API.

---
 lib/eal/include/generic/rte_mcslock.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/eal/include/generic/rte_mcslock.h +1 -2
index 9f323bd2a2..34f33c64a5 100644
@@ -84,8 +84,7 @@ rte_mcslock_lock(rte_mcslock_t **msl, rte_mcslock_t *me)
 	 * to spin on me->locked until the previous lock holder resets
 	 * the me->locked using mcslock_unlock().
 	 */
-	while (__atomic_load_n(&me->locked, __ATOMIC_ACQUIRE))
-		rte_pause();
+	rte_wait_until_equal_32((uint32_t *)&me->locked, 0, __ATOMIC_ACQUIRE);
 }
 
 /**
Signature · 1 line
2.25.1
#10 lore raw
In reply to Feifei Wang
Quoted 6 lines · Feifei Wang

For dpdk/lib, directly use wait_until_equal API to replace tight loop.

v2:
1. delete wrong 'volatile' in mcslock (David)

Quoted 8 lines

Feifei Wang (2):
eal/common: use wait until equal API for tight loop
mcslock: use wait until equal API for tight loop

 lib/eal/common/eal_common_mcfg.c      | 3 +--
 lib/eal/include/generic/rte_mcslock.h | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

Series applied, thanks.

Signature · 1 line
David Marchand