From patchwork Thu Dec 13 09:59:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 153623 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp613008ljp; Thu, 13 Dec 2018 02:03:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/V8voZrSwb1YRzJcHCBntGuLlPcwuZzkhSsdhWE/QsIRmPkoFW5e/dvkyVZDcB37XQJIKLU X-Received: by 2002:a63:ac1a:: with SMTP id v26mr21650935pge.293.1544695424554; Thu, 13 Dec 2018 02:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544695424; cv=none; d=google.com; s=arc-20160816; b=r+ff2jgFtjw4hwrSFd8FKXTeRLIIOQ664WJcqXEBl5hLEbl5Oo73tpX99u3SUDp4dC VuFTZvs2bEs77ktRIhMhbsDM/nb0FtOx65S2SxWk6fAzd5MtZC3KDYmXX6wsW4AtTst9 LUmlb2rYIpWmJJQ+sCBV7qfAz51CwuUIgbPwjBWaEF9GXp+iuprtocCiXHDZjumeH/vO 7SUewcrVsfuAmRIiuP7FM5rZBqOw0AI+1NGfc5HhfbucFp3DuEL9l1H+gIlI3vVd51Sl VodrAbsQoC06AACz2RF38yMi0VQQRimouud8ytnZEruJEpUUTrgk9clm6Hzx/KRlCv7k /RZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=hNmCPFaftK24Dzqx+MQ14NFA8KXiwAEI/vymgmjBy9Y=; b=OgeSyq2sFMM1BTwA/WRHhT0HT+ubRLaKX8ZCQhFtoV8HfisBjGxYYK/iIqZCSO1R6V qVrGM8KZcDQ9UhLCn2ZrqeWl4y4Fs4iyRGFo8YJCds8vokfd/fz4tP/oO7lnQDPiBIe7 PDmsk6SkVkBf0UgsbW+j3hHmSP08Xu2KHQQXdWGogoIAcICcZejE/BOJbCNudDt6hWSa UvYjIY7O7Hr8JzjGI7nus8hFfg9wmhX3XfpDEF1YuhGRmN4EAUVtZIRQmIFE0rcavFqH xw79zUxqLEahmUu0vQVzotyiKoEwzM+5wfOUZ+Gy9YPx8H85+PLvivIKGcjnRrIau4D+ hodg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=utdsLwHR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6si1206357plp.132.2018.12.13.02.03.44; Thu, 13 Dec 2018 02:03:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=utdsLwHR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728062AbeLMKDm (ORCPT + 31 others); Thu, 13 Dec 2018 05:03:42 -0500 Received: from conuserg-11.nifty.com ([210.131.2.78]:55802 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727455AbeLMKDm (ORCPT ); Thu, 13 Dec 2018 05:03:42 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id wBDA1oCm020380; Thu, 13 Dec 2018 19:01:50 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com wBDA1oCm020380 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1544695311; bh=hNmCPFaftK24Dzqx+MQ14NFA8KXiwAEI/vymgmjBy9Y=; h=From:To:Cc:Subject:Date:From; b=utdsLwHR3Lm9MffMGpF3qsW5uLkEl0uvHN1cXRR7C75x/G++w0wGKUffDDlTiInc0 6yXgvXTGcBUa9ymsPe9i7+YfOr+UiGGUmN7x+hK1Eydsn64yjdgEbzwIaD56kiDkIl oV0gj73kuU+smrGKVQDwhkYEtrC6OkjUih8+lcGtDyWnCCaxOfnH6DN8SzCrQyEXbh OCTdIOm1SsxOwFcW++apuJt3GSVKTcFc6MSom3whURyfrP3kVoe7LcLOPykgvRKrml QcYq2vsGVw9TCoD1t1F0uY2FcIYLLw13v2WVy9ztnaJqjOD2ZIy8rNKzpynExzwgik hbbP8O3/ph/kw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org Cc: Richard Biener , Nadav Amit , Peter Zijlstra , Segher Boessenkool , Masahiro Yamada , 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> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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(-) -- 2.7.4 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