Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp236642imm; Tue, 19 Jun 2018 20:07:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJtWGTV9M69FhPAOxs3WzvSk48Ykr5r8y343z7MdUcEiKIYCnDz0bPHkO5UNk4SYl+1zGsH X-Received: by 2002:a17:902:14b:: with SMTP id 69-v6mr21681042plb.184.1529464057393; Tue, 19 Jun 2018 20:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529464057; cv=none; d=google.com; s=arc-20160816; b=j75eqIgitG0fTrvErd3DVKVUfSV/WuBMNWbNmnu79FNTuH1VSUMq0q8fh7zsc7ErNc ns8Es2g5twtMkMIMJbYojIPpTluaBs/y1raQDZdyeX1p7eK9cS//JQwm8z96XNdi1Ooa hSztfqdvd4AJWQ14rOldNMhygR5NhwbvvJzDcmRs7gQQ4jWcoVEgRGgBaR3AsX7MlMvz DjrS5mUw9aM5QSBVVJpe5aEq2kqN/flSsa0KYeKhzFE3guU7vBetLdCLTTHsS+mSCVP5 KlIS7GQUgIIvWmeyajF4/SdFTZt+tui4LvZMwIif8KWkZdrC9lBhr0qdYUgeiYJvYl0E /r2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=5WvbsYokeKm2ylJlFc0oXy0DfO4ZBU67udY7ZeIfDC8=; b=m7dLv+f51R686oQGJXUCgXjsjPs5LWTbom0ANS6gOwk/altVbsOcA1dd7YXQnz+TLS cJxs6Rq4pB9t7/7icR4/I/YatnJfjCFwSCOr6CsT4E5RZfRlh3kxE6iPN+ODAn1T8Syw wuDQWxmYAvwTXDLe8A32gJdKRnZtMGcFRxzLMH75Ico087jILFljR2u7Ns0di6WudpGq r+zb0yQBIji3EExjbue347yU9LCIAijaRA7+kFbvpdGhlXjbAL+wuEhp1pOxR+hN0kX2 OEBXp2pe0QhGWDPJmxT5aVz8grKlJnmly519yRhGr54CMyGLTccUCZOERR+x6APItDCg lpmQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p29-v6si1035731pgc.199.2018.06.19.20.07.23; Tue, 19 Jun 2018 20:07:37 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754555AbeFTDFg (ORCPT + 99 others); Tue, 19 Jun 2018 23:05:36 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:58289 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754093AbeFTDDm (ORCPT ); Tue, 19 Jun 2018 23:03:42 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Tue, 19 Jun 2018 20:03:06 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 26C8940DED; Tue, 19 Jun 2018 20:03:40 -0700 (PDT) From: Nadav Amit To: , CC: Nadav Amit , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Josh Poimboeuf Subject: [PATCH v5 4/9] x86: alternatives: macrofy locks for better inlining Date: Tue, 19 Jun 2018 12:48:49 -0700 Message-ID: <20180619194854.69486-5-namit@vmware.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180619194854.69486-1-namit@vmware.com> References: <20180619194854.69486-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-001.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org GCC considers the number of statements in inlined assembly blocks, according to new-lines and semicolons, as an indication to the cost of the block in time and space. This data is distorted by the kernel code, which puts information in alternative sections. As a result, the compiler may perform incorrect inlining and branch optimizations. The solution is to set an assembly macro and call it from the inlined assembly block. As a result GCC considers the inline assembly block as a single instruction. This patch handles the LOCK prefix, allowing more aggresive inlining. text data bss dec hex filename 18140140 10225284 2957312 31322736 1ddf270 ./vmlinux before 18146889 10225380 2957312 31329581 1de0d2d ./vmlinux after (+6845) Static text symbols: Before: 40286 After: 40218 (-68) Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: Josh Poimboeuf Signed-off-by: Nadav Amit --- arch/x86/include/asm/alternative-asm.h | 20 ++++++++++++++------ arch/x86/include/asm/alternative.h | 11 ++--------- arch/x86/kernel/macros.S | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h index 31b627b43a8e..8e4ea39e55d0 100644 --- a/arch/x86/include/asm/alternative-asm.h +++ b/arch/x86/include/asm/alternative-asm.h @@ -7,16 +7,24 @@ #include #ifdef CONFIG_SMP - .macro LOCK_PREFIX -672: lock +.macro LOCK_PREFIX_HERE .pushsection .smp_locks,"a" .balign 4 - .long 672b - . + .long 671f - . # offset .popsection - .endm +671: +.endm + +.macro LOCK_PREFIX insn:vararg + LOCK_PREFIX_HERE + lock \insn +.endm #else - .macro LOCK_PREFIX - .endm +.macro LOCK_PREFIX_HERE +.endm + +.macro LOCK_PREFIX insn:vararg +.endm #endif /* diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index 4cd6a3b71824..d7faa16622d8 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -31,15 +31,8 @@ */ #ifdef CONFIG_SMP -#define LOCK_PREFIX_HERE \ - ".pushsection .smp_locks,\"a\"\n" \ - ".balign 4\n" \ - ".long 671f - .\n" /* offset */ \ - ".popsection\n" \ - "671:" - -#define LOCK_PREFIX LOCK_PREFIX_HERE "\n\tlock; " - +#define LOCK_PREFIX_HERE "LOCK_PREFIX_HERE\n\t" +#define LOCK_PREFIX "LOCK_PREFIX " #else /* ! CONFIG_SMP */ #define LOCK_PREFIX_HERE "" #define LOCK_PREFIX "" diff --git a/arch/x86/kernel/macros.S b/arch/x86/kernel/macros.S index f1fe1d570365..852487a9fc56 100644 --- a/arch/x86/kernel/macros.S +++ b/arch/x86/kernel/macros.S @@ -8,3 +8,4 @@ #include #include +#include -- 2.17.0