Commit 01ac33c1 authored by Jason Low's avatar Jason Low Committed by Ingo Molnar

locking/mutex: Further simplify mutex_spin_on_owner()

Similar to what Linus suggested for rwsem_spin_on_owner(), in
mutex_spin_on_owner() instead of having while (true) and
breaking out of the spin loop on lock->owner != owner, we can
have the loop directly check for while (lock->owner == owner) to
improve the readability of the code.

It also shrinks the code a bit:

   text    data     bss     dec     hex filename
   3721       0       0    3721     e89 mutex.o.before
   3705       0       0    3705     e79 mutex.o.after
Signed-off-by: default avatarJason Low <jason.low2@hp.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Aswin Chandramouleeswaran <aswin@hp.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Link: http://lkml.kernel.org/r/1428521960-5268-2-git-send-email-jason.low2@hp.com
[ Added code generation info. ]
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 7bd3e239
...@@ -224,20 +224,14 @@ ww_mutex_set_context_slowpath(struct ww_mutex *lock, ...@@ -224,20 +224,14 @@ ww_mutex_set_context_slowpath(struct ww_mutex *lock,
static noinline static noinline
bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner) bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
{ {
bool ret; bool ret = true;
rcu_read_lock(); rcu_read_lock();
while (true) { while (lock->owner == owner) {
/* Return success when the lock owner changed */
if (lock->owner != owner) {
ret = true;
break;
}
/* /*
* Ensure we emit the owner->on_cpu, dereference _after_ * Ensure we emit the owner->on_cpu, dereference _after_
* checking lock->owner still matches owner, if that fails, * checking lock->owner still matches owner. If that fails,
* owner might point to free()d memory, if it still matches, * owner might point to freed memory. If it still matches,
* the rcu_read_lock() ensures the memory stays valid. * the rcu_read_lock() ensures the memory stays valid.
*/ */
barrier(); barrier();
......
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