linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] compiler.h: support asm inline qualifier for better inlining
@ 2018-12-13  9:59 Masahiro Yamada
  0 siblings, 0 replies; only message in thread
From: Masahiro Yamada @ 2018-12-13  9:59 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, Borislav Petkov, H . Peter Anvin, x86
  Cc: Richard Biener, Nadav Amit, Peter Zijlstra, Segher Boessenkool,
	Masahiro Yamada, linux-kernel

With the 'inline' qualifier supported for GCC's extended asm, we can
improve inlining where we know the actual code size of asm statement
is smaller than it looks.

You can mark such asm statements as 'asm_inline' instead of 'asm'.
'asm_volatile_goto' is always considered as the minimum code size.

Kconfig checks if the compiler supports 'asm inline'. In unsupported,
'asm_inline' falls back to 'asm'.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

GCC 9 is not released yet, but I wanted to show how easy it is
to improve asm inlining thanks to the brand new 'asm inline' syntax.

The 'inline' qualifier is explained here:
  https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

To try this patch, the following two prerequisites are necessary.

 [1] Revert in-kernel workarounds

  https://lore.kernel.org/patchwork/patch/1024584/

 [2] Replace the macros like follows:

     __inline    ->  inline
     __inline__  ->  inline

     Peter Zijlstra suggested to do this by scripting:
     https://lkml.org/lkml/2018/10/31/511

Then, replace 'asm' with 'asm_inline', for example, like follows:

 diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h
 index 6804d66..5dbe012 100644
 --- a/arch/x86/include/asm/bug.h
 +++ b/arch/x86/include/asm/bug.h
 @@ -32,7 +32,7 @@

  #define _BUG_FLAGS(ins, flags)                                         \
  do {                                                                   \
 -       asm volatile("1:\t" ins "\n"                                    \
 +       asm_inline volatile("1:\t" ins "\n"                             \
                      ".pushsection __bug_table,\"aw\"\n"                \
                      "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n"   \
                      "\t"  __BUG_REL(%c0) "\t# bug_entry::file\n"       \


 include/linux/compiler-gcc.h   | 2 +-
 include/linux/compiler_types.h | 8 +++++++-
 init/Kconfig                   | 3 +++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 2010493..c04b350 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -121,7 +121,7 @@
  *
  * (asm goto is automatically volatile - the naming reflects this.)
  */
-#define asm_volatile_goto(x...)	do { asm goto(x); asm (""); } while (0)
+#define asm_volatile_goto(x...)	do { asm_inline goto(x); asm (""); } while (0)
 
 /*
  * sparse (__CHECKER__) pretends to be gcc, but can't do constant
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 5280aee..c989bcf 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -131,7 +131,13 @@ struct ftrace_likely_data {
 #endif
 
 #ifndef asm_volatile_goto
-#define asm_volatile_goto(x...) asm goto(x)
+#define asm_volatile_goto(x...) asm_inline goto(x)
+#endif
+
+#ifdef CONFIG_CC_HAS_ASM_INLINE
+# define asm_inline asm __inline__
+#else
+# define asm_inline asm
 #endif
 
 /* Are two types/vars the same type (ignoring qualifiers)? */
diff --git a/init/Kconfig b/init/Kconfig
index cf5b5a0..52cf7f1 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -23,6 +23,9 @@ config CLANG_VERSION
 	int
 	default $(shell,$(srctree)/scripts/clang-version.sh $(CC))
 
+config CC_HAS_ASM_INLINE
+	def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
+
 config CONSTRUCTORS
 	bool
 	depends on !UML
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-12-13 10:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13  9:59 [RFC PATCH] compiler.h: support asm inline qualifier for better inlining Masahiro Yamada

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).