[BACK]Return to sched.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

Annotation of src/sys/sys/sched.h, Revision 1.26.6.1

1.26.6.1! simonb      1: /* $NetBSD: sched.h,v 1.27 2006/03/26 20:19:52 erh Exp $ */
1.1       ross        2:
                      3: /*-
1.15      thorpej     4:  * Copyright (c) 1999, 2000, 2001, 2002 The NetBSD Foundation, Inc.
1.1       ross        5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
1.15      thorpej     8:  * by Ross Harvey, Jason R. Thorpe, and Nathan J. Williams.
1.1       ross        9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *        This product includes software developed by the NetBSD
                     21:  *        Foundation, Inc. and its contributors.
                     22:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     23:  *    contributors may be used to endorse or promote products derived
                     24:  *    from this software without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     27:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     30:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36:  * POSSIBILITY OF SUCH DAMAGE.
                     37:  */
                     38:
                     39: /*-
                     40:  * Copyright (c) 1982, 1986, 1991, 1993
                     41:  *     The Regents of the University of California.  All rights reserved.
                     42:  * (c) UNIX System Laboratories, Inc.
                     43:  * All or some portions of this file are derived from material licensed
                     44:  * to the University of California by American Telephone and Telegraph
                     45:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     46:  * the permission of UNIX System Laboratories, Inc.
                     47:  *
                     48:  * Redistribution and use in source and binary forms, with or without
                     49:  * modification, are permitted provided that the following conditions
                     50:  * are met:
                     51:  * 1. Redistributions of source code must retain the above copyright
                     52:  *    notice, this list of conditions and the following disclaimer.
                     53:  * 2. Redistributions in binary form must reproduce the above copyright
                     54:  *    notice, this list of conditions and the following disclaimer in the
                     55:  *    documentation and/or other materials provided with the distribution.
1.19      agc        56:  * 3. Neither the name of the University nor the names of its contributors
1.1       ross       57:  *    may be used to endorse or promote products derived from this software
                     58:  *    without specific prior written permission.
                     59:  *
                     60:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     61:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     62:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     63:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     64:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     65:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     66:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     67:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     68:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     69:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     70:  * SUCH DAMAGE.
                     71:  *
                     72:  *     @(#)kern_clock.c        8.5 (Berkeley) 1/21/94
                     73:  */
                     74:
                     75: #ifndef        _SYS_SCHED_H_
                     76: #define        _SYS_SCHED_H_
                     77:
1.17      bjh21      78: #include <sys/featuretest.h>
                     79:
1.13      mrg        80: #if defined(_KERNEL_OPT)
1.6       thorpej    81: #include "opt_multiprocessor.h"
                     82: #include "opt_lockdebug.h"
                     83: #endif
                     84:
1.15      thorpej    85: struct sched_param {
                     86:        int     sched_priority;
                     87: };
                     88:
1.1       ross       89: /*
1.15      thorpej    90:  * Scheduling policies required by IEEE Std 1003.1-2001
1.1       ross       91:  */
1.15      thorpej    92: #define        SCHED_OTHER     0       /* Behavior can be FIFO or RR, or not */
                     93: #define        SCHED_FIFO      1
                     94: #define        SCHED_RR        2
                     95:
                     96: /* Other nonstandard policies: */
1.1       ross       97:
1.17      bjh21      98: #if defined(_NETBSD_SOURCE)
1.4       sommerfe   99:
                    100: #include <sys/time.h>
                    101:
1.3       thorpej   102: /*
                    103:  * Sleep queues.
                    104:  */
                    105: struct slpque {
1.15      thorpej   106:        struct lwp *sq_head;
                    107:        struct lwp **sq_tailp;
1.3       thorpej   108: };
                    109:
                    110: /*
                    111:  * Run queues.
                    112:  *
                    113:  * We have 32 run queues in descending priority of 0..31.  We maintain
                    114:  * a bitmask of non-empty queues in order speed up finding the first
                    115:  * runnable process.  The bitmask is maintained only by machine-dependent
                    116:  * code, allowing the most efficient instructions to be used to find the
                    117:  * first non-empty queue.
                    118:  */
                    119: #define        RUNQUE_NQS              32
                    120: struct prochd {
1.15      thorpej   121:        struct lwp *ph_link;
                    122:        struct lwp *ph_rlink;
1.3       thorpej   123: };
                    124:
                    125: /*
1.5       thorpej   126:  * CPU states.
                    127:  * XXX Not really scheduler state, but no other good place to put
                    128:  * it right now, and it really is per-CPU.
                    129:  */
                    130: #define        CP_USER         0
                    131: #define        CP_NICE         1
                    132: #define        CP_SYS          2
                    133: #define        CP_INTR         3
                    134: #define        CP_IDLE         4
                    135: #define        CPUSTATES       5
                    136:
                    137: /*
1.3       thorpej   138:  * Per-CPU scheduler state.
                    139:  */
                    140: struct schedstate_percpu {
                    141:        struct timeval spc_runtime;     /* time curproc started running */
1.25      perry     142:        volatile int spc_flags; /* flags; see below */
1.5       thorpej   143:        u_int spc_schedticks;           /* ticks for schedclock() */
1.26      perry     144:        uint64_t spc_cp_time[CPUSTATES]; /* CPU state statistics */
1.3       thorpej   145:        u_char spc_curpriority;         /* usrpri of curproc */
1.8       sommerfe  146:        int spc_rrticks;                /* ticks until roundrobin() */
                    147:        int spc_pscnt;                  /* prof/stat counter */
1.20      perry     148:        int spc_psdiv;                  /* prof/stat divisor */
1.3       thorpej   149: };
                    150:
                    151: /* spc_flags */
                    152: #define        SPCF_SEENRR             0x0001  /* process has seen roundrobin() */
                    153: #define        SPCF_SHOULDYIELD        0x0002  /* process should yield the CPU */
                    154:
                    155: #define        SPCF_SWITCHCLEAR        (SPCF_SEENRR|SPCF_SHOULDYIELD)
                    156:
