DPDK patches and discussions
 help / color / mirror / Atom feed
From: Joyce Kong <joyce.kong@arm.com>
To: thomas@monjalon.net, david.marchand@redhat.com,
	stephen@networkplumber.org, olivier.matz@6wind.com,
	andrew.rybchenko@oktetlabs.ru, harry.van.haaren@intel.com,
	honnappa.nagarahalli@arm.com, ruifeng.wang@arm.com
Cc: dev@dpdk.org, nd@arm.com
Subject: [dpdk-dev] [PATCH v2 7/8] test/service_cores: use GCC atomic builtins for lock sync
Date: Tue, 15 Jun 2021 21:54:58 -0500	[thread overview]
Message-ID: <20210616025459.22717-8-joyce.kong@arm.com> (raw)
In-Reply-To: <20210616025459.22717-1-joyce.kong@arm.com>

Convert rte_atomic usages to GCC atomic builtins for lock sync
in service core testcases.

Signed-off-by: Joyce Kong <joyce.kong@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_service_cores.c | 36 +++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/app/test/test_service_cores.c b/app/test/test_service_cores.c
index 37d7172d5..9d908d44e 100644
--- a/app/test/test_service_cores.c
+++ b/app/test/test_service_cores.c
@@ -53,18 +53,20 @@ static int32_t dummy_cb(void *args)
 static int32_t dummy_mt_unsafe_cb(void *args)
 {
 	/* before running test, the initialization has set pass_test to 1.
-	 * If the cmpset in service-cores is working correctly, the code here
+	 * If the cas in service-cores is working correctly, the code here
 	 * should never fail to take the lock. If the lock *is* taken, fail the
 	 * test, because two threads are concurrently in a non-MT safe callback.
 	 */
 	uint32_t *test_params = args;
-	uint32_t *atomic_lock = &test_params[0];
+	uint32_t *lock = &test_params[0];
 	uint32_t *pass_test = &test_params[1];
-	int lock_taken = rte_atomic32_cmpset(atomic_lock, 0, 1);
+	uint32_t exp = 0;
+	int lock_taken = __atomic_compare_exchange_n(lock, &exp, 1, 0,
+					__ATOMIC_RELAXED, __ATOMIC_RELAXED);
 	if (lock_taken) {
 		/* delay with the lock held */
 		rte_delay_ms(250);
-		rte_atomic32_clear((rte_atomic32_t *)atomic_lock);
+		__atomic_store_n(lock, 0, __ATOMIC_RELAXED);
 	} else {
 		/* 2nd thread will fail to take lock, so set pass flag */
 		*pass_test = 0;
@@ -83,13 +85,15 @@ static int32_t dummy_mt_safe_cb(void *args)
 	 *    that 2 threads are running the callback at the same time: MT safe
 	 */
 	uint32_t *test_params = args;
-	uint32_t *atomic_lock = &test_params[0];
+	uint32_t *lock = &test_params[0];
 	uint32_t *pass_test = &test_params[1];
-	int lock_taken = rte_atomic32_cmpset(atomic_lock, 0, 1);
+	uint32_t exp = 0;
+	int lock_taken = __atomic_compare_exchange_n(lock, &exp, 1, 0,
+					__ATOMIC_RELAXED, __ATOMIC_RELAXED);
 	if (lock_taken) {
 		/* delay with the lock held */
 		rte_delay_ms(250);
-		rte_atomic32_clear((rte_atomic32_t *)atomic_lock);
+		__atomic_store_n(lock, 0, __ATOMIC_RELAXED);
 	} else {
 		/* 2nd thread will fail to take lock, so set pass flag */
 		*pass_test = 1;
@@ -622,9 +626,9 @@ service_threaded_test(int mt_safe)
 	TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_2),
 			"mt safe lcore add fail");
 
-	/* Use atomic locks to verify that two threads are in the same function
-	 * at the same time. These are passed to the unit tests through the
-	 * callback userdata parameter
+	/* Use locks to verify that two threads are in the same function
+	 * at the same time. These are passed to the unit tests through
+	 * the callback userdata parameter.
 	 */
 	uint32_t test_params[2];
 	memset(test_params, 0, sizeof(uint32_t) * 2);
@@ -713,7 +717,7 @@ service_mt_safe_poll(void)
 }
 
 /* tests a NON mt safe service with two cores, the callback is serialized
- * using the atomic cmpset.
+ * using the cas.
  */
 static int
 service_mt_unsafe_poll(void)
@@ -735,17 +739,17 @@ delay_as_a_mt_safe_service(void *args)
 	RTE_SET_USED(args);
 	uint32_t *params = args;
 
-	/* retrieve done flag and atomic lock to inc/dec */
+	/* retrieve done flag and lock to add/sub */
 	uint32_t *done = &params[0];
-	rte_atomic32_t *lock = (rte_atomic32_t *)&params[1];
+	uint32_t *lock = &params[1];
 
 	while (!*done) {
-		rte_atomic32_inc(lock);
+		__atomic_add_fetch(lock, 1, __ATOMIC_RELAXED);
 		rte_delay_us(500);
-		if (rte_atomic32_read(lock) > 1)
+		if (__atomic_load_n(lock, __ATOMIC_RELAXED) > 1)
 			/* pass: second core has simultaneously incremented */
 			*done = 1;
-		rte_atomic32_dec(lock);
+		__atomic_sub_fetch(lock, 1, __ATOMIC_RELAXED);
 	}
 
 	return 0;
