This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Userspace RCU library relicensed to LGPLv2.1
- From: Mathieu Desnoyers <mathieu dot desnoyers at polymtl dot ca>
- To: Jan Blunck <jblunck at suse dot de>
- Cc: ltt-dev at lists dot casi dot polymtl dot ca, "Paul E. McKenney" <paulmck at linux dot vnet dot ibm dot com>, steven dot bennett at us dot ibm dot com, tech-board <tech-board at lists dot linux-foundation dot org>, Robert Wisniewski <bob at watson dot ibm dot com>, Evgeniy Polyakov <zbr at ioremap dot net>, Dominique Toupin <dominique dot toupin at ericsson dot com>, Jonathan Corbet <corbet at lwn dot net>, Jake Edge <jake at lwn dot net>, zbrown at tumblerings dot org, libc-alpha at sources dot redhat dot com
- Date: Thu, 14 May 2009 10:03:46 -0400
- Subject: Re: Userspace RCU library relicensed to LGPLv2.1
- References: <20090513204308.GA27340@Krystal> <20090514092738.GO17988@bolzano.suse.de> <20090514130639.GD21241@Krystal> <20090514134622.GT17988@bolzano.suse.de>
* Jan Blunck (jblunck@suse.de) wrote:
> On Thu, May 14, Mathieu Desnoyers wrote:
>
> > If we look at
> > http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html
> >
> > The instruction closest to an xchg() instruction (to exchange a pointer
> > in memory) is :
> >
> >
> > "type __sync_lock_test_and_set (type *ptr, type value, ...)
>
> Couldn't you make us of the following?
>
> type __sync_val_compare_and_swap (type *ptr, type oldval type newval, ...)
>
> These builtins perform an atomic compare and swap. That is, if the current
> value of *ptr is oldval, then write newval into *ptr.
>
That would be more expensive. We would need to :
1 - oldval = pointer read (cpu taking the cache line as "shared")
2 - compare and swap newval with *ptr (if *ptr == oldval)
(cpu taking the cache line as "exclusive")
3 - loop to 2; if it fails, re-using the value returned by compare and
swap for the next loop
compared to :
oldptr = xchg(&rcu_pointer, newptr);
As you see, using a compare and swap for this is just a waste at many
levels :
- cache line exchanges increase
- code size increase
- code speed decrease
The gcc-friendly solution would be to add a
type __sync_val_xchg(type *ptr, type value)
primitive to gcc atomic ops.
Mathieu
> At least __sync_lock_test_and_set() and __sync_lock_release() seem to be only
> usable when implementing spin locks.
>
> Regards,
> Jan
>
> --
> Jan Blunck <jblunck@suse.de>
--
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68