linux-stable/arch
Linus Torvalds bc08b449ee lockref: implement lockless reference count updates using cmpxchg()
Instead of taking the spinlock, the lockless versions atomically check
that the lock is not taken, and do the reference count update using a
cmpxchg() loop.  This is semantically identical to doing the reference
count update protected by the lock, but avoids the "wait for lock"
contention that you get when accesses to the reference count are
contended.

Note that a "lockref" is absolutely _not_ equivalent to an atomic_t.
Even when the lockref reference counts are updated atomically with
cmpxchg, the fact that they also verify the state of the spinlock means
that the lockless updates can never happen while somebody else holds the
spinlock.

So while "lockref_put_or_lock()" looks a lot like just another name for
"atomic_dec_and_lock()", and both optimize to lockless updates, they are
fundamentally different: the decrement done by atomic_dec_and_lock() is
truly independent of any lock (as long as it doesn't decrement to zero),
so a locked region can still see the count change.

The lockref structure, in contrast, really is a *locked* reference
count.  If you hold the spinlock, the reference count will be stable and
you can modify the reference count without using atomics, because even
the lockless updates will see and respect the state of the lock.

In order to enable the cmpxchg lockless code, the architecture needs to
do three things:

 (1) Make sure that the "arch_spinlock_t" and an "unsigned int" can fit
     in an aligned u64, and have a "cmpxchg()" implementation that works
     on such a u64 data type.

 (2) define a helper function to test for a spinlock being unlocked
     ("arch_spin_value_unlocked()")

 (3) select the "ARCH_USE_CMPXCHG_LOCKREF" config variable in its
     Kconfig file.

This enables it for x86-64 (but not 32-bit, we'd need to make sure
cmpxchg() turns into the proper cmpxchg8b in order to enable it for
32-bit mode).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-09-02 12:12:15 -07:00
..
alpha alpha: Use handle_percpu_irq for the timer interrupt 2013-07-19 13:54:26 -07:00
arc ARC: [lib] strchr breakage in Big-endian configuration 2013-08-24 11:24:53 -07:00
arm Merge branch 'fixes' of git://git.linaro.org/people/rmk/linux-arm 2013-08-25 12:41:37 -07:00
arm64 Perf backend fixes for arm64 where the user can cause kernel panic 2013-08-21 16:36:32 -07:00
avr32 avr32: boards/atngw100/mrmt.c: fix building error 2013-08-08 14:16:22 +02:00
blackfin Merge branch 'cpuinit_phase2' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux 2013-07-18 10:50:26 -07:00
c6x Merge branch 'akpm' (updates from Andrew Morton) 2013-07-03 17:12:13 -07:00
cris cris: delete __cpuinit usage from all cris files 2013-07-14 19:36:54 -04:00
frv frv: delete __cpuinit usage from all frv files 2013-07-14 19:36:55 -04:00
h8300 net: rename busy poll socket op and globals 2013-07-10 17:08:27 -07:00
hexagon arch: *: Kconfig: add "kernel/Kconfig.freezer" to "arch/*/Kconfig" 2013-08-13 17:57:49 -07:00
ia64 Fix TLB gather virtual address range invalidation corner cases 2013-08-16 08:52:46 -07:00
m32r m32r: delete __cpuinit usage from all m32r files 2013-07-14 19:36:55 -04:00
m68k m68k: Truncate base in do_div() 2013-08-14 11:46:30 +02:00
metag metag: delete __cpuinit usage from all metag files 2013-07-14 19:36:54 -04:00
microblaze microblaze: fix clone syscall 2013-08-13 17:57:48 -07:00
mips MIPS: Handle OCTEON BBIT instructions in FPU emulator. 2013-08-20 19:17:40 +02:00
mn10300 net: rename busy poll socket op and globals 2013-07-10 17:08:27 -07:00
openrisc arch: *: Kconfig: add "kernel/Kconfig.freezer" to "arch/*/Kconfig" 2013-08-13 17:57:49 -07:00
parisc parisc: Fix interrupt routing for C8000 serial ports 2013-07-31 23:42:32 +02:00
powerpc powerpc: Work around gcc miscompilation of __pa() on 64-bit 2013-08-27 16:59:30 +10:00
s390 s390: Fix broken build 2013-08-16 21:16:37 -07:00
score arch: *: Kconfig: add "kernel/Kconfig.freezer" to "arch/*/Kconfig" 2013-08-13 17:57:49 -07:00
sh Fix TLB gather virtual address range invalidation corner cases 2013-08-16 08:52:46 -07:00
sparc sparc: delete __cpuinit/__CPUINIT usage from all users 2013-07-14 19:36:52 -04:00
tile tile: delete __cpuinit usage from all tile files 2013-07-14 19:36:54 -04:00
um Fix TLB gather virtual address range invalidation corner cases 2013-08-16 08:52:46 -07:00
unicore32 reboot: move arch/x86 reboot= handling to generic kernel 2013-07-09 10:33:29 -07:00
x86 lockref: implement lockless reference count updates using cmpxchg() 2013-09-02 12:12:15 -07:00
xtensa xtensa: delete __cpuinit usage from all xtensa files 2013-07-14 19:36:56 -04:00
.gitignore
Kconfig microblaze: fix clone syscall 2013-08-13 17:57:48 -07:00