diff options
author | Jason Low <jason.low2@hp.com> | 2015-04-08 15:39:19 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2015-04-09 02:10:23 -0400 |
commit | 01ac33c1f907b366dcc50551316b372f1519cca9 (patch) | |
tree | 3acec01dacf54ca648dda938b21fe5a0626f9e5b /kernel/locking/mutex.c | |
parent | 7bd3e239d6c6d1cad276e8f130b386df4234dcd7 (diff) |
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: Jason 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: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/locking/mutex.c')
-rw-r--r-- | kernel/locking/mutex.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 16b2d3cc88b0..4cccea6b8934 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c | |||
@@ -224,20 +224,14 @@ ww_mutex_set_context_slowpath(struct ww_mutex *lock, | |||
224 | static noinline | 224 | static noinline |
225 | bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner) | 225 | bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner) |
226 | { | 226 | { |
227 | bool ret; | 227 | bool ret = true; |
228 | 228 | ||
229 | rcu_read_lock(); | 229 | rcu_read_lock(); |
230 | while (true) { | 230 | while (lock->owner == owner) { |
231 | /* Return success when the lock owner changed */ | ||
232 | if (lock->owner != owner) { | ||
233 | ret = true; | ||
234 | break; | ||
235 | } | ||
236 | |||
237 | /* | 231 | /* |
238 | * Ensure we emit the owner->on_cpu, dereference _after_ | 232 | * Ensure we emit the owner->on_cpu, dereference _after_ |
239 | * checking lock->owner still matches owner, if that fails, | 233 | * checking lock->owner still matches owner. If that fails, |
240 | * owner might point to free()d memory, if it still matches, | 234 | * owner might point to freed memory. If it still matches, |
241 | * the rcu_read_lock() ensures the memory stays valid. | 235 | * the rcu_read_lock() ensures the memory stays valid. |
242 | */ | 236 | */ |
243 | barrier(); | 237 | barrier(); |