From b2f7f9858f5516a029e1c5dfe2140538ed36c9de Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 27 Jun 2025 21:13:17 -0400 Subject: kernel/amd64: mp: Give each core an idle thread Having the same amount of idle threads per core allow the CPU to always have a thread assigned to one of its cores even when there are currently no other threads for it to take. Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/mp.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'sys') diff --git a/sys/arch/amd64/amd64/mp.c b/sys/arch/amd64/amd64/mp.c index 1e6d8d9..dbee32c 100644 --- a/sys/arch/amd64/amd64/mp.c +++ b/sys/arch/amd64/amd64/mp.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #define pr_trace(fmt, ...) kprintf("cpu_mp: " fmt, ##__VA_ARGS__) +extern struct proc g_proc0; static volatile struct limine_smp_request g_smp_req = { .id = LIMINE_SMP_REQUEST, .revision = 0 @@ -91,12 +93,14 @@ mp_bootstrap_aps(struct cpu_info *ci) struct limine_smp_response *resp = g_smp_req.response; struct limine_smp_info **cpus; size_t cpu_init_counter; + uint32_t ncpu; /* Should not happen */ __assert(resp != NULL); cpus = resp->cpus; - cpu_init_counter = resp->cpu_count - 1; + ncpu = resp->cpu_count; + cpu_init_counter = ncpu - 1; ci_list[0] = ci; if (resp->cpu_count == 1) { @@ -114,6 +118,12 @@ mp_bootstrap_aps(struct cpu_info *ci) cpus[i]->goto_address = ap_trampoline; } + /* Start up idle threads */ + pr_trace("kicking %d idle threads...\n", ncpu); + for (uint32_t i = 0; i < ncpu; ++i) { + spawn(&g_proc0, sched_enter, NULL, 0, NULL); + } + /* Wait for all cores to be ready */ while ((ncpu_up - 1) < cpu_init_counter); } -- cgit v1.2.3