Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1140631imm; Tue, 15 May 2018 14:31:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqTlBdCez24bCfiNFuBfKX4qzUJVdMDHO8vKU6mwKJbL4AMglEYmxkaRyplRoL5OSEW1aoi X-Received: by 2002:a17:902:a586:: with SMTP id az6-v6mr16308745plb.210.1526419861707; Tue, 15 May 2018 14:31:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526419861; cv=none; d=google.com; s=arc-20160816; b=QyupBo47C+Jp6L7Q7mpfu0hYU7TnsvKEwaYCEV0+XUnbfq8nMo9UB5VxhPe9NEHlYL Rk0kALssszFkxMnMO1KTYbG6YGaaPZSJVS+tPPahhuPQfTm8hK4TMJgRNAvwUDNYD6ze oYTqihhFEnneR2KIsaah20Kwm7vi50zw3APRsWMqz3ecMxq5P0G2GTZSwdEgmk2VDAB0 Rxa0kFlnAwDcq8a4o7R0dcruD+8QvGwPBbYm2Dh7EMORt/9jt4aogf4RYqXUdaon6Jfo f/zAZ6UEGzsumwEjaizbwDb0HsuRK+Lb+HZbGuOsvivYGj/4hY6TdqWRLm1z4Te88xki cQPA== 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=DSChGPSELCgvwvkszEafTkTrkBEaevGTmM+hPKmR77CEbOIBAZZ6PP8fTOyU4monoK 9tDUnPjJfXPmU4vBOe+9GB783Bi5OsjBA19cndCZq9BEq9Q5RKFctYUb+XWaKYhG8dQL D+AyIgJbDXACsNAIufiIDjQtOGpao2e/snrTaDfGxZdjUbxgsB6GopKjNRyp4YseUa/6 5wViPDProgEN796Q0Tg4mSz8iC3swGkvayODr5aOtynlBTMKkTg4X0j5U8Y2P0yq6kh/ BPdIvAyzjKO/Mx7vREaK/AeMrB/bNM6v5NuxTa8oNXQskjXdoa6kUsSDnh2nHBWJ6OBl 5iaw== 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 u15-v6si757932pgv.355.2018.05.15.14.30.47; Tue, 15 May 2018 14:31:01 -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 S1752944AbeEOV2W (ORCPT + 99 others); Tue, 15 May 2018 17:28:22 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:54610 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752226AbeEOV0O (ORCPT ); Tue, 15 May 2018 17:26:14 -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; Tue, 15 May 2018 14:26:07 -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 39CD3B07B5; Tue, 15 May 2018 14:26:11 -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:19 -0700 Message-ID: <20180515141124.84254-13-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-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 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