Annotation of kernel/kern/sched.h, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /* 
        !            26:  * Mach Operating System
        !            27:  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
        !            28:  * All Rights Reserved.
        !            29:  * 
        !            30:  * Permission to use, copy, modify and distribute this software and its
        !            31:  * documentation is hereby granted, provided that both the copyright
        !            32:  * notice and this permission notice appear in all copies of the
        !            33:  * software, derivative works or modified versions, and any portions
        !            34:  * thereof, and that both notices appear in supporting documentation.
        !            35:  * 
        !            36:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
        !            37:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
        !            38:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
        !            39:  * 
        !            40:  * Carnegie Mellon requests users of this software to return to
        !            41:  * 
        !            42:  *  Software Distribution Coordinator  or  [email protected]
        !            43:  *  School of Computer Science
        !            44:  *  Carnegie Mellon University
        !            45:  *  Pittsburgh PA 15213-3890
        !            46:  * 
        !            47:  * any improvements or extensions that they make and grant Carnegie Mellon
        !            48:  * the rights to redistribute these changes.
        !            49:  */
        !            50: /*
        !            51:  *     File:   sched.h
        !            52:  *     Author: Avadis Tevanian, Jr.
        !            53:  *     Date:   1985
        !            54:  *
        !            55:  *     Header file for scheduler.
        !            56:  *
        !            57:  */
        !            58: 
        !            59: #ifndef        _KERN_SCHED_H_
        !            60: #define _KERN_SCHED_H_
        !            61: 
        !            62: #ifdef KERNEL_BUILD
        !            63: #include <cpus.h>
        !            64: #include <mach_fixpri.h>
        !            65: #include <simple_clock.h>
        !            66: #include <stat_time.h>
        !            67: #else  /* KERNEL_BUILD */
        !            68: #include <mach/features.h>
        !            69: #endif /* KERNEL_BUILD */
        !            70: 
        !            71: #include <kern/queue.h>
        !            72: #include <kern/lock.h>
        !            73: #include <kern/macro_help.h>
        !            74: 
        !            75: #if    STAT_TIME
        !            76: 
        !            77: /*
        !            78:  *     Statistical timing uses microseconds as timer units.  18 bit shift
        !            79:  *     yields priorities.  PRI_SHIFT_2 isn't needed.
        !            80:  */
        !            81: #define PRI_SHIFT      18
        !            82: 
        !            83: #else  /* STAT_TIME */
        !            84: 
        !            85: /*
        !            86:  *     Otherwise machine provides shift(s) based on time units it uses.
        !            87:  */
        !            88: #include <machine/sched_param.h>
        !            89: 
        !            90: #endif /* STAT_TIME */
        !            91: #define NRQS   32                      /* 32 run queues per cpu */
        !            92: 
        !            93: struct run_queue {
        !            94:        queue_head_t            runq[NRQS];     /* one for each priority */
        !            95:        decl_simple_lock_data(, lock)           /* one lock for all queues */
        !            96:        int                     high;           /* high queue value */
        !            97:        int                     count;          /* count of threads runable */
        !            98: };
        !            99: 
        !           100: typedef struct run_queue       *run_queue_t;
        !           101: #define RUN_QUEUE_NULL ((run_queue_t) 0)
        !           102: 
        !           103: #define csw_needed(thread, processor) (                                          \
        !           104:        ((thread)->state & TH_SUSP) ||                                    \
        !           105:        ((processor)->runq.count > 0) ||                                  \
        !           106:        (((processor)->processor_set->runq.count > 0) &&                  \
        !           107:         ((processor)->first_quantum?                                     \
        !           108:          (processor)->processor_set->runq.high > (thread)->sched_pri :   \
        !           109:          (processor)->processor_set->runq.high >= (thread)->sched_pri)))
        !           110: 
        !           111: /*
        !           112:  *     Scheduler routines.
        !           113:  */
        !           114: 
        !           115: extern struct run_queue        *rem_runq();
        !           116: extern struct thread   *choose_thread();
        !           117: extern queue_head_t    action_queue;   /* assign/shutdown queue */
        !           118: decl_simple_lock_data(extern,action_lock);
        !           119: 
        !           120: extern int             min_quantum;    /* defines max context switch rate */
        !           121: 
        !           122: /*
        !           123:  *     Default base priorities for threads.
        !           124:  */
        !           125: #define BASEPRI_SYSTEM 24
        !           126: #define MAXPRI_USER    18
        !           127: #define BASEPRI_USER   10
        !           128: 
        !           129: /*
        !           130:  *     Macro to check for invalid priorities.
        !           131:  */
        !           132: 
        !           133: #define invalid_pri(pri) (((pri) < 0) || ((pri) >= NRQS))
        !           134: 
        !           135: /*
        !           136:  *     Shift structures for holding update shifts.  Actual computation
        !           137:  *     is  usage = (usage >> shift1) +/- (usage >> abs(shift2))  where the
        !           138:  *     +/- is determined by the sign of shift 2.
        !           139:  */
        !           140: struct shift {
        !           141:        int     shift1;
        !           142:        int     shift2;
        !           143: };
        !           144: 
        !           145: typedef        struct shift    *shift_t, shift_data_t;
        !           146: 
        !           147: /*
        !           148:  *     sched_tick increments once a second.  Used to age priorities.
        !           149:  */
        !           150: 
        !           151: extern unsigned        sched_tick;
        !           152: 
        !           153: #define SCHED_SCALE    128
        !           154: #define SCHED_SHIFT    7
        !           155: 
        !           156: /*
        !           157:  *     thread_timer_delta macro takes care of both thread timers.
        !           158:  */
        !           159: 
        !           160: #define thread_timer_delta(thread)                             \
        !           161: MACRO_BEGIN                                                    \
        !           162:        register unsigned       delta;                          \
        !           163:                                                                \
        !           164:        delta = 0;                                              \
        !           165:        TIMER_DELTA((thread)->system_timer,                     \
        !           166:                (thread)->system_timer_save, delta);            \
        !           167:        TIMER_DELTA((thread)->user_timer,                       \
        !           168:                (thread)->user_timer_save, delta);              \
        !           169:        (thread)->cpu_delta += delta;                           \
        !           170:        (thread)->sched_delta += delta *                        \
        !           171:                        (thread)->processor_set->sched_load;    \
        !           172: MACRO_END
        !           173: 
        !           174: #if    SIMPLE_CLOCK
        !           175: /*
        !           176:  *     sched_usec is an exponential average of number of microseconds
        !           177:  *     in a second for clock drift compensation.
        !           178:  */
        !           179: 
        !           180: extern int     sched_usec;
        !           181: #endif /* SIMPLE_CLOCK */
        !           182: 
        !           183: #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.