2 * Copyright (c) 2000, All rights reserved. See /usr/src/COPYRIGHT
7 #include "opt_ktrace.h"
10 #include <sys/systm.h>
12 #include <sys/kernel.h>
14 #include <sys/signalvar.h>
15 #include <sys/resourcevar.h>
16 #include <sys/vmmeter.h>
17 #include <sys/sysctl.h>
18 #include <sys/unistd.h>
20 #include <sys/kthread.h>
21 #include <sys/queue.h>
22 #include <sys/eventhandler.h>
24 #include <vm/vm_extern.h>
27 #include <sys/ktrace.h>
30 #include <machine/cpu.h>
31 #include <machine/mutex.h>
32 #include <machine/smp.h>
34 #include <machine/globaldata.h>
35 #include <machine/globals.h>
39 #include <i386/isa/icu.h>
40 #include <i386/isa/intr_machdep.h>
43 static void idle_setup(void *dummy);
44 SYSINIT(idle_setup, SI_SUB_SCHED_IDLE, SI_ORDER_FIRST, idle_setup, NULL)
46 static void idle_proc(void *dummy);
48 EVENTHANDLER_FAST_DEFINE(idle_event, idle_eventhandler_t);
51 * setup per-cpu idle process contexts
54 idle_setup(void *dummy)
56 struct globaldata *gd;
59 SLIST_FOREACH(gd, &cpuhead, gd_allcpu) {
61 error = kthread_create(idle_proc, NULL, &gd->gd_idleproc,
62 RFSTOPPED|RFHIGHPID, "idle: cpu%d",
65 error = kthread_create(idle_proc, NULL, &gd->gd_idleproc,
66 RFSTOPPED|RFHIGHPID, "idle");
69 panic("idle_setup: kthread_create error %d\n", error);
71 gd->gd_idleproc->p_flag |= P_NOLOAD;
72 gd->gd_idleproc->p_stat = SRUN;
77 * idle process context
80 idle_proc(void *dummy)
85 mtx_assert(&Giant, MA_NOTOWNED);
89 while (count >= 0 && procrunnable() == 0) {
91 * This is a good place to put things to be done in
92 * the background, including sanity checks.
96 CTR0(KTR_PROC, "idle_proc: timed out waiting"
99 /* call out to any cpu-becoming-idle events */
100 EVENTHANDLER_FAST_INVOKE(idle_event, count);
103 mtx_enter(&sched_lock, MTX_SPIN);
105 mtx_exit(&sched_lock, MTX_SPIN);