locking tree changes for v3.18
Subsystems (9)
Linus,
Please pull the latest locking-core-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking-core-for-linus
# HEAD: 8acd91e8620836a56ff62028ed28ba629f2881a0 locking/lockdep: Revert qrwlock recusive stuff
The main updates in this cycle were:
- mutex MCS refactoring finishing touches: improve comments, refactor and clean up code, reduce debug data structure footprint, etc.
- qrwlock finishing touches: remove old code, self-test updates.
- small rwsem optimization
- various smaller fixes/cleanups
Thanks,
Ingo
------------------>
Bart Van Assche (1):
locking/spinlocks: Always evaluate the second argument of spin_lock_nested()
Davidlohr Bueso (8):
locking/mutexes: Standardize arguments in lock/unlock slowpaths locking/mutexes: Document quick lock release when unlocking locking/mcs: Remove obsolete comment
locking/mutexes: Refactor optimistic spinning code locking/mutexes: Use MUTEX_SPIN_ON_OWNER when appropriate locking/Documentation: Move locking related docs into Documentation/locking/ locking/Documentation: Update locking/mutex-design.txt disadvantages locking/rwsem: Move EXPORT_SYMBOL() lines to follow function definition
Jason Low (1):
locking/rwsem: Avoid double checking before try acquiring write lock
Mark Rustad (1):
locking/semaphore: Resolve some shadow warnings
Peter Zijlstra (2):
locking: Remove deprecated smp_mb__() barriers locking/lockdep: Revert qrwlock recusive stuff
Waiman Long (4):
locking/lockdep: Restrict the use of recursive read_lock() with qrwlock locking/selftest: Support queued rwlock
locking/rwlock, x86: Clean up asm/spinlock*.h to remove old rwlock code locking/rwlock, x86: Delete unused asm/rwlock.h and rwlock.S
Documentation/00-INDEX | 2 +
Documentation/DocBook/kernel-locking.tmpl | 2 +-
Documentation/{ => locking}/lockdep-design.txt | 0
Documentation/{ => locking}/lockstat.txt | 2 +-
Documentation/{ => locking}/mutex-design.txt | 6 +-
Documentation/{ => locking}/rt-mutex-design.txt | 0
Documentation/{ => locking}/rt-mutex.txt | 0
Documentation/{ => locking}/spinlocks.txt | 14 +-
Documentation/{ => locking}/ww-mutex-design.txt | 0
MAINTAINERS | 4 +-
arch/x86/include/asm/rwlock.h | 49 ---
arch/x86/include/asm/spinlock.h | 81 +----
arch/x86/include/asm/spinlock_types.h | 4 -
arch/x86/lib/Makefile | 1 -
arch/x86/lib/rwlock.S | 44 ---
drivers/gpu/drm/drm_modeset_lock.c | 2 +-
include/linux/atomic.h | 36 --
include/linux/bitops.h | 20 --
include/linux/lockdep.h | 2 +-
include/linux/mutex.h | 4 +-
include/linux/rwsem.h | 2 +-
include/linux/spinlock.h | 8 +-
kernel/locking/mcs_spinlock.h | 3 -
kernel/locking/mutex.c | 416 +++++++++++++-----------
kernel/locking/mutex.h | 2 +-
kernel/locking/rtmutex.c | 2 +-
kernel/locking/rwsem-xadd.c | 27 +-
kernel/locking/semaphore.c | 12 +-
kernel/sched/core.c | 16 -
lib/Kconfig.debug | 4 +-
30 files changed, 282 insertions(+), 483 deletions(-)
rename Documentation/{ => locking}/lockdep-design.txt (100%)
rename Documentation/{ => locking}/lockstat.txt (99%)
rename Documentation/{ => locking}/mutex-design.txt (97%)
rename Documentation/{ => locking}/rt-mutex-design.txt (100%)
rename Documentation/{ => locking}/rt-mutex.txt (100%)
rename Documentation/{ => locking}/spinlocks.txt (98%)
rename Documentation/{ => locking}/ww-mutex-design.txt (100%)
delete mode 100644 arch/x86/include/asm/rwlock.h
delete mode 100644 arch/x86/lib/rwlock.SDocumentation/00-INDEX +2 -0
@@ -287,6 +287,8 @@ local_ops.txt - semantics and behavior of local atomic operations. lockdep-design.txt - documentation on the runtime locking correctness validator. +locking/ + - directory with info about kernel locking primitives lockstat.txt - info on collecting statistics on locks (and contention). lockup-watchdogs.txt
Documentation/DocBook/kernel-locking.tmpl +1 -1
@@ -1972,7 +1972,7 @@ machines due to caching. <itemizedlist> <listitem> <para> - <filename>Documentation/spinlocks.txt</filename>: + <filename>Documentation/locking/spinlocks.txt</filename>: Linus Torvalds' spinlocking tutorial in the kernel sources. </para> </listitem>
Documentation/locking/lockdep-design.txt renamed from Documentation/lockdep-design.txt +0 -0
Documentation/locking/lockstat.txt renamed from Documentation/lockstat.txt +1 -1
@@ -12,7 +12,7 @@ Because things like lock contention can severely impact performance. - HOW Lockdep already has hooks in the lock functions and maps lock instances to -lock classes. We build on that (see Documentation/lockdep-design.txt). +lock classes. We build on that (see Documentation/lokcing/lockdep-design.txt). The graph below shows the relation between the lock functions and the various hooks therein.
Documentation/locking/mutex-design.txt renamed from Documentation/mutex-design.txt +3 -3
@@ -145,9 +145,9 @@ Disadvantages Unlike its original design and purpose, 'struct mutex' is larger than most locks in the kernel. E.g: on x86-64 it is 40 bytes, almost twice -as large as 'struct semaphore' (24 bytes) and 8 bytes shy of the -'struct rw_semaphore' variant. Larger structure sizes mean more CPU -cache and memory footprint. +as large as 'struct semaphore' (24 bytes) and tied, along with rwsems, +for the largest lock in the kernel. Larger structure sizes mean more +CPU cache and memory footprint. When to use mutexes -------------------
Documentation/locking/rt-mutex-design.txt renamed from Documentation/rt-mutex-design.txt +0 -0
Documentation/locking/rt-mutex.txt renamed from Documentation/rt-mutex.txt +0 -0
Documentation/locking/spinlocks.txt renamed from Documentation/spinlocks.txt +7 -7
@@ -105,9 +105,9 @@ cheaper versions of the spinlocks. IFF you know that the spinlocks are spin_unlock(&lock); (and the equivalent read-write versions too, of course). The spinlock will -guarantee the same kind of exclusive access, and it will be much faster. +guarantee the same kind of exclusive access, and it will be much faster. This is useful if you know that the data in question is only ever -manipulated from a "process context", ie no interrupts involved. +manipulated from a "process context", ie no interrupts involved. The reasons you mustn't use these versions if you have interrupts that play with the spinlock is that you can get deadlocks:
@@ -122,21 +122,21 @@ the other interrupt happens on another CPU, but it is _not_ ok if the interrupt happens on the same CPU that already holds the lock, because the lock will obviously never be released (because the interrupt is waiting for the lock, and the lock-holder is interrupted by the interrupt and will -not continue until the interrupt has been processed). +not continue until the interrupt has been processed). (This is also the reason why the irq-versions of the spinlocks only need to disable the _local_ interrupts - it's ok to use spinlocks in interrupts on other CPU's, because an interrupt on another CPU doesn't interrupt the CPU that holds the lock, so the lock-holder can continue and eventually -releases the lock). +releases the lock). Note that you can be clever with read-write locks and interrupts. For example, if you know that the interrupt only ever gets a read-lock, then you can use a non-irq version of read locks everywhere - because they -don't block on each other (and thus there is no dead-lock wrt interrupts. -But when you do the write-lock, you have to use the irq-safe version. +don't block on each other (and thus there is no dead-lock wrt interrupts. +But when you do the write-lock, you have to use the irq-safe version. -For an example of being clever with rw-locks, see the "waitqueue_lock" +For an example of being clever with rw-locks, see the "waitqueue_lock" handling in kernel/sched/core.c - nothing ever _changes_ a wait-queue from within an interrupt, they only read the queue in order to know whom to wake up. So read-locks are safe (which is good: they are very common
Documentation/locking/ww-mutex-design.txt renamed from Documentation/ww-mutex-design.txt +0 -0
MAINTAINERS +2 -2
@@ -5523,8 +5523,8 @@ M: Ingo Molnar <[email protected]> L: [email protected] T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core/locking S: Maintained -F: Documentation/lockdep*.txt -F: Documentation/lockstat.txt +F: Documentation/locking/lockdep*.txt +F: Documentation/locking/lockstat.txt F: include/linux/lockdep.h F: kernel/locking/
arch/x86/include/asm/rwlock.h deleted +0 -49
49 lines not on this page · raw message
arch/x86/include/asm/spinlock.h +2 -79
100 lines not on this page · raw message
arch/x86/include/asm/spinlock_types.h +0 -4
@@ -34,10 +34,6 @@ typedef struct arch_spinlock {#define __ARCH_SPIN_LOCK_UNLOCKED { { 0 } } -#ifdef CONFIG_QUEUE_RWLOCK #include <asm-generic/qrwlock_types.h> -#else -#include <asm/rwlock.h> -#endif #endif /* _ASM_X86_SPINLOCK_TYPES_H */
arch/x86/lib/Makefile +0 -1
@@ -20,7 +20,6 @@ lib-y := delay.o misc.o cmdline.o lib-y += thunk_$(BITS).o lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o lib-y += memcpy_$(BITS).o -lib-$(CONFIG_SMP) += rwlock.o lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o
arch/x86/lib/rwlock.S deleted +0 -44
44 lines not on this page · raw message
drivers/gpu/drm/drm_modeset_lock.c +1 -1
@@ -35,7 +35,7 @@* of extra utility/tracking out of our acquire-ctx. This is provided * by drm_modeset_lock / drm_modeset_acquire_ctx. * -* For basic principles of ww_mutex, see: Documentation/ww-mutex-design.txt +* For basic principles of ww_mutex, see: Documentation/locking/ww-mutex-design.txt * * The basic usage pattern is to: *
include/linux/atomic.h +0 -36
@@ -3,42 +3,6 @@#define _LINUX_ATOMIC_H#include <asm/atomic.h> -/* -* Provide __deprecated wrappers for the new interface, avoid flag day changes. -* We need the ugly external functions to break header recursion hell. -*/ -#ifndef smp_mb__before_atomic_inc -static inline void __deprecated smp_mb__before_atomic_inc (void ) -{ -extern void __smp_mb__before_atomic (void ); -__smp_mb__before_atomic (); -} -#endif - -#ifndef smp_mb__after_atomic_inc -static inline void __deprecated smp_mb__after_atomic_inc (void ) -{ -extern void __smp_mb__after_atomic (void ); -__smp_mb__after_atomic (); -} -#endif - -#ifndef smp_mb__before_atomic_dec -static inline void __deprecated smp_mb__before_atomic_dec (void ) -{ -extern void __smp_mb__before_atomic (void ); -__smp_mb__before_atomic (); -} -#endif - -#ifndef smp_mb__after_atomic_dec -static inline void __deprecated smp_mb__after_atomic_dec (void ) -{ -extern void __smp_mb__after_atomic (void ); -__smp_mb__after_atomic (); -} -#endif -/** * atomic_add_unless - add unless the number is already a given value * @v: pointer of type atomic_t
include/linux/bitops.h +0 -20
@@ -32,26 +32,6 @@ extern unsigned long __sw_hweight64(__u64 w);*/ #include <asm/bitops.h> -/* -* Provide __deprecated wrappers for the new interface, avoid flag day changes. -* We need the ugly external functions to break header recursion hell. -*/ -#ifndef smp_mb__before_clear_bit -static inline void __deprecated smp_mb__before_clear_bit (void ) -{ -extern void __smp_mb__before_atomic (void ); -__smp_mb__before_atomic (); -} -#endif - -#ifndef smp_mb__after_clear_bit -static inline void __deprecated smp_mb__after_clear_bit (void ) -{ -extern void __smp_mb__after_atomic (void ); -__smp_mb__after_atomic (); -} -#endif -#define for_each_set_bit (bit, addr, size) \ for ((bit) = find_first_bit((addr), (size)); \ (bit) < (size); \
include/linux/lockdep.h +1 -1
@@ -4,7 +4,7 @@* Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <[email protected]> * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> * -* see Documentation/lockdep-design.txt for more details. +* see Documentation/locking/lockdep-design.txt for more details. */ #ifndef __LINUX_LOCKDEP_H#define __LINUX_LOCKDEP_H
include/linux/mutex.h +2 -2
@@ -52,7 +52,7 @@ struct mutex {atomic_t count;spinlock_t wait_lock;struct list_head wait_list; -#if defined(CONFIG_DEBUG_MUTEXES ) || defined(CONFIG_SMP ) +#if defined(CONFIG_DEBUG_MUTEXES ) || defined(CONFIG_MUTEX_SPIN_ON_OWNER )struct task_struct *owner;#endif #ifdef CONFIG_MUTEX_SPIN_ON_OWNER
@@ -133,7 +133,7 @@ static inline int mutex_is_locked(struct mutex *lock)/* * See kernel/locking/mutex.c for detailed documentation of these APIs. -* Also see Documentation/mutex-design.txt. +* Also see Documentation/locking/mutex-design.txt. */ #ifdef CONFIG_DEBUG_LOCK_ALLOC extern void mutex_lock_nested (struct mutex *lock,unsigned int subclass);
include/linux/rwsem.h +1 -1
@@ -149,7 +149,7 @@ extern void downgrade_write(struct rw_semaphore *sem);* static then another method for expressing nested locking is * the explicit definition of lock class keys and the use of * lockdep_set_class() at lock initialization time. -* See Documentation/lockdep-design.txt for more details.) +* See Documentation/locking/lockdep-design.txt for more details.) */ extern void down_read_nested (struct rw_semaphore *sem,int subclass);extern void down_write_nested (struct rw_semaphore *sem,int subclass);
include/linux/spinlock.h +7 -1
@@ -197,7 +197,13 @@ static inline void do_raw_spin_unlock(raw_spinlock_t *lock) __releases(lock)_raw_spin_lock_nest_lock (lock, &(nest_lock)->dep_map); \ } while (0)#else -# define raw_spin_lock_nested (lock, subclass) _raw_spin_lock(lock) +/* +* Always evaluate the 'subclass' argument to avoid that the compiler +* warns about set-but-not-used variables when building with +* CONFIG_DEBUG_LOCK_ALLOC=n and with W=1. +*/ +# define raw_spin_lock_nested (lock, subclass) \ + _raw_spin_lock(((void)(subclass), (lock)))# define raw_spin_lock_nest_lock (lock, nest_lock) _raw_spin_lock(lock)#endif
kernel/locking/mcs_spinlock.h +0 -3
@@ -56,9 +56,6 @@ do { \* If the lock has already been acquired, then this will proceed to spin * on this node->locked until the previous lock holder sets the node->locked * in mcs_spin_unlock(). -* -* We don't inline mcs_spin_lock() so that perf can correctly account for the -* time spent in this lock function. */ static inline void mcs_spin_lock (struct mcs_spinlock **lock,struct mcs_spinlock *node)
kernel/locking/mutex.c +228 -188
464 lines not on this page · raw message
kernel/locking/mutex.h +1 -1
@@ -16,7 +16,7 @@#define mutex_remove_waiter (lock, waiter, ti) \ __list_del((waiter)->list.prev, (waiter)->list.next) -#ifdef CONFIG_SMP +#ifdef CONFIG_MUTEX_SPIN_ON_OWNER static inline void mutex_set_owner (struct mutex *lock) { lock->owner = current;
kernel/locking/rtmutex.c +1 -1
@@ -8,7 +8,7 @@* Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt * Copyright (C) 2006 Esben Nielsen * -* See Documentation/rt-mutex-design.txt for details. +* See Documentation/locking/rt-mutex-design.txt for details. */ #include <linux/spinlock.h> #include <linux/export.h>
kernel/locking/rwsem-xadd.c +14 -13
@@ -246,19 +246,22 @@ struct rw_semaphore __sched *rwsem_down_read_failed(struct rw_semaphore *sem)return sem; } +EXPORT_SYMBOL (rwsem_down_read_failed);static inline bool rwsem_try_write_lock (long count,struct rw_semaphore *sem) { -if (!(count &RWSEM_ACTIVE_MASK )) { -/* try acquiring the write lock */ -if (sem->count ==RWSEM_WAITING_BIAS && -cmpxchg (&sem->count,RWSEM_WAITING_BIAS , -RWSEM_ACTIVE_WRITE_BIAS ) ==RWSEM_WAITING_BIAS ) { -if (!list_is_singular (&sem->wait_list)) -rwsem_atomic_update (RWSEM_WAITING_BIAS , sem); -return true; - } +/* +* Try acquiring the write lock. Check count first in order +* to reduce unnecessary expensive cmpxchg() operations. +*/ +if (count ==RWSEM_WAITING_BIAS && +cmpxchg (&sem->count,RWSEM_WAITING_BIAS , +RWSEM_ACTIVE_WRITE_BIAS ) ==RWSEM_WAITING_BIAS ) { +if (!list_is_singular (&sem->wait_list)) +rwsem_atomic_update (RWSEM_WAITING_BIAS , sem); +return true; } +return false; }
@@ -465,6 +468,7 @@ struct rw_semaphore __sched *rwsem_down_write_failed(struct rw_semaphore *sem)return sem; } +EXPORT_SYMBOL (rwsem_down_write_failed);/* * handle waking up a waiter on the semaphore
@@ -485,6 +489,7 @@ struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem)return sem; } +EXPORT_SYMBOL (rwsem_wake);/* * downgrade a write lock into a read lock
@@ -506,8 +511,4 @@ struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem)return sem; } - -EXPORT_SYMBOL (rwsem_down_read_failed); -EXPORT_SYMBOL (rwsem_down_write_failed); -EXPORT_SYMBOL (rwsem_wake);EXPORT_SYMBOL (rwsem_downgrade_wake);
kernel/locking/semaphore.c +6 -6
@@ -36,7 +36,7 @@ static noinline void __down(struct semaphore *sem); static noinline int __down_interruptible(struct semaphore *sem); static noinline int __down_killable(struct semaphore *sem); -static noinline int __down_timeout(struct semaphore *sem, long jiffies); +static noinline int __down_timeout(struct semaphore *sem, long timeout); static noinline void __up(struct semaphore *sem);/**
@@ -145,14 +145,14 @@ EXPORT_SYMBOL(down_trylock);/** * down_timeout - acquire the semaphore within a specified time * @sem: the semaphore to be acquired -* @jiffies: how long to wait before failing +* @timeout: how long to wait before failing * * Attempts to acquire the semaphore. If no more tasks are allowed to * acquire the semaphore, calling this function will put the task to sleep. * If the semaphore is not released within the specified number of jiffies, * this function returns -ETIME. It returns 0 if the semaphore was acquired. */ -int down_timeout (struct semaphore *sem,long jiffies) +int down_timeout (struct semaphore *sem,long timeout) {unsigned long flags;int result =0 ;
@@ -161,7 +161,7 @@ int down_timeout(struct semaphore *sem, long jiffies)if (likely (sem->count >0 )) sem->count--;else - result =__down_timeout (sem, jiffies); + result =__down_timeout (sem, timeout);raw_spin_unlock_irqrestore (&sem->lock, flags);return result;
@@ -248,9 +248,9 @@ static noinline int __sched __down_killable(struct semaphore *sem)return __down_common (sem,TASK_KILLABLE ,MAX_SCHEDULE_TIMEOUT ); } -static noinline int __sched __down_timeout(struct semaphore *sem, long jiffies) +static noinline int __sched __down_timeout(struct semaphore *sem, long timeout) { -return __down_common (sem,TASK_UNINTERRUPTIBLE , jiffies); +return __down_common (sem,TASK_UNINTERRUPTIBLE , timeout); } static noinline void __sched __up(struct semaphore *sem)
kernel/sched/core.c +0 -16
@@ -90,22 +90,6 @@#define CREATE_TRACE_POINTS #include <trace/events/sched.h> -#ifdef smp_mb__before_atomic -void __smp_mb__before_atomic (void ) -{ -smp_mb__before_atomic (); -} -EXPORT_SYMBOL (__smp_mb__before_atomic); -#endif - -#ifdef smp_mb__after_atomic -void __smp_mb__after_atomic (void ) -{ -smp_mb__after_atomic (); -} -EXPORT_SYMBOL (__smp_mb__after_atomic); -#endif -void start_bandwidth_timer (struct hrtimer *period_timer,ktime_t period) {unsigned long delta;
lib/Kconfig.debug +2 -2
@@ -924,7 +924,7 @@ config PROVE_LOCKING the proof of observed correctness is also maintained for an arbitrary combination of these separate locking variants. - For more details, see Documentation/lockdep-design.txt. + For more details, see Documentation/locking/lockdep-design.txt. config LOCKDEP bool
@@ -945,7 +945,7 @@ config LOCK_STAT help This feature enables tracking lock contention points - For more details, see Documentation/lockstat.txt + For more details, see Documentation/locking/lockstat.txt This also enables lock events required by "perf lock", subcommand of perf.