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 /*-
    2  * Copyright (c) 1996, 1997
    3  *      HD Associates, Inc.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *      This product includes software developed by HD Associates, Inc
   16  *      and Jukka Antero Ukkonen.
   17  * 4. Neither the name of the author nor the names of any co-contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
   25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   31  * SUCH DAMAGE.
   32  */
   33 
   34 /*-
   35  * Copyright (c) 2002-2008, Jeffrey Roberson <jeff@freebsd.org>
   36  * All rights reserved.
   37  *
   38  * Redistribution and use in source and binary forms, with or without
   39  * modification, are permitted provided that the following conditions
   40  * are met:
   41  * 1. Redistributions of source code must retain the above copyright
   42  *    notice unmodified, this list of conditions, and the following
   43  *    disclaimer.
   44  * 2. Redistributions in binary form must reproduce the above copyright
   45  *    notice, this list of conditions and the following disclaimer in the
   46  *    documentation and/or other materials provided with the distribution.
   47  *
   48  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   49  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   50  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   51  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   52  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   53  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   54  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   55  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   56  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   57  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   58  *
   59  * $FreeBSD: releng/8.0/sys/sys/sched.h 194936 2009-06-25 01:33:51Z jeff $
   60  */
   61 
   62 #ifndef _SCHED_H_
   63 #define _SCHED_H_
   64 
   65 #ifdef _KERNEL
   66 /*
   67  * General scheduling info.
   68  *
   69  * sched_load:
   70  *      Total runnable non-ithread threads in the system.
   71  *
   72  * sched_runnable:
   73  *      Runnable threads for this processor.
   74  */
   75 int     sched_load(void);
   76 int     sched_rr_interval(void);
   77 int     sched_runnable(void);
   78 
   79 /* 
   80  * Proc related scheduling hooks.
   81  */
   82 void    sched_exit(struct proc *p, struct thread *childtd);
   83 void    sched_fork(struct thread *td, struct thread *childtd);
   84 void    sched_fork_exit(struct thread *td);
   85 void    sched_class(struct thread *td, int class);
   86 void    sched_nice(struct proc *p, int nice);
   87 
   88 /*
   89  * Threads are switched in and out, block on resources, have temporary
   90  * priorities inherited from their procs, and use up cpu time.
   91  */
   92 void    sched_exit_thread(struct thread *td, struct thread *child);
   93 void    sched_fork_thread(struct thread *td, struct thread *child);
   94 void    sched_lend_prio(struct thread *td, u_char prio);
   95 void    sched_lend_user_prio(struct thread *td, u_char pri);
   96 fixpt_t sched_pctcpu(struct thread *td);
   97 void    sched_prio(struct thread *td, u_char prio);
   98 void    sched_sleep(struct thread *td, int prio);
   99 void    sched_switch(struct thread *td, struct thread *newtd, int flags);
  100 void    sched_throw(struct thread *td);
  101 void    sched_unlend_prio(struct thread *td, u_char prio);
  102 void    sched_unlend_user_prio(struct thread *td, u_char pri);
  103 void    sched_user_prio(struct thread *td, u_char prio);
  104 void    sched_userret(struct thread *td);
  105 void    sched_wakeup(struct thread *td);
  106 void    sched_preempt(struct thread *td);
  107 
  108 /*
  109  * Threads are moved on and off of run queues
  110  */
  111 void    sched_add(struct thread *td, int flags);
  112 void    sched_clock(struct thread *td);
  113 void    sched_rem(struct thread *td);
  114 void    sched_tick(void);
  115 void    sched_relinquish(struct thread *td);
  116 struct thread *sched_choose(void);
  117 void    sched_idletd(void *);
  118 
  119 /*
  120  * Binding makes cpu affinity permanent while pinning is used to temporarily
  121  * hold a thread on a particular CPU.
  122  */
  123 void    sched_bind(struct thread *td, int cpu);
  124 static __inline void sched_pin(void);
  125 void    sched_unbind(struct thread *td);
  126 static __inline void sched_unpin(void);
  127 int     sched_is_bound(struct thread *td);
  128 void    sched_affinity(struct thread *td);
  129 
  130 /*
  131  * These procedures tell the process data structure allocation code how
  132  * many bytes to actually allocate.
  133  */
  134 int     sched_sizeof_proc(void);
  135 int     sched_sizeof_thread(void);
  136 
  137 /*
  138  * This routine provides a consistent thread name for use with KTR graphing
  139  * functions.
  140  */
  141 char    *sched_tdname(struct thread *td);
  142 
  143 static __inline void
  144 sched_pin(void)
  145 {
  146         curthread->td_pinned++;
  147 }
  148 
  149 static __inline void
  150 sched_unpin(void)
  151 {
  152         curthread->td_pinned--;
  153 }
  154 
  155 /* sched_add arguments (formerly setrunqueue) */
  156 #define SRQ_BORING      0x0000          /* No special circumstances. */
  157 #define SRQ_YIELDING    0x0001          /* We are yielding (from mi_switch). */
  158 #define SRQ_OURSELF     0x0002          /* It is ourself (from mi_switch). */
  159 #define SRQ_INTR        0x0004          /* It is probably urgent. */
  160 #define SRQ_PREEMPTED   0x0008          /* has been preempted.. be kind */
  161 #define SRQ_BORROWING   0x0010          /* Priority updated due to prio_lend */
  162 
  163 /* Scheduler stats. */
  164 #ifdef SCHED_STATS
  165 DPCPU_DECLARE(long, sched_switch_stats[SWT_COUNT]);
  166 
  167 #define SCHED_STAT_DEFINE_VAR(name, ptr, descr)                         \
  168 static void name ## _add_proc(void *dummy __unused)                     \
  169 {                                                                       \
  170                                                                         \
  171         SYSCTL_ADD_PROC(NULL,                                           \
  172             SYSCTL_STATIC_CHILDREN(_kern_sched_stats), OID_AUTO,        \
  173             #name, CTLTYPE_LONG|CTLFLAG_RD|CTLFLAG_MPSAFE,              \
  174             ptr, 0, sysctl_dpcpu_long, "LU", descr);                    \
  175 }                                                                       \
  176 SYSINIT(name, SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY, name ## _add_proc, NULL);
  177 
  178 #define SCHED_STAT_DEFINE(name, descr)                                  \
  179     DPCPU_DEFINE(unsigned long, name);                                  \
  180     SCHED_STAT_DEFINE_VAR(name, &DPCPU_NAME(name), descr)
  181 /*
  182  * Sched stats are always incremented in critical sections so no atomic
  183  * is necesssary to increment them.
  184  */
  185 #define SCHED_STAT_INC(var)     DPCPU_GET(var)++;
  186 #else
  187 #define SCHED_STAT_DEFINE_VAR(name, descr, ptr)
  188 #define SCHED_STAT_DEFINE(name, descr)
  189 #define SCHED_STAT_INC(var)                     (void)0
  190 #endif
  191 
  192 /*
  193  * Fixup scheduler state for proc0 and thread0
  194  */
  195 void schedinit(void);
  196 #endif /* _KERNEL */
  197 
  198 /* POSIX 1003.1b Process Scheduling */
  199 
  200 /*
  201  * POSIX scheduling policies
  202  */
  203 #define SCHED_FIFO      1
  204 #define SCHED_OTHER     2
  205 #define SCHED_RR        3
  206 
  207 struct sched_param {
  208         int     sched_priority;
  209 };
  210 
  211 /*
  212  * POSIX scheduling declarations for userland.
  213  */
  214 #ifndef _KERNEL
  215 #include <sys/cdefs.h>
  216 #include <sys/_types.h>
  217 
  218 #ifndef _PID_T_DECLARED
  219 typedef __pid_t         pid_t;
  220 #define _PID_T_DECLARED
  221 #endif
  222 
  223 struct timespec;
  224 
  225 __BEGIN_DECLS
  226 int     sched_get_priority_max(int);
  227 int     sched_get_priority_min(int);
  228 int     sched_getparam(pid_t, struct sched_param *);
  229 int     sched_getscheduler(pid_t);
  230 int     sched_rr_get_interval(pid_t, struct timespec *);
  231 int     sched_setparam(pid_t, const struct sched_param *);
  232 int     sched_setscheduler(pid_t, int, const struct sched_param *);
  233 int     sched_yield(void);
  234 __END_DECLS
  235 
  236 #endif
  237 #endif /* !_SCHED_H_ */

Cache object: e59e75054a6518d792429b48e60c1610


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