From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966959AbdCXT1s (ORCPT ); Fri, 24 Mar 2017 15:27:48 -0400 Received: from mail-vk0-f49.google.com ([209.85.213.49]:32846 "EHLO mail-vk0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966429AbdCXT1j (ORCPT ); Fri, 24 Mar 2017 15:27:39 -0400 MIME-Version: 1.0 In-Reply-To: References: <20170324142140.vpyzl755oj6rb5qv@hirez.programming.kicks-ass.net> <20170324164108.ibcxxqbhvx6ao54r@hirez.programming.kicks-ass.net> <20170324172342.radlrhk2z6mwmdgk@hirez.programming.kicks-ass.net> <20170324180838.crc2dmxswklqmyrx@hirez.programming.kicks-ass.net> <20170324181303.fnasnmtw2tmcy27u@hirez.programming.kicks-ass.net> From: Andy Lutomirski Date: Fri, 24 Mar 2017 12:27:16 -0700 Message-ID: Subject: Re: locking/atomic: Introduce atomic_try_cmpxchg() To: Linus Torvalds Cc: Andy Lutomirski , Peter Zijlstra , Dmitry Vyukov , Andrew Morton , Borislav Petkov , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Josh Poimboeuf , Paul McKenney , Thomas Gleixner , Ingo Molnar , LKML Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 24, 2017 at 12:20 PM, Linus Torvalds wrote: > On Fri, Mar 24, 2017 at 12:16 PM, Andy Lutomirski wrote: >>> >>> Not to mention we cannot use the C11 atomics in kernel because we want >>> to be able to runtime patch LOCK prefixes when only 1 CPU is available. >> >> Is this really a show-stopper? I bet that objtool could be persuaded >> to emit a list of the locations of all those LOCK prefixes. > > I doubt it's a show-stopper, if only because nobody cares about UP any > more. Not even the embedded world does. > > That said, I'm not convinced that there will ever really be a reason > for the kernel to use the C11 atomics. They just aren't any better > than what we can do ourselves. > > The reason for C11 atomics is "portably good atomics". We use > "architecture-specific good atomics" instead, and are willing to > maintain that. We will *have* to maintain that in the forseeable > future anyway, for legacy compiler issues. In theory, though, the compiler could optimize based on its knowledge of what the C11 atomics do. ISTR reading about a few optimizations that were already starting to be developed. Using asm goto seems okay, too, but it's a lot more tedious is less friendly to the optimizers. --Andy