From: Ben LaHaise <bcrl@redhat.com>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Andrew Morton <andrewm@uow.edu.au>,
David Howells <dhowells@redhat.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: rw_semaphores
Date: Mon, 9 Apr 2001 09:55:04 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.33.0104090902150.16636-100000@devserv.devel.redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.31.0104082030080.7830-100000@penguin.transmeta.com>
On Sun, 8 Apr 2001, Linus Torvalds wrote:
>
> The "down_writer_failed()" case was wrong:
Which is exactly the same problem in the original code. How about the
following patch against the original code? I hadn't sent it yet as the
test code isn't finished (hence, it's untested), but given that Andrew is
going full steam ahead, people might as well give this a try.
-ben
rwsem-2.4.4-pre1-A0.diff
diff -ur v2.4.4-pre1/arch/i386/kernel/semaphore.c work-2.4.4-pre1/arch/i386/kernel/semaphore.c
--- v2.4.4-pre1/arch/i386/kernel/semaphore.c Sat Nov 18 20:31:25 2000
+++ work-2.4.4-pre1/arch/i386/kernel/semaphore.c Mon Apr 9 09:47:02 2001
@@ -269,10 +269,9 @@
ret
2: call down_write_failed
- " LOCK "subl $" RW_LOCK_BIAS_STR ",(%eax)
- jz 1b
- jnc 2b
- jmp 3b
+ popl %ecx
+ popl %edx
+ ret
"
);
@@ -366,19 +365,56 @@
struct task_struct *tsk = current;
DECLARE_WAITQUEUE(wait, tsk);
- __up_write(sem); /* this takes care of granting the lock */
+ /* Originally we called __up_write here, but that
+ * doesn't work: the lock add operation could result
+ * in us failing to detect a bias grant. Instead,
+ * we'll use a compare and exchange to get the lock
+ * from a known state: either <= -BIAS while another
+ * waiter is still around, or > -BIAS if we were given
+ * the lock's bias.
+ */
+ do {
+ int old = atomic_read(&sem->count), new, res;
+ if (old > -RW_LOCK_BIAS)
+ return down_write_failed_biased(sem);
+ new = old + RW_LOCK_BIAS;
+ res = cmpxchg(&sem->count.counter, old, new);
+ } while (res != old);
+
+again:
+ /* We are now removed from the lock. Wait for all other
+ * waiting writers to go away.
+ */
add_wait_queue_exclusive(&sem->wait, &wait);
while (atomic_read(&sem->count) < 0) {
set_task_state(tsk, TASK_UNINTERRUPTIBLE);
- if (atomic_read(&sem->count) >= 0)
+ if (atomic_read(&sem->count) >= 0) {
break; /* we must attempt to acquire or bias the lock */
+ }
+
schedule();
}
remove_wait_queue(&sem->wait, &wait);
tsk->state = TASK_RUNNING;
+
+ /* Okay, try to grab the lock. */
+ for (;;) {
+ int old = atomic_read(&sem->count), new, res;
+ if (old < 0)
+ goto again;
+ new = old - RW_LOCK_BIAS;
+ res = cmpxchg(&sem->count.counter, old, new);
+ if (res != old)
+ continue;
+ if (old == RW_LOCK_BIAS)
+ break;
+ if (old >= 0)
+ return down_write_failed_biased(sem);
+ goto again;
+ }
return sem;
}
next prev parent reply other threads:[~2001-04-09 13:56 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3AD0FD0F.9B0C47FD@uow.edu.au>
2001-04-09 3:08 ` rw_semaphores Linus Torvalds
2001-04-09 4:18 ` rw_semaphores Linus Torvalds
2001-04-09 13:55 ` Ben LaHaise [this message]
2001-04-10 2:41 ` rw_semaphores Tachino Nobuhiro
2001-04-10 5:43 ` rw_semaphores Linus Torvalds
2001-04-10 7:47 ` rw_semaphores David Howells
2001-04-10 18:02 ` [PATCH] i386 rw_semaphores fix David Howells
2001-04-10 19:42 ` Linus Torvalds
2001-04-10 19:56 ` x86 cpu configuration (was: Re: [PATCH] i386 rw_semaphores fix) Jeff Garzik
2001-04-10 21:58 ` Alan Cox
2001-04-10 20:05 ` [PATCH] i386 rw_semaphores fix Andi Kleen
2001-04-10 20:16 ` Linus Torvalds
2001-04-10 22:00 ` Alan Cox
2001-04-11 0:00 ` Andi Kleen
2001-04-11 0:13 ` David Weinehall
2001-04-11 0:20 ` Andi Kleen
2001-04-11 0:56 ` David Weinehall
2001-04-11 1:04 ` Andi Kleen
2001-04-11 12:32 ` Alan Cox
2001-04-11 0:55 ` Linus Torvalds
2001-04-11 1:07 ` Andi Kleen
2001-04-11 1:12 ` Linus Torvalds
2001-04-11 1:23 ` Andi Kleen
2001-04-11 12:36 ` Alan Cox
2001-04-11 18:05 ` H. Peter Anvin
2001-04-11 12:28 ` Alan Cox
2001-04-11 18:06 ` H. Peter Anvin
2001-04-11 22:06 ` Alan Cox
2001-04-11 22:42 ` H. Peter Anvin
2001-04-11 22:55 ` Alan Cox
2001-04-10 21:57 ` Alan Cox
2001-04-11 0:40 ` Tim Wright
2001-04-11 7:38 ` David Howells
2001-04-11 12:24 ` Maciej W. Rozycki
2001-04-11 12:57 ` [PATCH] 2nd try: " David Howells
2001-04-11 16:37 ` [PATCH] 3rd " David Howells
2001-04-11 21:41 ` [PATCH] 4th " David Howells
2001-04-12 18:16 ` Andrew Morton
2001-04-11 23:00 ` [PATCH] 3rd " Anton Blanchard
2001-04-12 15:06 ` [PATCH] i386 rw_semaphores, general abstraction patch David Howells
2001-04-11 16:56 ` [PATCH] i386 rw_semaphores fix Andrew Morton
2001-04-11 17:36 ` David Howells
2001-04-11 18:41 ` Linus Torvalds
2001-04-11 21:27 ` David Howells
2001-04-16 14:39 ` rw_semaphores yodaiken
2001-04-16 14:56 ` rw_semaphores Alan Cox
2001-04-16 17:05 ` rw_semaphores Linus Torvalds
2001-04-16 17:34 ` rw_semaphores yodaiken
2001-04-16 17:26 ` rw_semaphores Andrew Morton
2001-04-10 6:33 ` rw_semaphores Tachino Nobuhiro
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=Pine.LNX.4.33.0104090902150.16636-100000@devserv.devel.redhat.com \
--to=bcrl@redhat.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=andrewm@uow.edu.au \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/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®