LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>, "H . Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org
Cc: Richard Biener <rguenther@suse.de>, Nadav Amit <namit@vmware.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Segher Boessenkool <segher@kernel.crashing.org>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH] compiler.h: support asm inline qualifier for better inlining
Date: Thu, 13 Dec 2018 18:59:14 +0900
Message-ID: <1544695154-15250-1-git-send-email-yamada.masahiro@socionext.com> (raw)

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


                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1544695154-15250-1-git-send-email-yamada.masahiro@socionext.com \
    --to=yamada.masahiro@socionext.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namit@vmware.com \
    --cc=peterz@infradead.org \
    --cc=rguenther@suse.de \
    --cc=segher@kernel.crashing.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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