diff options
-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"); } } |