summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-06-27 21:13:17 -0400
committerIan Moffett <ian@osmora.org>2025-06-27 21:13:17 -0400
commitb2f7f9858f5516a029e1c5dfe2140538ed36c9de (patch)
treefa6c8f03326551cb393bce9b7d811e4c18063239 /sys
parent5e4cf6049be6cf8bd8033295973c5aa8282995b8 (diff)
kernel/amd64: mp: Give each core an idle threadexpt
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 <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/amd64/amd64/mp.c12
1 files changed, 11 insertions, 1 deletions
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 <sys/limine.h>
#include <sys/limits.h>
#include <sys/syslog.h>
+#include <sys/proc.h>
#include <sys/spinlock.h>
#include <sys/sched.h>
#include <sys/atomic.h>
@@ -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);
}