Skip to contentSkip to conversation

lib/eal: fix macros for noinline and alwaysinline for MSVC

PATCH Superseded Andre Muezerie 3 participants 5 messages Nov 27, 2024 – Jan 23, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/eal: fix macros for noinline and alwaysinline for MSVC

From: Andre Muezerie <[email protected]>

MSVC supports forcing code to be inlined or forcing code to not be inlined, like other compilers.

This patch fixes existing macros __rte_noinline and __rte_always_inline so that they also do what is expected from them when used with MSVC.

---
 lib/eal/include/rte_common.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/eal/include/rte_common.h +5 -1
index 4d299f2b36..f97e52f869 100644
@@ -408,7 +408,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  * Force a function to be inlined
  */
 #ifdef RTE_TOOLCHAIN_MSVC
-#define __rte_always_inline
+#define __rte_always_inline __forceinline
 #else
 #define __rte_always_inline inline __attribute__((always_inline))
 #endif
@@ -416,7 +416,11 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 /**
  * Force a function to be noinlined
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_noinline __declspec(noinline)
+#else
 #define __rte_noinline __attribute__((noinline))
+#endif
 
 /**
  * Hint function in the hot path
Signature · 1 line
2.47.0.vfs.0.3
#1 lore raw

PATCH v2 1/1 lib/eal: fix macros for noinline and alwaysinline for MSVC

MSVC supports forcing code to be inlined or forcing code to not be inlined, like other compilers.

This patch fixes existing macros __rte_noinline and __rte_always_inline so that they also do what is expected from them when used with MSVC.

---
 lib/eal/include/rte_common.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/eal/include/rte_common.h +5 -1
index 21bfd26b2b..ed6e2c7ffd 100644
@@ -410,7 +410,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  * Force a function to be inlined
  */
 #ifdef RTE_TOOLCHAIN_MSVC
-#define __rte_always_inline
+#define __rte_always_inline __forceinline
 #else
 #define __rte_always_inline inline __attribute__((always_inline))
 #endif
@@ -418,7 +418,11 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 /**
  * Force a function to be noinlined
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_noinline __declspec(noinline)
+#else
 #define __rte_noinline __attribute__((noinline))
+#endif
 
 /**
  * Hint function in the hot path
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 1/1 eal: fix macros for MSVC: noinline, alwaysinline, hot

In reply to Andre Muezerie

MSVC supports forcing code to be inlined or forcing code to not be inlined, like other compilers. It does not support the "hot" hint though.

This patch fixes existing macros __rte_noinline and __rte_always_inline so that they also do what is expected from them when used with MSVC. __rte_hot is updated to become a noop when MSCS is used.

---
 lib/eal/include/rte_common.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
lib/eal/include/rte_common.h +9 -1
index 40592f71b1..f344d54fce 100644
@@ -427,7 +427,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  * Force a function to be inlined
  */
 #ifdef RTE_TOOLCHAIN_MSVC
-#define __rte_always_inline
+#define __rte_always_inline __forceinline
 #else
 #define __rte_always_inline inline __attribute__((always_inline))
 #endif
@@ -435,12 +435,20 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 /**
  * Force a function to be noinlined
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_noinline __declspec(noinline)
+#else
 #define __rte_noinline __attribute__((noinline))
+#endif
 
 /**
  * Hint function in the hot path
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_hot
+#else
 #define __rte_hot __attribute__((hot))
+#endif
 
 /**
  * Hint function in the cold path
Signature · 1 line
2.47.2.vfs.0.1
Acked-by on v3 1/1
#3 lore raw

RE: [PATCH v3] eal: fix macros for MSVC: noinline, alwaysinline, hot

Quoted 7 lines

From: Andre Muezerie [mailto:[email protected]]
Sent: Wednesday, 22 January 2025 17.24

MSVC supports forcing code to be inlined or forcing code to not be inlined, like other compilers. It does not support the "hot" hint though.

Quoted 7 lines

This patch fixes existing macros __rte_noinline and __rte_always_inline so that they also do what is expected from them when used with MSVC. __rte_hot is updated to become a noop when MSCS is used.

---

#4 lore raw

Re: [PATCH v3] eal: fix macros for MSVC: noinline, alwaysinline, hot

Quoted 8 lines · Morten Brørup
Quoted 8 lines

From: Andre Muezerie [mailto:[email protected]]
Sent: Wednesday, 22 January 2025 17.24

MSVC supports forcing code to be inlined or forcing code to not be inlined, like other compilers. It does not support the "hot" hint though.

Quoted 7 lines
Quoted 6 lines

This patch fixes existing macros __rte_noinline and __rte_always_inline so that they also do what is expected from them when used with MSVC. __rte_hot is updated to become a noop when MSCS is used.

Applied, thanks Andre.

Signature · 1 line
David Marchand