From ca7b8ae031d9ce12139d96caedc5d1bd369feeca Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 15 Feb 2023 10:59:42 +0100 Subject: smp: Fix more busy loops We need to avoid the kernel optimizing away the reads from memory. Use a standard relaxing instruction for that. --- kern/lock.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'kern/lock.c') diff --git a/kern/lock.c b/kern/lock.c index a4b82522..81c6a129 100644 --- a/kern/lock.c +++ b/kern/lock.c @@ -36,6 +36,8 @@ #include +#include + #include #include #include @@ -88,7 +90,7 @@ void simple_lock_init(simple_lock_t l) void simple_lock(simple_lock_t l) { while (test_and_set((boolean_t *)l)) - continue; + cpu_pause(); } void simple_unlock(simple_lock_t l) @@ -290,7 +292,7 @@ void lock_write( if ((i = lock_wait_time) > 0) { simple_unlock(&l->interlock); while (--i > 0 && l->want_write) - continue; + cpu_pause(); simple_lock(&l->interlock); } @@ -310,7 +312,7 @@ void lock_write( simple_unlock(&l->interlock); while (--i > 0 && (l->read_count != 0 || l->want_upgrade)) - continue; + cpu_pause(); simple_lock(&l->interlock); } @@ -384,7 +386,7 @@ void lock_read( if ((i = lock_wait_time) > 0) { simple_unlock(&l->interlock); while (--i > 0 && (l->want_write || l->want_upgrade)) - continue; + cpu_pause(); simple_lock(&l->interlock); } @@ -450,7 +452,7 @@ boolean_t lock_read_to_write( if ((i = lock_wait_time) > 0) { simple_unlock(&l->interlock); while (--i > 0 && l->read_count != 0) - continue; + cpu_pause(); simple_lock(&l->interlock); } -- cgit v1.2.3