mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 19:00:25 +00:00
[PATCH] s390: Increase spinlock retry code performance
Currently the code tries up to spin_retry times to grab a lock using the cs instruction. The cs instruction has exclusive access to a memory region and therefore invalidates the appropiate cache line of all other cpus. If there is contention on a lock this leads to cache line trashing. This can be avoided if we first check wether a cs instruction is likely to succeed before the instruction gets actually executed. Signed-off-by: Christian Ehrhardt <ehrhardt@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
6a88231fc7
commit
96567161de
1 changed files with 13 additions and 2 deletions
|
@ -2,8 +2,7 @@
|
||||||
* arch/s390/lib/spinlock.c
|
* arch/s390/lib/spinlock.c
|
||||||
* Out of line spinlock code.
|
* Out of line spinlock code.
|
||||||
*
|
*
|
||||||
* S390 version
|
* Copyright (C) IBM Corp. 2004, 2006
|
||||||
* Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
|
|
||||||
* Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
|
* Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -44,6 +43,8 @@ _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc)
|
||||||
_diag44();
|
_diag44();
|
||||||
count = spin_retry;
|
count = spin_retry;
|
||||||
}
|
}
|
||||||
|
if (__raw_spin_is_locked(lp))
|
||||||
|
continue;
|
||||||
if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
|
if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -56,6 +57,8 @@ _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
|
||||||
int count = spin_retry;
|
int count = spin_retry;
|
||||||
|
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
|
if (__raw_spin_is_locked(lp))
|
||||||
|
continue;
|
||||||
if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
|
if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +77,8 @@ _raw_read_lock_wait(raw_rwlock_t *rw)
|
||||||
_diag44();
|
_diag44();
|
||||||
count = spin_retry;
|
count = spin_retry;
|
||||||
}
|
}
|
||||||
|
if (!__raw_read_can_lock(rw))
|
||||||
|
continue;
|
||||||
old = rw->lock & 0x7fffffffU;
|
old = rw->lock & 0x7fffffffU;
|
||||||
if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
|
if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
|
||||||
return;
|
return;
|
||||||
|
@ -88,6 +93,8 @@ _raw_read_trylock_retry(raw_rwlock_t *rw)
|
||||||
int count = spin_retry;
|
int count = spin_retry;
|
||||||
|
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
|
if (!__raw_read_can_lock(rw))
|
||||||
|
continue;
|
||||||
old = rw->lock & 0x7fffffffU;
|
old = rw->lock & 0x7fffffffU;
|
||||||
if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
|
if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -106,6 +113,8 @@ _raw_write_lock_wait(raw_rwlock_t *rw)
|
||||||
_diag44();
|
_diag44();
|
||||||
count = spin_retry;
|
count = spin_retry;
|
||||||
}
|
}
|
||||||
|
if (!__raw_write_can_lock(rw))
|
||||||
|
continue;
|
||||||
if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
|
if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -118,6 +127,8 @@ _raw_write_trylock_retry(raw_rwlock_t *rw)
|
||||||
int count = spin_retry;
|
int count = spin_retry;
|
||||||
|
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
|
if (!__raw_write_can_lock(rw))
|
||||||
|
continue;
|
||||||
if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
|
if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue