From mboxrd@z Thu Jan 1 00:00:00 1970 From: Waiman Long Subject: Re: [PATCH v7 1/4] qrwlock: A queue read/write lock implementation Date: Wed, 18 Dec 2013 13:51:02 -0500 Message-ID: <52B1EE96.9000708@hp.com> References: <1385147087-26588-1-git-send-email-Waiman.Long@hp.com> <1385147087-26588-2-git-send-email-Waiman.Long@hp.com> <20131217192128.GA15969@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from g6t0187.atlanta.hp.com ([15.193.32.64]:36296 "EHLO g6t0187.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755480Ab3LRSvN (ORCPT ); Wed, 18 Dec 2013 13:51:13 -0500 In-Reply-To: Sender: linux-arch-owner@vger.kernel.org List-ID: To: Linus Torvalds Cc: Paul McKenney , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Arnd Bergmann , "linux-arch@vger.kernel.org" , the arch/x86 maintainers , Linux Kernel Mailing List , Peter Zijlstra , Steven Rostedt , Andrew Morton , Michel Lespinasse , Andi Kleen , Rik van Riel , Raghavendra K T , George Spelvin , Tim Chen , Aswin Chandramouleeswaran , Scott J Norton On 12/17/2013 02:27 PM, Linus Torvalds wrote: > On Tue, Dec 17, 2013 at 11:21 AM, Paul E. McKenney > wrote: >> Looks like xadd() is x86-specific, but this is common code. One >> approach would be to do xadd() for other arches, another approach >> would be to make .rw be an atomic_t rather than a u32. Making it >> be atomic_t is probably easiest. (The cmpxchg()s would then need >> to be atomic_cmpxchg().) > Note that "xadd()" has different semantics from "atomic_add_return()". > > xadd() returns the original value, while atomic_add_return() returns > the result of the addition. > > In this case, we seem to want the xadd() semantics. I guess we can use > "atomic_add_return(val,&atomic)-val" and just assume that the compiler > gets it right (with the addition and the subtraction cancelling out). > Or maybe we should have a "atomic_add_return_original()" with xadd > semantics? > > Linus I will use the atomic_add_return() for the combined count. Actually what the code is looking for in the returned value is the state of the writer byte. So it doesn't really matter if _QR_BIAS has or hasn't been added to the count. -Longman