From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 928D6A0C41; Mon, 2 Aug 2021 12:20:17 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 79F4441137; Mon, 2 Aug 2021 12:20:17 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id DC55F41137 for ; Mon, 2 Aug 2021 12:20:15 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5E144D6E; Mon, 2 Aug 2021 03:20:15 -0700 (PDT) Received: from net-arm-n1sdp.shanghai.arm.com (net-arm-n1sdp.shanghai.arm.com [10.169.208.222]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A50D43F70D; Mon, 2 Aug 2021 03:20:08 -0700 (PDT) From: Joyce Kong To: thomas@monjalon.net, david.marchand@redhat.com, honnappa.nagarahalli@arm.com, ruifeng.wang@arm.com, konstantin.ananyev@intel.com, rsanford@akamai.com, erik.g.carrillo@intel.com, olivier.matz@6wind.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, vladimir.medvedkin@intel.com, anatoly.burakov@intel.com, andrew.rybchenko@oktetlabs.ru, jerinj@marvell.com, declan.doherty@intel.com, ciara.power@intel.com, xiaoyun.li@intel.com, nicolas.chautru@intel.com, maryam.tahhan@intel.com, reshma.pattan@intel.com, cristian.dumitrescu@intel.com Cc: dev@dpdk.org, nd@arm.com Date: Mon, 2 Aug 2021 05:18:38 -0500 Message-Id: <20210802101847.3462-4-joyce.kong@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210802101847.3462-1-joyce.kong@arm.com> References: <20210802101847.3462-1-joyce.kong@arm.com> Subject: [dpdk-dev] [PATCH v1 03/12] test/timer: use compiler atomic builtins for sync X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Convert rte_atomic usages to compiler atomic built-ins for lcore_state and collisions sync. Signed-off-by: Joyce Kong Reviewed-by: Ruifeng Wang --- app/test/test_timer.c | 28 ++++++++++++---------------- app/test/test_timer_secondary.c | 1 - 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/app/test/test_timer.c b/app/test/test_timer.c index a10b2fe9da..9a3e1b53e4 100644 --- a/app/test/test_timer.c +++ b/app/test/test_timer.c @@ -102,7 +102,6 @@ #include #include #include -#include #include #include #include @@ -203,7 +202,7 @@ timer_stress_main_loop(__rte_unused void *arg) /* Need to synchronize worker lcores through multiple steps. */ enum { WORKER_WAITING = 1, WORKER_RUN_SIGNAL, WORKER_RUNNING, WORKER_FINISHED }; -static rte_atomic16_t lcore_state[RTE_MAX_LCORE]; +static uint16_t lcore_state[RTE_MAX_LCORE]; static void main_init_workers(void) @@ -211,7 +210,7 @@ main_init_workers(void) unsigned i; RTE_LCORE_FOREACH_WORKER(i) { - rte_atomic16_set(&lcore_state[i], WORKER_WAITING); + __atomic_store_n(&lcore_state[i], WORKER_WAITING, __ATOMIC_RELAXED); } } @@ -221,11 +220,10 @@ main_start_workers(void) unsigned i; RTE_LCORE_FOREACH_WORKER(i) { - rte_atomic16_set(&lcore_state[i], WORKER_RUN_SIGNAL); + __atomic_store_n(&lcore_state[i], WORKER_RUN_SIGNAL, __ATOMIC_RELAXED); } RTE_LCORE_FOREACH_WORKER(i) { - while (rte_atomic16_read(&lcore_state[i]) != WORKER_RUNNING) - rte_pause(); + rte_wait_until_equal_16(&lcore_state[i], WORKER_RUNNING, __ATOMIC_RELAXED); } } @@ -235,8 +233,7 @@ main_wait_for_workers(void) unsigned i; RTE_LCORE_FOREACH_WORKER(i) { - while (rte_atomic16_read(&lcore_state[i]) != WORKER_FINISHED) - rte_pause(); + rte_wait_until_equal_16(&lcore_state[i], WORKER_FINISHED, __ATOMIC_RELAXED); } } @@ -245,9 +242,8 @@ worker_wait_to_start(void) { unsigned lcore_id = rte_lcore_id(); - while (rte_atomic16_read(&lcore_state[lcore_id]) != WORKER_RUN_SIGNAL) - rte_pause(); - rte_atomic16_set(&lcore_state[lcore_id], WORKER_RUNNING); + rte_wait_until_equal_16(&lcore_state[lcore_id], WORKER_RUN_SIGNAL, __ATOMIC_RELAXED); + __atomic_store_n(&lcore_state[lcore_id], WORKER_RUNNING, __ATOMIC_RELAXED); } static void @@ -255,7 +251,7 @@ worker_finish(void) { unsigned lcore_id = rte_lcore_id(); - rte_atomic16_set(&lcore_state[lcore_id], WORKER_FINISHED); + __atomic_store_n(&lcore_state[lcore_id], WORKER_FINISHED, __ATOMIC_RELAXED); } @@ -281,12 +277,12 @@ timer_stress2_main_loop(__rte_unused void *arg) unsigned int lcore_id = rte_lcore_id(); unsigned int main_lcore = rte_get_main_lcore(); int32_t my_collisions = 0; - static rte_atomic32_t collisions; + static uint32_t collisions; if (lcore_id == main_lcore) { cb_count = 0; test_failed = 0; - rte_atomic32_set(&collisions, 0); + __atomic_store_n(&collisions, 0, __ATOMIC_RELAXED); main_init_workers(); timers = rte_malloc(NULL, sizeof(*timers) * NB_STRESS2_TIMERS, 0); if (timers == NULL) { @@ -315,7 +311,7 @@ timer_stress2_main_loop(__rte_unused void *arg) my_collisions++; } if (my_collisions != 0) - rte_atomic32_add(&collisions, my_collisions); + __atomic_fetch_add(&collisions, my_collisions, __ATOMIC_RELAXED); /* wait long enough for timers to expire */ rte_delay_ms(100); @@ -329,7 +325,7 @@ timer_stress2_main_loop(__rte_unused void *arg) /* now check that we get the right number of callbacks */ if (lcore_id == main_lcore) { - my_collisions = rte_atomic32_read(&collisions); + my_collisions = __atomic_load_n(&collisions, __ATOMIC_RELAXED); if (my_collisions != 0) printf("- %d timer reset collisions (OK)\n", my_collisions); rte_timer_manage(); diff --git a/app/test/test_timer_secondary.c b/app/test/test_timer_secondary.c index 16a9f1878b..5795c97f07 100644 --- a/app/test/test_timer_secondary.c +++ b/app/test/test_timer_secondary.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include -- 2.17.1