public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] compiler_types: Introduce inline_for_performance
@ 2026-01-18 15:24 Eric Dumazet
  2026-01-18 15:32 ` Florian Westphal
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Eric Dumazet @ 2026-01-18 15:24 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, netdev, Jakub Kicinski, Eric Dumazet, Eric Dumazet,
	Paolo Abeni, Nicolas Pitre

inline keyword is often ignored by compilers.

We need something slightly stronger in networking fast paths
but __always_inline is too strong.

Instead, generalize idea Nicolas used in commit d533cb2d2af4
("__arch_xprod64(): make __always_inline when optimizing for performance")

This will help CONFIG_CC_OPTIMIZE_FOR_SIZE=y users keeping
their kernels small.

Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/netdev/176847720679.3956289.12601442580224129560.git-patchwork-notify@kernel.org/T/#m2d7e201372a8aae1ce62a0b548e55fd4fe804909
Cc: Nicolas Pitre <npitre@baylibre.com>
---
 arch/arm/include/asm/div64.h   |  6 +-----
 include/asm-generic/div64.h    |  6 +-----
 include/linux/compiler_types.h | 10 ++++++++++
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/arm/include/asm/div64.h b/arch/arm/include/asm/div64.h
index d3ef8e416b27d22d38bf084e091b0e4795f74bd4..877dfc4c4c7344849eec2109b66c2825561719dc 100644
--- a/arch/arm/include/asm/div64.h
+++ b/arch/arm/include/asm/div64.h
@@ -52,11 +52,7 @@ static inline uint32_t __div64_32(uint64_t *n, uint32_t base)
 
 #else
 
-#ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
-static __always_inline
-#else
-static inline
-#endif
+static inline_for_performance
 uint64_t __arch_xprod_64(uint64_t m, uint64_t n, bool bias)
 {
 	unsigned long long res;
diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h
index 25e7b4b58dcf55a395b9db72e01f2cd220da58a0..9893356fff55679304f68833c11c8ae9052b9cea 100644
--- a/include/asm-generic/div64.h
+++ b/include/asm-generic/div64.h
@@ -134,11 +134,7 @@
  * Hoping for compile-time optimization of  conditional code.
  * Architectures may provide their own optimized assembly implementation.
  */
-#ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
-static __always_inline
-#else
-static inline
-#endif
+static inline_for_performance
 uint64_t __arch_xprod_64(const uint64_t m, uint64_t n, bool bias)
 {
 	uint32_t m_lo = m;
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index d3318a3c257775d4f44e8f2eb7911ac52eefecc5..58b3de1f4c2540b6ffabd916948396ac8df9ba8f 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -248,6 +248,16 @@ struct ftrace_likely_data {
  */
 #define inline inline __gnu_inline __inline_maybe_unused notrace
 
+/*
+ * Compilers might decide to ignore inline hint.
+ * Functions that are performance critical can use inline_for_performance.
+ */
+#ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
+#define inline_for_performance __always_inline
+#else
+#define inline_for_performance
+#endif
+
 /*
  * gcc provides both __inline__ and __inline as alternate spellings of
  * the inline keyword, though the latter is undocumented. New kernel

base-commit: e84d960149e71e8d5e4db69775ce31305898ed0c
-- 
2.52.0.457.g6b5491de43-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2026-01-19 19:44 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-18 15:24 [PATCH] compiler_types: Introduce inline_for_performance Eric Dumazet
2026-01-18 15:32 ` Florian Westphal
2026-01-18 15:39   ` Eric Dumazet
2026-01-18 18:36 ` kernel test robot
2026-01-18 22:33   ` David Laight
2026-01-18 19:47 ` Andrew Morton
2026-01-18 20:38   ` Eric Dumazet
2026-01-18 22:58   ` David Laight
2026-01-19  0:01     ` Andrew Morton
2026-01-19  9:33       ` David Laight
2026-01-19 10:25         ` Eric Dumazet
2026-01-19 10:33           ` Eric Dumazet
2026-01-19 10:50           ` David Laight
2026-01-19 15:47     ` Nicolas Pitre
2026-01-19 19:03       ` David Laight
2026-01-19 19:44         ` Nicolas Pitre
2026-01-18 21:04 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox