From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Lai Jiangshan <laijs@cn.fujitsu.com>,
Jason Low <jason.low2@hp.com>
Subject: [patch v2 4/5] rtmutex: Clarify the lock chain walk
Date: Sat, 31 May 2014 15:57:51 -0000 [thread overview]
Message-ID: <20140531155739.430525601@linutronix.de> (raw)
In-Reply-To: <20140531155229.493650009@linutronix.de>
[-- Attachment #1: rtmutex-clarify-the-lock-chain-walk.patch --]
[-- Type: text/plain, Size: 4277 bytes --]
Add a separate local variable for the boost/deboost logic to make the
code more readable. Add comments where appropriate.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Link: http://lkml.kernel.org/r/20140522031950.168005692@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/locking/rtmutex.c | 51 +++++++++++++++++++++++++++++++++++++++--------
1 file changed, 43 insertions(+), 8 deletions(-)
Index: tip/kernel/locking/rtmutex.c
===================================================================
--- tip.orig/kernel/locking/rtmutex.c
+++ tip/kernel/locking/rtmutex.c
@@ -303,10 +303,11 @@ static int rt_mutex_adjust_prio_chain(st
struct rt_mutex_waiter *orig_waiter,
struct task_struct *top_task)
{
- struct rt_mutex *lock;
struct rt_mutex_waiter *waiter, *top_waiter = orig_waiter;
+ struct rt_mutex_waiter *prerequeue_top_waiter;
enum rtmutex_chainwalk detect_deadlock;
int ret = 0, depth = 0;
+ struct rt_mutex *lock;
unsigned long flags;
detect_deadlock = rt_mutex_cond_detect_deadlock(orig_waiter,
@@ -381,6 +382,11 @@ static int rt_mutex_adjust_prio_chain(st
if (!detect_deadlock && waiter->prio == task->prio)
goto out_unlock_pi;
+ /*
+ * We need to trylock here as we are holding task->pi_lock,
+ * which is the reverse lock order versus the other rtmutex
+ * operations.
+ */
lock = waiter->lock;
if (!raw_spin_trylock(&lock->wait_lock)) {
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
@@ -401,7 +407,11 @@ static int rt_mutex_adjust_prio_chain(st
goto out_unlock_pi;
}
- top_waiter = rt_mutex_top_waiter(lock);
+ /*
+ * Store the top waiter before doing any requeue operation. We
+ * need it for the boost/deboost decision below.
+ */
+ prerequeue_top_waiter = rt_mutex_top_waiter(lock);
/* Requeue the waiter */
rt_mutex_dequeue(lock, waiter);
@@ -410,13 +420,18 @@ static int rt_mutex_adjust_prio_chain(st
/* Release the task */
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
+
+ /*
+ * We must abort the chain walk if there is no lock owner even
+ * in the dead lock detection case, as we have nothing to
+ * follow here. This is the end of the chain we are walking.
+ */
if (!rt_mutex_owner(lock)) {
/*
* If the requeue above changed the top waiter, then we need
* to wake the new top waiter up to try to get the lock.
*/
-
- if (top_waiter != rt_mutex_top_waiter(lock))
+ if (prerequeue_top_waiter != rt_mutex_top_waiter(lock))
wake_up_process(rt_mutex_top_waiter(lock)->task);
raw_spin_unlock(&lock->wait_lock);
goto out_put_task;
@@ -429,17 +444,32 @@ static int rt_mutex_adjust_prio_chain(st
raw_spin_lock_irqsave(&task->pi_lock, flags);
if (waiter == rt_mutex_top_waiter(lock)) {
- /* Boost the owner */
- rt_mutex_dequeue_pi(task, top_waiter);
+ /*
+ * The waiter became the new top (highest priority)
+ * waiter on the lock. Replace the previous top waiter
+ * in the owner tasks pi waiters list with this waiter.
+ */
+ rt_mutex_dequeue_pi(task, prerequeue_top_waiter);
rt_mutex_enqueue_pi(task, waiter);
__rt_mutex_adjust_prio(task);
- } else if (top_waiter == waiter) {
- /* Deboost the owner */
+ } else if (prerequeue_top_waiter == waiter) {
+ /*
+ * The waiter was the top waiter on the lock, but is
+ * no longer the top prority waiter. Replace waiter in
+ * the owner tasks pi waiters list with the new top
+ * (highest priority) waiter.
+ */
rt_mutex_dequeue_pi(task, waiter);
waiter = rt_mutex_top_waiter(lock);
rt_mutex_enqueue_pi(task, waiter);
__rt_mutex_adjust_prio(task);
+
+ } else {
+ /*
+ * Nothing changed. No need to do any priority
+ * adjustment.
+ */
}
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
@@ -447,6 +477,11 @@ static int rt_mutex_adjust_prio_chain(st
top_waiter = rt_mutex_top_waiter(lock);
raw_spin_unlock(&lock->wait_lock);
+ /*
+ * If the current waiter is not the top waiter on the lock,
+ * then we can stop the chain walk here if we are not in full
+ * deadlock detection mode.
+ */
if (!detect_deadlock && waiter != top_waiter)
goto out_put_task;
next prev parent reply other threads:[~2014-05-31 15:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-31 15:57 [patch v2 0/5] rtmutex: Code clarification and optimization Thomas Gleixner
2014-05-31 15:57 ` [patch v2 1/5] rtmutex: Remove builtin tester Thomas Gleixner
2014-05-31 19:55 ` Steven Rostedt
2014-05-31 15:57 ` [patch v2 2/5] rtmutex: Cleanup deadlock detector debug logic Thomas Gleixner
2014-05-31 20:00 ` Steven Rostedt
2014-06-04 13:17 ` Thomas Gleixner
2014-06-04 19:54 ` Steven Rostedt
2014-06-04 19:56 ` Thomas Gleixner
2014-05-31 15:57 ` [patch v2 3/5] rtmutex: Confine deadlock logic to futex Thomas Gleixner
2014-05-31 19:54 ` Steven Rostedt
2014-05-31 20:35 ` Thomas Gleixner
2014-05-31 15:57 ` Thomas Gleixner [this message]
2014-05-31 20:03 ` [patch v2 4/5] rtmutex: Clarify the lock chain walk Steven Rostedt
2014-05-31 15:57 ` [patch v2 5/5] rtmutex: Avoid pointless requeueing in the deadlock detection " Thomas Gleixner
2014-06-02 14:14 ` 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=20140531155739.430525601@linutronix.de \
--to=tglx@linutronix.de \
--cc=jason.low2@hp.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/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
all inboxes | Powered by JetHome®