mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-20 13:41:30 +00:00
rtmutex: Simplify rtmutex_slowtrylock()
Oleg noticed that rtmutex_slowtrylock() has a pointless check for rt_mutex_owner(lock) != current. To avoid calling try_to_take_rtmutex() we really want to check whether the lock has an owner at all or whether the trylock failed because the owner is NULL, but the RT_MUTEX_HAS_WAITERS bit is set. This covers the lock is owned by caller situation as well. We can actually do this check lockless. trylock is taking a chance whether we take lock->wait_lock to do the check or not. Add comments to the function while at it. Reported-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Steven Rostedt <rostedt@goodmis.org> Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com>
This commit is contained in:
parent
fddeca638e
commit
88f2b4c15e
1 changed files with 20 additions and 11 deletions
|
@ -960,22 +960,31 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
|
||||||
/*
|
/*
|
||||||
* Slow path try-lock function:
|
* Slow path try-lock function:
|
||||||
*/
|
*/
|
||||||
static inline int
|
static inline int rt_mutex_slowtrylock(struct rt_mutex *lock)
|
||||||
rt_mutex_slowtrylock(struct rt_mutex *lock)
|
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the lock already has an owner we fail to get the lock.
|
||||||
|
* This can be done without taking the @lock->wait_lock as
|
||||||
|
* it is only being read, and this is a trylock anyway.
|
||||||
|
*/
|
||||||
|
if (rt_mutex_owner(lock))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The mutex has currently no owner. Lock the wait lock and
|
||||||
|
* try to acquire the lock.
|
||||||
|
*/
|
||||||
raw_spin_lock(&lock->wait_lock);
|
raw_spin_lock(&lock->wait_lock);
|
||||||
|
|
||||||
if (likely(rt_mutex_owner(lock) != current)) {
|
ret = try_to_take_rt_mutex(lock, current, NULL);
|
||||||
|
|
||||||
ret = try_to_take_rt_mutex(lock, current, NULL);
|
/*
|
||||||
/*
|
* try_to_take_rt_mutex() sets the lock waiters bit
|
||||||
* try_to_take_rt_mutex() sets the lock waiters
|
* unconditionally. Clean this up.
|
||||||
* bit unconditionally. Clean this up.
|
*/
|
||||||
*/
|
fixup_rt_mutex_waiters(lock);
|
||||||
fixup_rt_mutex_waiters(lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
raw_spin_unlock(&lock->wait_lock);
|
raw_spin_unlock(&lock->wait_lock);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue