Commit c18eaa3a authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Ingo Molnar

futex: Clarify comment in futex_requeue()

The comment about the restriction of the number of waiters to wake for the
REQUEUE_PI case is confusing at best. Rewrite it.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20210815211305.524990421@linutronix.de
parent 64b7b715
...@@ -1939,15 +1939,27 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags, ...@@ -1939,15 +1939,27 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
*/ */
if (refill_pi_state_cache()) if (refill_pi_state_cache())
return -ENOMEM; return -ENOMEM;
/* /*
* requeue_pi must wake as many tasks as it can, up to nr_wake * futex_requeue() allows the caller to define the number
* + nr_requeue, since it acquires the rt_mutex prior to * of waiters to wake up via the @nr_wake argument. With
* returning to userspace, so as to not leave the rt_mutex with * REQUEUE_PI, waking up more than one waiter is creating
* waiters and no owner. However, second and third wake-ups * more problems than it solves. Waking up a waiter makes
* cannot be predicted as they involve race conditions with the * only sense if the PI futex @uaddr2 is uncontended as
* first wake and a fault while looking up the pi_state. Both * this allows the requeue code to acquire the futex
* pthread_cond_signal() and pthread_cond_broadcast() should * @uaddr2 before waking the waiter. The waiter can then
* use nr_wake=1. * return to user space without further action. A secondary
* wakeup would just make the futex_wait_requeue_pi()
* handling more complex, because that code would have to
* look up pi_state and do more or less all the handling
* which the requeue code has to do for the to be requeued
* waiters. So restrict the number of waiters to wake to
* one, and only wake it up when the PI futex is
* uncontended. Otherwise requeue it and let the unlock of
* the PI futex handle the wakeup.
*
* All REQUEUE_PI users, e.g. pthread_cond_signal() and
* pthread_cond_broadcast() must use nr_wake=1.
*/ */
if (nr_wake != 1) if (nr_wake != 1)
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment