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>
Subject: [PATCH RT 06/25] rtmutex: Clarify the boost/deboost part
Date: Fri, 13 Mar 2015 11:18:31 -0400 [thread overview]
Message-ID: <20150313151835.093875256@goodmis.org> (raw)
In-Reply-To: <20150313151825.583263173@goodmis.org>
[-- Attachment #1: 0006-rtmutex-Clarify-the-boost-deboost-part.patch --]
[-- Type: text/plain, Size: 4762 bytes --]
3.2.68-rt99-rc1 stable review patch.
If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <tglx@linutronix.de>
upstream commit: a57594a13a446d1a6ab1dcd48339f799ce586843
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>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Conflicts:
kernel/rtmutex.c
---
kernel/rtmutex.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 48 insertions(+), 9 deletions(-)
diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
index 7d338c8b23b9..34c63cb7ff22 100644
--- a/kernel/rtmutex.c
+++ b/kernel/rtmutex.c
@@ -289,9 +289,10 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
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,
@@ -398,9 +399,14 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
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->list_entry.prio = task->prio;
rt_mutex_enqueue(lock, waiter);
@@ -409,6 +415,11 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
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)) {
struct rt_mutex_waiter *lock_top_waiter;
@@ -417,29 +428,48 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
* to wake the new top waiter up to try to get the lock.
*/
lock_top_waiter = rt_mutex_top_waiter(lock);
- if (top_waiter != lock_top_waiter)
+ if (prerequeue_top_waiter != lock_top_waiter)
rt_mutex_wake_waiter(lock_top_waiter);
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.
+ */
}
/*
@@ -452,6 +482,10 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
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);
@@ -462,6 +496,11 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
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;
--
2.1.4
next prev parent reply other threads:[~2015-03-13 15:43 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-13 15:18 [PATCH RT 00/25] Linux 3.2.68-rt99-rc1 Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 01/25] gpio: omap: use raw locks for locking Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 02/25] create-rt-enqueue Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 03/25] rtmutex: Simplify rtmutex_slowtrylock() Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 04/25] rtmutex: Simplify and document try_to_take_rtmutex() Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 05/25] rtmutex: No need to keep task ref for lock owner check Steven Rostedt
2015-03-13 15:18 ` Steven Rostedt [this message]
2015-03-13 15:18 ` [PATCH RT 07/25] rtmutex: Document pi chain walk Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 08/25] rtmutex: Simplify remove_waiter() Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 09/25] rtmutex: Confine deadlock logic to futex Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 10/25] rtmutex: Cleanup deadlock detector debug logic Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 11/25] rtmutex: Avoid pointless requeueing in the deadlock detection chain walk Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 12/25] futex: Make unlock_pi more robust Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 13/25] futex: Use futex_top_waiter() in lookup_pi_state() Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 14/25] futex: Split out the waiter check from lookup_pi_state() Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 15/25] futex: Split out the first waiter attachment " Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 16/25] futex: Simplify futex_lock_pi_atomic() and make it more robust Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 17/25] rt-mutex: avoid a NULL pointer dereference on deadlock Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 18/25] x86: UV: raw_spinlock conversion Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 20/25] arm/futex: disable preemption during futex_atomic_cmpxchg_inatomic() Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 21/25] scheduling while atomic in cgroup code Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 22/25] work-simple: Simple work queue implemenation Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 23/25] sunrpc: make svc_xprt_do_enqueue() use get_cpu_light() Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 24/25] lockdep: selftest: fix warnings due to missing PREEMPT_RT conditionals Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 25/25] Linux 3.2.68-rt99-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=20150313151835.093875256@goodmis.org \
--to=rostedt@goodmis.org \
--cc=C.Emde@osadl.org \
--cc=bigeasy@linutronix.de \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--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