Re: Why Semaphore Hardware-Dependent?

David Howells
2006-09-13T18:51:16Z

Nick Piggin <nickpiggin@yahoo.com.au> wrote:

> + while ((tmp = atomic_read(&sem->count)) >= 0) {
> + if (tmp == atomic_cmpxchg(&sem->count, tmp,
> + tmp + RWSEM_ACTIVE_READ_BIAS)) {

NAK for FRV. Do not use atomic_cmpxchg() there as it isn't strictly atomic
(FRV only has one strictly atomic operation: SWAP). Please leave FRV as using
the spinlock version which is more efficient on UP.

Please also show benchmarks to show the performance difference between your
version and the old version before Ingo messed it up and made everything
unconditionally out of line without cleaning the inline asm up.

If you are going to generalise, you should get rid of everything barring the
spinlock-based version and stick with that. It will cost you performance
under some circumstances, but it's better under others than attempting to use
atomic_cmpxchg() which may not really exist on all archs.

You've also caused another problem: the spinlock based version permits up to
2^31 - 1 readers at one time, the inline optimised version, on a 32-bit arch,
will only permit up to 2^16 - 1 at most. By doing this to x86_64, you've
reduced the number of processes it can support.

David