Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752165AbbEAQ3h (ORCPT ); Fri, 1 May 2015 12:29:37 -0400 Received: from casper.infradead.org ([85.118.1.10]:47116 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751966AbbEAQ3d (ORCPT ); Fri, 1 May 2015 12:29:33 -0400 Date: Fri, 1 May 2015 18:29:21 +0200 From: Peter Zijlstra To: Linus Torvalds Cc: Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Linux Kernel Mailing List , Borislav Petkov , Jakub Jelinek Subject: Re: [PATCH] x86: Optimize variable_test_bit() Message-ID: <20150501162921.GD24151@twins.programming.kicks-ass.net> References: <20150501151630.GH5029@twins.programming.kicks-ass.net> <20150501161654.GI5029@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150501161654.GI5029@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1996 Lines: 44 On Fri, May 01, 2015 at 06:16:54PM +0200, Peter Zijlstra wrote: > On Fri, May 01, 2015 at 09:03:32AM -0700, Linus Torvalds wrote: > > On Fri, May 1, 2015 at 8:16 AM, Peter Zijlstra wrote: > > > > > > Since test_bit() doesn't actually have any output variables, we can use > > > asm goto without having to add a memory clobber. This reduces the code > > > to something sensible: > > > > Yes, looks good, except if we have anything that actually wants to use > > the value rather than branch on it. But a quick grep seems to show > > that the vast majority of them are all about just directly testing the > > result. > > > > It worries me a bit that gcc now cannot pick the likely branch any > > more. It will always branch out for the bit being set. So code like > > this: > > > > net/core/dev.c: if > > (likely(!test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) > > > > wouldn't work, but almost all of those seem to be the constant case > > that doesn't get to this anyway. > > Ah yes, that's another thing we've previously discussed with the GCC > people (IIRC). The GCC manual states you can use hot and cold attributes > on the labels (although when we tested that it didn't actually work, it > might now). But that's no good if the hint is one (or more) layer up > from the asm goto. > > If would indeed be very good if the likely/unlikely thing would work as > expected. Ah, I see what you meant. Yes we're stuck with the 'jc', the compiler cannot flip that into a jnc. The best it can do is add unconditional jumps to re-arrange the blocks, and that's somewhat ugly indeed, although better than nothing at all. And from experiments back when we did the static_branch stuff that all didn't work at all. -- 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/