t2ex/bsd_source/lib/libc/src_bsd/include/sys/sched.h | bare source | permlink (0.03 seconds) |
1: /* $OpenBSD: sched.h,v 1.30 2011/11/16 20:50:19 deraadt Exp $ */ 2: /* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */ 3: 4: /*- 5: * Copyright (c) 1999 The NetBSD Foundation, Inc. 6: * All rights reserved. 7: * 8: * This code is derived from software contributed to The NetBSD Foundation 9: * by Ross Harvey. 10: * 11: * Redistribution and use in source and binary forms, with or without 12: * modification, are permitted provided that the following conditions 13: * are met: 14: * 1. Redistributions of source code must retain the above copyright 15: * notice, this list of conditions and the following disclaimer. 16: * 2. Redistributions in binary form must reproduce the above copyright 17: * notice, this list of conditions and the following disclaimer in the 18: * documentation and/or other materials provided with the distribution. 19: * 20: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30: * POSSIBILITY OF SUCH DAMAGE. 31: */ 32: 33: /*- 34: * Copyright (c) 1982, 1986, 1991, 1993 35: * The Regents of the University of California. All rights reserved. 36: * (c) UNIX System Laboratories, Inc. 37: * All or some portions of this file are derived from material licensed 38: * to the University of California by American Telephone and Telegraph 39: * Co. or Unix System Laboratories, Inc. and are reproduced herein with 40: * the permission of UNIX System Laboratories, Inc. 41: * 42: * Redistribution and use in source and binary forms, with or without 43: * modification, are permitted provided that the following conditions 44: * are met: 45: * 1. Redistributions of source code must retain the above copyright 46: * notice, this list of conditions and the following disclaimer. 47: * 2. Redistributions in binary form must reproduce the above copyright 48: * notice, this list of conditions and the following disclaimer in the 49: * documentation and/or other materials provided with the distribution. 50: * 3. Neither the name of the University nor the names of its contributors 51: * may be used to endorse or promote products derived from this software 52: * without specific prior written permission. 53: * 54: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 55: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 56: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 57: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 58: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 60: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 62: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 63: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 64: * SUCH DAMAGE. 65: * 66: * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94 67: */ 68: 69: #ifndef _SYS_SCHED_H_ 70: #define _SYS_SCHED_H_ 71: 72: #include <sys/queue.h> 73: 74: /* 75: * Posix defines a <sched.h> which may want to include <sys/sched.h> 76: */ 77: 78: /* 79: * CPU states. 80: * XXX Not really scheduler state, but no other good place to put 81: * it right now, and it really is per-CPU. 82: */ 83: #define CP_USER 0 84: #define CP_NICE 1 85: #define CP_SYS 2 86: #define CP_INTR 3 87: #define CP_IDLE 4 88: #define CPUSTATES 5 89: 90: #define SCHED_NQS 32 /* 32 run queues. */ 91: 92: /* 93: * Per-CPU scheduler state. 94: * XXX - expose to userland for now. 95: */ 96: struct schedstate_percpu { 97: struct timeval spc_runtime; /* time curproc started running */ 98: __volatile int spc_schedflags; /* flags; see below */ 99: u_int spc_schedticks; /* ticks for schedclock() */ 100: u_int64_t spc_cp_time[CPUSTATES]; /* CPU state statistics */ 101: u_char spc_curpriority; /* usrpri of curproc */ 102: int spc_rrticks; /* ticks until roundrobin() */ 103: int spc_pscnt; /* prof/stat counter */ 104: int spc_psdiv; /* prof/stat divisor */ 105: struct proc *spc_idleproc; /* idle proc for this cpu */ 106: 107: u_int spc_nrun; /* procs on the run queues */ 108: fixpt_t spc_ldavg; /* shortest load avg. for this cpu */ 109: 110: TAILQ_HEAD(prochead, proc) spc_qs[SCHED_NQS]; 111: volatile uint32_t spc_whichqs; 112: 113: #ifdef notyet 114: struct proc *spc_reaper; /* dead proc reaper */ 115: #endif 116: LIST_HEAD(,proc) spc_deadproc; 117: }; 118: 119: #ifdef _KERNEL 120: 121: /* spc_flags */ 122: #define SPCF_SEENRR 0x0001 /* process has seen roundrobin() */ 123: #define SPCF_SHOULDYIELD 0x0002 /* process should yield the CPU */ 124: #define SPCF_SWITCHCLEAR (SPCF_SEENRR|SPCF_SHOULDYIELD) 125: #define SPCF_SHOULDHALT 0x0004 /* CPU should be vacated */ 126: #define SPCF_HALTED 0x0008 /* CPU has been halted */ 127: 128: #define SCHED_PPQ (128 / SCHED_NQS) /* priorities per queue */ 129: #define NICE_WEIGHT 2 /* priorities per nice level */ 130: #define ESTCPULIM(e) min((e), NICE_WEIGHT * PRIO_MAX - SCHED_PPQ) 131: 132: extern int schedhz; /* ideally: 16 */ 133: extern int rrticks_init; /* ticks per roundrobin() */ 134: 135: struct proc; 136: void schedclock(struct proc *); 137: struct cpu_info; 138: void roundrobin(struct cpu_info *); 139: void scheduler_start(void); 140: void updatepri(struct proc *); 141: void userret(struct proc *p); 142: 143: void sched_init_cpu(struct cpu_info *); 144: void sched_idle(void *); 145: void sched_exit(struct proc *); 146: void mi_switch(void); 147: void cpu_switchto(struct proc *, struct proc *); 148: struct proc *sched_chooseproc(void); 149: struct cpu_info *sched_choosecpu(struct proc *); 150: struct cpu_info *sched_choosecpu_fork(struct proc *parent, int); 151: void cpu_idle_enter(void); 152: void cpu_idle_cycle(void); 153: void cpu_idle_leave(void); 154: void sched_peg_curproc(struct cpu_info *ci); 155: 156: #ifdef MULTIPROCESSOR 157: void sched_start_secondary_cpus(void); 158: void sched_stop_secondary_cpus(void); 159: #endif 160: 161: #define curcpu_is_idle() (curcpu()->ci_schedstate.spc_whichqs == 0) 162: 163: void sched_init_runqueues(void); 164: void setrunqueue(struct proc *); 165: void remrunqueue(struct proc *); 166: 167: /* Inherit the parent's scheduler history */ 168: #define scheduler_fork_hook(parent, child) do { \ 169: (child)->p_estcpu = (parent)->p_estcpu; \ 170: } while (0) 171: 172: /* Chargeback parents for the sins of their children. */ 173: #define scheduler_wait_hook(parent, child) do { \ 174: (parent)->p_estcpu = ESTCPULIM((parent)->p_estcpu + (child)->p_estcpu);\ 175: } while (0) 176: 177: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG) 178: #include <sys/lock.h> 179: 180: /* 181: * XXX Instead of using struct lock for the kernel lock and thus requiring us 182: * XXX to implement simplelocks, causing all sorts of fine-grained locks all 183: * XXX over our tree getting activated consuming both time and potentially 184: * XXX introducing locking protocol bugs. 185: */ 186: extern struct __mp_lock sched_lock; 187: 188: #define SCHED_ASSERT_LOCKED() KASSERT(__mp_lock_held(&sched_lock)) 189: #define SCHED_ASSERT_UNLOCKED() KASSERT(__mp_lock_held(&sched_lock) == 0) 190: 191: #define SCHED_LOCK_INIT() __mp_lock_init(&sched_lock) 192: 193: #define SCHED_LOCK(s) \ 194: do { \ 195: s = splsched(); \ 196: __mp_lock(&sched_lock); \ 197: } while (/* CONSTCOND */ 0) 198: 199: #define SCHED_UNLOCK(s) \ 200: do { \ 201: __mp_unlock(&sched_lock); \ 202: splx(s); \ 203: } while (/* CONSTCOND */ 0) 204: 205: #else /* ! MULTIPROCESSOR || LOCKDEBUG */ 206: 207: #define SCHED_ASSERT_LOCKED() splassert(IPL_SCHED); 208: #define SCHED_ASSERT_UNLOCKED() /* nothing */ 209: 210: #define SCHED_LOCK_INIT() /* nothing */ 211: 212: #define SCHED_LOCK(s) s = splsched() 213: #define SCHED_UNLOCK(s) splx(s) 214: 215: #endif /* MULTIPROCESSOR || LOCKDEBUG */ 216: 217: #endif /* _KERNEL */ 218: #endif /* _SYS_SCHED_H_ */