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>,
Peter Zijlstra <peterz@infradead.org>,
Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH RT 11/27] rtmutex: Avoid pointless requeueing in the deadlock detection chain walk
Date: Fri, 13 Mar 2015 11:17:52 -0400 [thread overview]
Message-ID: <20150313151756.676736657@goodmis.org> (raw)
In-Reply-To: 20150313151741.132137234@goodmis.org
[-- Attachment #1: 0011-rtmutex-Avoid-pointless-requeueing-in-the-deadlock-d.patch --]
[-- Type: text/plain, Size: 4357 bytes --]
3.4.106-rt132-rc1 stable review patch.
If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <tglx@linutronix.de>
upstream commit: 67792e2cabadbadd1a93f6790fa7bcbd47eca7c3
In case the dead lock detector is enabled we follow the lock chain to
the end in rt_mutex_adjust_prio_chain, even if we could stop earlier
due to the priority/waiter constellation.
But once we are no longer the top priority waiter in a certain step
or the task holding the lock has already the same priority then there
is no point in dequeing and enqueing along the lock chain as there is
no change at all.
So stop the queueing at this point.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Link: http://lkml.kernel.org/r/20140522031950.280830190@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/rtmutex.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 70 insertions(+), 7 deletions(-)
diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
index 4a4040a34463..1889aedfad86 100644
--- a/kernel/rtmutex.c
+++ b/kernel/rtmutex.c
@@ -347,6 +347,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
struct rt_mutex *lock;
bool detect_deadlock;
unsigned long flags;
+ bool requeue = true;
detect_deadlock = rt_mutex_cond_detect_deadlock(orig_waiter, chwalk);
@@ -436,18 +437,31 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
goto out_unlock_pi;
/*
* If deadlock detection is off, we stop here if we
- * are not the top pi waiter of the task.
+ * are not the top pi waiter of the task. If deadlock
+ * detection is enabled we continue, but stop the
+ * requeueing in the chain walk.
*/
- if (!detect_deadlock && top_waiter != task_top_pi_waiter(task))
- goto out_unlock_pi;
+ if (top_waiter != task_top_pi_waiter(task)) {
+ if (!detect_deadlock)
+ goto out_unlock_pi;
+ else
+ requeue = false;
+ }
}
/*
- * When deadlock detection is off then we check, if further
- * priority adjustment is necessary.
+ * If the waiter priority is the same as the task priority
+ * then there is no further priority adjustment necessary. If
+ * deadlock detection is off, we stop the chain walk. If its
+ * enabled we continue, but stop the requeueing in the chain
+ * walk.
*/
- if (!detect_deadlock && waiter->list_entry.prio == task->prio)
- goto out_unlock_pi;
+ if (waiter->list_entry.prio == task->prio) {
+ if (!detect_deadlock)
+ goto out_unlock_pi;
+ else
+ requeue = false;
+ }
/*
* [4] Get the next lock
@@ -481,6 +495,55 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
}
/*
+ * If we just follow the lock chain for deadlock detection, no
+ * need to do all the requeue operations. To avoid a truckload
+ * of conditionals around the various places below, just do the
+ * minimum chain walk checks.
+ */
+ if (!requeue) {
+ /*
+ * No requeue[7] here. Just release @task [8]
+ */
+ raw_spin_unlock_irqrestore(&task->pi_lock, flags);
+ put_task_struct(task);
+
+ /*
+ * [9] check_exit_conditions_3 protected by lock->wait_lock.
+ * If there is no owner of the lock, end of chain.
+ */
+ if (!rt_mutex_owner(lock)) {
+ raw_spin_unlock(&lock->wait_lock);
+ return 0;
+ }
+
+ /* [10] Grab the next task, i.e. owner of @lock */
+ task = rt_mutex_owner(lock);
+ get_task_struct(task);
+ raw_spin_lock_irqsave(&task->pi_lock, flags);
+
+ /*
+ * No requeue [11] here. We just do deadlock detection.
+ *
+ * [12] Store whether owner is blocked
+ * itself. Decision is made after dropping the locks
+ */
+ next_lock = task_blocked_on_lock(task);
+ /*
+ * Get the top waiter for the next iteration
+ */
+ top_waiter = rt_mutex_top_waiter(lock);
+
+ /* [13] Drop locks */
+ raw_spin_unlock_irqrestore(&task->pi_lock, flags);
+ raw_spin_unlock(&lock->wait_lock);
+
+ /* If owner is not blocked, end of chain. */
+ if (!next_lock)
+ goto out_put_task;
+ goto again;
+ }
+
+ /*
* Store the current top waiter before doing the requeue
* operation on @lock. We need it for the boost/deboost
* decision below.
--
2.1.4
next prev parent reply other threads:[~2015-03-13 15:17 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-13 15:17 [PATCH RT 00/27] Linux 3.4.106-rt132-rc1 Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 01/27] gpio: omap: use raw locks for locking Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 02/27] create-rt-enqueue Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 03/27] rtmutex: Simplify rtmutex_slowtrylock() Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 04/27] rtmutex: Simplify and document try_to_take_rtmutex() Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 05/27] rtmutex: No need to keep task ref for lock owner check Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 06/27] rtmutex: Clarify the boost/deboost part Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 07/27] rtmutex: Document pi chain walk Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 08/27] rtmutex: Simplify remove_waiter() Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 09/27] rtmutex: Confine deadlock logic to futex Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 10/27] rtmutex: Cleanup deadlock detector debug logic Steven Rostedt
2015-03-13 15:17 ` Steven Rostedt [this message]
2015-03-13 15:17 ` [PATCH RT 12/27] futex: Make unlock_pi more robust Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 13/27] futex: Use futex_top_waiter() in lookup_pi_state() Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 14/27] futex: Split out the waiter check from lookup_pi_state() Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 15/27] futex: Split out the first waiter attachment " Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 16/27] futex: Simplify futex_lock_pi_atomic() and make it more robust Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 17/27] rt-mutex: avoid a NULL pointer dereference on deadlock Steven Rostedt
2015-03-13 15:17 ` [PATCH RT 18/27] x86: UV: raw_spinlock conversion Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 20/27] arm/futex: disable preemption during futex_atomic_cmpxchg_inatomic() Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 21/27] ARM: cmpxchg: define __HAVE_ARCH_CMPXCHG for armv6 and later Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 22/27] sas-ata/isci: dontt disable interrupts in qc_issue handler Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 23/27] scheduling while atomic in cgroup code Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 24/27] work-simple: Simple work queue implemenation Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 25/27] sunrpc: make svc_xprt_do_enqueue() use get_cpu_light() Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 26/27] lockdep: selftest: fix warnings due to missing PREEMPT_RT conditionals Steven Rostedt
2015-03-13 15:18 ` [PATCH RT 27/27] Linux 3.4.106-rt132-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=20150313151756.676736657@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=paul.gortmaker@windriver.com \
--cc=peterz@infradead.org \
--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;
as well as URLs for NNTP newsgroup(s).