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 8CD3C43200; Thu, 26 Oct 2023 02:33:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AD1B142E11; Thu, 26 Oct 2023 02:32:21 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 8B08840A81 for ; Thu, 26 Oct 2023 02:32:01 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 61A8D20B74D2; Wed, 25 Oct 2023 17:31:59 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 61A8D20B74D2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1698280320; bh=ksPBnGZVkQjfGW3tponcU3SwQmffIB+F16y056Piuzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o9qB4IH2S8Oayz1MU2o4+hQjE66X4QhX1cmhaTFT/qDZkn289ammXyYR/tgqjHDkH jYYj+1rUosqioQSvbXboSc9OfZuo8iz1iiSoRCLWf+fsghInVcFF/uepLKPl2mBWHz oEqEgec6wgky22IVcNRClkWnTxbKG8CIoGMtuTkQ= From: Tyler Retzlaff To: dev@dpdk.org Cc: Akhil Goyal , Anatoly Burakov , Andrew Rybchenko , Bruce Richardson , Chenbo Xia , Ciara Power , David Christensen , David Hunt , Dmitry Kozlyuk , Dmitry Malloy , Elena Agostini , Erik Gabriel Carrillo , Fan Zhang , Ferruh Yigit , Harman Kalra , Harry van Haaren , Honnappa Nagarahalli , Jerin Jacob , Konstantin Ananyev , Matan Azrad , Maxime Coquelin , Narcisa Ana Maria Vasile , Nicolas Chautru , Olivier Matz , Ori Kam , Pallavi Kadam , Pavan Nikhilesh , Reshma Pattan , Sameh Gobriel , Shijith Thotton , Sivaprasad Tummala , Stephen Hemminger , Suanming Mou , Sunil Kumar Kori , Thomas Monjalon , Viacheslav Ovsiienko , Vladimir Medvedkin , Yipeng Wang , Tyler Retzlaff Subject: [PATCH v3 18/19] timer: use rte optional stdatomic API Date: Wed, 25 Oct 2023 17:31:53 -0700 Message-Id: <1698280314-25861-19-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1698280314-25861-1-git-send-email-roretzla@linux.microsoft.com> References: <1697497745-20664-1-git-send-email-roretzla@linux.microsoft.com> <1698280314-25861-1-git-send-email-roretzla@linux.microsoft.com> 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 Replace the use of gcc builtin __atomic_xxx intrinsics with corresponding rte_atomic_xxx optional stdatomic API Signed-off-by: Tyler Retzlaff --- lib/timer/rte_timer.c | 50 +++++++++++++++++++++++++------------------------- lib/timer/rte_timer.h | 6 +++--- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/timer/rte_timer.c b/lib/timer/rte_timer.c index 85d6757..53ed221 100644 --- a/lib/timer/rte_timer.c +++ b/lib/timer/rte_timer.c @@ -210,7 +210,7 @@ struct rte_timer_data { status.state = RTE_TIMER_STOP; status.owner = RTE_TIMER_NO_OWNER; - __atomic_store_n(&tim->status.u32, status.u32, __ATOMIC_RELAXED); + rte_atomic_store_explicit(&tim->status.u32, status.u32, rte_memory_order_relaxed); } /* @@ -231,7 +231,7 @@ struct rte_timer_data { /* wait that the timer is in correct status before update, * and mark it as being configured */ - prev_status.u32 = __atomic_load_n(&tim->status.u32, __ATOMIC_RELAXED); + prev_status.u32 = rte_atomic_load_explicit(&tim->status.u32, rte_memory_order_relaxed); while (success == 0) { /* timer is running on another core @@ -254,11 +254,11 @@ struct rte_timer_data { * timer is in CONFIG state, the state cannot be changed * by other threads. So, we should use ACQUIRE here. */ - success = __atomic_compare_exchange_n(&tim->status.u32, - &prev_status.u32, - status.u32, 0, - __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); + success = rte_atomic_compare_exchange_strong_explicit(&tim->status.u32, + (uint32_t *)(uintptr_t)&prev_status.u32, + status.u32, + rte_memory_order_acquire, + rte_memory_order_relaxed); } ret_prev_status->u32 = prev_status.u32; @@ -277,7 +277,7 @@ struct rte_timer_data { /* wait that the timer is in correct status before update, * and mark it as running */ - prev_status.u32 = __atomic_load_n(&tim->status.u32, __ATOMIC_RELAXED); + prev_status.u32 = rte_atomic_load_explicit(&tim->status.u32, rte_memory_order_relaxed); while (success == 0) { /* timer is not pending anymore */ @@ -293,11 +293,11 @@ struct rte_timer_data { * timer is in RUNNING state, the state cannot be changed * by other threads. So, we should use ACQUIRE here. */ - success = __atomic_compare_exchange_n(&tim->status.u32, - &prev_status.u32, - status.u32, 0, - __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); + success = rte_atomic_compare_exchange_strong_explicit(&tim->status.u32, + (uint32_t *)(uintptr_t)&prev_status.u32, + status.u32, + rte_memory_order_acquire, + rte_memory_order_relaxed); } return 0; @@ -530,7 +530,7 @@ struct rte_timer_data { /* The "RELEASE" ordering guarantees the memory operations above * the status update are observed before the update by all threads */ - __atomic_store_n(&tim->status.u32, status.u32, __ATOMIC_RELEASE); + rte_atomic_store_explicit(&tim->status.u32, status.u32, rte_memory_order_release); if (tim_lcore != lcore_id || !local_is_locked) rte_spinlock_unlock(&priv_timer[tim_lcore].list_lock); @@ -612,7 +612,7 @@ struct rte_timer_data { /* The "RELEASE" ordering guarantees the memory operations above * the status update are observed before the update by all threads */ - __atomic_store_n(&tim->status.u32, status.u32, __ATOMIC_RELEASE); + rte_atomic_store_explicit(&tim->status.u32, status.u32, rte_memory_order_release); return 0; } @@ -646,8 +646,8 @@ struct rte_timer_data { int rte_timer_pending(struct rte_timer *tim) { - return __atomic_load_n(&tim->status.state, - __ATOMIC_RELAXED) == RTE_TIMER_PENDING; + return rte_atomic_load_explicit(&tim->status.state, + rte_memory_order_relaxed) == RTE_TIMER_PENDING; } /* must be called periodically, run all timer that expired */ @@ -753,8 +753,8 @@ struct rte_timer_data { * operations above the status update are observed * before the update by all threads */ - __atomic_store_n(&tim->status.u32, status.u32, - __ATOMIC_RELEASE); + rte_atomic_store_explicit(&tim->status.u32, status.u32, + rte_memory_order_release); } else { /* keep it in list and mark timer as pending */ @@ -766,8 +766,8 @@ struct rte_timer_data { * operations above the status update are observed * before the update by all threads */ - __atomic_store_n(&tim->status.u32, status.u32, - __ATOMIC_RELEASE); + rte_atomic_store_explicit(&tim->status.u32, status.u32, + rte_memory_order_release); __rte_timer_reset(tim, tim->expire + tim->period, tim->period, lcore_id, tim->f, tim->arg, 1, timer_data); @@ -941,8 +941,8 @@ struct rte_timer_data { * operations above the status update are observed * before the update by all threads */ - __atomic_store_n(&tim->status.u32, status.u32, - __ATOMIC_RELEASE); + rte_atomic_store_explicit(&tim->status.u32, status.u32, + rte_memory_order_release); } else { /* keep it in list and mark timer as pending */ rte_spinlock_lock( @@ -954,8 +954,8 @@ struct rte_timer_data { * operations above the status update are observed * before the update by all threads */ - __atomic_store_n(&tim->status.u32, status.u32, - __ATOMIC_RELEASE); + rte_atomic_store_explicit(&tim->status.u32, status.u32, + rte_memory_order_release); __rte_timer_reset(tim, tim->expire + tim->period, tim->period, this_lcore, tim->f, tim->arg, 1, data); diff --git a/lib/timer/rte_timer.h b/lib/timer/rte_timer.h index d3927d5..a35bc08 100644 --- a/lib/timer/rte_timer.h +++ b/lib/timer/rte_timer.h @@ -65,10 +65,10 @@ enum rte_timer_type { */ union rte_timer_status { struct { - uint16_t state; /**< Stop, pending, running, config. */ - int16_t owner; /**< The lcore that owns the timer. */ + RTE_ATOMIC(uint16_t) state; /**< Stop, pending, running, config. */ + RTE_ATOMIC(int16_t) owner; /**< The lcore that owns the timer. */ }; - uint32_t u32; /**< To atomic-set status + owner. */ + RTE_ATOMIC(uint32_t) u32; /**< To atomic-set status + owner. */ }; #ifdef RTE_LIBRTE_TIMER_DEBUG -- 1.8.3.1