Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3929872imm; Mon, 4 Jun 2018 11:39:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKs3u26XZQlQTrXtykCMszOXwx+2blPIKyFUT4aL2CCM7xnEJPW/TnfT2BZiyAdmgfcj8WZ X-Received: by 2002:a62:86c3:: with SMTP id x186-v6mr159375pfd.4.1528137547564; Mon, 04 Jun 2018 11:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528137547; cv=none; d=google.com; s=arc-20160816; b=vpx09EOP7InsJj/ccb5gR8pawAXIxM322ZMpBS2hfapYnWEdQm2ZCIfWipIhsrBIve 6nFB5dlmlvtMrKqhi6Ehh/4Fy/kmUilh3g9EKhYFW8tAnyMya/TwItJvLhRrOh2uCmm8 bbK68E6Rg/n5AWOP0AjmUuhf6a8pfFSs4cuPRntXX+0rA7A+PD4DRKmrTdNImHGk9rPQ U3pN7wSfie/HzCQCsjsP6cfMTTecgTeL899O6MPklJnUZR08X0sKn9SvGKonbBKBDgLi 0kOz4Qwdkrqe9xx28lsSjRR7EYjdakoaOKa6Vjwf5yrl3lNbQ/NTPsgVZKXu9pgxm9zB vq5A== 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=ABG1x3UGHjszHOP0odNhSA1rquhZG014gV5mqLoE2qA=; b=WudKwuWSTgTE+0wCcCHtpgUFps7q7QwDujbIt491RmHMOlj7sNbGKkObkzdqxs2ScR vdfnD2/71Y5nME0vNJt29jNBLHn/2FNNRjfhs+73vXq1uiwYd7RzAdBMqcdhGH+ymb7z WuhjDl1bRaxS9fPSoysIrvaUtdxnKjnzY4MM2Z0IKOBp2sjVFQe6Y7JKXFjzkYCCUpPJ 1nFqVBZRRPshnZsOCjbLrx0tuKMCsvv2yDuqiMj3+oN4X9n+qyQ8DIzDjfJ+4JLdTDDq fFLTkEUrPSfhbcsvzLqYeY56/UO1p76bg912hWDWpW+VHrk282ryHFD4yxZhLKeMPMqX lTeQ== 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 u76-v6si24315303pfj.58.2018.06.04.11.38.52; Mon, 04 Jun 2018 11:39:07 -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 S1751313AbeFDShh (ORCPT + 99 others); Mon, 4 Jun 2018 14:37:37 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:51805 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750999AbeFDSg3 (ORCPT ); Mon, 4 Jun 2018 14:36:29 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Mon, 4 Jun 2018 11:36:14 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 1AFE1B0A0F; Mon, 4 Jun 2018 11:36:27 -0700 (PDT) From: Nadav Amit To: , CC: Nadav Amit , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Josh Poimboeuf Subject: [PATCH v2 4/9] x86: alternatives: macrofy locks for better inlining Date: Mon, 4 Jun 2018 04:21:26 -0700 Message-ID: <20180604112131.59100-5-namit@vmware.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180604112131.59100-1-namit@vmware.com> References: <20180604112131.59100-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.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 | 16 ++-------------- arch/x86/kernel/macros.S | 1 + 3 files changed, 17 insertions(+), 20 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..c1a3d7c76151 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -30,20 +30,8 @@ * and size information. That keeps the table sizes small. */ -#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; " - -#else /* ! CONFIG_SMP */ -#define LOCK_PREFIX_HERE "" -#define LOCK_PREFIX "" -#endif +#define LOCK_PREFIX_HERE "LOCK_PREFIX_HERE\n\t" +#define LOCK_PREFIX "LOCK_PREFIX " struct alt_instr { s32 instr_offset; /* original instruction */ 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