lib/thread,lib/hardwaremain: Lazy initialize threads
By lazy initializing the threads, if a stage doesn't use them, they will be garbage collected. BUG=b:179699789 TEST=Boot guybrush to the OS and verify threads worked Suggested-by: Julius Werner <jwerner@chromium.org> Signed-off-by: Raul E Rangel <rrangel@chromium.org> Change-Id: I7208ffb5dcda63d916bc6cfdea28d92a62435da6 Reviewed-on: https://review.coreboot.org/c/coreboot/+/56532 Reviewed-by: Furquan Shaikh <furquan@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
		
				
					committed by
					
						
						Patrick Georgi
					
				
			
			
				
	
			
			
			
						parent
						
							7db7ee984c
						
					
				
				
					commit
					a2d83c68a3
				
			@@ -257,13 +257,16 @@ static void *thread_alloc_space(struct thread *t, size_t bytes)
 | 
			
		||||
	return (void *)t->stack_current;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void threads_initialize(void)
 | 
			
		||||
static void threads_initialize(void)
 | 
			
		||||
{
 | 
			
		||||
	int i;
 | 
			
		||||
	struct thread *t;
 | 
			
		||||
	u8 *stack_top;
 | 
			
		||||
	struct cpu_info *ci;
 | 
			
		||||
 | 
			
		||||
	if (initialized)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	/* `cpu_info()` requires the stacks to be STACK_SIZE aligned */
 | 
			
		||||
	assert(IS_ALIGNED((uintptr_t)thread_stacks, CONFIG_STACK_SIZE));
 | 
			
		||||
 | 
			
		||||
@@ -295,6 +298,9 @@ int thread_run(struct thread_handle *handle, enum cb_err (*func)(void *), void *
 | 
			
		||||
	struct thread *current;
 | 
			
		||||
	struct thread *t;
 | 
			
		||||
 | 
			
		||||
	/* Lazy initialization */
 | 
			
		||||
	threads_initialize();
 | 
			
		||||
 | 
			
		||||
	current = current_thread();
 | 
			
		||||
 | 
			
		||||
	if (!thread_can_yield(current)) {
 | 
			
		||||
@@ -327,6 +333,9 @@ int thread_run_until(struct thread_handle *handle, enum cb_err (*func)(void *),
 | 
			
		||||
	if (!ENV_RAMSTAGE)
 | 
			
		||||
		dead_code();
 | 
			
		||||
 | 
			
		||||
	/* Lazy initialization */
 | 
			
		||||
	threads_initialize();
 | 
			
		||||
 | 
			
		||||
	current = current_thread();
 | 
			
		||||
 | 
			
		||||
	if (!thread_can_yield(current)) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user