From: Andre Muezerie <andremue@linux.microsoft.com>
To: andremue@linux.microsoft.com
Cc: dev@dpdk.org, david.marchand@redhat.com
Subject: [PATCH v2 2/2] stack: enable build with MSVC
Date: Tue, 28 Jan 2025 13:16:54 -0800 [thread overview]
Message-ID: <1738099014-16629-3-git-send-email-andremue@linux.microsoft.com> (raw)
In-Reply-To: <1738099014-16629-1-git-send-email-andremue@linux.microsoft.com>
An implementation compatible with MSVC is provided for
atomic128_cmp_exchange in rte_stack_lf_c11.h.
Now that the issues preventing the code needed to build lib/stack
have been addressed, it can be enabled so that it also gets built
when using the MSVC compiler.
Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
lib/stack/meson.build | 6 ----
lib/stack/rte_stack_lf_c11.h | 62 ++++++++++++++++++++++++++++++++++--
2 files changed, 60 insertions(+), 8 deletions(-)
diff --git a/lib/stack/meson.build b/lib/stack/meson.build
index 7631a14784..18177a742f 100644
--- a/lib/stack/meson.build
+++ b/lib/stack/meson.build
@@ -1,12 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2019 Intel Corporation
-if is_ms_compiler
- build = false
- reason = 'not supported building with Visual Studio Toolset'
- subdir_done()
-endif
-
sources = files('rte_stack.c', 'rte_stack_std.c', 'rte_stack_lf.c')
headers = files('rte_stack.h')
# subheaders, not for direct inclusion by apps
diff --git a/lib/stack/rte_stack_lf_c11.h b/lib/stack/rte_stack_lf_c11.h
index 60d46e963b..79d40486f9 100644
--- a/lib/stack/rte_stack_lf_c11.h
+++ b/lib/stack/rte_stack_lf_c11.h
@@ -8,6 +8,64 @@
#include <rte_branch_prediction.h>
#include <rte_prefetch.h>
+/**
+ * The maximum lock-free data size that can be manipulated atomically using C11
+ * standard is limited to 8 bytes.
+ *
+ * This implementation for __rte_atomic128_cmp_exchange operates on 16-byte
+ * data types and is made available here so that it can be used without the
+ * need to unnecessarily expose other non-C11 atomics present in
+ * rte_atomic_64.h.
+ */
+#ifdef RTE_TOOLCHAIN_MSVC
+static inline int
+__rte_atomic128_cmp_exchange(rte_int128_t *dst,
+ rte_int128_t *exp,
+ const rte_int128_t *src,
+ unsigned int weak,
+ int success,
+ int failure)
+{
+ return (int)_InterlockedCompareExchange128(
+ (int64_t volatile *) dst,
+ src->val[1], /* exchange high */
+ src->val[0], /* exchange low */
+ (int64_t *) exp /* comparand result */
+ );
+}
+#else
+static inline int
+__rte_atomic128_cmp_exchange(rte_int128_t *dst,
+ rte_int128_t *exp,
+ const rte_int128_t *src,
+ unsigned int weak,
+ int success,
+ int failure)
+{
+ RTE_SET_USED(weak);
+ RTE_SET_USED(success);
+ RTE_SET_USED(failure);
+ uint8_t res;
+
+ asm volatile (
+ MPLOCKED
+ "cmpxchg16b %[dst];"
+ " sete %[res]"
+ : [dst] "=m" (dst->val[0]),
+ "=a" (exp->val[0]),
+ "=d" (exp->val[1]),
+ [res] "=r" (res)
+ : "b" (src->val[0]),
+ "c" (src->val[1]),
+ "a" (exp->val[0]),
+ "d" (exp->val[1]),
+ "m" (dst->val[0])
+ : "memory");
+
+ return res;
+}
+#endif /* RTE_TOOLCHAIN_MSVC */
+
static __rte_always_inline unsigned int
__rte_stack_lf_count(struct rte_stack *s)
{
@@ -55,7 +113,7 @@ __rte_stack_lf_push_elems(struct rte_stack_lf_list *list,
/* Use the release memmodel to ensure the writes to the LF LIFO
* elements are visible before the head pointer write.
*/
- success = rte_atomic128_cmp_exchange(
+ success = __rte_atomic128_cmp_exchange(
(rte_int128_t *)&list->head,
(rte_int128_t *)&old_head,
(rte_int128_t *)&new_head,
@@ -155,7 +213,7 @@ __rte_stack_lf_pop_elems(struct rte_stack_lf_list *list,
* length is visible before the head update, but
* acquire semantics on the length update is enough.
*/
- success = rte_atomic128_cmp_exchange(
+ success = __rte_atomic128_cmp_exchange(
(rte_int128_t *)&list->head,
(rte_int128_t *)&old_head,
(rte_int128_t *)&new_head,
--
2.47.2.vfs.0.1
prev parent reply other threads:[~2025-01-28 21:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 16:32 [PATCH 0/3] enable build of lib/stack when using MSVC Andre Muezerie
2024-12-10 16:32 ` [PATCH 1/3] lib/eal: add rte_atomic128_cmp_exchange compatible with MSVC Andre Muezerie
2025-01-24 14:27 ` David Marchand
2025-01-28 21:25 ` Andre Muezerie
2024-12-10 16:32 ` [PATCH 2/3] app/test: add basic test for rte_atomic128_cmp_exchange Andre Muezerie
2024-12-10 16:32 ` [PATCH 3/3] lib/stack: enable build with MSVC Andre Muezerie
2025-01-28 21:16 ` [PATCH v2 0/2] enable build of lib/stack when using MSVC Andre Muezerie
2025-01-28 21:16 ` [PATCH v2 1/2] test: disable non-C11 atomic tests for MSVC Andre Muezerie
2025-01-28 21:16 ` Andre Muezerie [this message]
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=1738099014-16629-3-git-send-email-andremue@linux.microsoft.com \
--to=andremue@linux.microsoft.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
/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).