From: "H. Peter Anvin" <hpa@zytor.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: linux-kernel@vger.kernel.org
Subject: Re: furwocks: Fast Userspace Read/Write Locks
Date: Thu, 07 Mar 2002 22:29:44 -0800 [thread overview]
Message-ID: <3C885A58.4040307@zytor.com> (raw)
In-Reply-To: <E16iwkE-000216-00@wagner.rustcorp.com.au> <20020307153228.3A6773FE06@smtp.linux.ibm.com> <20020307104241.D24040@devserv.devel.redhat.com> <20020307191043.9C5F33FE15@smtp.linux.ibm.com> <a68htg$bc1$1@cesium.transmeta.com> <20020308172706.1e4d3f5e.rusty@rustcorp.com.au>
Rusty Russell wrote:
> On 7 Mar 2002 12:17:52 -0800
> "H. Peter Anvin" <hpa@zytor.com> wrote:
>
>
>>Followup to: <20020307191043.9C5F33FE15@smtp.linux.ibm.com>
>>By author: Hubertus Franke <frankeh@watson.ibm.com>
>>In newsgroup: linux.dev.kernel
>>
>>>Take a look at Rusty's futex-1.2, the code is not that different, however
>>>if its all inlined it creates additional code on the critical path
>>>and why do it if not necessary.
>>>
>>>In this case the futexes are the well tested path, the rest is a cludge on
>>>top of it.
>>>
>>>
>>Perhaps someone could give a high-level description of how these
>>"futexes" work?
>>
>
> Certainly! This is how Futexes IV (and Futexes V, ignoring the fairness
> stuff that adds) works:
>
> One or more userspace processes share address space, so they can both do
> simple atomic operations on the same memory (hence the new PROT_SEM flag to
> mmap/mprotect for architectures which need to know). They agree that "this
> address contains an integer which we use as a mutex" (aka. struct futex).
>
> The futex starts at 1 (available). down() looks like:
> if (atomic_dec_and_test(futex)) return 0; /* We got it! */
> else sys_futex(futex, DOWN); /* Go to kernel, wait. */
>
> up() looks like:
> if (atomic_inc_positive(futex)) return 0; /* Noone waiting */
> else sys_futex(futex, UP); /* go to kernel, wake people */
>
> Inside the kernel, we do what you'd expect. For sys_futex(futex, DOWN):
> Pin the page containing the futex, for convenience.
> Hash the kernel address of the futex to get a waitqueue.
> Add ourselves to the waitqueue.
> While !atomic_dec_and_test() (ie. futex still unavailable):
> sleep
> if signal pending, break;
> Unhash from waitqueue
> unpin page.
> return success or -EINTR.
>
> For sys_futex(futex, UP):
> Pin page for convenience.
> Hash kernel address of futex to get the waitqueue.
> set futex to 1 (ie. available).
> Wake up the first one on the waitqueue waiting for this futex.
> unpin page
>
> The only two twists to add are that we don't keep atomic_dec_and_test'ing
> in the loop forever (if it's already negative we don't bother), so counter
> doesn't wrap, and we don't use actual waitqueues because we share them, but
> we want to know which futex each waiter is waiting on.
>
Okay, dumb question...
What can this do that shared memory + existing semaphores can't do?
-hpa
next prev parent reply other threads:[~2002-03-08 6:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-07 12:11 furwocks: Fast Userspace Read/Write Locks Rusty Russell
2002-03-07 12:40 ` Peter Wächtler
2002-03-07 14:41 ` Hubertus Franke
2002-03-07 12:50 ` Arjan van de Ven
2002-03-07 15:33 ` Hubertus Franke
2002-03-07 15:42 ` Arjan van de Ven
2002-03-07 19:11 ` Hubertus Franke
2002-03-07 20:17 ` H. Peter Anvin
2002-03-08 6:27 ` Rusty Russell
2002-03-08 6:29 ` H. Peter Anvin [this message]
2002-03-08 7:09 ` Rusty Russell
2002-03-08 19:32 ` Jamie Lokier
2002-03-08 1:22 ` Rusty Russell
2002-03-08 3:26 ` H. Peter Anvin
2002-03-08 9:21 ` Peter Wächtler
2002-03-08 18:13 ` Hubertus Franke
2002-03-09 4:50 ` Rusty Russell
2002-03-11 18:47 ` Hubertus Franke
2002-03-07 15:28 ` Hubertus Franke
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=3C885A58.4040307@zytor.com \
--to=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
/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