Skip to content

Commit 45ab4ef

Browse files
Davidlohr BuesoKAGA-KOKO
authored andcommitted
locking/rtmutex: Implement lockless top-waiter wakeup
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> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Mike Galbraith <umgwanakikbuti@gmail.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1432056298-18738-2-git-send-email-dave@stgolabs.net Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 6f9aad0 commit 45ab4ef

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

‎kernel/locking/rtmutex.c‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -955,14 +955,13 @@ static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
955955
}
956956

957957
/*
958-
* Wake up the next waiter on the lock.
959-
*
960958
* Remove the top waiter from the current tasks pi waiter list and
961-
* wake it up.
959+
* queue it up.
962960
*
963961
* Called with lock->wait_lock held.
964962
*/
965-
static void wakeup_next_waiter(struct rt_mutex *lock)
963+
static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
964+
struct rt_mutex *lock)
966965
{
967966
struct rt_mutex_waiter *waiter;
968967
unsigned long flags;
@@ -991,12 +990,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
991990

992991
raw_spin_unlock_irqrestore(&current->pi_lock, flags);
993992

994-
/*
995-
* It's safe to dereference waiter as it cannot go away as
996-
* long as we hold lock->wait_lock. The waiter task needs to
997-
* acquire it in order to dequeue the waiter.
998-
*/
999-
wake_up_process(waiter->task);
993+
wake_q_add(wake_q, waiter->task);
1000994
}
1001995

1002996
/*
@@ -1258,6 +1252,8 @@ static inline int rt_mutex_slowtrylock(struct rt_mutex *lock)
12581252
static void __sched
12591253
rt_mutex_slowunlock(struct rt_mutex *lock)
12601254
{
1255+
WAKE_Q(wake_q);
1256+
12611257
raw_spin_lock(&lock->wait_lock);
12621258

12631259
debug_rt_mutex_unlock(lock);
@@ -1306,10 +1302,13 @@ rt_mutex_slowunlock(struct rt_mutex *lock)
13061302
/*
13071303
* The wakeup next waiter path does not suffer from the above
13081304
* race. See the comments there.
1305+
*
1306+
* Queue the next waiter for wakeup once we release the wait_lock.
13091307
*/
1310-
wakeup_next_waiter(lock);
1308+
mark_wakeup_next_waiter(&wake_q, lock);
13111309

13121310
raw_spin_unlock(&lock->wait_lock);
1311+
wake_up_q(&wake_q);
13131312

13141313
/* Undo pi boosting if necessary: */
13151314
rt_mutex_adjust_prio(current);

0 commit comments

Comments
 (0)