1.14      thorpej   157: /*
                    158:  * Flags passed to the Linux-compatible __clone(2) system call.
                    159:  */
                    160: #define        CLONE_CSIGNAL           0x000000ff      /* signal to be sent at exit */
                    161: #define        CLONE_VM                0x00000100      /* share address space */
                    162: #define        CLONE_FS                0x00000200      /* share "file system" info */
                    163: #define        CLONE_FILES             0x00000400      /* share file descriptors */
                    164: #define        CLONE_SIGHAND           0x00000800      /* share signal actions */
                    165: #define        CLONE_PID               0x00001000      /* share process ID */
1.20      perry     166: #define        CLONE_PTRACE            0x00002000      /* ptrace(2) continues on
1.14      thorpej   167:                                                   child */
                    168: #define        CLONE_VFORK             0x00004000      /* parent blocks until child
                    169:                                                   exits */
                    170:
1.3       thorpej   171: #endif /* !_POSIX_SOURCE && !_XOPEN_SOURCE && !_ANSI_SOURCE */
                    172:
1.14      thorpej   173: #ifdef _KERNEL
1.1       ross      174:
1.12      simonb    175: extern int schedhz;                    /* ideally: 16 */
                    176: extern int rrticks;                    /* ticks per roundrobin() */
1.1       ross      177:
1.3       thorpej   178: /*
                    179:  * Global scheduler state.  We would like to group these all together
                    180:  * in a single structure to make them easier to find, but leaving
                    181:  * whichqs and qs as independent globals makes for more efficient
                    182:  * assembly language in the low-level context switch code.  So we
                    183:  * simply give them meaningful names; the globals are actually declared
                    184:  * in kern/kern_synch.c.
                    185:  */
                    186: extern struct prochd sched_qs[];
1.26      perry     187: extern volatile uint32_t sched_whichqs;
1.3       thorpej   188:
                    189: struct proc;
1.10      sommerfe  190: struct cpu_info;
1.3       thorpej   191:
1.18      itojun    192: void schedclock(struct lwp *);
1.25      perry     193: void sched_wakeup(volatile const void *);
1.9       sommerfe  194: void roundrobin(struct cpu_info *);
1.3       thorpej   195:
1.22      yamt      196: void scheduler_fork_hook(struct proc *, struct proc *);
                    197: void scheduler_wait_hook(struct proc *, struct proc *);
1.6       thorpej   198:
                    199: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
                    200: #include <sys/lock.h>
                    201:
                    202: extern struct simplelock sched_lock;
                    203:
1.26.6.1! simonb    204: #define        SCHED_ASSERT_LOCKED()   simple_lock_assert_locked(&sched_lock, "sched_lock")
        !           205: #define        SCHED_ASSERT_UNLOCKED() simple_lock_assert_unlocked(&sched_lock, "sched_lock")
        !           206:
1.6       thorpej   207:
                    208: #define        SCHED_LOCK(s)                                                   \
                    209: do {                                                                   \
1.7       thorpej   210:        s = splsched();                                                 \
1.6       thorpej   211:        simple_lock(&sched_lock);                                       \
1.11      lukem     212: } while (/* CONSTCOND */ 0)
1.6       thorpej   213:
                    214: #define        SCHED_UNLOCK(s)                                                 \
                    215: do {                                                                   \
                    216:        simple_unlock(&sched_lock);                                     \
                    217:        splx(s);                                                        \
1.11      lukem     218: } while (/* CONSTCOND */ 0)
1.6       thorpej   219:
                    220: void   sched_lock_idle(void);
                    221: void   sched_unlock_idle(void);
                    222:
                    223: #else /* ! MULTIPROCESSOR || LOCKDEBUG */
                    224:
                    225: #define        SCHED_ASSERT_LOCKED()           /* nothing */
                    226: #define        SCHED_ASSERT_UNLOCKED()         /* nothing */
                    227:
1.7       thorpej   228: #define        SCHED_LOCK(s)                   s = splsched()
1.6       thorpej   229: #define        SCHED_UNLOCK(s)                 splx(s)
                    230:
                    231: #endif /* MULTIPROCESSOR || LOCKDEBUG */
                    232:
1.1       ross      233: #endif /* _KERNEL */
                    234: #endif /* _SYS_SCHED_H_ */

CVSweb <webmaster@jp.NetBSD.org>