|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * The contents of this file constitute Original Code as defined in and
7: * are subject to the Apple Public Source License Version 1.1 (the
8: * "License"). You may not use this file except in compliance with the
9: * License. Please obtain a copy of the License at
10: * http://www.apple.com/publicsource and read it before using this file.
11: *
12: * This Original Code and all software distributed under the License are
13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17: * License for the specific language governing rights and limitations
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /*
23: * @OSF_COPYRIGHT@
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: */
52: /*
53: * File: sched.h
54: * Author: Avadis Tevanian, Jr.
55: * Date: 1985
56: *
57: * Header file for scheduler.
58: *
59: */
60:
61: #ifndef _KERN_SCHED_H_
62: #define _KERN_SCHED_H_
63:
64: #include <cpus.h>
65: #include <simple_clock.h>
66: #include <stat_time.h>
67:
68: #include <mach/policy.h>
69: #include <kern/kern_types.h>
70: #include <kern/queue.h>
71: #include <kern/lock.h>
72: #include <kern/macro_help.h>
73:
74: #if STAT_TIME
75:
76: /*
77: * Statistical timing uses microseconds as timer units. 15 bit shift
78: * yields priorities. PRI_SHIFT_2 isn't needed.
79: */
80: #define PRI_SHIFT 15
81:
82: #else /* STAT_TIME */
83:
84: /*
85: * Otherwise machine provides shift(s) based on time units it uses.
86: */
87: #include <machine/sched_param.h>
88:
89: #endif /* STAT_TIME */
90:
91: #define NRQS 128 /* 128 run queues per cpu */
92: #define NRQBM (NRQS / 32) /* number of run queue bit maps */
93:
94: #define MAXPRI (NRQS-1)
95: #define LPRI (IDLEPRI+2) /* lowest pri reachable w/o depress */
96: #define MINPRI (IDLEPRI+1) /* lowest legal priority schedulable */
97: #define IDLEPRI 0 /* idle thread priority */
98: #define DEPRESSPRI MINPRI /* depress priority */
99:
100: /*
101: * Default base priorities for threads.
102: */
103: #define BASEPRI_KERNEL MAXPRI
104: #define BASEPRI_SYSTEM (BASEPRI_KERNEL - (NRQS / 4))
105: #define BASEPRI_SERVER (BASEPRI_SYSTEM - (NRQS / 8))
106: #define BASEPRI_USER (BASEPRI_SERVER - (NRQS / 8))
107:
108: /*
109: * Macro to check for invalid priorities.
110: */
111: #define invalid_pri(pri) ((pri) < MINPRI || (pri) > MAXPRI)
112:
113: struct run_queue {
114: queue_head_t runq[NRQS]; /* one for each priority */
115: decl_simple_lock_data(,lock) /* one lock for all queues */
116: int bitmap[NRQBM]; /* run queue bitmap array */
117: int highq; /* highest runnable queue */
118: int count; /* # of runnable threads */
119: int depress_count; /* # of depressed threads */
120: };
121:
122: typedef struct run_queue *run_queue_t;
123: #define RUN_QUEUE_NULL ((run_queue_t) 0)
124:
125: #define csw_needed(thread, processor) ( \
126: ((thread)->state & TH_SUSP) || \
127: ((processor)->first_quantum? \
128: ((processor)->runq.highq > (thread)->sched_pri || \
129: (processor)->processor_set->runq.highq > (thread)->sched_pri) : \
130: ((processor)->runq.highq >= (thread)->sched_pri || \
131: (processor)->processor_set->runq.highq >= (thread)->sched_pri)) )
132:
133: /*
134: * Scheduler routines.
135: */
136:
137: /* Remove thread from its run queue */
138: extern run_queue_t rem_runq(
139: thread_t thread);
140:
141: /* Mach factor computation (in mach_factor.c) */
142: extern void compute_mach_factor(void);
143:
144: /* Update threads quantum (in priority.c) */
145: extern void thread_quantum_update(
146: int mycpu,
147: thread_t thread,
148: int nticks,
149: int state);
150:
151: extern queue_head_t action_queue; /* assign/shutdown queue */
152:
153: decl_simple_lock_data(,action_lock)
154:
155: extern int min_quantum; /* defines max context switch rate */
156:
157: /*
158: * Shift structures for holding update shifts. Actual computation
159: * is usage = (usage >> shift1) +/- (usage >> abs(shift2)) where the
160: * +/- is determined by the sign of shift 2.
161: */
162: struct shift {
163: int shift1;
164: int shift2;
165: };
166:
167: typedef struct shift *shift_t, shift_data_t;
168:
169: /*
170: * sched_tick increments once a second. Used to age priorities.
171: */
172:
173: extern unsigned sched_tick;
174:
175: #define SCHED_SCALE 128
176: #define SCHED_SHIFT 7
177:
178: /*
179: * thread_timer_delta macro takes care of both thread timers.
180: */
181:
182: #define thread_timer_delta(thread) \
183: MACRO_BEGIN \
184: register unsigned delta; \
185: \
186: delta = 0; \
187: TIMER_DELTA((thread)->system_timer, \
188: (thread)->system_timer_save, delta); \
189: TIMER_DELTA((thread)->user_timer, \
190: (thread)->user_timer_save, delta); \
191: (thread)->cpu_delta += delta; \
192: (thread)->sched_delta += (delta * \
193: (thread)->processor_set->sched_load); \
194: MACRO_END
195:
196: #if SIMPLE_CLOCK
197: /*
198: * sched_usec is an exponential average of number of microseconds
199: * in a second for clock drift compensation.
200: */
201:
202: extern int sched_usec;
203: #endif /* SIMPLE_CLOCK */
204:
205: #endif /* _KERN_SCHED_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.