lib/thread: Remove thread stack alignment requirement

CPU_INFO_V2 now encapsulates the cpu_info requirements. They no longer
need to leak through to thread.c. This allows us to remove the alignment
requirement.

BUG=b:179699789
TEST=Reboot stress test guybrush 50 times.

Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Change-Id: I0af91feddcbd93b7f7d0f17009034bd1868d5aef
Reviewed-on: https://review.coreboot.org/c/coreboot/+/57928
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Eric Peers <epeers@google.com>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
This commit is contained in:
Raul E Rangel 2021-09-24 14:00:56 -06:00 committed by Raul Rangel
parent 968f140ecb
commit db16ac9578

View file

@ -11,16 +11,7 @@
#include <thread.h>
#include <timer.h>
/* Can't use the IS_POWER_OF_2 in _Static_assert */
_Static_assert((CONFIG_STACK_SIZE & (CONFIG_STACK_SIZE - 1)) == 0,
"`cpu_info()` requires the stack size to be a power of 2");
/*
* struct cpu_info lives at the top of each thread's stack. `cpu_info()` locates this struct by
* taking the current stack pointer and masking off CONFIG_STACK_SIZE. This requires the stack
* to be STACK_SIZE aligned.
*/
static u8 thread_stacks[CONFIG_STACK_SIZE * CONFIG_NUM_THREADS] __aligned(CONFIG_STACK_SIZE);
static u8 thread_stacks[CONFIG_STACK_SIZE * CONFIG_NUM_THREADS] __aligned(sizeof(uint64_t));
static bool initialized;
static void idle_thread_init(void);
@ -90,6 +81,9 @@ static inline struct thread *get_free_thread(void)
t = pop_thread(&free_threads);
/* Reset the current stack value to the original. */
if (!t->stack_orig)
die("%s: Invalid stack value\n", __func__);
t->stack_current = t->stack_orig;
return t;
@ -250,15 +244,10 @@ static void threads_initialize(void)
if (initialized)
return;
/* `cpu_info()` requires the stacks to be STACK_SIZE aligned */
assert(IS_ALIGNED((uintptr_t)thread_stacks, CONFIG_STACK_SIZE));
/* Initialize the BSP thread first. The cpu_info structure is assumed
* to be just under the top of the stack. */
t = &all_threads[0];
ci = cpu_info();
ci->thread = t;
t->stack_orig = (uintptr_t)ci;
t->stack_orig = (uintptr_t)NULL; /* We never free the main thread */
t->id = 0;
t->can_yield = 1;