[v2,1/9] eal: use rdtsc intrinsic when compiling with msvc

Message ID 1680638847-26430-2-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series msvc integration changes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff April 4, 2023, 8:07 p.m. UTC
  Inline assembly is not supported for msvc x64 instead use __rdtsc
intrinsic.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/eal/x86/include/rte_cycles.h | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Bruce Richardson April 5, 2023, 8:59 a.m. UTC | #1
On Tue, Apr 04, 2023 at 01:07:19PM -0700, Tyler Retzlaff wrote:
> Inline assembly is not supported for msvc x64 instead use __rdtsc
> intrinsic.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  lib/eal/x86/include/rte_cycles.h | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/lib/eal/x86/include/rte_cycles.h b/lib/eal/x86/include/rte_cycles.h
> index a461a4d..0c142ce 100644
> --- a/lib/eal/x86/include/rte_cycles.h
> +++ b/lib/eal/x86/include/rte_cycles.h
> @@ -6,6 +6,10 @@
>  #ifndef _RTE_CYCLES_X86_64_H_
>  #define _RTE_CYCLES_X86_64_H_
>  
> +#ifdef RTE_TOOLCHAIN_MSVC
> +#include <intrin.h>
> +#endif
> +
>  #ifdef __cplusplus
>  extern "C" {
>  #endif
> @@ -23,6 +27,7 @@
>  static inline uint64_t
>  rte_rdtsc(void)
>  {
> +#ifndef RTE_TOOLCHAIN_MSVC
>  	union {
>  		uint64_t tsc_64;
>  		RTE_STD_C11
> @@ -47,6 +52,9 @@
>  		     "=a" (tsc.lo_32),
>  		     "=d" (tsc.hi_32));
>  	return tsc.tsc_64;
> +#else
> +	return __rdtsc();
> +#endif
>  }

Checking with google it seems that gcc/clang have an __rdtsc intrinsic as
well, so we may be able to avoid ifdefs here completely.

/Bruce
  

Patch

diff --git a/lib/eal/x86/include/rte_cycles.h b/lib/eal/x86/include/rte_cycles.h
index a461a4d..0c142ce 100644
--- a/lib/eal/x86/include/rte_cycles.h
+++ b/lib/eal/x86/include/rte_cycles.h
@@ -6,6 +6,10 @@ 
 #ifndef _RTE_CYCLES_X86_64_H_
 #define _RTE_CYCLES_X86_64_H_
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#include <intrin.h>
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -23,6 +27,7 @@ 
 static inline uint64_t
 rte_rdtsc(void)
 {
+#ifndef RTE_TOOLCHAIN_MSVC
 	union {
 		uint64_t tsc_64;
 		RTE_STD_C11
@@ -47,6 +52,9 @@ 
 		     "=a" (tsc.lo_32),
 		     "=d" (tsc.hi_32));
 	return tsc.tsc_64;
+#else
+	return __rdtsc();
+#endif
 }
 
 static inline uint64_t