The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/kern_idle.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2000, All rights reserved.  See /usr/src/COPYRIGHT
    3  *
    4  */
    5 
    6 #include <sys/cdefs.h>
    7 __FBSDID("$FreeBSD: releng/5.2/sys/kern/kern_idle.c 121238 2003-10-19 02:43:57Z peter $");
    8 
    9 #include <sys/param.h>
   10 #include <sys/systm.h>
   11 #include <sys/kernel.h>
   12 #include <sys/kthread.h>
   13 #include <sys/lock.h>
   14 #include <sys/mutex.h>
   15 #include <sys/proc.h>
   16 #include <sys/resourcevar.h>
   17 #include <sys/sched.h>
   18 #include <sys/unistd.h>
   19 
   20 static void idle_setup(void *dummy);
   21 SYSINIT(idle_setup, SI_SUB_SCHED_IDLE, SI_ORDER_FIRST, idle_setup, NULL)
   22 
   23 static void idle_proc(void *dummy);
   24 
   25 /*
   26  * Set up per-cpu idle process contexts.  The AP's shouldn't be running or
   27  * accessing their idle processes at this point, so don't bother with
   28  * locking.
   29  */
   30 static void
   31 idle_setup(void *dummy)
   32 {
   33 #ifdef SMP
   34         struct pcpu *pc;
   35 #endif
   36         struct proc *p;
   37         struct thread *td;
   38         int error;
   39 
   40 #ifdef SMP
   41         SLIST_FOREACH(pc, &cpuhead, pc_allcpu) {
   42                 error = kthread_create(idle_proc, NULL, &p,
   43                     RFSTOPPED | RFHIGHPID, 0, "idle: cpu%d", pc->pc_cpuid);
   44                 pc->pc_idlethread = FIRST_THREAD_IN_PROC(p);
   45                 if (pc->pc_curthread == NULL) {
   46                         pc->pc_curthread = pc->pc_idlethread;
   47                         pc->pc_idlethread->td_critnest = 0;
   48                 }
   49 #else
   50                 error = kthread_create(idle_proc, NULL, &p,
   51                     RFSTOPPED | RFHIGHPID, 0, "idle");
   52                 PCPU_SET(idlethread, FIRST_THREAD_IN_PROC(p));
   53 #endif
   54                 if (error)
   55                         panic("idle_setup: kthread_create error %d\n", error);
   56 
   57                 PROC_LOCK(p);
   58                 p->p_flag |= P_NOLOAD;
   59                 mtx_lock_spin(&sched_lock);
   60                 p->p_state = PRS_NORMAL;
   61                 td = FIRST_THREAD_IN_PROC(p);
   62                 td->td_state = TDS_CAN_RUN;
   63                 td->td_flags |= TDF_IDLETD;
   64                 mtx_unlock_spin(&sched_lock);
   65                 PROC_UNLOCK(p);
   66 #ifdef SMP
   67         }
   68 #endif
   69 }
   70 
   71 /*
   72  * The actual idle process.
   73  */
   74 static void
   75 idle_proc(void *dummy)
   76 {
   77         struct proc *p;
   78         struct thread *td;
   79 
   80         td = curthread;
   81         p = td->td_proc;
   82         for (;;) {
   83                 mtx_assert(&Giant, MA_NOTOWNED);
   84 
   85                 while (sched_runnable() == 0)
   86                         cpu_idle();
   87 
   88                 mtx_lock_spin(&sched_lock);
   89                 td->td_state = TDS_CAN_RUN;
   90                 p->p_stats->p_ru.ru_nvcsw++;
   91                 mi_switch();
   92                 mtx_unlock_spin(&sched_lock);
   93         }
   94 }

Cache object: 086150cabed4427d1771e65efce12bff


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.