-- 
2.17.1


  parent reply	other threads:[~2021-06-16  2:56 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04  9:46 [dpdk-dev] [PATCH v1 0/8] use GCC's C11 atomic builtins for test Joyce Kong
2021-06-04  9:46 ` [dpdk-dev] [PATCH v1 1/8] test/ticketlock: use GCC atomic builtins for lcores sync Joyce Kong
2021-06-04  9:46 ` [dpdk-dev] [PATCH v1 2/8] test/spinlock: " Joyce Kong
2021-06-04  9:46 ` [dpdk-dev] [PATCH v1 3/8] test/rwlock: " Joyce Kong
2021-06-04  9:46 ` [dpdk-dev] [PATCH v1 4/8] test/mcslock: " Joyce Kong
2021-06-04  9:46 ` [dpdk-dev] [PATCH v1 5/8] test/mempool: remove unused variable " Joyce Kong
2021-06-04  9:46 ` [dpdk-dev] [PATCH v1 6/8] test/mempool_perf: use GCC atomic builtins " Joyce Kong
2021-06-04  9:46 ` [dpdk-dev] [PATCH v1 7/8] test/service_cores: use GCC atomic builtins for lock sync Joyce Kong
2021-06-04  9:46 ` [dpdk-dev] [PATCH v1 8/8] test/rcu_perf: use GCC atomic builtins for data sync Joyce Kong
2021-06-04 19:57 ` [dpdk-dev] [PATCH v1 0/8] use GCC's C11 atomic builtins for test Stephen Hemminger
2021-06-11  8:40 ` David Marchand
2021-06-11 10:45   ` Joyce Kong
2021-06-16  2:54 ` [dpdk-dev] [PATCH v2 " Joyce Kong
2021-06-16  2:54   ` [dpdk-dev] [PATCH v2 1/8] test/ticketlock: use GCC atomic builtins for lcores sync Joyce Kong
2021-06-16  2:54   ` [dpdk-dev] [PATCH v2 2/8] test/spinlock: " Joyce Kong
2021-06-16  2:54   ` [dpdk-dev] [PATCH v2 3/8] test/rwlock: " Joyce Kong
2021-06-16  2:54   ` [dpdk-dev] [PATCH v2 4/8] test/mcslock: " Joyce Kong
2021-06-16  2:54   ` [dpdk-dev] [PATCH v2 5/8] test/mempool: remove unused variable " Joyce Kong
2021-06-16  2:54   ` [dpdk-dev] [PATCH v2 6/8] test/mempool_perf: use GCC atomic builtins " Joyce Kong
2021-06-16  2:54   ` Joyce Kong [this message]
2021-06-16  2:54   ` [dpdk-dev] [PATCH v2 8/8] test/rcu: use GCC atomic builtins for data sync Joyce Kong
2021-06-17 15:21   ` [dpdk-dev] [PATCH v2 0/8] use GCC's C11 atomic builtins for test Tyler Retzlaff
2021-06-17 23:26     ` Honnappa Nagarahalli
2021-06-23 10:24       ` Thomas Monjalon
2021-06-23 16:02         ` Tyler Retzlaff
2021-06-29 17:04         ` Honnappa Nagarahalli
2021-06-30 18:51           ` Tyler Retzlaff
2021-06-30 19:06             ` Honnappa Nagarahalli
2021-06-30 19:38               ` Tyler Retzlaff
2021-06-30 20:25                 ` Honnappa Nagarahalli
2021-06-30 21:49                   ` Tyler Retzlaff
2021-06-30 22:41                     ` Honnappa Nagarahalli
2021-07-13  7:28                       ` Joyce Kong
2021-07-14 11:44                         ` Thomas Monjalon
2021-07-20  3:51   ` [dpdk-dev] [PATCH v3 0/8] use compiler " Joyce Kong
2021-07-20  3:51     ` [dpdk-dev] [PATCH v3 1/8] test/ticketlock: use compiler atomics for lcores sync Joyce Kong
2021-07-20  3:51     ` [dpdk-dev] [PATCH v3 2/8] test/spinlock: use compile " Joyce Kong
2021-07-20  3:51     ` [dpdk-dev] [PATCH v3 3/8] test/rwlock: use compiler " Joyce Kong
2021-07-20  3:51     ` [dpdk-dev] [PATCH v3 4/8] test/mcslock: " Joyce Kong
2021-07-28  9:56       ` Olivier Matz
2021-07-29  7:19         ` Joyce Kong
2021-07-29  7:58           ` Olivier Matz
2021-07-20  3:51     ` [dpdk-dev] [PATCH v3 5/8] test/mempool: remove unused variable " Joyce Kong
2021-07-20  3:51     ` [dpdk-dev] [PATCH v3 6/8] test/mempool_perf: use compiler atomics " Joyce Kong
2021-07-20  3:51     ` [dpdk-dev] [PATCH v3 7/8] test/service_cores: use compiler atomics for lock sync Joyce Kong
2021-07-20  3:51     ` [dpdk-dev] [PATCH v3 8/8] test/rcu: use compiler atomics for data sync Joyce Kong
2021-07-23 19:52       ` Andrew Rybchenko
2021-07-28  7:07         ` Joyce Kong
2021-07-30 21:58     ` [dpdk-dev] [PATCH v3 0/8] use compiler atomic builtins for test Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210616025459.22717-8-joyce.kong@arm.com \
    --to=joyce.kong@arm.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=harry.van.haaren@intel.com \
    --cc=honnappa.nagarahalli@arm.com \
    --cc=nd@arm.com \
    --cc=olivier.matz@6wind.com \
    --cc=ruifeng.wang@arm.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).