|
|
1.1 ! root 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 [email protected] ! 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: * 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 <cpus.h> ! 39: #include <mach_fixpri.h> ! 40: #include <simple_clock.h> ! 41: #include <stat_time.h> ! 42: ! 43: #include <kern/queue.h> ! 44: #include <kern/lock.h> ! 45: #include <kern/macro_help.h> ! 46: ! 47: #if MACH_FIXPRI ! 48: #include <mach/policy.h> ! 49: #endif /* MACH_FIXPRI */ ! 50: ! 51: #if STAT_TIME ! 52: ! 53: /* ! 54: * Statistical timing uses microseconds as timer units. 18 bit shift ! 55: * yields priorities. PRI_SHIFT_2 isn't needed. ! 56: */ ! 57: #define PRI_SHIFT 18 ! 58: ! 59: #else /* STAT_TIME */ ! 60: ! 61: /* ! 62: * Otherwise machine provides shift(s) based on time units it uses. ! 63: */ ! 64: #include <machine/sched_param.h> ! 65: ! 66: #endif /* STAT_TIME */ ! 67: #define NRQS 32 /* 32 run queues per cpu */ ! 68: ! 69: struct run_queue { ! 70: queue_head_t runq[NRQS]; /* one for each priority */ ! 71: decl_simple_lock_data(, lock) /* one lock for all queues */ ! 72: int low; /* low queue value */ ! 73: int count; /* count of threads runable */ ! 74: }; ! 75: ! 76: typedef struct run_queue *run_queue_t; ! 77: #define RUN_QUEUE_NULL ((run_queue_t) 0) ! 78: ! 79: #if MACH_FIXPRI ! 80: /* ! 81: * NOTE: For fixed priority threads, first_quantum indicates ! 82: * whether context switch at same priority is ok. For timeshareing ! 83: * it indicates whether preempt is ok. ! 84: */ ! 85: ! 86: #define csw_needed(thread, processor) ((thread)->state & TH_SUSP || \ ! 87: ((processor)->runq.count > 0) || \ ! 88: ((thread)->policy == POLICY_TIMESHARE && \ ! 89: (processor)->first_quantum == FALSE && \ ! 90: (processor)->processor_set->runq.count > 0 && \ ! 91: (processor)->processor_set->runq.low <= \ ! 92: (thread)->sched_pri) || \ ! 93: ((thread)->policy == POLICY_FIXEDPRI && \ ! 94: (processor)->processor_set->runq.count > 0 && \ ! 95: ((((processor)->first_quantum == FALSE) && \ ! 96: ((processor)->processor_set->runq.low <= \ ! 97: (thread)->sched_pri)) || \ ! 98: ((processor)->processor_set->runq.low < \ ! 99: (thread)->sched_pri)))) ! 100: ! 101: #else /* MACH_FIXPRI */ ! 102: #define csw_needed(thread, processor) ((thread)->state & TH_SUSP || \ ! 103: ((processor)->runq.count > 0) || \ ! 104: ((processor)->first_quantum == FALSE && \ ! 105: ((processor)->processor_set->runq.count > 0 && \ ! 106: (processor)->processor_set->runq.low <= \ ! 107: ((thread)->sched_pri)))) ! 108: #endif /* MACH_FIXPRI */ ! 109: ! 110: /* ! 111: * Scheduler routines. ! 112: */ ! 113: ! 114: extern struct run_queue *rem_runq(); ! 115: extern struct thread *choose_thread(); ! 116: extern queue_head_t action_queue; /* assign/shutdown queue */ ! 117: decl_simple_lock_data(extern,action_lock); ! 118: ! 119: extern int min_quantum; /* defines max context switch rate */ ! 120: ! 121: /* ! 122: * Default base priorities for threads. ! 123: */ ! 124: #define BASEPRI_SYSTEM 6 ! 125: #define BASEPRI_USER 12 ! 126: ! 127: /* ! 128: * Macro to check for invalid priorities. ! 129: */ ! 130: ! 131: #define invalid_pri(pri) (((pri) < 0) || ((pri) >= NRQS)) ! 132: ! 133: /* ! 134: * Shift structures for holding update shifts. Actual computation ! 135: * is usage = (usage >> shift1) +/- (usage >> abs(shift2)) where the ! 136: * +/- is determined by the sign of shift 2. ! 137: */ ! 138: struct shift { ! 139: int shift1; ! 140: int shift2; ! 141: }; ! 142: ! 143: typedef struct shift *shift_t, shift_data_t; ! 144: ! 145: /* ! 146: * sched_tick increments once a second. Used to age priorities. ! 147: */ ! 148: ! 149: extern unsigned sched_tick; ! 150: ! 151: #define SCHED_SCALE 128 ! 152: #define SCHED_SHIFT 7 ! 153: ! 154: /* ! 155: * thread_timer_delta macro takes care of both thread timers. ! 156: */ ! 157: ! 158: #define thread_timer_delta(thread) \ ! 159: MACRO_BEGIN \ ! 160: register unsigned delta; \ ! 161: \ ! 162: delta = 0; \ ! 163: TIMER_DELTA((thread)->system_timer, \ ! 164: (thread)->system_timer_save, delta); \ ! 165: TIMER_DELTA((thread)->user_timer, \ ! 166: (thread)->user_timer_save, delta); \ ! 167: (thread)->cpu_delta += delta; \ ! 168: (thread)->sched_delta += delta * \ ! 169: (thread)->processor_set->sched_load; \ ! 170: MACRO_END ! 171: ! 172: #if SIMPLE_CLOCK ! 173: /* ! 174: * sched_usec is an exponential average of number of microseconds ! 175: * in a second for clock drift compensation. ! 176: */ ! 177: ! 178: extern int sched_usec; ! 179: #endif /* SIMPLE_CLOCK */ ! 180: ! 181: #endif /* _KERN_SCHED_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.