Commit 8efb90cf authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull locking updates from Ingo Molnar:
 "The main changes in this cycle are:

   - big rtmutex and futex cleanup and robustification from Thomas
     Gleixner
   - mutex optimizations and refinements from Jason Low
   - arch_mutex_cpu_relax() removal and related cleanups
   - smaller lockdep tweaks"

* 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (23 commits)
  arch, locking: Ciao arch_mutex_cpu_relax()
  locking/lockdep: Only ask for /proc/lock_stat output when available
  locking/mutexes: Optimize mutex trylock slowpath
  locking/mutexes: Try to acquire mutex only if it is unlocked
  locking/mutexes: Delete the MUTEX_SHOW_NO_WAITER macro
  locking/mutexes: Correct documentation on mutex optimistic spinning
  rtmutex: Make the rtmutex tester depend on BROKEN
  futex: Simplify futex_lock_pi_atomic() and make it more robust
  futex: Split out the first waiter attachment from lookup_pi_state()
  futex: Split out the waiter check from lookup_pi_state()
  futex: Use futex_top_waiter() in lookup_pi_state()
  futex: Make unlock_pi more robust
  rtmutex: Avoid pointless requeueing in the deadlock detection chain walk
  rtmutex: Cleanup deadlock detector debug logic
  rtmutex: Confine deadlock logic to futex
  rtmutex: Simplify remove_waiter()
  rtmutex: Document pi chain walk
  rtmutex: Clarify the boost/deboost part
  rtmutex: No need to keep task ref for lock owner check
  rtmutex: Simplify and document try_to_take_rtmutex()
  ...
