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.91 2022/10/26 23:24:09 riastradh Exp $     */
    2 
    3 /*-
    4  * Copyright (c) 1999, 2000, 2001, 2002, 2007, 2008, 2019, 2020
    5  *    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, Jason R. Thorpe, Nathan J. Williams, Andrew Doran and
   10  * Daniel Sieger.
   11  *
   12  * Redistribution and use in source and binary forms, with or without
   13  * modification, are permitted provided that the following conditions
   14  * are met:
   15  * 1. Redistributions of source code must retain the above copyright
   16  *    notice, this list of conditions and the following disclaimer.
   17  * 2. Redistributions in binary form must reproduce the above copyright
   18  *    notice, this list of conditions and the following disclaimer in the
   19  *    documentation and/or other materials provided with the distribution.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   31  * POSSIBILITY OF SUCH DAMAGE.
   32  */
   33 
   34 /*-
   35  * Copyright (c) 1982, 1986, 1991, 1993
   36  *      The Regents of the University of California.  All rights reserved.
   37  * (c) UNIX System Laboratories, Inc.
   38  * All or some portions of this file are derived from material licensed
   39  * to the University of California by American Telephone and Telegraph
   40  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
   41  * the permission of UNIX System Laboratories, Inc.
   42  *
   43  * Redistribution and use in source and binary forms, with or without
   44  * modification, are permitted provided that the following conditions
   45  * are met:
   46  * 1. Redistributions of source code must retain the above copyright
   47  *    notice, this list of conditions and the following disclaimer.
   48  * 2. Redistributions in binary form must reproduce the above copyright
   49  *    notice, this list of conditions and the following disclaimer in the
   50  *    documentation and/or other materials provided with the distribution.
   51  * 3. Neither the name of the University nor the names of its contributors
   52  *    may be used to endorse or promote products derived from this software
   53  *    without specific prior written permission.
   54  *
   55  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   58  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   65  * SUCH DAMAGE.
   66  *
   67  *      @(#)kern_clock.c        8.5 (Berkeley) 1/21/94
   68  */
   69 
   70 #ifndef _SYS_SCHED_H_
   71 #define _SYS_SCHED_H_
   72 
   73 #include <sys/featuretest.h>
   74 #include <sys/types.h>
   75 
   76 #if defined(_KERNEL_OPT)
   77 #include "opt_multiprocessor.h"
   78 #include "opt_lockdebug.h"
   79 #endif
   80 
   81 struct sched_param {
   82         int     sched_priority;
   83 };
   84 
   85 /*
   86  * Scheduling policies required by IEEE Std 1003.1-2001
   87  */
   88 #define SCHED_NONE      -1
   89 #define SCHED_OTHER     0
   90 #define SCHED_FIFO      1
   91 #define SCHED_RR        2
   92 
   93 #if defined(_NETBSD_SOURCE)
   94 __BEGIN_DECLS
   95 
   96 /*
   97  * Interface of CPU-sets.
   98  */
   99 typedef struct _cpuset cpuset_t;
  100 
  101 #ifndef _KERNEL
  102 
  103 #define cpuset_create()         _cpuset_create()
  104 #define cpuset_destroy(c)       _cpuset_destroy(c)
  105 #define cpuset_size(c)          _cpuset_size(c)
  106 #define cpuset_zero(c)          _cpuset_zero(c)
  107 #define cpuset_isset(i, c)      _cpuset_isset(i, c)
  108 #define cpuset_set(i, c)        _cpuset_set(i, c)
  109 #define cpuset_clr(i, c)        _cpuset_clr(i, c)
  110 
  111 cpuset_t *_cpuset_create(void);
  112 void    _cpuset_destroy(cpuset_t *);
  113 void    _cpuset_zero(cpuset_t *);
  114 int     _cpuset_set(cpuid_t, cpuset_t *);
  115 int     _cpuset_clr(cpuid_t, cpuset_t *);
  116 int     _cpuset_isset(cpuid_t, const cpuset_t *);
  117 size_t  _cpuset_size(const cpuset_t *);
  118 
  119 #endif
  120 
  121 /*
  122  * Internal affinity and scheduling calls.
  123  */
  124 int     _sched_getaffinity(pid_t, lwpid_t, size_t, cpuset_t *);
  125 int     _sched_setaffinity(pid_t, lwpid_t, size_t, const cpuset_t *);
  126 int     _sched_getparam(pid_t, lwpid_t, int *, struct sched_param *);
  127 int     _sched_setparam(pid_t, lwpid_t, int, const struct sched_param *);
  128 int     _sched_protect(int);
  129 __END_DECLS
  130 
  131 /*
  132  * CPU states.
  133  * XXX Not really scheduler state, but no other good place to put
  134  * it right now, and it really is per-CPU.
  135  */
  136 #define CP_USER         0
  137 #define CP_NICE         1
  138 #define CP_SYS          2
  139 #define CP_INTR         3
  140 #define CP_IDLE         4
  141 #define CPUSTATES       5
  142 
  143 #if defined(_KERNEL) || defined(_KMEMUSER)
  144 
  145 #include <sys/mutex.h>
  146 #include <sys/time.h>
  147 #include <sys/queue.h>
  148 
  149 /*
  150  * Per-CPU scheduler state.  Field markings and the corresponding locks: 
  151  *
  152  * s:   splsched, may only be safely accessed by the CPU itself
  153  * m:   spc_mutex
  154  * (:   unlocked, stable
  155  * c:   cpu_lock
  156  */
  157 struct schedstate_percpu {
  158         kmutex_t        *spc_mutex;     /* (: lock on below, runnable LWPs */
  159         kmutex_t        *spc_lwplock;   /* (: general purpose lock for LWPs */
  160         struct lwp      *spc_migrating; /* (: migrating LWP */
  161         struct cpu_info *spc_nextpkg;   /* (: next package 1st for RR */
  162         psetid_t        spc_psid;       /* c: processor-set ID */
  163         time_t          spc_lastmod;    /* c: time of last cpu state change */
  164         volatile int    spc_flags;      /* s: flags; see below */
  165         u_int           spc_schedticks; /* s: ticks for schedclock() */
  166         uint64_t        spc_cp_time[CPUSTATES];/* s: CPU state statistics */
  167         int             spc_ticks;      /* s: ticks until sched_tick() */
  168         int             spc_pscnt;      /* s: prof/stat counter */
  169         int             spc_psdiv;      /* s: prof/stat divisor */
  170         int             spc_nextskim;   /* s: next time to skim other queues */
  171         /* Run queue */
  172         volatile pri_t  spc_curpriority;/* s: usrpri of curlwp */
  173         pri_t           spc_maxpriority;/* m: highest priority queued */
  174         u_int           spc_count;      /* m: count of the threads */
  175         u_int           spc_mcount;     /* m: count of migratable threads */
  176         uint32_t        spc_bitmap[8];  /* m: bitmap of active queues */
  177         TAILQ_HEAD(,lwp) *spc_queue;    /* m: queue for each priority */
  178 };
  179 
  180 /* spc_flags */
  181 #define SPCF_SEENRR             0x0001  /* process has seen roundrobin() */
  182 #define SPCF_SHOULDYIELD        0x0002  /* process should yield the CPU */
  183 #define SPCF_OFFLINE            0x0004  /* CPU marked offline */
  184 #define SPCF_RUNNING            0x0008  /* CPU is running */
  185 #define SPCF_NOINTR             0x0010  /* shielded from interrupts */
  186 #define SPCF_IDLE               0x0020  /* CPU is currently idle */
  187 #define SPCF_1STCLASS           0x0040  /* first class scheduling entity */
  188 #define SPCF_CORE1ST            0x0100  /* first CPU in core */
  189 #define SPCF_PACKAGE1ST         0x0200  /* first CPU in package */
  190 
  191 #define SPCF_SWITCHCLEAR        (SPCF_SEENRR|SPCF_SHOULDYIELD)
  192 
  193 #endif /* defined(_KERNEL) || defined(_KMEMUSER) */
  194 
  195 /*
  196  * Flags passed to the Linux-compatible __clone(2) system call.
  197  */
  198 #define CLONE_CSIGNAL           0x000000ff      /* signal to be sent at exit */
  199 #define CLONE_VM                0x00000100      /* share address space */
  200 #define CLONE_FS                0x00000200      /* share "file system" info */
  201 #define CLONE_FILES             0x00000400      /* share file descriptors */
  202 #define CLONE_SIGHAND           0x00000800      /* share signal actions */
  203 #define CLONE_PTRACE            0x00002000      /* ptrace(2) continues on
  204                                                    child */
  205 #define CLONE_VFORK             0x00004000      /* parent blocks until child
  206                                                    exits */
  207 
  208 #endif /* _NETBSD_SOURCE */
  209 
  210 #ifdef _KERNEL
  211 
  212 extern int schedhz;                     /* ideally: 16 */
  213 extern u_int sched_rrticks;
  214 extern u_int sched_pstats_ticks;
  215 
  216 struct proc;
  217 struct cpu_info;
  218 
  219 /*
  220  * Common Scheduler Interface.
  221  */
  222 
  223 /* Scheduler initialization */
  224 void            runq_init(void);
  225 void            synch_init(void);
  226 void            sched_init(void);
  227 void            sched_rqinit(void);
  228 void            sched_cpuattach(struct cpu_info *);
  229 
  230 /* Time-driven events */
  231 void            sched_tick(struct cpu_info *);
  232 void            schedclock(struct lwp *);
  233 void            sched_schedclock(struct lwp *);
  234 void            sched_pstats(void);
  235 void            sched_lwp_stats(struct lwp *);
  236 void            sched_pstats_hook(struct lwp *, int);
  237 
  238 /* Runqueue-related functions */
  239 bool            sched_curcpu_runnable_p(void);
  240 void            sched_dequeue(struct lwp *);
  241 void            sched_enqueue(struct lwp *);
  242 void            sched_preempted(struct lwp *);
  243 void            sched_resched_cpu(struct cpu_info *, pri_t, bool);
  244 void            sched_resched_lwp(struct lwp *, bool);
  245 struct lwp *    sched_nextlwp(void);
  246 void            sched_oncpu(struct lwp *);
  247 void            sched_newts(struct lwp *);
  248 void            sched_vforkexec(struct lwp *, bool);
  249 
  250 /* Priority adjustment */
  251 void            sched_nice(struct proc *, int);
  252 
  253 /* Handlers of fork and exit */
  254 void            sched_proc_fork(struct proc *, struct proc *);
  255 void            sched_proc_exit(struct proc *, struct proc *);
  256 void            sched_lwp_fork(struct lwp *, struct lwp *);
  257 void            sched_lwp_collect(struct lwp *);
  258 
  259 void            sched_slept(struct lwp *);
  260 void            sched_wakeup(struct lwp *);
  261 
  262 void            setrunnable(struct lwp *);
  263 void            sched_setrunnable(struct lwp *);
  264 
  265 struct cpu_info *sched_takecpu(struct lwp *);
  266 void            sched_print_runqueue(void (*pr)(const char *, ...)
  267     __printflike(1, 2));
  268 
  269 /* Dispatching */
  270 bool            kpreempt(uintptr_t);
  271 void            preempt(void);
  272 bool            preempt_needed(void);
  273 void            preempt_point(void);
  274 void            yield(void);
  275 void            mi_switch(struct lwp *);
  276 void            updatertime(lwp_t *, const struct bintime *);
  277 void            sched_idle(void);
  278 void            suspendsched(void);
  279 
  280 int             do_sched_setparam(pid_t, lwpid_t, int, const struct sched_param *);
  281 int             do_sched_getparam(pid_t, lwpid_t, int *, struct sched_param *);
  282 
  283 #endif  /* _KERNEL */
  284 #endif  /* _SYS_SCHED_H_ */

Cache object: abfb737c99d80806596cddea53f770f6


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