2 * Copyright (c) 2000, All rights reserved. See /usr/src/COPYRIGHT
7 #include "opt_ktrace.h"
10 #include <sys/systm.h>
11 #include <sys/kernel.h>
13 #include <sys/kthread.h>
15 #include <sys/mutex.h>
18 #include <sys/resourcevar.h>
20 #include <sys/unistd.h>
23 #include <sys/ktrace.h>
26 static void idle_setup(void *dummy);
27 SYSINIT(idle_setup, SI_SUB_SCHED_IDLE, SI_ORDER_FIRST, idle_setup, NULL)
29 static void idle_proc(void *dummy);
32 * Setup per-cpu idle process contexts. The AP's shouldn't be running or
33 * accessing their idle processes at this point, so don't bother with
37 idle_setup(void *dummy)
46 SLIST_FOREACH(pc, &cpuhead, pc_allcpu) {
47 error = kthread_create(idle_proc, NULL, &p,
48 RFSTOPPED | RFHIGHPID, "idle: cpu%d", pc->pc_cpuid);
49 pc->pc_idlethread = FIRST_THREAD_IN_PROC(p);
50 if (pc->pc_curthread == NULL) {
51 pc->pc_curthread = pc->pc_idlethread;
52 pc->pc_idlethread->td_critnest = 0;
55 error = kthread_create(idle_proc, NULL, &p,
56 RFSTOPPED | RFHIGHPID, "idle");
57 PCPU_SET(idlethread, FIRST_THREAD_IN_PROC(p));
60 panic("idle_setup: kthread_create error %d\n", error);
62 p->p_flag |= P_NOLOAD;
70 * idle process context
73 idle_proc(void *dummy)
80 mtx_assert(&Giant, MA_NOTOWNED);
85 while (count >= 0 && procrunnable() == 0) {
87 while (procrunnable() == 0) {
90 * This is a good place to put things to be done in
91 * the background, including sanity checks.
96 CTR0(KTR_PROC, "idle_proc: timed out waiting"
105 mtx_lock_spin(&sched_lock);
106 curproc->p_stats->p_ru.ru_nvcsw++;
108 mtx_unlock_spin(&sched_lock);