From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Lai Jiangshan <laijs@cn.fujitsu.com>,
Jason Low <jason.low2@hp.com>, Brad Mouring <bmouring@ni.com>
Subject: [patch V3 2/7] rtmutex: Clarify the boost/deboost part
Date: Mon, 09 Jun 2014 20:28:07 -0000 [thread overview]
Message-ID: <20140609202336.068962483@linutronix.de> (raw)
In-Reply-To: <20140609201118.387571774@linutronix.de>
[-- Attachment #1: rtmutex-clarify-the-lock-chain-walk.patch --]
[-- Type: text/plain, Size: 4249 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>
---
kernel/locking/rtmutex.c | 58 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 48 insertions(+), 10 deletions(-)
Index: tip/kernel/locking/rtmutex.c
===================================================================
--- tip.orig/kernel/locking/rtmutex.c
+++ tip/kernel/locking/rtmutex.c
@@ -293,9 +293,10 @@ 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;
int detect_deadlock, ret = 0, depth = 0;
+ struct rt_mutex *lock;
unsigned long flags;
detect_deadlock = debug_rt_mutex_detect_deadlock(orig_waiter,
@@ -402,9 +403,14 @@ static int rt_mutex_adjust_prio_chain(st
goto out_unlock_pi;
}
- top_waiter = rt_mutex_top_waiter(lock);
+ /*
+ * Store the current top waiter before doing the requeue
+ * operation on @lock. We need it for the boost/deboost
+ * decision below.
+ */
+ prerequeue_top_waiter = rt_mutex_top_waiter(lock);
- /* Requeue the waiter */
+ /* Requeue the waiter in the lock waiter list. */
rt_mutex_dequeue(lock, waiter);
waiter->prio = task->prio;
rt_mutex_enqueue(lock, waiter);
@@ -413,35 +419,58 @@ static int rt_mutex_adjust_prio_chain(st
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
put_task_struct(task);
+ /*
+ * 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);
return 0;
}
- /* Grab the next task */
+ /* Grab the next task, i.e. the owner of @lock */
task = rt_mutex_owner(lock);
get_task_struct(task);
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
+ * and adjust the priority of the owner.
+ */
+ 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 and adjust the priority
+ * of the owner.
+ * The new top waiter is stored in @waiter so that
+ * @waiter == @top_waiter evaluates to true below and
+ * we continue to deboost the rest of the chain.
+ */
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.
+ */
}
/*
@@ -454,6 +483,10 @@ static int rt_mutex_adjust_prio_chain(st
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
+ /*
+ * Store the top waiter of @lock for the end of chain walk
+ * decision below.
+ */
top_waiter = rt_mutex_top_waiter(lock);
raw_spin_unlock(&lock->wait_lock);
@@ -464,6 +497,11 @@ static int rt_mutex_adjust_prio_chain(st
if (!next_lock)
goto out_put_task;
+ /*
+ * 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-06-09 20:28 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-09 20:28 [patch V3 0/7] rtmutex: Code clarification and optimization Thomas Gleixner
2014-06-09 20:28 ` [patch V3 1/7] rtmutex: Deobfuscate chain walk Thomas Gleixner
2014-06-09 20:59 ` Steven Rostedt
2014-06-10 3:52 ` Lai Jiangshan
2014-06-10 3:21 ` Jason Low
2014-06-10 13:57 ` Brad Mouring
2014-06-09 20:28 ` Thomas Gleixner [this message]
2014-06-10 0:37 ` [patch V3 2/7] rtmutex: Clarify the boost/deboost part Steven Rostedt
2014-06-10 3:22 ` Jason Low
2014-06-10 14:04 ` Brad Mouring
2014-06-09 20:28 ` [patch V3 3/7] rtmutex: Document pi chain walk Thomas Gleixner
2014-06-10 0:45 ` Steven Rostedt
2014-06-10 3:51 ` Lai Jiangshan
2014-06-10 14:21 ` Brad Mouring
2014-06-09 20:28 ` [patch V3 4/7] rtmutex: Siplify remove_waiter() Thomas Gleixner
2014-06-10 0:53 ` Steven Rostedt
2014-06-10 3:35 ` Lai Jiangshan
2014-06-10 3:44 ` Jason Low
2014-06-10 14:10 ` Brad Mouring
2014-06-09 20:28 ` [patch V3 5/7] rtmutex: Confine deadlock logic to futex Thomas Gleixner
2014-06-10 0:59 ` Steven Rostedt
2014-06-10 4:03 ` Lai Jiangshan
2014-06-10 17:39 ` Thomas Gleixner
2014-06-09 20:28 ` [patch V3 6/7] rtmutex: Cleanup deadlock detector debug logic Thomas Gleixner
2014-06-10 1:04 ` Steven Rostedt
2014-06-10 15:09 ` Brad Mouring
2014-06-09 20:28 ` [patch V3 7/7] rtmutex: Avoid pointless requeueing in the deadlock detection chain walk Thomas Gleixner
2014-06-10 1:20 ` Steven Rostedt
2014-06-10 3:48 ` Jason Low
2014-06-10 17:41 ` Thomas Gleixner
2014-06-10 17:47 ` Steven Rostedt
2014-06-10 20:45 ` Thomas Gleixner
2014-06-10 14:57 ` Brad Mouring
2014-06-10 15:19 ` Steven Rostedt
2014-06-10 17:43 ` Thomas Gleixner
2014-06-10 17:51 ` Steven Rostedt
2014-06-10 20:46 ` Thomas Gleixner
2014-06-10 0:27 ` [patch V3 0/7] rtmutex: Code clarification and optimization Steven Rostedt
2014-06-10 0:35 ` Steven Rostedt
2014-06-10 3:00 ` Lai Jiangshan
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=20140609202336.068962483@linutronix.de \
--to=tglx@linutronix.de \
--cc=bmouring@ni.com \
--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
Powered by JetHome