Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933894AbbDIJCG (ORCPT ); Thu, 9 Apr 2015 05:02:06 -0400 Received: from terminus.zytor.com ([198.137.202.10]:51738 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932465AbbDIJBj (ORCPT ); Thu, 9 Apr 2015 05:01:39 -0400 Date: Thu, 9 Apr 2015 02:00:38 -0700 From: tip-bot for Jason Low Message-ID: Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, tim.c.chen@linux.intel.com, tglx@linutronix.de, akpm@linux-foundation.org, aswin@hp.com, peterz@infradead.org, torvalds@linux-foundation.org, paulmck@linux.vnet.ibm.com, dave@stgolabs.net, hpa@zytor.com, jason.low2@hp.com Reply-To: peterz@infradead.org, torvalds@linux-foundation.org, jason.low2@hp.com, hpa@zytor.com, dave@stgolabs.net, paulmck@linux.vnet.ibm.com, tglx@linutronix.de, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, mingo@kernel.org, tim.c.chen@linux.intel.com, aswin@hp.com In-Reply-To: <1428521960-5268-2-git-send-email-jason.low2@hp.com> References: <1428521960-5268-2-git-send-email-jason.low2@hp.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/mutex: Further simplify mutex_spin_on_owner() Git-Commit-ID: 01ac33c1f907b366dcc50551316b372f1519cca9 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2674 Lines: 71 Commit-ID: 01ac33c1f907b366dcc50551316b372f1519cca9 Gitweb: http://git.kernel.org/tip/01ac33c1f907b366dcc50551316b372f1519cca9 Author: Jason Low AuthorDate: Wed, 8 Apr 2015 12:39:19 -0700 Committer: Ingo Molnar CommitDate: Thu, 9 Apr 2015 08:10:23 +0200 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 Cc: Andrew Morton Cc: Aswin Chandramouleeswaran Cc: Davidlohr Bueso Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Tim Chen 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 --- kernel/locking/mutex.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 16b2d3c..4cccea6 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -224,20 +224,14 @@ ww_mutex_set_context_slowpath(struct ww_mutex *lock, static noinline bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner) { - bool ret; + bool ret = true; rcu_read_lock(); - while (true) { - /* Return success when the lock owner changed */ - if (lock->owner != owner) { - ret = true; - break; - } - + while (lock->owner == owner) { /* * Ensure we emit the owner->on_cpu, dereference _after_ - * checking lock->owner still matches owner, if that fails, - * owner might point to free()d memory, if it still matches, + * checking lock->owner still matches owner. If that fails, + * owner might point to freed memory. If it still matches, * the rcu_read_lock() ensures the memory stays valid. */ barrier(); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/