mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Davidlohr Bueso <davidlohr@hp.com>
To: mingo@kernel.org, tglx@linutronix.de
Cc: peterz@infradead.org, davidlohr@hp.com, aswin@hp.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] futex: update comments for ordering guarantees
Date: Sun, 30 Mar 2014 16:08:47 -0700	[thread overview]
Message-ID: <1396220928-4426-2-git-send-email-davidlohr@hp.com> (raw)
In-Reply-To: <1396220928-4426-1-git-send-email-davidlohr@hp.com>

Commit 11d4616bd07f (futex: revert back to the explicit waiter counting code)
was a late fix that changed the way we account for waiters on a futex. However,
it made the general documentation we have regarding this topic slightly stale.

Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
---
 kernel/futex.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 08ec814..395e285 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -119,7 +119,7 @@
  * sys_futex(WAIT, futex, val);
  *   futex_wait(futex, val);
  *
- *   waiters++;
+ *   waiters++; (a)
  *   mb(); (A) <-- paired with -.
  *                              |
  *   lock(hash_bucket(futex));  |
@@ -134,15 +134,14 @@
  *     queue();
  *     unlock(hash_bucket(futex));
  *     schedule();                         if (waiters)
- *                                           lock(hash_bucket(futex));
- *                                           wake_waiters(futex);
+ *   else                                    lock(hash_bucket(futex));
+ *     waiters--; (b)                        wake_waiters(futex);
  *                                           unlock(hash_bucket(futex));
  *
- * Where (A) orders the waiters increment and the futex value read -- this
- * is guaranteed by the head counter in the hb spinlock; and where (B)
- * orders the write to futex and the waiters read -- this is done by the
- * barriers in get_futex_key_refs(), through either ihold or atomic_inc,
- * depending on the futex type.
+ * Where (A) orders the waiters increment and the futex value read and
+ * where (B) orders the write to futex and the waiters read -- this is
+ * done by the barriers in get_futex_key_refs(), through either ihold
+ * or atomic_inc, depending on the futex type.
  *
  * This yields the following case (where X:=waiters, Y:=futex):
  *
@@ -155,6 +154,10 @@
  * Which guarantees that x==0 && y==0 is impossible; which translates back into
  * the guarantee that we cannot both miss the futex variable change and the
  * enqueue.
+ *
+ * Note that a new waiter is accounted for in (a) even when it is possible that
+ * the wait call can return error, in which case we backtrack from it in (b).
+ * Refer to the comment in queue_lock().
  */
 
 int __read_mostly futex_cmpxchg_enabled;
-- 
1.8.1.4


  reply	other threads:[~2014-03-30 23:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-30 23:08 [PATCH 0/2] futex: updates for hb waiters Davidlohr Bueso
2014-03-30 23:08 ` Davidlohr Bueso [this message]
2014-03-30 23:08 ` [PATCH 2/2] futex: add plist_del + atomic_dec helper Davidlohr Bueso

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=1396220928-4426-2-git-send-email-davidlohr@hp.com \
    --to=davidlohr@hp.com \
    --cc=aswin@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --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

all inboxes | Powered by JetHome®