lkml.org 
[lkml]   [2013]   [Dec]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v7 1/4] qrwlock: A queue read/write lock implementation
On Tue, Dec 17, 2013 at 11:27:29AM -0800, Linus Torvalds wrote:
> On Tue, Dec 17, 2013 at 11:21 AM, Paul E. McKenney
> <paulmck@linux.vnet.ibm.com> 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()".

Gah, that one always trips me up. :-/

> 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).

That seems like it would work well.

> Or maybe we should have a "atomic_add_return_original()" with xadd
> semantics?

My lazy side prefers the autocancellation. ;-) But yes, there are a
number of architectures (including ARM and Power) where the compiler
would have to be very tricky to reach into an asm to do the cancellation.

So perhaps a generic atomic_add_return_original() that is defined in
terms of atomic_add_return() as you say above, allowing architectures
to override with more-efficient implementations? The same could be done
for add_smp() and xadd(), for that matter.

Thanx, Paul



\
 
 \ /
  Last update: 2013-12-17 21:21    [W:0.096 / U:0.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site