[v3,2/2] stack: enable build with MSVC

Message ID 1738634318-12876-3-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Accepted
Delegated to: David Marchand
Headers
Series enable build of lib/stack when using MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS RETEST #1
ci/iol-marvell-Functional success Functional Testing PASS RETEST #1
ci/iol-sample-apps-testing success Testing PASS RETEST #1
ci/iol-broadcom-Performance success Performance Testing PASS RETEST #1
ci/iol-intel-Performance success Performance Testing PASS RETEST #1
ci/iol-intel-Functional success Functional Testing PASS RETEST #1

Commit Message

Andre Muezerie Feb. 4, 2025, 1:58 a.m. UTC
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 | 27 +++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 6 deletions(-)
  

Comments

Bruce Richardson Feb. 4, 2025, 10:30 a.m. UTC | #1
On Mon, Feb 03, 2025 at 05:58:38PM -0800, Andre Muezerie wrote:
> 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 | 27 +++++++++++++++++++++++++++
>  2 files changed, 27 insertions(+), 6 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..898d43edb2 100644
> --- a/lib/stack/rte_stack_lf_c11.h
> +++ b/lib/stack/rte_stack_lf_c11.h
> @@ -8,6 +8,33 @@
>  #include <rte_branch_prediction.h>
>  #include <rte_prefetch.h>
>  
> +#ifdef RTE_TOOLCHAIN_MSVC
> +/**
> + * 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 when using 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 */
> +	);
> +}
> +#endif /* RTE_TOOLCHAIN_MSVC */
> +

Is there a particular reason for having this only in the stack library,
more than more generically available?

/Bruce
  
Andre Muezerie Feb. 4, 2025, 3:25 p.m. UTC | #2
On Tue, Feb 04, 2025 at 10:30:03AM +0000, Bruce Richardson wrote:
> On Mon, Feb 03, 2025 at 05:58:38PM -0800, Andre Muezerie wrote:
> > 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 | 27 +++++++++++++++++++++++++++
> >  2 files changed, 27 insertions(+), 6 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..898d43edb2 100644
> > --- a/lib/stack/rte_stack_lf_c11.h
> > +++ b/lib/stack/rte_stack_lf_c11.h
> > @@ -8,6 +8,33 @@
> >  #include <rte_branch_prediction.h>
> >  #include <rte_prefetch.h>
> >  
> > +#ifdef RTE_TOOLCHAIN_MSVC
> > +/**
> > + * 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 when using 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 */
> > +	);
> > +}
> > +#endif /* RTE_TOOLCHAIN_MSVC */
> > +
> 
> Is there a particular reason for having this only in the stack library,
> more than more generically available?
> 
> /Bruce

The PR history shows that the intention with MSVC (which is a new toolchain/platform)
was to block visibility of the rte_atomic APIs from day 1.

More details can be seen here:
https://github.com/JoverZhang/dpdk/pull/21/commits/27da6a1234148fef43687d324ab2221df0631b5c

If there's a strong need we could revert that decision, but for now it seems it
would be better to follow the established direction.
--
Andre Muezerie
  
Patrick Robb Feb. 4, 2025, 5:42 p.m. UTC | #3
Recheck-request: iol-intel-Performance

Triggering a retest in CI for the failed performance result.
  

Patch

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..898d43edb2 100644
--- a/lib/stack/rte_stack_lf_c11.h
+++ b/lib/stack/rte_stack_lf_c11.h
@@ -8,6 +8,33 @@ 
 #include <rte_branch_prediction.h>
 #include <rte_prefetch.h>
 
+#ifdef RTE_TOOLCHAIN_MSVC
+/**
+ * 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 when using 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 */
+	);
+}
+#endif /* RTE_TOOLCHAIN_MSVC */
+
 static __rte_always_inline unsigned int
 __rte_stack_lf_count(struct rte_stack *s)
 {