Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/129810/?format=api
http://patches.dpdk.org/api/patches/129810/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/1690954318-3126-5-git-send-email-roretzla@linux.microsoft.com/", "project": { "id": 1, "url": "http://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1690954318-3126-5-git-send-email-roretzla@linux.microsoft.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1690954318-3126-5-git-send-email-roretzla@linux.microsoft.com", "date": "2023-08-02T05:31:58", "name": "[v4,4/4] eal: adapt rte spinlock and rwlock APIs to use C11 atomics", "commit_ref": null, "pull_url": null, "state": "rejected", "archived": true, "hash": "db205c165880d77e95497b2c2be87cfd59396edc", "submitter": { "id": 2077, "url": "http://patches.dpdk.org/api/people/2077/?format=api", "name": "Tyler Retzlaff", "email": "roretzla@linux.microsoft.com" }, "delegate": { "id": 1, "url": "http://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/1690954318-3126-5-git-send-email-roretzla@linux.microsoft.com/mbox/", "series": [ { "id": 29086, "url": "http://patches.dpdk.org/api/series/29086/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=29086", "date": "2023-08-02T05:31:55", "name": "eal: update public API to use stdatomic atomics", "version": 4, "mbox": "http://patches.dpdk.org/series/29086/mbox/" } ], "comments": "http://patches.dpdk.org/api/patches/129810/comments/", "check": "fail", "checks": "http://patches.dpdk.org/api/patches/129810/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "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])\n\tby inbox.dpdk.org (Postfix) with ESMTP id AB56A42FB4;\n\tWed, 2 Aug 2023 07:32:17 +0200 (CEST)", "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 6DA8B43252;\n\tWed, 2 Aug 2023 07:32:04 +0200 (CEST)", "from linux.microsoft.com (linux.microsoft.com [13.77.154.182])\n by mails.dpdk.org (Postfix) with ESMTP id 381A443251\n for <dev@dpdk.org>; Wed, 2 Aug 2023 07:32:00 +0200 (CEST)", "by linux.microsoft.com (Postfix, from userid 1086)\n id 4DC22238AF7B; Tue, 1 Aug 2023 22:31:59 -0700 (PDT)" ], "DKIM-Filter": "OpenDKIM Filter v2.11.0 linux.microsoft.com 4DC22238AF7B", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;\n s=default; t=1690954319;\n bh=jEkJw4GKpB3w+at6JrkNStOLeHdzmZLjFNn/JmI1ZLI=;\n h=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n b=XrOxN/1LuFlU6r9eGYJFllZPDll/FVj0igFRHcBASknIm5+j8tiwuRUTHRD9qgoCk\n JSKrzwlGG9T6r4n7bRXACPNgv/EIJ3VcqRyvA5tBZl/DJ92JPlz2YXOG9MKSJwCcWq\n wqCYAF5BLdStT0sO5wpKjjADrF80wmam0I6CcsqE=", "From": "Tyler Retzlaff <roretzla@linux.microsoft.com>", "To": "dev@dpdk.org", "Cc": "Gaetan Rivet <grive@u256.net>,\n Bruce Richardson <bruce.richardson@intel.com>,\n Thomas Monjalon <thomas@monjalon.net>,\n Nicolas Chautru <nicolas.chautru@intel.com>,\n Yipeng Wang <yipeng1.wang@intel.com>,\n Sameh Gobriel <sameh.gobriel@intel.com>,\n Vladimir Medvedkin <vladimir.medvedkin@intel.com>,\n Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>,\n Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>,\n Anatoly Burakov <anatoly.burakov@intel.com>,\n Olivier Matz <olivier.matz@6wind.com>,\n Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,\n Joyce Kong <joyce.kong@arm.com>,\n Erik Gabriel Carrillo <erik.g.carrillo@intel.com>,\n Liang Ma <liangma@liangbit.com>, Peter Mccarthy <peter.mccarthy@intel.com>,\n Jerin Jacob <jerinj@marvell.com>, Maciej Czekaj <mczekaj@marvell.com>,\n David Hunt <david.hunt@intel.com>, Ruifeng Wang <ruifeng.wang@arm.com>,\n Min Zhou <zhoumin@loongson.cn>, David Christensen <drc@linux.vnet.ibm.com>,\n Stanislaw Kardach <kda@semihalf.com>, david.marchand@redhat.com,\n stephen@networkplumber.org, mb@smartsharesystems.com,\n Tyler Retzlaff <roretzla@linux.microsoft.com>", "Subject": "[PATCH v4 4/4] eal: adapt rte spinlock and rwlock APIs to use C11\n atomics", "Date": "Tue, 1 Aug 2023 22:31:58 -0700", "Message-Id": "<1690954318-3126-5-git-send-email-roretzla@linux.microsoft.com>", "X-Mailer": "git-send-email 1.8.3.1", "In-Reply-To": "<1690954318-3126-1-git-send-email-roretzla@linux.microsoft.com>", "References": "<1690837661-27573-1-git-send-email-roretzla@linux.microsoft.com>\n <1690954318-3126-1-git-send-email-roretzla@linux.microsoft.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org" }, "content": "Adapt rte_spinlock.h and rte_rwlock.h APIs to use standard C11 atomics.\nUpdate consumers of the spinlock and rwlock APIs for the API break.\n\nSigned-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>\nAcked-by: Morten Brørup <mb@smartsharesystems.com>\n---\n lib/eal/include/generic/rte_rwlock.h | 46 ++++++++++++++++++----------------\n lib/eal/include/generic/rte_spinlock.h | 21 ++++++++--------\n lib/eal/x86/include/rte_spinlock.h | 2 +-\n 3 files changed, 36 insertions(+), 33 deletions(-)", "diff": "diff --git a/lib/eal/include/generic/rte_rwlock.h b/lib/eal/include/generic/rte_rwlock.h\nindex 9e083bb..b659c4c 100644\n--- a/lib/eal/include/generic/rte_rwlock.h\n+++ b/lib/eal/include/generic/rte_rwlock.h\n@@ -22,6 +22,8 @@\n * https://locklessinc.com/articles/locks/\n */\n \n+#include <stdatomic.h>\n+\n #ifdef __cplusplus\n extern \"C\" {\n #endif\n@@ -57,7 +59,7 @@\n #define RTE_RWLOCK_READ\t 0x4\t/* Reader increment */\n \n typedef struct __rte_lockable {\n-\tint32_t cnt;\n+\tint32_t _Atomic cnt;\n } rte_rwlock_t;\n \n /**\n@@ -92,21 +94,21 @@\n \n \twhile (1) {\n \t\t/* Wait while writer is present or pending */\n-\t\twhile (__atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED)\n+\t\twhile (atomic_load_explicit(&rwl->cnt, memory_order_relaxed)\n \t\t & RTE_RWLOCK_MASK)\n \t\t\trte_pause();\n \n \t\t/* Try to get read lock */\n-\t\tx = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,\n-\t\t\t\t __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;\n+\t\tx = atomic_fetch_add_explicit(&rwl->cnt, RTE_RWLOCK_READ,\n+\t\t\t\t memory_order_acquire) + RTE_RWLOCK_READ;\n \n \t\t/* If no writer, then acquire was successful */\n \t\tif (likely(!(x & RTE_RWLOCK_MASK)))\n \t\t\treturn;\n \n \t\t/* Lost race with writer, backout the change. */\n-\t\t__atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_READ,\n-\t\t\t\t __ATOMIC_RELAXED);\n+\t\tatomic_fetch_sub_explicit(&rwl->cnt, RTE_RWLOCK_READ,\n+\t\t\t\t memory_order_relaxed);\n \t}\n }\n \n@@ -127,20 +129,20 @@\n {\n \tint32_t x;\n \n-\tx = __atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED);\n+\tx = atomic_load_explicit(&rwl->cnt, memory_order_relaxed);\n \n \t/* fail if write lock is held or writer is pending */\n \tif (x & RTE_RWLOCK_MASK)\n \t\treturn -EBUSY;\n \n \t/* Try to get read lock */\n-\tx = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,\n-\t\t\t __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;\n+\tx = atomic_fetch_add_explicit(&rwl->cnt, RTE_RWLOCK_READ,\n+\t\t\t memory_order_acquire) + RTE_RWLOCK_READ;\n \n \t/* Back out if writer raced in */\n \tif (unlikely(x & RTE_RWLOCK_MASK)) {\n-\t\t__atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_READ,\n-\t\t\t\t __ATOMIC_RELEASE);\n+\t\tatomic_fetch_sub_explicit(&rwl->cnt, RTE_RWLOCK_READ,\n+\t\t\t\t memory_order_release);\n \n \t\treturn -EBUSY;\n \t}\n@@ -158,7 +160,7 @@\n \t__rte_unlock_function(rwl)\n \t__rte_no_thread_safety_analysis\n {\n-\t__atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_READ, __ATOMIC_RELEASE);\n+\tatomic_fetch_sub_explicit(&rwl->cnt, RTE_RWLOCK_READ, memory_order_release);\n }\n \n /**\n@@ -178,10 +180,10 @@\n {\n \tint32_t x;\n \n-\tx = __atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED);\n+\tx = atomic_load_explicit(&rwl->cnt, memory_order_relaxed);\n \tif (x < RTE_RWLOCK_WRITE &&\n-\t __atomic_compare_exchange_n(&rwl->cnt, &x, x + RTE_RWLOCK_WRITE,\n-\t\t\t\t\t1, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))\n+\t atomic_compare_exchange_weak_explicit(&rwl->cnt, &x, x + RTE_RWLOCK_WRITE,\n+\t\t\t\t\tmemory_order_acquire, memory_order_relaxed))\n \t\treturn 0;\n \telse\n \t\treturn -EBUSY;\n@@ -201,22 +203,22 @@\n \tint32_t x;\n \n \twhile (1) {\n-\t\tx = __atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED);\n+\t\tx = atomic_load_explicit(&rwl->cnt, memory_order_relaxed);\n \n \t\t/* No readers or writers? */\n \t\tif (likely(x < RTE_RWLOCK_WRITE)) {\n \t\t\t/* Turn off RTE_RWLOCK_WAIT, turn on RTE_RWLOCK_WRITE */\n-\t\t\tif (__atomic_compare_exchange_n(&rwl->cnt, &x, RTE_RWLOCK_WRITE, 1,\n-\t\t\t\t\t\t\t__ATOMIC_ACQUIRE, __ATOMIC_RELAXED))\n+\t\t\tif (atomic_compare_exchange_weak_explicit(&rwl->cnt, &x, RTE_RWLOCK_WRITE,\n+\t\t\t\t\t\t\tmemory_order_acquire, memory_order_relaxed))\n \t\t\t\treturn;\n \t\t}\n \n \t\t/* Turn on writer wait bit */\n \t\tif (!(x & RTE_RWLOCK_WAIT))\n-\t\t\t__atomic_fetch_or(&rwl->cnt, RTE_RWLOCK_WAIT, __ATOMIC_RELAXED);\n+\t\t\tatomic_fetch_or_explicit(&rwl->cnt, RTE_RWLOCK_WAIT, memory_order_relaxed);\n \n \t\t/* Wait until no readers before trying again */\n-\t\twhile (__atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED) > RTE_RWLOCK_WAIT)\n+\t\twhile (atomic_load_explicit(&rwl->cnt, memory_order_relaxed) > RTE_RWLOCK_WAIT)\n \t\t\trte_pause();\n \n \t}\n@@ -233,7 +235,7 @@\n \t__rte_unlock_function(rwl)\n \t__rte_no_thread_safety_analysis\n {\n-\t__atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_WRITE, __ATOMIC_RELEASE);\n+\tatomic_fetch_sub_explicit(&rwl->cnt, RTE_RWLOCK_WRITE, memory_order_release);\n }\n \n /**\n@@ -247,7 +249,7 @@\n static inline int\n rte_rwlock_write_is_locked(rte_rwlock_t *rwl)\n {\n-\tif (__atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED) & RTE_RWLOCK_WRITE)\n+\tif (atomic_load_explicit(&rwl->cnt, memory_order_relaxed) & RTE_RWLOCK_WRITE)\n \t\treturn 1;\n \n \treturn 0;\ndiff --git a/lib/eal/include/generic/rte_spinlock.h b/lib/eal/include/generic/rte_spinlock.h\nindex c50ebaa..d92432d 100644\n--- a/lib/eal/include/generic/rte_spinlock.h\n+++ b/lib/eal/include/generic/rte_spinlock.h\n@@ -17,6 +17,8 @@\n * All locks must be initialised before use, and only initialised once.\n */\n \n+#include <stdatomic.h>\n+\n #include <rte_lcore.h>\n #ifdef RTE_FORCE_INTRINSICS\n #include <rte_common.h>\n@@ -28,7 +30,7 @@\n * The rte_spinlock_t type.\n */\n typedef struct __rte_lockable {\n-\tvolatile int locked; /**< lock status 0 = unlocked, 1 = locked */\n+\tint _Atomic locked; /**< lock status 0 = unlocked, 1 = locked */\n } rte_spinlock_t;\n \n /**\n@@ -65,10 +67,10 @@\n {\n \tint exp = 0;\n \n-\twhile (!__atomic_compare_exchange_n(&sl->locked, &exp, 1, 0,\n-\t\t\t\t__ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {\n-\t\trte_wait_until_equal_32((volatile uint32_t *)&sl->locked,\n-\t\t\t 0, __ATOMIC_RELAXED);\n+\twhile (!atomic_compare_exchange_strong_explicit(&sl->locked, &exp, 1,\n+\t\t\t\tmemory_order_acquire, memory_order_relaxed)) {\n+\t\trte_wait_until_equal_32((uint32_t _Atomic *)&sl->locked,\n+\t\t\t 0, memory_order_relaxed);\n \t\texp = 0;\n \t}\n }\n@@ -89,7 +91,7 @@\n rte_spinlock_unlock(rte_spinlock_t *sl)\n \t__rte_no_thread_safety_analysis\n {\n-\t__atomic_store_n(&sl->locked, 0, __ATOMIC_RELEASE);\n+\tatomic_store_explicit(&sl->locked, 0, memory_order_release);\n }\n #endif\n \n@@ -112,9 +114,8 @@\n \t__rte_no_thread_safety_analysis\n {\n \tint exp = 0;\n-\treturn __atomic_compare_exchange_n(&sl->locked, &exp, 1,\n-\t\t\t\t0, /* disallow spurious failure */\n-\t\t\t\t__ATOMIC_ACQUIRE, __ATOMIC_RELAXED);\n+\treturn atomic_compare_exchange_strong_explicit(&sl->locked, &exp, 1,\n+\t\t\t\tmemory_order_acquire, memory_order_relaxed);\n }\n #endif\n \n@@ -128,7 +129,7 @@\n */\n static inline int rte_spinlock_is_locked (rte_spinlock_t *sl)\n {\n-\treturn __atomic_load_n(&sl->locked, __ATOMIC_ACQUIRE);\n+\treturn atomic_load_explicit(&sl->locked, memory_order_acquire);\n }\n \n /**\ndiff --git a/lib/eal/x86/include/rte_spinlock.h b/lib/eal/x86/include/rte_spinlock.h\nindex 0b20ddf..3e7f8ac 100644\n--- a/lib/eal/x86/include/rte_spinlock.h\n+++ b/lib/eal/x86/include/rte_spinlock.h\n@@ -78,7 +78,7 @@ static inline int rte_tm_supported(void)\n }\n \n static inline int\n-rte_try_tm(volatile int *lock)\n+rte_try_tm(int _Atomic *lock)\n {\n \tint i, retries;\n \n", "prefixes": [ "v4", "4/4" ] }{ "id": 129810, "url": "