Raul Rangel has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/59322 )
Change subject: arch/x86: Remove spinlock dependency on threading. ......................................................................
arch/x86: Remove spinlock dependency on threading.
Since we only have one spinlock caller left, we can move the thread_coop_ calls out of the spinlock.
This is mostly a revert of CB:56320.
BUG=b:179699789 TEST=Boot guybrush to OS with threading enabled
Signed-off-by: Raul E Rangel rrangel@chromium.org Change-Id: I55d0cd2bcd82721098ca24ae2368bb6a16a07df4 --- M src/arch/x86/include/arch/smp/spinlock.h M src/console/printk.c 2 files changed, 9 insertions(+), 10 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/22/59322/1
diff --git a/src/arch/x86/include/arch/smp/spinlock.h b/src/arch/x86/include/arch/smp/spinlock.h index c7008c1..f8fffdb 100644 --- a/src/arch/x86/include/arch/smp/spinlock.h +++ b/src/arch/x86/include/arch/smp/spinlock.h @@ -3,8 +3,6 @@ #ifndef ARCH_SMP_SPINLOCK_H #define ARCH_SMP_SPINLOCK_H
-#include <thread.h> - /* * Your basic SMP spinlocks, allowing only a single CPU anywhere */ @@ -52,16 +50,10 @@ __asm__ __volatile__( spin_lock_string : "=m" (lock->lock) : : "memory"); - - /* Switching contexts while holding a spinlock will lead to deadlocks */ - thread_coop_disable(); - }
static __always_inline void spin_unlock(spinlock_t *lock) { - thread_coop_enable(); - __asm__ __volatile__( spin_unlock_string : "=m" (lock->lock) : : "memory"); diff --git a/src/console/printk.c b/src/console/printk.c index 1ed39cb..99e0151 100644 --- a/src/console/printk.c +++ b/src/console/printk.c @@ -8,11 +8,12 @@ #include <console/console.h> #include <console/streams.h> #include <console/vtxprintf.h> -#include <smp/spinlock.h> #include <smp/node.h> +#include <smp/spinlock.h> +#include <thread.h> #include <timer.h>
-DECLARE_SPIN_LOCK(console_lock) +DECLARE_SPIN_LOCK(console_lock);
#define TRACK_CONSOLE_TIME (!ENV_SMM && CONFIG(HAVE_MONOTONIC_TIMER))
@@ -80,6 +81,10 @@ if (log_this < CONSOLE_LOG_FAST) return 0;
+ /* Context switching while holding a spin lock can lead to a dead lock. */ + thread_coop_disable(); + + /* We use a spinlock instead of a mutex to allow coop-threading to use printk. */ spin_lock(&console_lock);
console_time_run(); @@ -95,6 +100,8 @@
spin_unlock(&console_lock);
+ thread_coop_enable(); + return i; }