Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1139490imm; Tue, 15 May 2018 14:30:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpUu88jeh6n58WSgt/GHPIv1lrY0kyuIYrwooQsO+I4RHMSALMgRjDSmBs9P17dx8R15vM8 X-Received: by 2002:a62:a391:: with SMTP id q17-v6mr16950299pfl.87.1526419806715; Tue, 15 May 2018 14:30:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526419806; cv=none; d=google.com; s=arc-20160816; b=BKQXSFC2KLmsL967MiEN+tJx5/f2Nned20HAetAnZ8YzfpxW4fzLduljM0yDLCuPK5 jhc1AbnxHxDxjVc7jpRPgHO0lRu3x59SMo8ah0F3N6QyTj4uq95UZB644PNjSnHVP0ST Jl9htOsDkmPbW7oqOcJypGGIg9wtf59fHIaAFVKlHl2FRMn50mqEXJa0aUUFYr/ZyLqc atvXNWCZx2Wkfmg3lF8vBy+39xDnso9BnMjVeGLfGSa6dSpHZgQxzHC+sQszcK3/xd5d L5euxokX2xFRWhylZKwpYi5znul1tsiuwmUdQwljfFAhodR9UoMs5d55DG6S+65M8Ol4 n0wA== 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=8HYbhdXjh1uqUhDb+MsfrBHbuC+jZfwuc8Y+oLvWNjk=; b=EQMf026fXJL8wcxrlH4Iva1AIWgIGtcIydPytHjnHeC0xcs9jqQYSiEZoTtujyA3Jc dtWln/4fdvxMBClO2NDt/b0XTHjhbaux1MJuK3UZO88vog3Ho7gv2Nnq88WtibFpogmH lLRNFMEY5IndCNu6SvjHI6roemBiFO2Bd5XDPDYjlsDXu6hMQrH+J5N3aRO7X7BsWuq9 cL/UrBNea0iUWwCI840TPRMef1dOmCCRnkDj+DIn5Z00BVzstH7T8sQT+cVQo8bTv0/0 tipeimZWxAXrtTCCbFAin6lFu50M389LuimNrGGo7xrMXKKJoiO6Oi7TIXpHqNjGqnob y5jw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r9-v6si949489pfg.247.2018.05.15.14.29.52; Tue, 15 May 2018 14:30:06 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752670AbeEOV0N (ORCPT + 99 others); Tue, 15 May 2018 17:26:13 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:48538 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752226AbeEOV0L (ORCPT ); Tue, 15 May 2018 17:26:11 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Tue, 15 May 2018 14:25:46 -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 D3118B0795; Tue, 15 May 2018 14:26:10 -0700 (PDT) From: Nadav Amit To: CC: , Nadav Amit , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , , Josh Poimboeuf Subject: [RFC 3/8] x86: alternative: macrofy locks for better inlining Date: Tue, 15 May 2018 07:11:10 -0700 Message-ID: <20180515141124.84254-4-namit@vmware.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180515141124.84254-1-namit@vmware.com> References: <20180515141124.84254-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 18127205 10068388 2936832 31132425 1db0b09 ./vmlinux before 18131468 10068488 2936832 31136788 1db1c14 ./vmlinux after (+4363) Static text symbols: Before: 39860 After: 39788 (-72) 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.h | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index 4cd6a3b71824..daa68ad51665 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -31,14 +31,26 @@ */ #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; " + +asm ("\n" + ".macro __LOCK_PREFIX_HERE\n\t" + ".pushsection .smp_locks,\"a\"\n\t" + ".balign 4\n\t" + ".long 671f - .\n\t" /* offset */ + ".popsection\n" + "671:\n" + ".endm"); + +#define LOCK_PREFIX_HERE "__LOCK_PREFIX_HERE" + +asm ("\n" + ".macro __LOCK_PREFIX ins:vararg\n\t" + "__LOCK_PREFIX_HERE\n\t" + "lock; \\ins\n" + ".endm"); + +#define LOCK_PREFIX "__LOCK_PREFIX " + #else /* ! CONFIG_SMP */ #define LOCK_PREFIX_HERE "" -- 2.17.0