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/kern/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  * Mach Operating System
    3  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
    4  * All Rights Reserved.
    5  * 
    6  * Permission to use, copy, modify and distribute this software and its
    7  * documentation is hereby granted, provided that both the copyright
    8  * notice and this permission notice appear in all copies of the
    9  * software, derivative works or modified versions, and any portions
   10  * thereof, and that both notices appear in supporting documentation.
   11  * 
   12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   15  * 
   16  * Carnegie Mellon requests users of this software to return to
   17  * 
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  * 
   23  * any improvements or extensions that they make and grant Carnegie Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /*
   27  * HISTORY
   28  * $Log:        sched.h,v $
   29  * Revision 2.5  91/05/14  16:46:04  mrt
   30  *      Correcting copyright
   31  * 
   32  * Revision 2.4  91/02/05  17:28:50  mrt
   33  *      Changed to new Mach copyright
   34  *      [91/02/01  16:16:37  mrt]
   35  * 
   36  * Revision 2.3  90/08/07  17:58:47  rpd
   37  *      Picked up fix to MACH_FIXPRI version of csw_needed.
   38  *      [90/08/07            rpd]
   39  * 
   40  * Revision 2.2  90/06/02  14:55:44  rpd
   41  *      Updated to new scheduling technology.
   42  *      [90/03/26  22:15:22  rpd]
   43  * 
   44  * Revision 2.1  89/08/03  15:52:50  rwd
   45  * Created.
   46  * 
   47  * 20-Oct-88  David Golub (dbg) at Carnegie-Mellon University
   48  *      Use macro_help to avoid lint.
   49  *
   50  * 11-Aug-88  David Black (dlb) at Carnegie-Mellon University
   51  *      Make csw_needed a macro here.  Ignore first_quantum for local_runq.
   52  *
   53  *  9-Aug-88  David Black (dlb) at Carnegie-Mellon University
   54  *      No more runrun.
   55  *
   56  * 18-May-88  David Black (dlb) at Carnegie-Mellon University
   57  *      Added shutdown queue for shutdown thread.
   58  *
   59  * 29-Mar-88  David Black (dlb) at Carnegie-Mellon University
   60  *      SIMPLE_CLOCK: added sched_usec for drift compensation.
   61  *
   62  * 25-Mar-88  David Black (dlb) at Carnegie-Mellon University
   63  *      Added sched_load and related constants.  Moved thread_timer_delta
   64  *      here because it depends on sched_load.
   65  *
   66  * 19-Feb-88  David Black (dlb) at Carnegie-Mellon University
   67  *      Added sched_tick and shift definitions for more flexible ageing.
   68  *
   69  * 18-Nov-87  Avadis Tevanian (avie) at Carnegie-Mellon University
   70  *      Removed conditionals, purged history.
   71  */
   72 /*
   73  *      File:   sched.h
   74  *      Author: Avadis Tevanian, Jr.
   75  *      Date:   1985
   76  *
   77  *      Header file for scheduler.
   78  *
   79  */
   80 
   81 #ifndef _KERN_SCHED_H_
   82 #define _KERN_SCHED_H_
   83 
   84 #include <cpus.h>
   85 #include <mach_fixpri.h>
   86 #include <simple_clock.h>
   87 #include <stat_time.h>
   88 
   89 #include <kern/queue.h>
   90 #include <kern/lock.h>
   91 #include <kern/macro_help.h>
   92 
   93 #if     MACH_FIXPRI
   94 #include <mach/policy.h>
   95 #endif  MACH_FIXPRI
   96 
   97 #if     STAT_TIME
   98 
   99 /*
  100  *      Statistical timing uses microseconds as timer units.  18 bit shift
  101  *      yields priorities.  PRI_SHIFT_2 isn't needed.
  102  */
  103 #define PRI_SHIFT       18
  104 
  105 #else   STAT_TIME
  106 
  107 /*
  108  *      Otherwise machine provides shift(s) based on time units it uses.
  109  */
  110 #include <machine/sched_param.h>
  111 
  112 #endif  STAT_TIME
  113 #define NRQS    32                      /* 32 run queues per cpu */
  114 
  115 struct run_queue {
  116         queue_head_t            runq[NRQS];     /* one for each priority */
  117         decl_simple_lock_data(, lock)           /* one lock for all queues */
  118         int                     low;            /* low queue value */
  119         int                     count;          /* count of threads runable */
  120 };
  121 
  122 typedef struct run_queue        *run_queue_t;
  123 #define RUN_QUEUE_NULL  ((run_queue_t) 0)
  124 
  125 #if     MACH_FIXPRI
  126 /*
  127  *      NOTE: For fixed priority threads, first_quantum indicates
  128  *      whether context switch at same priority is ok.  For timeshareing
  129  *      it indicates whether preempt is ok.
  130  */
  131 
  132 #define csw_needed(thread, processor) ((thread)->state & TH_SUSP ||     \
  133         ((processor)->runq.count > 0) ||                                \
  134         ((thread)->policy == POLICY_TIMESHARE &&                        \
  135                 (processor)->first_quantum == FALSE &&                  \
  136                 (processor)->processor_set->runq.count > 0 &&           \
  137                   (processor)->processor_set->runq.low <=               \
  138                         (thread)->sched_pri) ||                         \
  139         ((thread)->policy == POLICY_FIXEDPRI &&                         \
  140                 (processor)->processor_set->runq.count > 0 &&           \
  141                  ((((processor)->first_quantum == FALSE) &&             \
  142                   ((processor)->processor_set->runq.low <=              \
  143                         (thread)->sched_pri)) ||                        \
  144                  ((processor)->processor_set->runq.low <                \
  145                         (thread)->sched_pri))))
  146 
  147 #else   MACH_FIXPRI
  148 #define csw_needed(thread, processor) ((thread)->state & TH_SUSP ||     \
  149                 ((processor)->runq.count > 0) ||                        \
  150                 ((processor)->first_quantum == FALSE &&                 \
  151                  ((processor)->processor_set->runq.count > 0 &&         \
  152                   (processor)->processor_set->runq.low <=               \
  153                         ((thread)->sched_pri))))
  154 #endif  MACH_FIXPRI
  155 
  156 /*
  157  *      Scheduler routines.
  158  */
  159 
  160 extern struct run_queue *rem_runq();
  161 extern struct thread    *choose_thread();
  162 extern queue_head_t     action_queue;   /* assign/shutdown queue */
  163 decl_simple_lock_data(extern,action_lock);
  164 
  165 extern int              min_quantum;    /* defines max context switch rate */
  166 
  167 /*
  168  *      Default base priorities for threads.
  169  */
  170 #define BASEPRI_SYSTEM  6
  171 #define BASEPRI_USER    12
  172 
  173 /*
  174  *      Macro to check for invalid priorities.
  175  */
  176 
  177 #define invalid_pri(pri) (((pri) < 0) || ((pri) >= NRQS))
  178 
  179 /*
  180  *      Shift structures for holding update shifts.  Actual computation
  181  *      is  usage = (usage >> shift1) +/- (usage >> abs(shift2))  where the
  182  *      +/- is determined by the sign of shift 2.
  183  */
  184 struct shift {
  185         int     shift1;
  186         int     shift2;
  187 };
  188 
  189 typedef struct shift    *shift_t, shift_data_t;
  190 
  191 /*
  192  *      sched_tick increments once a second.  Used to age priorities.
  193  */
  194 
  195 extern unsigned sched_tick;
  196 
  197 #define SCHED_SCALE     128
  198 #define SCHED_SHIFT     7
  199 
  200 /*
  201  *      thread_timer_delta macro takes care of both thread timers.
  202  */
  203 
  204 #define thread_timer_delta(thread)                              \
  205 MACRO_BEGIN                                                     \
  206         register unsigned       delta;                          \
  207                                                                 \
  208         delta = 0;                                              \
  209         TIMER_DELTA((thread)->system_timer,                     \
  210                 (thread)->system_timer_save, delta);            \
  211         TIMER_DELTA((thread)->user_timer,                       \
  212                 (thread)->user_timer_save, delta);              \
  213         (thread)->cpu_delta += delta;                           \
  214         (thread)->sched_delta += delta *                        \
  215                         (thread)->processor_set->sched_load;    \
  216 MACRO_END
  217 
  218 #if     SIMPLE_CLOCK
  219 /*
  220  *      sched_usec is an exponential average of number of microseconds
  221  *      in a second for clock drift compensation.
  222  */
  223 
  224 extern int      sched_usec;
  225 #endif  SIMPLE_CLOCK
  226 
  227 #endif  _KERN_SCHED_H_

Cache object: a6546d3b17b77e6f1c65eafa969f71f1


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