5 */ 6 7#include "opt_ktrace.h" 8 9#include <sys/param.h> 10#include <sys/systm.h> 11#include <sys/kernel.h> 12#include <sys/ktr.h> 13#include <sys/kthread.h> 14#include <sys/lock.h> 15#include <sys/mutex.h> 16#include <sys/pcpu.h> 17#include <sys/proc.h> 18#include <sys/resourcevar.h> 19#include <sys/sched.h> 20#include <sys/smp.h> 21#include <sys/unistd.h> 22#ifdef KTRACE 23#include <sys/uio.h> 24#include <sys/ktrace.h> 25#endif 26 27static void idle_setup(void *dummy); 28SYSINIT(idle_setup, SI_SUB_SCHED_IDLE, SI_ORDER_FIRST, idle_setup, NULL) 29 30static void idle_proc(void *dummy); 31 32/* 33 * Setup per-cpu idle process contexts. The AP's shouldn't be running or 34 * accessing their idle processes at this point, so don't bother with 35 * locking. 36 */ 37static void 38idle_setup(void *dummy) 39{ 40#ifdef SMP 41 struct pcpu *pc; 42#endif 43 struct proc *p; 44 struct thread *td; 45 int error; 46 47#ifdef SMP 48 SLIST_FOREACH(pc, &cpuhead, pc_allcpu) { 49 error = kthread_create(idle_proc, NULL, &p, 50 RFSTOPPED | RFHIGHPID, 0, "idle: cpu%d", pc->pc_cpuid); 51 pc->pc_idlethread = FIRST_THREAD_IN_PROC(p); 52 if (pc->pc_curthread == NULL) { 53 pc->pc_curthread = pc->pc_idlethread; 54 pc->pc_idlethread->td_critnest = 0; 55 } 56#else 57 error = kthread_create(idle_proc, NULL, &p, 58 RFSTOPPED | RFHIGHPID, 0, "idle"); 59 PCPU_SET(idlethread, FIRST_THREAD_IN_PROC(p)); 60#endif 61 if (error) 62 panic("idle_setup: kthread_create error %d\n", error); 63 64 PROC_LOCK(p); 65 p->p_flag |= P_NOLOAD; 66 mtx_lock_spin(&sched_lock); 67 p->p_state = PRS_NORMAL; 68 td = FIRST_THREAD_IN_PROC(p); 69 td->td_state = TDS_CAN_RUN;
|