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/sys/sched.h

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 /* $NetBSD: sched.h,v 1.28 2006/05/14 21:38:18 elad Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 1999, 2000, 2001, 2002 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Ross Harvey, Jason R. Thorpe, and Nathan J. Williams.
    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.
   56  * 3. Neither the name of the University nor the names of its contributors
   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 
   78 #include <sys/featuretest.h>
   79 
   80 #if defined(_KERNEL_OPT)
   81 #include "opt_multiprocessor.h"
   82 #include "opt_lockdebug.h"
   83 #endif
   84 
   85 struct sched_param {
   86         int     sched_priority;
   87 };
   88 
   89 /*
   90  * Scheduling policies required by IEEE Std 1003.1-2001
   91  */
   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: */
   97 
   98 #if defined(_NETBSD_SOURCE)
   99 
  100 #include <sys/time.h>
  101 
  102 /*
  103  * Sleep queues.
  104  */
  105 struct slpque {
  106         struct lwp *sq_head;
  107         struct lwp **sq_tailp;
  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 {
  121         struct lwp *ph_link;
  122         struct lwp *ph_rlink;
  123 };
  124 
  125 /*
  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 /*
  138  * Per-CPU scheduler state.
  139  */
  140 struct schedstate_percpu {
  141         struct timeval spc_runtime;     /* time curproc started running */
  142         volatile int spc_flags; /* flags; see below */
  143         u_int spc_schedticks;           /* ticks for schedclock() */
  144         uint64_t spc_cp_time[CPUSTATES]; /* CPU state statistics */
  145         u_char spc_curpriority;         /* usrpri of curproc */
  146         int spc_rrticks;                /* ticks until roundrobin() */
  147         int spc_pscnt;                  /* prof/stat counter */
  148         int spc_psdiv;                  /* prof/stat divisor */
  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 
  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 */
  166 #define CLONE_PTRACE            0x00002000      /* ptrace(2) continues on
  167                                                    child */
  168 #define CLONE_VFORK             0x00004000      /* parent blocks until child
  169                                                    exits */
  170 
  171 #endif /* !_POSIX_SOURCE && !_XOPEN_SOURCE && !_ANSI_SOURCE */
  172 
  173 #ifdef _KERNEL
  174 
  175 extern int schedhz;                     /* ideally: 16 */
  176 extern int rrticks;                     /* ticks per roundrobin() */
  177 
  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[];
  187 extern volatile uint32_t sched_whichqs;
  188 
  189 struct proc;
  190 struct cpu_info;
  191 
  192 void schedclock(struct lwp *);
  193 void sched_wakeup(volatile const void *);
  194 void roundrobin(struct cpu_info *);
  195 
  196 void scheduler_fork_hook(struct proc *, struct proc *);
  197 void scheduler_wait_hook(struct proc *, struct proc *);
  198 
  199 #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
  200 #include <sys/lock.h>
  201 
  202 extern struct simplelock sched_lock;
  203 
  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 
  207 
  208 #define SCHED_LOCK(s)                                                   \
  209 do {                                                                    \
  210         s = splsched();                                                 \
  211         simple_lock(&sched_lock);                                       \
  212 } while (/* CONSTCOND */ 0)
  213 
  214 #define SCHED_UNLOCK(s)                                                 \
  215 do {                                                                    \
  216         simple_unlock(&sched_lock);                                     \
  217         splx(s);                                                        \
  218 } while (/* CONSTCOND */ 0)
  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 
  228 #define SCHED_LOCK(s)                   s = splsched()
  229 #define SCHED_UNLOCK(s)                 splx(s)
  230 
  231 #endif /* MULTIPROCESSOR || LOCKDEBUG */
  232 
  233 #endif  /* _KERNEL */
  234 #endif  /* _SYS_SCHED_H_ */

Cache object: 70099a7051c90a439a0fd44649e2b4ba


[ 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.