From patchwork Mon Oct 16 23:09:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 132681 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F263343183; Tue, 17 Oct 2023 01:11:22 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E655D42D0B; Tue, 17 Oct 2023 01:09:32 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 60B5E40A7F for ; Tue, 17 Oct 2023 01:09:09 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 0703420B74D4; Mon, 16 Oct 2023 16:09:07 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0703420B74D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1697497748; bh=ksPBnGZVkQjfGW3tponcU3SwQmffIB+F16y056Piuzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XTFWlZzHoijNGMF1lXTzahaCsVRstU4subYWDeO80X/dOiB3/yYTlkBb7nq+kt7wb bzYMdEYa5w/eT5df8AE1cHRhmxkh9wxeqWa2xTn042lqAshPm8O0rN0ef+KMF4MbCE Fl7ehER5gvExoCFDkI7uOi4pfxfoVCR/axdFlC7U= 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 20/21] timer: use rte optional stdatomic API Date: Mon, 16 Oct 2023 16:09:04 -0700 Message-Id: <1697497745-20664-21-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1697497745-20664-1-git-send-email-roretzla@linux.microsoft.com> References: <1697497745-20664-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