Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751242AbdCYVOK (ORCPT ); Sat, 25 Mar 2017 17:14:10 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:34411 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750903AbdCYVOJ (ORCPT ); Sat, 25 Mar 2017 17:14:09 -0400 Date: Sat, 25 Mar 2017 22:13:30 +0100 From: Peter Zijlstra To: Linus Torvalds Cc: Andy Lutomirski , Dmitry Vyukov , Andrew Morton , Andy Lutomirski , Borislav Petkov , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Josh Poimboeuf , Paul McKenney , Thomas Gleixner , Ingo Molnar , LKML Subject: Re: locking/atomic: Introduce atomic_try_cmpxchg() Message-ID: <20170325211330.duvzsioxs5ll4qbe@hirez.programming.kicks-ass.net> References: <20170324172342.radlrhk2z6mwmdgk@hirez.programming.kicks-ass.net> <20170324212329.GC5680@worktop> <20170325075156.GF32474@worktop> <20170325182023.qfnj6vaixibbgbmd@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1052 Lines: 33 On Sat, Mar 25, 2017 at 11:34:32AM -0700, Linus Torvalds wrote: > On Sat, Mar 25, 2017 at 11:28 AM, Linus Torvalds > wrote: > > > > Hmm. Sad. The label approach looked like it would match the semantics > > of cmpxchg perfectly, but it's not as optimal as it superficially > > would have seemed. > > Oh, I just noticed that at least your other one didn't mark "success" > as being likely. 10730509 4540256 843776 16114541 f5e36d defconfig-build/vmlinux --- arch/x86/include/asm/cmpxchg.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h index fb961db..d347abc 100644 --- a/arch/x86/include/asm/cmpxchg.h +++ b/arch/x86/include/asm/cmpxchg.h @@ -212,8 +212,9 @@ extern void __add_wrong_size(void) default: \ __cmpxchg_wrong_size(); \ } \ + if (unlikely(!success)) \ *_old = __old; \ - success; \ + likely(success); \ }) #define __try_cmpxchg(ptr, pold, new, size) \