Raul Rangel has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/58199 )
Change subject: arch/x86,cpu/x86,lib/thread: Remove usage of cpu_info from lib/thread ......................................................................
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 bootblock and romstage.
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 --- M src/arch/x86/include/arch/cpu.h M src/cpu/x86/cpu_info.S.inc M src/cpu/x86/lapic/lapic_cpu_init.c M src/cpu/x86/mp_init.c M src/include/thread.h M src/lib/thread.c 6 files changed, 14 insertions(+), 24 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/99/58199/1
diff --git a/src/arch/x86/include/arch/cpu.h b/src/arch/x86/include/arch/cpu.h index 8e96fae..9a3b63d 100644 --- a/src/arch/x86/include/arch/cpu.h +++ b/src/arch/x86/include/arch/cpu.h @@ -231,9 +231,6 @@ struct cpu_info { struct device *cpu; size_t index; -#if CONFIG(COOP_MULTITASKING) - struct thread *thread; -#endif };
/* diff --git a/src/cpu/x86/cpu_info.S.inc b/src/cpu/x86/cpu_info.S.inc index dffd1bc..fc3e26d 100644 --- a/src/cpu/x86/cpu_info.S.inc +++ b/src/cpu/x86/cpu_info.S.inc @@ -2,9 +2,6 @@
/* Push struct cpu_info */ .macro push_cpu_info index=$0 -#if CONFIG(COOP_MULTITASKING) - push $0 /* *thread */ -#endif push \index /* index */ push $0 /* *cpu */ .endm diff --git a/src/cpu/x86/lapic/lapic_cpu_init.c b/src/cpu/x86/lapic/lapic_cpu_init.c index e141ad8..d463c69 100644 --- a/src/cpu/x86/lapic/lapic_cpu_init.c +++ b/src/cpu/x86/lapic/lapic_cpu_init.c @@ -253,7 +253,6 @@ info->index = index; info->cpu = cpu; cpu_add_map_entry(info->index); - thread_init_cpu_info_non_bsp(info);
/* Advertise the new stack and index to start_cpu */ secondary_stack = stack_top; diff --git a/src/cpu/x86/mp_init.c b/src/cpu/x86/mp_init.c index 123b2b5..497ed3c 100644 --- a/src/cpu/x86/mp_init.c +++ b/src/cpu/x86/mp_init.c @@ -193,7 +193,6 @@ info->cpu = cpus_dev[cpu];
cpu_add_map_entry(info->index); - thread_init_cpu_info_non_bsp(info);
/* Fix up APIC id with reality. */ info->cpu->path.apic.apic_id = lapicid(); diff --git a/src/include/thread.h b/src/include/thread.h index cb085b5..62c6283 100644 --- a/src/include/thread.h +++ b/src/include/thread.h @@ -73,11 +73,6 @@ void thread_mutex_lock(struct thread_mutex *mutex); void thread_mutex_unlock(struct thread_mutex *mutex);
-static inline void thread_init_cpu_info_non_bsp(struct cpu_info *ci) -{ - ci->thread = NULL; -} - /* Architecture specific thread functions. */ asmlinkage void switch_to_thread(uintptr_t new_stack, uintptr_t *saved_stack); /* Set up the stack frame for a new thread so that a switch_to_thread() call @@ -96,8 +91,6 @@ } static inline void thread_coop_enable(void) {} static inline void thread_coop_disable(void) {} -struct cpu_info; -static inline void thread_init_cpu_info_non_bsp(struct cpu_info *ci) { }
static inline void thread_mutex_lock(struct thread_mutex *mutex) {}
diff --git a/src/lib/thread.c b/src/lib/thread.c index 9008147e..8cc2637 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,24 @@ 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) +{ + 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 +115,6 @@ 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 +129,7 @@ if (t->handle) t->handle->state = THREAD_STARTED;
- ci->thread = t; + set_current_thread(t);
switch_to_thread(t->stack_current, ¤t->stack_current); } @@ -239,18 +245,17 @@ int i; struct thread *t; u8 *stack_top; - struct cpu_info *ci;
- if (initialized) + if (initialized || !boot_cpu()) return;
t = &all_threads[0]; - ci = cpu_info(); - ci->thread = t; t->stack_orig = (uintptr_t)NULL; /* We never free the main thread */ t->id = 0; t->can_yield = 1;
+ set_current_thread(t); + stack_top = &thread_stacks[CONFIG_STACK_SIZE]; for (i = 1; i < TOTAL_NUM_THREADS; i++) { t = &all_threads[i];