LKML Archive on lore.kernel.org
 help / color / 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	[flat|nested] only message in thread

only message in thread, back to index

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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git