diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-10 15:15:47 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-10 15:15:47 -0400 |
commit | 50f78ebbe69c8d5e0573b4987d1e7dc21af9779c (patch) | |
tree | ae8689ebca4ace5c2b30a46053df450dbb746ab2 | |
parent | 58d7188fbd9ff448479f4a5c9ddcdcfae446ad16 (diff) |
kern/amd64: Attempt to dequeue on a cores first go
When a CPU core first starts up, it has no proceses to assign to itself.
This commit ensures that the processor will right away start trying to
find tasks to grab from its runqueue.
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | src/sys/arch/amd64/cpu/cpu_mp.c | 3 | ||||
-rw-r--r-- | src/sys/arch/amd64/os/os_proc.c | 17 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/sys/arch/amd64/cpu/cpu_mp.c b/src/sys/arch/amd64/cpu/cpu_mp.c index d95ba70..ae7b367 100644 --- a/src/sys/arch/amd64/cpu/cpu_mp.c +++ b/src/sys/arch/amd64/cpu/cpu_mp.c @@ -77,6 +77,9 @@ ap_entry(struct limine_smp_info *) corelist[ncores_up - 1] = pcore; atomic_inc_64(&ncores_up); spinlock_release(&lock); + + md_proc_yield(); + __builtin_unreachable(); for (;;); } diff --git a/src/sys/arch/amd64/os/os_proc.c b/src/sys/arch/amd64/os/os_proc.c index d944f41..b8e7c99 100644 --- a/src/sys/arch/amd64/os/os_proc.c +++ b/src/sys/arch/amd64/os/os_proc.c @@ -137,11 +137,24 @@ md_proc_init(struct proc *procp, int flags) __dead void md_proc_yield(void) { - /* Clear pending interrupts and oneshot */ + struct proc *proc; + struct pcore *core = this_core(); + int error; + lapic_eoi(); - lapic_timer_oneshot_us(9000); + /* + * Set the oneshot timer and check if there is + * any procs in our runqueues. If not, wait for + * it to fire again. + */ for (;;) { + lapic_timer_oneshot_us(9000); + error = sched_deq(&core->scq, &proc); + if (error == 0) { + core->curproc = proc; + md_proc_kick(proc); + } __ASMV("sti; hlt"); } } |