diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index 834838659004..2a8eb6d52bce 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -197,7 +197,7 @@ thread_ctor(void *mem, int size, void *arg, int flags) td = (struct thread *)mem; td->td_state = TDS_INACTIVE; - td->td_oncpu = NOCPU; + td->td_lastcpu = td->td_oncpu = NOCPU; td->td_tid = tid_alloc(); diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index 83535988435c..fbb8bdf61f76 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -1071,9 +1071,23 @@ init_secondary_tail(void) /* NOTREACHED */ } -/******************************************************************* - * local functions and data - */ +static void +smp_after_idle_runnable(void *arg __unused) +{ + struct thread *idle_td; + int cpu; + + for (cpu = 1; cpu < mp_ncpus; cpu++) { + idle_td = pcpu_find(cpu)->pc_idlethread; + while (idle_td->td_lastcpu == NOCPU && + idle_td->td_oncpu == NOCPU) + cpu_spinwait(); + kmem_free((vm_offset_t)bootstacks[cpu], kstack_pages * + PAGE_SIZE); + } +} +SYSINIT(smp_after_idle_runnable, SI_SUB_SMP, SI_ORDER_ANY, + smp_after_idle_runnable, NULL); /* * We tell the I/O APIC code about all the CPUs we want to receive