mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-23 15:13:02 +00:00
utils: Use WFE/SEV in spinlock
This should reduce memory traffic spam and power usage from lock contention when threads are blocked on a spinlock. Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
dd111b22b8
commit
9c795fbdbf
1 changed files with 4 additions and 1 deletions
|
@ -133,8 +133,10 @@ void spin_lock(spinlock_t *lock)
|
|||
s64 free = -1;
|
||||
|
||||
while (!__atomic_compare_exchange_n(&lock->lock, &free, me, false, __ATOMIC_ACQUIRE,
|
||||
__ATOMIC_RELAXED))
|
||||
__ATOMIC_RELAXED)) {
|
||||
free = -1;
|
||||
sysop("wfe");
|
||||
}
|
||||
|
||||
assert(__atomic_load_n(&lock->lock, __ATOMIC_RELAXED) == me);
|
||||
lock->count++;
|
||||
|
@ -147,6 +149,7 @@ void spin_unlock(spinlock_t *lock)
|
|||
assert(lock->count > 0);
|
||||
if (!--lock->count)
|
||||
__atomic_store_n(&lock->lock, -1L, __ATOMIC_RELEASE);
|
||||
sysop("sev");
|
||||
}
|
||||
|
||||
bool is_heap(void *addr)
|
||||
|
|
Loading…
Reference in a new issue