From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org,
linux-rt-users <linux-rt-users@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Carsten Emde <C.Emde@osadl.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
John Kacur <jkacur@redhat.com>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Oleg Nesterov <oleg@redhat.com>,
Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH RT 03/31] rtmutex: Simplify rtmutex_slowtrylock()
Date: Fri, 13 Mar 2015 11:14:57 -0400 [thread overview]
Message-ID: <20150313151515.365546754@goodmis.org> (raw)
In-Reply-To: <20150313151454.809081378@goodmis.org>
[-- Attachment #1: 0003-rtmutex-Simplify-rtmutex_slowtrylock.patch --]
[-- Type: text/plain, Size: 2456 bytes --]
3.10.70-rt75-rc1 stable review patch.
If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <tglx@linutronix.de>
upstream-commit: 88f2b4c15e561bb5c28709d666364f273bf54b98
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>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Conflicts:
kernel/rtmutex.c
---
kernel/rtmutex.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
index 7cd751bb891a..c9989ae1cfa5 100644
--- a/kernel/rtmutex.c
+++ b/kernel/rtmutex.c
@@ -1255,24 +1255,33 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
/*
* Slow path try-lock function:
*/
-static inline int
-rt_mutex_slowtrylock(struct rt_mutex *lock)
+static inline int 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.
+ */
if (!raw_spin_trylock(&lock->wait_lock))
- return ret;
+ return 0;
init_lists(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 unconditionally. Clean this up.
- */
- fixup_rt_mutex_waiters(lock);
- }
+ /*
+ * try_to_take_rt_mutex() sets the lock waiters bit
+ * unconditionally. Clean this up.
+ */
+ fixup_rt_mutex_waiters(lock);
raw_spin_unlock(&lock->wait_lock);
--
2.1.4
next prev parent reply other threads:[~2015-03-13 15:15 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-13 15:14 [PATCH RT 00/31] Linux 3.10.70-rt75-rc1 Steven Rostedt
2015-03-13 15:14 ` [PATCH RT 01/31] gpio: omap: use raw locks for locking Steven Rostedt
2015-03-13 15:14 ` [PATCH RT 02/31] create-rt-enqueue Steven Rostedt
2015-03-13 15:14 ` Steven Rostedt [this message]
2015-03-13 15:14 ` [PATCH RT 04/31] rtmutex: Simplify and document try_to_take_rtmutex() Steven Rostedt
2015-03-13 15:14 ` [PATCH RT 05/31] rtmutex: No need to keep task ref for lock owner check Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 06/31] rtmutex: Clarify the boost/deboost part Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 07/31] rtmutex: Document pi chain walk Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 08/31] rtmutex: Simplify remove_waiter() Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 09/31] rtmutex: Confine deadlock logic to futex Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 10/31] rtmutex: Cleanup deadlock detector debug logic Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 11/31] rtmutex: Avoid pointless requeueing in the deadlock detection chain walk Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 12/31] futex: Make unlock_pi more robust Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 13/31] futex: Use futex_top_waiter() in lookup_pi_state() Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 14/31] futex: Split out the waiter check from lookup_pi_state() Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 15/31] futex: Split out the first waiter attachment " Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 16/31] futex: Simplify futex_lock_pi_atomic() and make it more robust Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 17/31] rt-mutex: avoid a NULL pointer dereference on deadlock Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 18/31] x86: UV: raw_spinlock conversion Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 20/31] arm/futex: disable preemption during futex_atomic_cmpxchg_inatomic() Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 21/31] ARM: cmpxchg: define __HAVE_ARCH_CMPXCHG for armv6 and later Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 22/31] sas-ata/isci: dontt disable interrupts in qc_issue handler Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 23/31] scheduling while atomic in cgroup code Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 24/31] work-simple: Simple work queue implemenation Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 25/31] sunrpc: make svc_xprt_do_enqueue() use get_cpu_light() Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 26/31] lockdep: selftest: fix warnings due to missing PREEMPT_RT conditionals Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 27/31] timers: Track total number of timers in list Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 28/31] timers: Reduce __run_timers() latency for empty list Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 29/31] timers: Reduce future __run_timers() latency for newly emptied list Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 30/31] timers: Reduce future __run_timers() latency for first add to empty list Steven Rostedt
2015-03-13 15:15 ` [PATCH RT 31/31] Linux 3.10.70-rt75-rc1 Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150313151515.365546754@goodmis.org \
--to=rostedt@goodmis.org \
--cc=C.Emde@osadl.org \
--cc=bigeasy@linutronix.de \
--cc=jkacur@redhat.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=paul.gortmaker@windriver.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome