Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754897AbbDKJUk (ORCPT ); Sat, 11 Apr 2015 05:20:40 -0400 Received: from mail-wi0-f173.google.com ([209.85.212.173]:35892 "EHLO mail-wi0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751861AbbDKJU1 (ORCPT ); Sat, 11 Apr 2015 05:20:27 -0400 Date: Sat, 11 Apr 2015 11:20:21 +0200 From: Ingo Molnar To: "Paul E. McKenney" Cc: Linus Torvalds , Jason Low , Peter Zijlstra , Davidlohr Bueso , Tim Chen , Aswin Chandramouleeswaran , LKML , Borislav Petkov , Andy Lutomirski , Denys Vlasenko , Brian Gerst , "H. Peter Anvin" , Thomas Gleixner , Peter Zijlstra Subject: [PATCH] x86: Turn off GCC branch probability heuristics Message-ID: <20150411092021.GA9478@gmail.com> References: <20150409175652.GI6464@linux.vnet.ibm.com> <20150409183926.GM6464@linux.vnet.ibm.com> <20150410090051.GA28549@gmail.com> <20150410091252.GA27630@gmail.com> <20150410092152.GA21332@gmail.com> <20150410111427.GA30477@gmail.com> <20150410112748.GB30477@gmail.com> <20150410120846.GA17101@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150410120846.GA17101@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2193 Lines: 64 * Ingo Molnar wrote: > Btw., totally off topic, the following NOP caught my attention: > > > 5a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1) > > That's a dead NOP that boats the function a bit, added for the 16 byte > alignment of one of the jump targets. Another thing caught my attention (and I'm hijacking the RCU thread again): GCC's notion of how to place branches seems somewhat random, and rather bloaty. So I tried the experiment below on an x86 defconfig, turning off GCC's branch heuristics, and it's rather surprising: text data bss dec filename 12566447 1617840 1089536 15273823 vmlinux.fguess-branch-probability 11923593 1617840 1089536 14630969 vmlinux.fno-guess-branch-probability That's an 5.4% code size improvement! So maybe we should try this, as it results in much more predictable (and more compact!) code by default - and allows us to shape loops and branches in a natural fashion: by their placement, and also via likely()/unlikely() hints when absolutely necessary. Thoughts? Thanks, Ingo =================> From: Ingo Molnar Date: Sat, 11 Apr 2015 11:16:30 +0200 Subject: [PATCH] x86: Turn off GCC branch probability heuristics Not-Signed-off-by: Ingo Molnar --- arch/x86/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 5ba2d9ce82dc..7c12b3f56915 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -81,6 +81,9 @@ else KBUILD_CFLAGS += $(call cc-option,-mno-80387) KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387) + # Don't guess branch probabilities, follow the code and unlikely()/likely() hints: + KBUILD_CFLAGS += -fno-guess-branch-probability + # Use -mpreferred-stack-boundary=3 if supported. KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/