All of lore.kernel.org
 help / color / mirror / Atom feed
* Update futex_q to clarify single waiter symmantics
@ 2008-12-18  1:29 Darren Hart
  2008-12-18 10:44 ` Ingo Molnar
  0 siblings, 1 reply; 2+ messages in thread
From: Darren Hart @ 2008-12-18  1:29 UTC (permalink / raw)
  To: lkml,; +Cc: Thomas Gleixner, Ingo Molnar

From: Darren Hart <dvhltc@us.ibm.com>

I've tripped over this a couple times.  The futex_q uses a waiters list
to represent a single blocked task and then calles wake_up_all().  This
can lead to confusion in trying to understand the intent of the code,
which is to have a single futex_q for every task waiting on a futex.
This patch corrects the problem, using a single pointer to the waiting
task, and an appropriate call to wake_up, rather than wake_up_all.

Compile and boot tested on an 8way x86_64 machine.

Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
---

 kernel/futex.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)


diff --git a/kernel/futex.c b/kernel/futex.c
index ba0d3b8..99f8acc 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -92,11 +92,12 @@ struct futex_pi_state {
  * A futex_q has a woken state, just like tasks have TASK_RUNNING.
  * It is considered woken when plist_node_empty(&q->list) || q->lock_ptr == 0.
  * The order of wakup is always to make the first condition true, then
- * wake up q->waiters, then make the second condition true.
+ * wake up q->waiter, then make the second condition true.
  */
 struct futex_q {
 	struct plist_node list;
-	wait_queue_head_t waiters;
+	/* There can only be a single waiter */
+	wait_queue_head_t waiter;
 
 	/* Which hash list lock to use: */
 	spinlock_t *lock_ptr;
@@ -573,7 +574,7 @@ static void wake_futex(struct futex_q *q)
 	 * The lock in wake_up_all() is a crucial memory barrier after the
 	 * plist_del() and also before assigning to q->lock_ptr.
 	 */
-	wake_up_all(&q->waiters);
+	wake_up(&q->waiter);
 	/*
 	 * The waiting task can free the futex_q as soon as this is written,
 	 * without taking any locks.  This must come last.
@@ -930,7 +931,7 @@ static inline struct futex_hash_bucket *queue_lock(struct futex_q *q)
 {
 	struct futex_hash_bucket *hb;
 
-	init_waitqueue_head(&q->waiters);
+	init_waitqueue_head(&q->waiter);
 
 	get_futex_key_refs(&q->key);
 	hb = hash_futex(&q->key);
@@ -1221,7 +1222,7 @@ static int futex_wait(u32 __user *uaddr, int fshared,
 
 	/* add_wait_queue is the barrier after __set_current_state. */
 	__set_current_state(TASK_INTERRUPTIBLE);
-	add_wait_queue(&q.waiters, &wait);
+	add_wait_queue(&q.waiter, &wait);
 	/*
 	 * !plist_node_empty() is safe here without any lock.
 	 * q.lock_ptr != 0 is not safe, because of ordering against wakeup.

-- 
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: Update futex_q to clarify single waiter symmantics
  2008-12-18  1:29 Update futex_q to clarify single waiter symmantics Darren Hart
@ 2008-12-18 10:44 ` Ingo Molnar
  0 siblings, 0 replies; 2+ messages in thread
From: Ingo Molnar @ 2008-12-18 10:44 UTC (permalink / raw)
  To: Darren Hart; +Cc: lkml,, Thomas Gleixner, Rusty Russell, Nick Piggin


* Darren Hart <dvhltc@us.ibm.com> wrote:

> From: Darren Hart <dvhltc@us.ibm.com>
>
> I've tripped over this a couple times.  The futex_q uses a waiters list
> to represent a single blocked task and then calles wake_up_all().  This
> can lead to confusion in trying to understand the intent of the code,
> which is to have a single futex_q for every task waiting on a futex.
> This patch corrects the problem, using a single pointer to the waiting
> task, and an appropriate call to wake_up, rather than wake_up_all.
>
> Compile and boot tested on an 8way x86_64 machine.
>
> Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
> ---
>
> kernel/futex.c |   11 ++++++-----
> 1 files changed, 6 insertions(+), 5 deletions(-)

applied to tip/core/futexes, thanks Darren!

> -	wake_up_all(&q->waiters);
> +	wake_up(&q->waiter);

yeah, the naming and the wake_up_all is a relic from the FUTEX_FD days - 
but we removed that earlier this year:

| commit 82af7aca56c67061420d618cc5a30f0fd4106b80
| Author: Eric Sesterhenn <snakebyte@gmx.de>
| Date:   Fri Jan 25 10:40:46 2008 +0100
|
|     Removal of FUTEX_FD

	Ingo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-12-18 10:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-18  1:29 Update futex_q to clarify single waiter symmantics Darren Hart
2008-12-18 10:44 ` Ingo Molnar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.