From: Davidlohr Bueso <dave@stgolabs.net>
To: Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Mike Galbraith <umgwanakikbuti@gmail.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Davidlohr Bueso <dave@stgolabs.net>,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>
Subject: [PATCH 1/4] locking/rtmutex: Implement lockless top-waiter wakeup
Date: Tue, 19 May 2015 10:24:55 -0700 [thread overview]
Message-ID: <1432056298-18738-2-git-send-email-dave@stgolabs.net> (raw)
In-Reply-To: <1432056298-18738-1-git-send-email-dave@stgolabs.net>
Mark the task for later wakeup after the wait_lock has been released.
This way, once the next task is awoken, it will have a better chance
to of finding the wait_lock free when continuing executing in
__rt_mutex_slowlock() when trying to acquire the rtmutex, calling
try_to_take_rt_mutex(). Upon contended scenarios, other tasks attempting
take the lock may acquire it first, right after the wait_lock is released,
but (a) this can also occur with the current code, as it relies on the
spinlock fairness, and (b) we are dealing with the top-waiter anyway,
so it will always take the lock next.
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
kernel/locking/rtmutex.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 36573e9..74188d8 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -955,14 +955,13 @@ static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
}
/*
- * Wake up the next waiter on the lock.
- *
* Remove the top waiter from the current tasks pi waiter list and
- * wake it up.
+ * queue it up.
*
* Called with lock->wait_lock held.
*/
-static void wakeup_next_waiter(struct rt_mutex *lock)
+static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
+ struct rt_mutex *lock)
{
struct rt_mutex_waiter *waiter;
unsigned long flags;
@@ -991,12 +990,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
raw_spin_unlock_irqrestore(¤t->pi_lock, flags);
- /*
- * It's safe to dereference waiter as it cannot go away as
- * long as we hold lock->wait_lock. The waiter task needs to
- * acquire it in order to dequeue the waiter.
- */
- wake_up_process(waiter->task);
+ wake_q_add(wake_q, waiter->task);
}
/*
@@ -1255,6 +1249,8 @@ static inline int rt_mutex_slowtrylock(struct rt_mutex *lock)
static void __sched
rt_mutex_slowunlock(struct rt_mutex *lock)
{
+ WAKE_Q(wake_q);
+
raw_spin_lock(&lock->wait_lock);
debug_rt_mutex_unlock(lock);
@@ -1303,10 +1299,13 @@ rt_mutex_slowunlock(struct rt_mutex *lock)
/*
* The wakeup next waiter path does not suffer from the above
* race. See the comments there.
+ *
+ * Queue the next waiter for wakeup once we release the wait_lock.
*/
- wakeup_next_waiter(lock);
+ mark_wakeup_next_waiter(&wake_q, lock);
raw_spin_unlock(&lock->wait_lock);
+ wake_up_q(&wake_q);
/* Undo pi boosting if necessary: */
rt_mutex_adjust_prio(current);
--
2.1.4
next prev parent reply other threads:[~2015-05-19 17:25 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-19 17:24 [PATCH -tip 0/4] rtmutex: Spin on owner Davidlohr Bueso
2015-05-19 17:24 ` Davidlohr Bueso [this message]
2015-06-05 12:35 ` [PATCH 1/4] locking/rtmutex: Implement lockless top-waiter wakeup Thomas Gleixner
2015-06-16 19:29 ` [PATCH] futex: lower the lock contention on the HB lock during wake up Sebastian Andrzej Siewior
2015-06-16 19:50 ` Davidlohr Bueso
2015-06-17 8:33 ` [PATCH v2] " Sebastian Andrzej Siewior
2015-06-17 14:17 ` Mike Galbraith
2015-06-17 14:28 ` Sebastian Andrzej Siewior
2015-06-17 14:31 ` Mike Galbraith
2015-06-21 4:35 ` Mike Galbraith
2015-06-18 20:30 ` [tip:sched/core] futex: Lower " tip-bot for Sebastian Andrzej Siewior
2015-06-19 17:51 ` [PATCH v2] futex: lower " Kevin Hilman
2015-06-19 18:54 ` Thomas Gleixner
2015-06-19 19:32 ` Kevin Hilman
2015-06-19 19:33 ` [tip:sched/locking] futex: Lower " tip-bot for Sebastian Andrzej Siewior
2015-06-18 20:30 ` [tip:sched/core] locking/rtmutex: Implement lockless top-waiter wakeup tip-bot for Davidlohr Bueso
2015-05-19 17:24 ` [PATCH 2/4] locking/rtmutex: Use cmp-cmpxchg Davidlohr Bueso
2015-06-05 12:38 ` Thomas Gleixner
2015-06-06 15:27 ` Davidlohr Bueso
2015-06-15 18:34 ` Jason Low
2015-06-15 19:37 ` Davidlohr Bueso
2015-06-16 1:00 ` Jason Low
2015-05-19 17:24 ` [PATCH 3/4] locking/rtmutex: Update stale plist comments Davidlohr Bueso
2015-06-05 12:39 ` Thomas Gleixner
2015-06-18 20:57 ` [tip:sched/core] " tip-bot for Davidlohr Bueso
2015-06-19 19:33 ` [tip:sched/locking] " tip-bot for Davidlohr Bueso
2015-05-19 17:24 ` [PATCH -rfc 4/4] locking/rtmutex: Support spin on owner (osq) Davidlohr Bueso
2015-05-20 7:11 ` Paul Bolle
2015-05-25 20:35 ` Davidlohr Bueso
2015-05-29 15:19 ` Davidlohr Bueso
2015-05-29 18:01 ` Davidlohr Bueso
2015-06-05 13:59 ` Thomas Gleixner
2015-06-09 4:41 ` Davidlohr Bueso
2015-06-09 9:29 ` Thomas Gleixner
2015-06-09 11:21 ` Peter Zijlstra
2015-06-09 12:53 ` Thomas Gleixner
2015-05-25 20:35 ` [PATCH -tip 0/4] rtmutex: Spin on owner Davidlohr Bueso
2015-05-26 19:05 ` Thomas Gleixner
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=1432056298-18738-2-git-send-email-dave@stgolabs.net \
--to=dave@stgolabs.net \
--cc=bigeasy@linutronix.de \
--cc=dbueso@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=umgwanakikbuti@gmail.com \
/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).