parents 5bda4f63 3a6bfbc9
...@@ -57,6 +57,7 @@ unsigned long get_wchan(struct task_struct *p); ...@@ -57,6 +57,7 @@ unsigned long get_wchan(struct task_struct *p);
((tsk) == current ? rdusp() : task_thread_info(tsk)->pcb.usp) ((tsk) == current ? rdusp() : task_thread_info(tsk)->pcb.usp)
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
#define ARCH_HAS_PREFETCH #define ARCH_HAS_PREFETCH
#define ARCH_HAS_PREFETCHW #define ARCH_HAS_PREFETCHW
......
...@@ -62,6 +62,8 @@ unsigned long thread_saved_pc(struct task_struct *t); ...@@ -62,6 +62,8 @@ unsigned long thread_saved_pc(struct task_struct *t);
#define cpu_relax() do { } while (0) #define cpu_relax() do { } while (0)
#endif #endif
#define cpu_relax_lowlatency() cpu_relax()
#define copy_segments(tsk, mm) do { } while (0) #define copy_segments(tsk, mm) do { } while (0)
#define release_segments(mm) do { } while (0) #define release_segments(mm) do { } while (0)
......
...@@ -82,6 +82,8 @@ unsigned long get_wchan(struct task_struct *p); ...@@ -82,6 +82,8 @@ unsigned long get_wchan(struct task_struct *p);
#define cpu_relax() barrier() #define cpu_relax() barrier()
#endif #endif
#define cpu_relax_lowlatency() cpu_relax()
#define task_pt_regs(p) \ #define task_pt_regs(p) \
((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1) ((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
......
...@@ -129,6 +129,7 @@ extern void release_thread(struct task_struct *); ...@@ -129,6 +129,7 @@ extern void release_thread(struct task_struct *);
unsigned long get_wchan(struct task_struct *p); unsigned long get_wchan(struct task_struct *p);
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
/* Thread switching */ /* Thread switching */
extern struct task_struct *cpu_switch_to(struct task_struct *prev, extern struct task_struct *cpu_switch_to(struct task_struct *prev,
......
...@@ -92,6 +92,7 @@ extern struct avr32_cpuinfo boot_cpu_data; ...@@ -92,6 +92,7 @@ extern struct avr32_cpuinfo boot_cpu_data;
#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3)) #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
#define cpu_sync_pipeline() asm volatile("sub pc, -2" : : : "memory") #define cpu_sync_pipeline() asm volatile("sub pc, -2" : : : "memory")
struct cpu_context { struct cpu_context {
......
...@@ -99,7 +99,7 @@ unsigned long get_wchan(struct task_struct *p); ...@@ -99,7 +99,7 @@ unsigned long get_wchan(struct task_struct *p);
#define KSTK_ESP(tsk) ((tsk) == current ? rdusp() : (tsk)->thread.usp) #define KSTK_ESP(tsk) ((tsk) == current ? rdusp() : (tsk)->thread.usp)
#define cpu_relax() smp_mb() #define cpu_relax() smp_mb()
#define cpu_relax_lowlatency() cpu_relax()
/* Get the Silicon Revision of the chip */ /* Get the Silicon Revision of the chip */
static inline uint32_t __pure bfin_revid(void) static inline uint32_t __pure bfin_revid(void)
......
...@@ -121,6 +121,7 @@ extern unsigned long get_wchan(struct task_struct *p); ...@@ -121,6 +121,7 @@ extern unsigned long get_wchan(struct task_struct *p);
#define KSTK_ESP(task) (task_pt_regs(task)->sp) #define KSTK_ESP(task) (task_pt_regs(task)->sp)
#define cpu_relax() do { } while (0) #define cpu_relax() do { } while (0)
#define cpu_relax_lowlatency() cpu_relax()
extern const struct seq_operations cpuinfo_op; extern const struct seq_operations cpuinfo_op;
......
...@@ -63,6 +63,7 @@ static inline void release_thread(struct task_struct *dead_task) ...@@ -63,6 +63,7 @@ static inline void release_thread(struct task_struct *dead_task)
#define init_stack (init_thread_union.stack) #define init_stack (init_thread_union.stack)
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
void default_idle(void); void default_idle(void);
......
...@@ -56,6 +56,7 @@ struct thread_struct { ...@@ -56,6 +56,7 @@ struct thread_struct {
} }
#define cpu_relax() __vmyield() #define cpu_relax() __vmyield()
#define cpu_relax_lowlatency() cpu_relax()
/* /*
* Decides where the kernel will search for a free chunk of vm space during * Decides where the kernel will search for a free chunk of vm space during
......
...@@ -548,6 +548,7 @@ ia64_eoi (void) ...@@ -548,6 +548,7 @@ ia64_eoi (void)
} }
#define cpu_relax() ia64_hint(ia64_hint_pause) #define cpu_relax() ia64_hint(ia64_hint_pause)
#define cpu_relax_lowlatency() cpu_relax()
static inline int static inline int
ia64_get_irr(unsigned int vector) ia64_get_irr(unsigned int vector)
......
...@@ -133,5 +133,6 @@ unsigned long get_wchan(struct task_struct *p); ...@@ -133,5 +133,6 @@ unsigned long get_wchan(struct task_struct *p);
#define KSTK_ESP(tsk) ((tsk)->thread.sp) #define KSTK_ESP(tsk) ((tsk)->thread.sp)
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
#endif /* _ASM_M32R_PROCESSOR_H */ #endif /* _ASM_M32R_PROCESSOR_H */
...@@ -176,5 +176,6 @@ unsigned long get_wchan(struct task_struct *p); ...@@ -176,5 +176,6 @@ unsigned long get_wchan(struct task_struct *p);
#define task_pt_regs(tsk) ((struct pt_regs *) ((tsk)->thread.esp0)) #define task_pt_regs(tsk) ((struct pt_regs *) ((tsk)->thread.esp0))
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
#endif #endif
...@@ -155,6 +155,7 @@ unsigned long get_wchan(struct task_struct *p); ...@@ -155,6 +155,7 @@ unsigned long get_wchan(struct task_struct *p);
#define user_stack_pointer(regs) ((regs)->ctx.AX[0].U0) #define user_stack_pointer(regs) ((regs)->ctx.AX[0].U0)
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
extern void setup_priv(void); extern void setup_priv(void);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
extern const struct seq_operations cpuinfo_op; extern const struct seq_operations cpuinfo_op;
# define cpu_relax() barrier() # define cpu_relax() barrier()
# define cpu_relax_lowlatency() cpu_relax()
#define task_pt_regs(tsk) \ #define task_pt_regs(tsk) \
(((struct pt_regs *)(THREAD_SIZE + task_stack_page(tsk))) - 1) (((struct pt_regs *)(THREAD_SIZE + task_stack_page(tsk))) - 1)
......
...@@ -367,6 +367,7 @@ unsigned long get_wchan(struct task_struct *p); ...@@ -367,6 +367,7 @@ unsigned long get_wchan(struct task_struct *p);
#define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status) #define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
/* /*
* Return_address is a replacement for __builtin_return_address(count) * Return_address is a replacement for __builtin_return_address(count)
......
...@@ -68,7 +68,9 @@ extern struct mn10300_cpuinfo cpu_data[]; ...@@ -68,7 +68,9 @@ extern struct mn10300_cpuinfo cpu_data[];
extern void identify_cpu(struct mn10300_cpuinfo *); extern void identify_cpu(struct mn10300_cpuinfo *);
extern void print_cpu_info(struct mn10300_cpuinfo *); extern void print_cpu_info(struct mn10300_cpuinfo *);
extern void dodgy_tsc(void); extern void dodgy_tsc(void);
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
/* /*
* User space process size: 1.75GB (default). * User space process size: 1.75GB (default).
......
...@@ -101,6 +101,7 @@ extern unsigned long thread_saved_pc(struct task_struct *t); ...@@ -101,6 +101,7 @@ extern unsigned long thread_saved_pc(struct task_struct *t);
#define init_stack (init_thread_union.stack) #define init_stack (init_thread_union.stack)
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __ASM_OPENRISC_PROCESSOR_H */ #endif /* __ASM_OPENRISC_PROCESSOR_H */
...@@ -338,6 +338,7 @@ extern unsigned long get_wchan(struct task_struct *p); ...@@ -338,6 +338,7 @@ extern unsigned long get_wchan(struct task_struct *p);
#define KSTK_ESP(tsk) ((tsk)->thread.regs.gr[30]) #define KSTK_ESP(tsk) ((tsk)->thread.regs.gr[30])
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
/* Used as a macro to identify the combined VIPT/PIPT cached /* Used as a macro to identify the combined VIPT/PIPT cached
* CPUs which require a guarantee of coherency (no inequivalent * CPUs which require a guarantee of coherency (no inequivalent
......
...@@ -400,6 +400,8 @@ static inline unsigned long __pack_fe01(unsigned int fpmode) ...@@ -400,6 +400,8 @@ static inline unsigned long __pack_fe01(unsigned int fpmode)
#define cpu_relax() barrier() #define cpu_relax() barrier()
#endif #endif
#define cpu_relax_lowlatency() cpu_relax()
/* Check that a certain kernel stack pointer is valid in task_struct p */ /* Check that a certain kernel stack pointer is valid in task_struct p */
int validate_sp(unsigned long sp, struct task_struct *p, int validate_sp(unsigned long sp, struct task_struct *p,
unsigned long nbytes); unsigned long nbytes);
......
...@@ -217,7 +217,7 @@ static inline void cpu_relax(void) ...@@ -217,7 +217,7 @@ static inline void cpu_relax(void)
barrier(); barrier();
} }
#define arch_mutex_cpu_relax() barrier() #define cpu_relax_lowlatency() barrier()
static inline void psw_set_key(unsigned int key) static inline void psw_set_key(unsigned int key)
{ {
......
...@@ -24,6 +24,7 @@ extern unsigned long get_wchan(struct task_struct *p); ...@@ -24,6 +24,7 @@ extern unsigned long get_wchan(struct task_struct *p);
#define current_text_addr() ({ __label__ _l; _l: &&_l; }) #define current_text_addr() ({ __label__ _l; _l: &&_l; })
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
#define release_thread(thread) do {} while (0) #define release_thread(thread) do {} while (0)
/* /*
......
...@@ -97,6 +97,7 @@ extern struct sh_cpuinfo cpu_data[]; ...@@ -97,6 +97,7 @@ extern struct sh_cpuinfo cpu_data[];
#define cpu_sleep() __asm__ __volatile__ ("sleep" : : : "memory") #define cpu_sleep() __asm__ __volatile__ ("sleep" : : : "memory")
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
void default_idle(void); void default_idle(void);
void stop_this_cpu(void *); void stop_this_cpu(void *);
......
...@@ -119,6 +119,8 @@ extern struct task_struct *last_task_used_math; ...@@ -119,6 +119,8 @@ extern struct task_struct *last_task_used_math;
int do_mathemu(struct pt_regs *regs, struct task_struct *fpt); int do_mathemu(struct pt_regs *regs, struct task_struct *fpt);
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
extern void (*sparc_idle)(void); extern void (*sparc_idle)(void);
#endif #endif
......
...@@ -216,6 +216,7 @@ unsigned long get_wchan(struct task_struct *task); ...@@ -216,6 +216,7 @@ unsigned long get_wchan(struct task_struct *task);
"nop\n\t" \ "nop\n\t" \
".previous" \ ".previous" \
::: "memory") ::: "memory")
#define cpu_relax_lowlatency() cpu_relax()
/* Prefetch support. This is tuned for UltraSPARC-III and later. /* Prefetch support. This is tuned for UltraSPARC-III and later.
* UltraSPARC-I will treat these as nops, and UltraSPARC-II has * UltraSPARC-I will treat these as nops, and UltraSPARC-II has
......
...@@ -266,6 +266,8 @@ static inline void cpu_relax(void) ...@@ -266,6 +266,8 @@ static inline void cpu_relax(void)
barrier(); barrier();
} }
#define cpu_relax_lowlatency() cpu_relax()
/* Info on this processor (see fs/proc/cpuinfo.c) */ /* Info on this processor (see fs/proc/cpuinfo.c) */
struct seq_operations; struct seq_operations;
extern const struct seq_operations cpuinfo_op; extern const struct seq_operations cpuinfo_op;
......
...@@ -71,6 +71,7 @@ extern void release_thread(struct task_struct *); ...@@ -71,6 +71,7 @@ extern void release_thread(struct task_struct *);
unsigned long get_wchan(struct task_struct *p); unsigned long get_wchan(struct task_struct *p);
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
#define task_pt_regs(p) \ #define task_pt_regs(p) \
((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1) ((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
......
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
#if defined(CONFIG_X86_PPRO_FENCE) #if defined(CONFIG_X86_PPRO_FENCE)
/* /*
* For either of these options x86 doesn't have a strong TSO memory * For this option x86 doesn't have a strong TSO memory
* model and we should fall back to full barriers. * model and we should fall back to full barriers.
*/ */
......
...@@ -696,6 +696,8 @@ static inline void cpu_relax(void) ...@@ -696,6 +696,8 @@ static inline void cpu_relax(void)
rep_nop(); rep_nop();
} }
#define cpu_relax_lowlatency() cpu_relax()
/* Stop speculative execution and prefetching of modified code. */ /* Stop speculative execution and prefetching of modified code. */
static inline void sync_core(void) static inline void sync_core(void)
{ {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <asm-generic/qrwlock_types.h> #include <asm-generic/qrwlock_types.h>
#if !defined(CONFIG_X86_OOSTORE) && !defined(CONFIG_X86_PPRO_FENCE) #ifndef CONFIG_X86_PPRO_FENCE
#define queue_write_unlock queue_write_unlock #define queue_write_unlock queue_write_unlock
static inline void queue_write_unlock(struct qrwlock *lock) static inline void queue_write_unlock(struct qrwlock *lock)
{ {
......
...@@ -25,7 +25,8 @@ static inline void rep_nop(void) ...@@ -25,7 +25,8 @@ static inline void rep_nop(void)
__asm__ __volatile__("rep;nop": : :"memory"); __asm__ __volatile__("rep;nop": : :"memory");
} }
#define cpu_relax() rep_nop() #define cpu_relax() rep_nop()
#define cpu_relax_lowlatency() cpu_relax()
#include <asm/processor-generic.h> #include <asm/processor-generic.h>
......
...@@ -182,6 +182,7 @@ extern unsigned long get_wchan(struct task_struct *p); ...@@ -182,6 +182,7 @@ extern unsigned long get_wchan(struct task_struct *p);
#define KSTK_ESP(tsk) (task_pt_regs(tsk)->areg[1]) #define KSTK_ESP(tsk) (task_pt_regs(tsk)->areg[1])
#define cpu_relax() barrier() #define cpu_relax() barrier()
#define cpu_relax_lowlatency() cpu_relax()
/* Special register access. */ /* Special register access. */
......
...@@ -176,8 +176,4 @@ extern void mutex_unlock(struct mutex *lock); ...@@ -176,8 +176,4 @@ extern void mutex_unlock(struct mutex *lock);
extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock); extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
#ifndef arch_mutex_cpu_relax
# define arch_mutex_cpu_relax() cpu_relax()
#endif
#endif /* __LINUX_MUTEX_H */ #endif /* __LINUX_MUTEX_H */
...@@ -90,11 +90,9 @@ extern void __rt_mutex_init(struct rt_mutex *lock, const char *name); ...@@ -90,11 +90,9 @@ extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
extern void rt_mutex_destroy(struct rt_mutex *lock); extern void rt_mutex_destroy(struct rt_mutex *lock);
extern void rt_mutex_lock(struct rt_mutex *lock); extern void rt_mutex_lock(struct rt_mutex *lock);
extern int rt_mutex_lock_interruptible(struct rt_mutex *lock, extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
int detect_deadlock);
extern int rt_mutex_timed_lock(struct rt_mutex *lock, extern int rt_mutex_timed_lock(struct rt_mutex *lock,
struct hrtimer_sleeper *timeout, struct hrtimer_sleeper *timeout);
int detect_deadlock);
extern int rt_mutex_trylock(struct rt_mutex *lock); extern int rt_mutex_trylock(struct rt_mutex *lock);
......
...@@ -164,8 +164,6 @@ static inline unsigned read_seqcount_begin(const seqcount_t *s) ...@@ -164,8 +164,6 @@ static inline unsigned read_seqcount_begin(const seqcount_t *s)
static inline unsigned raw_seqcount_begin(const seqcount_t *s) static inline unsigned raw_seqcount_begin(const seqcount_t *s)
{ {
unsigned ret = ACCESS_ONCE(s->sequence); unsigned ret = ACCESS_ONCE(s->sequence);
seqcount_lockdep_reader_access(s);
smp_rmb(); smp_rmb();
return ret & ~1; return ret & ~1;
} }
......
This diff is collapsed.
...@@ -384,7 +384,9 @@ static void print_lockdep_off(const char *bug_msg) ...@@ -384,7 +384,9 @@ static void print_lockdep_off(const char *bug_msg)
{ {
printk(KERN_DEBUG "%s\n", bug_msg); printk(KERN_DEBUG "%s\n", bug_msg);
printk(KERN_DEBUG "turning off the locking correctness validator.\n"); printk(KERN_DEBUG "turning off the locking correctness validator.\n");
#ifdef CONFIG_LOCK_STAT
printk(KERN_DEBUG "Please attach the output of /proc/lock_stat to the bug report\n"); printk(KERN_DEBUG "Please attach the output of /proc/lock_stat to the bug report\n");
#endif
} }
static int save_trace(struct stack_trace *trace) static int save_trace(struct stack_trace *trace)
......
#include <linux/percpu.h> #include <linux/percpu.h>
#include <linux/mutex.h>
#include <linux/sched.h> #include <linux/sched.h>
#include "mcs_spinlock.h" #include "mcs_spinlock.h"
...@@ -79,7 +77,7 @@ osq_wait_next(struct optimistic_spin_queue *lock, ...@@ -79,7 +77,7 @@ osq_wait_next(struct optimistic_spin_queue *lock,
break; break;
} }
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
} }
return next; return next;
...@@ -120,7 +118,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) ...@@ -120,7 +118,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
if (need_resched()) if (need_resched())
goto unqueue; goto unqueue;
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
} }
return true; return true;
...@@ -146,7 +144,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) ...@@ -146,7 +144,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
if (smp_load_acquire(&node->locked)) if (smp_load_acquire(&node->locked))
return true; return true;
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
/* /*
* Or we race against a concurrent unqueue()'s step-B, in which * Or we race against a concurrent unqueue()'s step-B, in which
......
...@@ -27,7 +27,7 @@ struct mcs_spinlock { ...@@ -27,7 +27,7 @@ struct mcs_spinlock {
#define arch_mcs_spin_lock_contended(l) \ #define arch_mcs_spin_lock_contended(l) \
do { \ do { \
while (!(smp_load_acquire(l))) \ while (!(smp_load_acquire(l))) \
arch_mutex_cpu_relax(); \ cpu_relax_lowlatency(); \
} while (0) } while (0)
#endif #endif
...@@ -104,7 +104,7 @@ void mcs_spin_unlock(struct mcs_spinlock **lock, struct mcs_spinlock *node) ...@@ -104,7 +104,7 @@ void mcs_spin_unlock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
return; return;
/* Wait until the next pointer is set */ /* Wait until the next pointer is set */
while (!(next = ACCESS_ONCE(node->next))) while (!(next = ACCESS_ONCE(node->next)))
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
} }
/* Pass lock to next waiter. */ /* Pass lock to next waiter. */
......
...@@ -46,12 +46,6 @@ ...@@ -46,12 +46,6 @@
# include <asm/mutex.h> # include <asm/mutex.h>
#endif #endif
/*
* A negative mutex count indicates that waiters are sleeping waiting for the
* mutex.
*/
#define MUTEX_SHOW_NO_WAITER(mutex) (atomic_read(&(mutex)->count) >= 0)
void void
__mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key) __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
{ {
...@@ -152,7 +146,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner) ...@@ -152,7 +146,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
if (need_resched()) if (need_resched())
break; break;
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
} }
rcu_read_unlock(); rcu_read_unlock();
...@@ -388,12 +382,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, ...@@ -388,12 +382,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
/* /*
* Optimistic spinning. * Optimistic spinning.
* *
* We try to spin for acquisition when we find that there are no * We try to spin for acquisition when we find that the lock owner
* pending waiters and the lock owner is currently running on a * is currently running on a (different) CPU and while we don't
* (different) CPU. * need to reschedule. The rationale is that if the lock owner is
* * running, it is likely to release the lock soon.
* The rationale is that if the lock owner is running, it is likely to
* release the lock soon.
* *
* Since this needs the lock owner, and this mutex implementation * Since this needs the lock owner, and this mutex implementation
* doesn't track the owner atomically in the lock field, we need to * doesn't track the owner atomically in the lock field, we need to
...@@ -440,7 +432,8 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, ...@@ -440,7 +432,8 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
if (owner && !mutex_spin_on_owner(lock, owner)) if (owner && !mutex_spin_on_owner(lock, owner))
break; break;
if ((atomic_read(&lock->count) == 1) && /* Try to acquire the mutex if it is unlocked. */
if (!mutex_is_locked(lock) &&
(atomic_cmpxchg(&lock->count, 1, 0) == 1)) { (atomic_cmpxchg(&lock->count, 1, 0) == 1)) {
lock_acquired(&lock->dep_map, ip); lock_acquired(&lock->dep_map, ip);
if (use_ww_ctx) { if (use_ww_ctx) {
...@@ -471,7 +464,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, ...@@ -471,7 +464,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
* memory barriers as we'll eventually observe the right * memory barriers as we'll eventually observe the right
* values at the cost of a few extra spins. * values at the cost of a few extra spins.
*/ */
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
} }
osq_unlock(&lock->osq); osq_unlock(&lock->osq);
slowpath: slowpath:
...@@ -485,8 +478,11 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, ...@@ -485,8 +478,11 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
#endif #endif
spin_lock_mutex(&lock->wait_lock, flags); spin_lock_mutex(&lock->wait_lock, flags);
/* once more, can we acquire the lock? */ /*
if (MUTEX_SHOW_NO_WAITER(lock) && (atomic_xchg(&lock->count, 0) == 1)) * Once more, try to acquire the lock. Only try-lock the mutex if
* it is unlocked to reduce unnecessary xchg() operations.
*/
if (!mutex_is_locked(lock) && (atomic_xchg(&lock->count, 0) == 1))
goto skip_wait; goto skip_wait;
debug_mutex_lock_common(lock, &waiter); debug_mutex_lock_common(lock, &waiter);
...@@ -506,9 +502,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, ...@@ -506,9 +502,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
* it's unlocked. Later on, if we sleep, this is the * it's unlocked. Later on, if we sleep, this is the
* operation that gives us the lock. We xchg it to -1, so * operation that gives us the lock. We xchg it to -1, so
* that when we release the lock, we properly wake up the * that when we release the lock, we properly wake up the
* other waiters: * other waiters. We only attempt the xchg if the count is
* non-negative in order to avoid unnecessary xchg operations:
*/ */
if (MUTEX_SHOW_NO_WAITER(lock) && if (atomic_read(&lock->count) >= 0 &&
(atomic_xchg(&lock->count, -1) == 1)) (atomic_xchg(&lock->count, -1) == 1))
break; break;
...@@ -823,6 +820,10 @@ static inline int __mutex_trylock_slowpath(atomic_t *lock_count) ...@@ -823,6 +820,10 @@ static inline int __mutex_trylock_slowpath(atomic_t *lock_count)
unsigned long flags; unsigned long flags;
int prev; int prev;
/* No need to trylock if the mutex is locked. */
if (mutex_is_locked(lock))
return 0;
spin_lock_mutex(&lock->wait_lock, flags); spin_lock_mutex(&lock->wait_lock, flags);
prev = atomic_xchg(&lock->count, -1); prev = atomic_xchg(&lock->count, -1);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/percpu.h> #include <linux/percpu.h>
#include <linux/hardirq.h> #include <linux/hardirq.h>
#include <linux/mutex.h>
#include <asm/qrwlock.h> #include <asm/qrwlock.h>
/** /**
...@@ -35,7 +34,7 @@ static __always_inline void ...@@ -35,7 +34,7 @@ static __always_inline void
rspin_until_writer_unlock(struct qrwlock *lock, u32 cnts) rspin_until_writer_unlock(struct qrwlock *lock, u32 cnts)
{ {
while ((cnts & _QW_WMASK) == _QW_LOCKED) { while ((cnts & _QW_WMASK) == _QW_LOCKED) {
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
cnts = smp_load_acquire((u32 *)&lock->cnts); cnts = smp_load_acquire((u32 *)&lock->cnts);
} }
} }
...@@ -75,7 +74,7 @@ void queue_read_lock_slowpath(struct qrwlock *lock) ...@@ -75,7 +74,7 @@ void queue_read_lock_slowpath(struct qrwlock *lock)
* to make sure that the write lock isn't taken. * to make sure that the write lock isn't taken.
*/ */
while (atomic_read(&lock->cnts) & _QW_WMASK) while (atomic_read(&lock->cnts) & _QW_WMASK)
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
cnts = atomic_add_return(_QR_BIAS, &lock->cnts) - _QR_BIAS; cnts = atomic_add_return(_QR_BIAS, &lock->cnts) - _QR_BIAS;
rspin_until_writer_unlock(lock, cnts); rspin_until_writer_unlock(lock, cnts);
...@@ -114,7 +113,7 @@ void queue_write_lock_slowpath(struct qrwlock *lock) ...@@ -114,7 +113,7 @@ void queue_write_lock_slowpath(struct qrwlock *lock)
cnts | _QW_WAITING) == cnts)) cnts | _QW_WAITING) == cnts))
break; break;
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
} }
/* When no more readers, set the locked flag */ /* When no more readers, set the locked flag */
...@@ -125,7 +124,7 @@ void queue_write_lock_slowpath(struct qrwlock *lock) ...@@ -125,7 +124,7 @@ void queue_write_lock_slowpath(struct qrwlock *lock)
_QW_LOCKED) == _QW_WAITING)) _QW_LOCKED) == _QW_WAITING))
break; break;
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
} }
unlock: unlock:
arch_spin_unlock(&lock->lock); arch_spin_unlock(&lock->lock);
......
...@@ -66,12 +66,13 @@ void rt_mutex_debug_task_free(struct task_struct *task) ...@@ -66,12 +66,13 @@ void rt_mutex_debug_task_free(struct task_struct *task)
* the deadlock. We print when we return. act_waiter can be NULL in * the deadlock. We print when we return. act_waiter can be NULL in
* case of a remove waiter operation. * case of a remove waiter operation.
*/ */
void debug_rt_mutex_deadlock(int detect, struct rt_mutex_waiter *act_waiter, void debug_rt_mutex_deadlock(enum rtmutex_chainwalk chwalk,
struct rt_mutex_waiter *act_waiter,
struct rt_mutex *lock) struct rt_mutex *lock)
{ {
struct task_struct *task; struct task_struct *task;
if (!debug_locks || detect || !act_waiter) if (!debug_locks || chwalk == RT_MUTEX_FULL_CHAINWALK || !act_waiter)
return; return;
task = rt_mutex_owner(act_waiter->lock); task = rt_mutex_owner(act_waiter->lock);
......
...@@ -20,14 +20,15 @@ extern void debug_rt_mutex_unlock(struct rt_mutex *lock); ...@@ -20,14 +20,15 @@ extern void debug_rt_mutex_unlock(struct rt_mutex *lock);
extern void debug_rt_mutex_proxy_lock(struct rt_mutex *lock, extern void debug_rt_mutex_proxy_lock(struct rt_mutex *lock,
struct task_struct *powner); struct task_struct *powner);
extern void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock); extern void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock);
extern void debug_rt_mutex_deadlock(int detect, struct rt_mutex_waiter *waiter, extern void debug_rt_mutex_deadlock(enum rtmutex_chainwalk chwalk,
struct rt_mutex_waiter *waiter,
struct rt_mutex *lock); struct rt_mutex *lock);
extern void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter); extern void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter);
# define debug_rt_mutex_reset_waiter(w) \ # define debug_rt_mutex_reset_waiter(w) \
do { (w)->deadlock_lock = NULL; } while (0) do { (w)->deadlock_lock = NULL; } while (0)
static inline int debug_rt_mutex_detect_deadlock(struct rt_mutex_waiter *waiter, static inline bool debug_rt_mutex_detect_deadlock(struct rt_mutex_waiter *waiter,
int detect) enum rtmutex_chainwalk walk)
{ {
return (waiter != NULL); return (waiter != NULL);
} }
......
This diff is collapsed.
...@@ -22,10 +22,15 @@ ...@@ -22,10 +22,15 @@
#define debug_rt_mutex_init(m, n) do { } while (0) #define debug_rt_mutex_init(m, n) do { } while (0)
#define debug_rt_mutex_deadlock(d, a ,l) do { } while (0) #define debug_rt_mutex_deadlock(d, a ,l) do { } while (0)
#define debug_rt_mutex_print_deadlock(w) do { } while (0) #define debug_rt_mutex_print_deadlock(w) do { } while (0)
#define debug_rt_mutex_detect_deadlock(w,d) (d)
#define debug_rt_mutex_reset_waiter(w) do { } while (0) #define debug_rt_mutex_reset_waiter(w) do { } while (0)
static inline void rt_mutex_print_deadlock(struct rt_mutex_waiter *w) static inline void rt_mutex_print_deadlock(struct rt_mutex_waiter *w)
{ {
WARN(1, "rtmutex deadlock detected\n"); WARN(1, "rtmutex deadlock detected\n");
} }
static inline bool debug_rt_mutex_detect_deadlock(struct rt_mutex_waiter *w,
enum rtmutex_chainwalk walk)
{
return walk == RT_MUTEX_FULL_CHAINWALK;
}
...@@ -101,6 +101,21 @@ static inline struct task_struct *rt_mutex_owner(struct rt_mutex *lock) ...@@ -101,6 +101,21 @@ static inline struct task_struct *rt_mutex_owner(struct rt_mutex *lock)
((unsigned long)lock->owner & ~RT_MUTEX_OWNER_MASKALL); ((unsigned long)lock->owner & ~RT_MUTEX_OWNER_MASKALL);
} }
/*
* Constants for rt mutex functions which have a selectable deadlock
* detection.
*
* RT_MUTEX_MIN_CHAINWALK: Stops the lock chain walk when there are
* no further PI adjustments to be made.
*
* RT_MUTEX_FULL_CHAINWALK: Invoke deadlock detection with a full
* walk of the lock chain.
*/
enum rtmutex_chainwalk {
RT_MUTEX_MIN_CHAINWALK,
RT_MUTEX_FULL_CHAINWALK,
};
/* /*
* PI-futex support (proxy locking functions, etc.): * PI-futex support (proxy locking functions, etc.):
*/ */
...@@ -111,12 +126,11 @@ extern void rt_mutex_proxy_unlock(struct rt_mutex *lock, ...@@ -111,12 +126,11 @@ extern void rt_mutex_proxy_unlock(struct rt_mutex *lock,
struct task_struct *proxy_owner); struct task_struct *proxy_owner);
extern int rt_mutex_start_proxy_lock(struct rt_mutex *lock, extern int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
struct rt_mutex_waiter *waiter, struct rt_mutex_waiter *waiter,
struct task_struct *task, struct task_struct *task);
int detect_deadlock);
extern int rt_mutex_finish_proxy_lock(struct rt_mutex *lock, extern int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
struct hrtimer_sleeper *to, struct hrtimer_sleeper *to,
struct rt_mutex_waiter *waiter, struct rt_mutex_waiter *waiter);
int detect_deadlock); extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
#ifdef CONFIG_DEBUG_RT_MUTEXES #ifdef CONFIG_DEBUG_RT_MUTEXES
# include "rtmutex-debug.h" # include "rtmutex-debug.h"
......
...@@ -329,7 +329,7 @@ bool rwsem_spin_on_owner(struct rw_semaphore *sem, struct task_struct *owner) ...@@ -329,7 +329,7 @@ bool rwsem_spin_on_owner(struct rw_semaphore *sem, struct task_struct *owner)
if (need_resched()) if (need_resched())
break; break;
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
} }
rcu_read_unlock(); rcu_read_unlock();
...@@ -381,7 +381,7 @@ static bool rwsem_optimistic_spin(struct rw_semaphore *sem) ...@@ -381,7 +381,7 @@ static bool rwsem_optimistic_spin(struct rw_semaphore *sem)
* memory barriers as we'll eventually observe the right * memory barriers as we'll eventually observe the right
* values at the cost of a few extra spins. * values at the cost of a few extra spins.
*/ */
arch_mutex_cpu_relax(); cpu_relax_lowlatency();
} }
osq_unlock(&sem->osq); osq_unlock(&sem->osq);
done: done:
......
...@@ -835,7 +835,7 @@ config DEBUG_RT_MUTEXES ...@@ -835,7 +835,7 @@ config DEBUG_RT_MUTEXES
config RT_MUTEX_TESTER config RT_MUTEX_TESTER
bool "Built-in scriptable tester for rt-mutexes" bool "Built-in scriptable tester for rt-mutexes"
depends on DEBUG_KERNEL && RT_MUTEXES depends on DEBUG_KERNEL && RT_MUTEXES && BROKEN
help help
This option enables a rt-mutex tester. This option enables a rt-mutex tester.
......
#include <linux/export.h> #include <linux/export.h>
#include <linux/lockref.h> #include <linux/lockref.h>
#include <linux/mutex.h>
#if USE_CMPXCHG_LOCKREF #if USE_CMPXCHG_LOCKREF
...@@ -29,7 +28,7 @@ ...@@ -29,7 +28,7 @@
if (likely(old.lock_count == prev.lock_count)) { \ if (likely(old.lock_count == prev.lock_count)) { \
SUCCESS; \ SUCCESS; \
} \ } \
arch_mutex_cpu_relax(); \ cpu_relax_lowlatency(); \
} \ } \
} while (0) } while (0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment