From 33d6f72cfe6fd011f7223eb7f08cc9469f08d709 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Wed, 12 Aug 2026 22:11:11 -0400 Subject: [PATCH] amd64: insert idle threads Signed-off-by: Michael Shaw --- amd64/amd64_init.c | 12 ++++++++++++ amd64/kernel/thread.c | 2 +- include/kernel/thread.h | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/amd64/amd64_init.c b/amd64/amd64_init.c index 9e122ea..f811f89 100644 --- a/amd64/amd64_init.c +++ b/amd64/amd64_init.c @@ -64,4 +64,16 @@ void arch_ap_startup() wrmsr(IA32_GS_BASE, (u64)this_local); tss_init(id, this_local); + + char buf[64]; + snprintf(buf, 64, "kidle_cpu%lld", id); + + struct thread *idle = kthread_create(yield, NULL, buf); + + if (idle) + kdebug("idle thread inserted for cpu %d\n", id); + else + panic("failed to create idle thread for cpu %d\n", id); + + this_local->idle_thread = idle; } diff --git a/amd64/kernel/thread.c b/amd64/kernel/thread.c index d95c2f1..ece02bd 100644 --- a/amd64/kernel/thread.c +++ b/amd64/kernel/thread.c @@ -86,7 +86,7 @@ tid_t sys_fork() extern void kthread_entry(); -struct thread *thread_kthread(void (*fn)(void *), void *arg, const char *name) +struct thread *kthread_create(void *fn, void *arg, const char *name) { struct thread *thread = slab_alloc(thread_slab); if (!thread) diff --git a/include/kernel/thread.h b/include/kernel/thread.h index c4de1b2..f3ede78 100644 --- a/include/kernel/thread.h +++ b/include/kernel/thread.h @@ -77,7 +77,7 @@ ssize_t thread_load_file(const char *file, struct thread *thread); struct thread *thread_create(void); struct thread *thread_fork(struct thread *parent); int thread_set_entry(struct thread *thread, uaddr_t entry); -struct thread *thread_kthread(void (*fn)(void *), void *arg, const char *name); +struct thread *kthread_create(void *fn, void *arg, const char *name); void thread_free(struct thread *thread); void thread_init(); tid_t alloc_tid();