Annotation of Gnu-Mach/kern/sched.h, revision 1.1.1.5

1.1.1.2   root        1: /*
1.1       root        2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
                      4:  * All Rights Reserved.
1.1.1.2   root        5:  *
1.1       root        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.
1.1.1.2   root       11:  *
1.1       root       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.
1.1.1.2   root       15:  *
1.1       root       16:  * Carnegie Mellon requests users of this software to return to
1.1.1.2   root       17:  *
1.1       root       18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
1.1.1.2   root       22:  *
1.1       root       23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
                     26: /*
                     27:  *     File:   sched.h
                     28:  *     Author: Avadis Tevanian, Jr.
                     29:  *     Date:   1985
                     30:  *
                     31:  *     Header file for scheduler.
                     32:  *
                     33:  */
                     34: 
                     35: #ifndef        _KERN_SCHED_H_
                     36: #define _KERN_SCHED_H_
                     37: 
                     38: #include <kern/queue.h>
                     39: #include <kern/lock.h>
1.1.1.3   root       40: #include <kern/kern_types.h>
1.1.1.5 ! root       41: #include <kern/macros.h>
1.1       root       42: 
                     43: #if    MACH_FIXPRI
                     44: #include <mach/policy.h>
1.1.1.2   root       45: #endif /* MACH_FIXPRI */
1.1       root       46: 
                     47: #if    STAT_TIME
                     48: 
                     49: /*
                     50:  *     Statistical timing uses microseconds as timer units.  18 bit shift
                     51:  *     yields priorities.  PRI_SHIFT_2 isn't needed.
                     52:  */
                     53: #define PRI_SHIFT      18
                     54: 
1.1.1.2   root       55: #else  /* STAT_TIME */
1.1       root       56: 
                     57: /*
                     58:  *     Otherwise machine provides shift(s) based on time units it uses.
                     59:  */
                     60: #include <machine/sched_param.h>
                     61: 
1.1.1.2   root       62: #endif /* STAT_TIME */
1.1.1.3   root       63: #define NRQS   50                      /* 50 run queues per cpu */
1.1       root       64: 
                     65: struct run_queue {
                     66:        queue_head_t            runq[NRQS];     /* one for each priority */
                     67:        decl_simple_lock_data(, lock)           /* one lock for all queues */
                     68:        int                     low;            /* low queue value */
                     69:        int                     count;          /* count of threads runable */
                     70: };
                     71: 
                     72: typedef struct run_queue       *run_queue_t;
                     73: #define RUN_QUEUE_NULL ((run_queue_t) 0)
                     74: 
                     75: #if    MACH_FIXPRI
                     76: /*
                     77:  *     NOTE: For fixed priority threads, first_quantum indicates
                     78:  *     whether context switch at same priority is ok.  For timeshareing
                     79:  *     it indicates whether preempt is ok.
                     80:  */
                     81: 
                     82: #define csw_needed(thread, processor) ((thread)->state & TH_SUSP ||    \
                     83:        ((processor)->runq.count > 0) ||                                \
                     84:        ((thread)->policy == POLICY_TIMESHARE &&                        \
                     85:                (processor)->first_quantum == FALSE &&                  \
                     86:                (processor)->processor_set->runq.count > 0 &&           \
                     87:                  (processor)->processor_set->runq.low <=               \
                     88:                        (thread)->sched_pri) ||                         \
                     89:        ((thread)->policy == POLICY_FIXEDPRI &&                         \
                     90:                (processor)->processor_set->runq.count > 0 &&           \
                     91:                 ((((processor)->first_quantum == FALSE) &&             \
                     92:                  ((processor)->processor_set->runq.low <=              \
                     93:                        (thread)->sched_pri)) ||                        \
                     94:                 ((processor)->processor_set->runq.low <                \
                     95:                        (thread)->sched_pri))))
                     96: 
1.1.1.2   root       97: #else  /* MACH_FIXPRI */
1.1       root       98: #define csw_needed(thread, processor) ((thread)->state & TH_SUSP ||    \
                     99:                ((processor)->runq.count > 0) ||                        \
                    100:                ((processor)->first_quantum == FALSE &&                 \
                    101:                 ((processor)->processor_set->runq.count > 0 &&         \
                    102:                  (processor)->processor_set->runq.low <=               \
                    103:                        ((thread)->sched_pri))))
1.1.1.2   root      104: #endif /* MACH_FIXPRI */
1.1       root      105: 
                    106: /*
                    107:  *     Scheduler routines.
                    108:  */
                    109: 
1.1.1.3   root      110: extern struct run_queue        *rem_runq(thread_t);
                    111: extern struct thread   *choose_thread(processor_t);
1.1       root      112: extern queue_head_t    action_queue;   /* assign/shutdown queue */
                    113: decl_simple_lock_data(extern,action_lock);
                    114: 
                    115: extern int             min_quantum;    /* defines max context switch rate */
                    116: 
                    117: /*
                    118:  *     Default base priorities for threads.
                    119:  */
                    120: #define BASEPRI_SYSTEM 6
1.1.1.3   root      121: #define BASEPRI_USER   25
1.1       root      122: 
                    123: /*
                    124:  *     Macro to check for invalid priorities.
                    125:  */
                    126: 
                    127: #define invalid_pri(pri) (((pri) < 0) || ((pri) >= NRQS))
                    128: 
                    129: /*
                    130:  *     Shift structures for holding update shifts.  Actual computation
                    131:  *     is  usage = (usage >> shift1) +/- (usage >> abs(shift2))  where the
                    132:  *     +/- is determined by the sign of shift 2.
                    133:  */
                    134: struct shift {
                    135:        int     shift1;
                    136:        int     shift2;
                    137: };
                    138: 
                    139: typedef        struct shift    *shift_t, shift_data_t;
                    140: 
                    141: /*
                    142:  *     sched_tick increments once a second.  Used to age priorities.
                    143:  */
                    144: 
                    145: extern unsigned        sched_tick;
                    146: 
                    147: #define SCHED_SCALE    128
                    148: #define SCHED_SHIFT    7
                    149: 
                    150: /*
                    151:  *     thread_timer_delta macro takes care of both thread timers.
                    152:  */
                    153: 
                    154: #define thread_timer_delta(thread)                             \
                    155: MACRO_BEGIN                                                    \
1.1.1.4   root      156:        unsigned        delta;                                  \
1.1       root      157:                                                                \
                    158:        delta = 0;                                              \
                    159:        TIMER_DELTA((thread)->system_timer,                     \
                    160:                (thread)->system_timer_save, delta);            \
                    161:        TIMER_DELTA((thread)->user_timer,                       \
                    162:                (thread)->user_timer_save, delta);              \
                    163:        (thread)->cpu_delta += delta;                           \
                    164:        (thread)->sched_delta += delta *                        \
                    165:                        (thread)->processor_set->sched_load;    \
                    166: MACRO_END
                    167: 
                    168: #if    SIMPLE_CLOCK
                    169: /*
                    170:  *     sched_usec is an exponential average of number of microseconds
                    171:  *     in a second for clock drift compensation.
                    172:  */
                    173: 
                    174: extern int     sched_usec;
1.1.1.2   root      175: #endif /* SIMPLE_CLOCK */
1.1       root      176: 
1.1.1.2   root      177: #endif /* _KERN_SCHED_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.