Commit c051b21f authored by Thomas Gleixner's avatar Thomas Gleixner

rtmutex: Confine deadlock logic to futex

The deadlock logic is only required for futexes.

Remove the extra arguments for the public functions and also for the
futex specific ones which get always called with deadlock detection
enabled.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 1ca7b860
...@@ -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);
......
...@@ -1718,7 +1718,7 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags, ...@@ -1718,7 +1718,7 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
this->pi_state = pi_state; this->pi_state = pi_state;
ret = rt_mutex_start_proxy_lock(&pi_state->pi_mutex, ret = rt_mutex_start_proxy_lock(&pi_state->pi_mutex,
this->rt_waiter, this->rt_waiter,
this->task, 1); this->task);
if (ret == 1) { if (ret == 1) {
/* We got the lock. */ /* We got the lock. */
requeue_pi_wake_futex(this, &key2, hb2); requeue_pi_wake_futex(this, &key2, hb2);
...@@ -2337,9 +2337,9 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, int detect, ...@@ -2337,9 +2337,9 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, int detect,
/* /*
* Block on the PI mutex: * Block on the PI mutex:
*/ */
if (!trylock) if (!trylock) {
ret = rt_mutex_timed_lock(&q.pi_state->pi_mutex, to, 1); ret = rt_mutex_timed_futex_lock(&q.pi_state->pi_mutex, to);
else { } else {
ret = rt_mutex_trylock(&q.pi_state->pi_mutex); ret = rt_mutex_trylock(&q.pi_state->pi_mutex);
/* Fixup the trylock return value: */ /* Fixup the trylock return value: */
ret = ret ? 0 : -EWOULDBLOCK; ret = ret ? 0 : -EWOULDBLOCK;
...@@ -2669,7 +2669,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, ...@@ -2669,7 +2669,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
*/ */
WARN_ON(!q.pi_state); WARN_ON(!q.pi_state);
pi_mutex = &q.pi_state->pi_mutex; pi_mutex = &q.pi_state->pi_mutex;
ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter, 1); ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
debug_rt_mutex_free_waiter(&rt_waiter); debug_rt_mutex_free_waiter(&rt_waiter);
spin_lock(q.lock_ptr); spin_lock(q.lock_ptr);
......
...@@ -1228,16 +1228,15 @@ rt_mutex_slowunlock(struct rt_mutex *lock) ...@@ -1228,16 +1228,15 @@ rt_mutex_slowunlock(struct rt_mutex *lock)
*/ */
static inline int static inline int
rt_mutex_fastlock(struct rt_mutex *lock, int state, rt_mutex_fastlock(struct rt_mutex *lock, int state,
int detect_deadlock,
int (*slowfn)(struct rt_mutex *lock, int state, int (*slowfn)(struct rt_mutex *lock, int state,
struct hrtimer_sleeper *timeout, struct hrtimer_sleeper *timeout,
int detect_deadlock)) int detect_deadlock))
{ {
if (!detect_deadlock && likely(rt_mutex_cmpxchg(lock, NULL, current))) { if (likely(rt_mutex_cmpxchg(lock, NULL, current))) {
rt_mutex_deadlock_account_lock(lock, current); rt_mutex_deadlock_account_lock(lock, current);
return 0; return 0;
} else } else
return slowfn(lock, state, NULL, detect_deadlock); return slowfn(lock, state, NULL, 0);
} }
static inline int static inline int
...@@ -1284,7 +1283,7 @@ void __sched rt_mutex_lock(struct rt_mutex *lock) ...@@ -1284,7 +1283,7 @@ void __sched rt_mutex_lock(struct rt_mutex *lock)
{ {
might_sleep(); might_sleep();
rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, 0, rt_mutex_slowlock); rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
} }
EXPORT_SYMBOL_GPL(rt_mutex_lock); EXPORT_SYMBOL_GPL(rt_mutex_lock);
...@@ -1292,23 +1291,31 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock); ...@@ -1292,23 +1291,31 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock);
* rt_mutex_lock_interruptible - lock a rt_mutex interruptible * rt_mutex_lock_interruptible - lock a rt_mutex interruptible
* *
* @lock: the rt_mutex to be locked * @lock: the rt_mutex to be locked
* @detect_deadlock: deadlock detection on/off
* *
* Returns: * Returns:
* 0 on success * 0 on success
* -EINTR when interrupted by a signal * -EINTR when interrupted by a signal
* -EDEADLK when the lock would deadlock (when deadlock detection is on)
*/ */
int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock, int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock)
int detect_deadlock)
{ {
might_sleep(); might_sleep();
return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
detect_deadlock, rt_mutex_slowlock);
} }
EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible); EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
/*
* Futex variant with full deadlock detection.
*/
int rt_mutex_timed_futex_lock(struct rt_mutex *lock,
struct hrtimer_sleeper *timeout)
{
might_sleep();
return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout, 1,
rt_mutex_slowlock);
}
/** /**
* rt_mutex_timed_lock - lock a rt_mutex interruptible * rt_mutex_timed_lock - lock a rt_mutex interruptible
* the timeout structure is provided * the timeout structure is provided
...@@ -1316,22 +1323,19 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible); ...@@ -1316,22 +1323,19 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
* *
* @lock: the rt_mutex to be locked * @lock: the rt_mutex to be locked
* @timeout: timeout structure or NULL (no timeout) * @timeout: timeout structure or NULL (no timeout)
* @detect_deadlock: deadlock detection on/off
* *
* Returns: * Returns:
* 0 on success * 0 on success
* -EINTR when interrupted by a signal * -EINTR when interrupted by a signal
* -ETIMEDOUT when the timeout expired * -ETIMEDOUT when the timeout expired
* -EDEADLK when the lock would deadlock (when deadlock detection is on)
*/ */
int int
rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout, rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout)
int detect_deadlock)
{ {
might_sleep(); might_sleep();
return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout, return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout, 0,
detect_deadlock, rt_mutex_slowlock); rt_mutex_slowlock);
} }
EXPORT_SYMBOL_GPL(rt_mutex_timed_lock); EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
...@@ -1437,7 +1441,6 @@ void rt_mutex_proxy_unlock(struct rt_mutex *lock, ...@@ -1437,7 +1441,6 @@ void rt_mutex_proxy_unlock(struct rt_mutex *lock,
* @lock: the rt_mutex to take * @lock: the rt_mutex to take
* @waiter: the pre-initialized rt_mutex_waiter * @waiter: the pre-initialized rt_mutex_waiter
* @task: the task to prepare * @task: the task to prepare
* @detect_deadlock: perform deadlock detection (1) or not (0)
* *
* Returns: * Returns:
* 0 - task blocked on lock * 0 - task blocked on lock
...@@ -1448,7 +1451,7 @@ void rt_mutex_proxy_unlock(struct rt_mutex *lock, ...@@ -1448,7 +1451,7 @@ void rt_mutex_proxy_unlock(struct rt_mutex *lock,
*/ */
int rt_mutex_start_proxy_lock(struct rt_mutex *lock, int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
struct rt_mutex_waiter *waiter, struct rt_mutex_waiter *waiter,
struct task_struct *task, int detect_deadlock) struct task_struct *task)
{ {
int ret; int ret;
...@@ -1508,20 +1511,18 @@ struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock) ...@@ -1508,20 +1511,18 @@ struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock)
* @to: the timeout, null if none. hrtimer should already have * @to: the timeout, null if none. hrtimer should already have
* been started. * been started.
* @waiter: the pre-initialized rt_mutex_waiter * @waiter: the pre-initialized rt_mutex_waiter
* @detect_deadlock: perform deadlock detection (1) or not (0)
* *
* Complete the lock acquisition started our behalf by another thread. * Complete the lock acquisition started our behalf by another thread.
* *
* Returns: * Returns:
* 0 - success * 0 - success
* <0 - error, one of -EINTR, -ETIMEDOUT, or -EDEADLK * <0 - error, one of -EINTR, -ETIMEDOUT
* *
* Special API call for PI-futex requeue support * Special API call for PI-futex requeue support
*/ */
int rt_mutex_finish_proxy_lock(struct rt_mutex *lock, 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)
{ {
int ret; int ret;
......
...@@ -111,12 +111,11 @@ extern void rt_mutex_proxy_unlock(struct rt_mutex *lock, ...@@ -111,12 +111,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"
......
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