summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorRaul E Rangel <rrangel@chromium.org>2021-10-08 13:10:38 -0600
committerFelix Held <felix-coreboot@felixheld.de>2021-10-18 12:36:30 +0000
commitc2c38f5fdea0579d1a64ce63c00737bbe3ca5759 (patch)
tree0372610e9b701006bb6c9935b474bd8671f97e17 /src/lib
parent12ae850dfc10709f8c3bcf92ab7ba1397eb4ae43 (diff)
downloadcoreboot-c2c38f5fdea0579d1a64ce63c00737bbe3ca5759.tar.gz
coreboot-c2c38f5fdea0579d1a64ce63c00737bbe3ca5759.tar.bz2
coreboot-c2c38f5fdea0579d1a64ce63c00737bbe3ca5759.zip
arch/x86,cpu/x86,lib/thread: Remove usage of cpu_info from lib/thread
We only ever start and execute threads on the BSP. By explicitly checking to see if the CPU is the BSP we can remove the dependency on cpu_info. With this change we can in theory enable threads in all stages. BUG=b:194391185, b:179699789 TEST=Boot guybrush to OS and verify coop multithreading still works Suggested-by: Julius Werner <jwerner@chromium.org> Signed-off-by: Raul E Rangel <rrangel@chromium.org> Change-Id: Iea4622d52c36d529e100b7ea55f32c334acfdf3e Reviewed-on: https://review.coreboot.org/c/coreboot/+/58199 Reviewed-by: Karthik Ramasubramanian <kramasub@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/thread.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/lib/thread.c b/src/lib/thread.c
index 9008147eaeba..da6189d6f18f 100644
--- a/src/lib/thread.c
+++ b/src/lib/thread.c
@@ -4,10 +4,10 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
-#include <arch/cpu.h>
#include <bootstate.h>
#include <commonlib/bsd/compiler.h>
#include <console/console.h>
+#include <smp/node.h>
#include <thread.h>
#include <timer.h>
@@ -27,17 +27,25 @@ static struct thread all_threads[TOTAL_NUM_THREADS];
static struct thread *runnable_threads;
static struct thread *free_threads;
+static struct thread *active_thread;
+
static inline int thread_can_yield(const struct thread *t)
{
return (t != NULL && t->can_yield > 0);
}
+static inline void set_current_thread(struct thread *t)
+{
+ assert(boot_cpu());
+ active_thread = t;
+}
+
static inline struct thread *current_thread(void)
{
- if (!initialized)
+ if (!initialized || !boot_cpu())
return NULL;
- return cpu_info()->thread;
+ return active_thread;
}
static inline int thread_list_empty(struct thread **list)
@@ -108,7 +116,6 @@ __noreturn static enum cb_err idle_thread(void *unused)
static void schedule(struct thread *t)
{
struct thread *current = current_thread();
- struct cpu_info *ci = cpu_info();
/* If t is NULL need to find new runnable thread. */
if (t == NULL) {
@@ -123,7 +130,7 @@ static void schedule(struct thread *t)
if (t->handle)
t->handle->state = THREAD_STARTED;
- ci->thread = t;
+ set_current_thread(t);
switch_to_thread(t->stack_current, &current->stack_current);
}
@@ -239,14 +246,14 @@ static void threads_initialize(void)
int i;
struct thread *t;
u8 *stack_top;
- struct cpu_info *ci;
if (initialized)
return;
t = &all_threads[0];
- ci = cpu_info();
- ci->thread = t;
+
+ set_current_thread(t);
+
t->stack_orig = (uintptr_t)NULL; /* We never free the main thread */
t->id = 0;
t->can_yield = 1;