lkml.org 
[lkml]   [1999]   [Aug]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] i386 rwlock bug?
Bug or feature?

Currently (2.3.13), an i386 write lock is acquired as follows:
1. Bit 31 is set to 1. If bit 31 was already set, goto step 5.
2. If bits 30-0 are nonzero, goto step 4.
3. Go to step 7.
4. Clear bit 31.
5. Wait for bits 31-0 to become 0.
6. Goto step 1.
7. We are done.

When the process trying to get the write lock sees that the lock has
readers (step 2) it clears the high bit (step 4) and waits until all
the readers go away. In the meantime, while the writer waits for his
write lock (step 5), more readers can come in.

I've modified this to leave the high bit on while waiting for the
readers to go away, thus making the high bit a 'write lock pending'
bit. This makes sure that while the writer is waiting for the write
lock no more readers can come in.

Does anyone consider the current behaviour a feature? Are there
arguments against my patch? Agreed, there isn't always much lock
contention, so you can say "Leave it this way." but I use rwlocks in
'heavy contention' situations and (for example) with 10 readers and 1
writer the writer never acquires the write lock without this patch.

Greetings,
Lennert Buytenhek

PS misc question: why do i386 rwlock_t's have a field 'unsigned long
previous' which is never used? Debugging cruft?


--- linux/include/asm-i386/spinlock.h.old Fri Aug 20 11:22:50 1999
+++ linux/include/asm-i386/spinlock.h Fri Aug 20 11:23:40 1999
@@ -207,13 +207,12 @@
#define write_lock(rw) \
asm volatile("\n1:\t" \
"lock ; btsl $31,%0\n\t" \
- "jc 4f\n" \
+ "jc 3f\n" \
"2:\ttestl $0x7fffffff,%0\n\t" \
- "jne 3f\n" \
+ "jne 2b\n" \
".section .text.lock,\"ax\"\n" \
- "3:\tlock ; btrl $31,%0\n" \
- "4:\tcmp $0,%0\n\t" \
- "jne 4b\n\t" \
+ "3:\tcmp $0,%0\n\t" \
+ "js 3b\n\t" \
"jmp 1b\n" \
".previous" \
:"=m" (__dummy_lock(&(rw)->lock)))

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:53    [W:0.037 / U:0.640 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site