Skip to content

Commit 94232a4

Browse files
author
Martin Schwidefsky
committed
s390/rwlock: improve writer fairness
Set the write-lock bit in the out-of-line rwlock code to indicate that a writer is waiting. Additional readers will no be able to get the lock until at least one writer got the lock. Additional writers have to wait for the first writer to release the lock again. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 2684e73 commit 94232a4

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎arch/s390/lib/spinlock.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ EXPORT_SYMBOL(_raw_read_trylock_retry);
149149

150150
void _raw_write_lock_wait(arch_rwlock_t *rw)
151151
{
152-
unsigned int owner, old;
152+
unsigned int owner, old, prev;
153153
int count = spin_retry;
154154

155+
prev = 0x80000000;
155156
owner = 0;
156157
while (1) {
157158
if (count-- <= 0) {
@@ -161,10 +162,13 @@ void _raw_write_lock_wait(arch_rwlock_t *rw)
161162
}
162163
old = ACCESS_ONCE(rw->lock);
163164
owner = ACCESS_ONCE(rw->owner);
164-
if (old)
165-
continue;
166-
if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000))
167-
return;
165+
if ((int) old >= 0 &&
166+
_raw_compare_and_swap(&rw->lock, old, old | 0x80000000))
167+
prev = old;
168+
else
169+
smp_rmb();
170+
if ((old & 0x7fffffff) == 0 && (int) prev >= 0)
171+
break;
168172
}
169173
}
170174
EXPORT_SYMBOL(_raw_write_lock_wait);

0 commit comments

Comments
 (0)