FreeBSD/Linux Kernel Cross Reference
sys/kern/processor.h
1 /*
2 * Mach Operating System
3 * Copyright (c) 1992,1991,1990,1989 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: processor.h,v $
29 * Revision 2.7 93/01/14 17:35:59 danner
30 * Removed definitions moved to kern/kern_types.h
31 * [93/01/12 14:50:37 danner]
32 *
33 * Moved actual declarations of struct processor, processor_t,
34 * struct processor_set, processor_set_t to kern/kern_types.h to
35 * permit mutually recursive structure definitions. Finished
36 * adding ANSI function prototypes.
37 * [92/12/28 dbg]
38 * Added separate pset_ref_lock, only governing reference count, to
39 * fix lock ordering to avoid deadlocks. Documented locking hierarchy.
40 * Added prototypes for pset functions.
41 * [92/10/28 dbg]
42 *
43 * Revision 2.6 91/05/14 16:45:38 mrt
44 * Correcting copyright
45 *
46 * Revision 2.5 91/02/05 17:28:34 mrt
47 * Changed to new Mach copyright
48 * [91/02/01 16:16:14 mrt]
49 *
50 * Revision 2.4 90/09/09 14:32:32 rpd
51 * Use decl_simple_lock_data.
52 * [90/08/30 rpd]
53 *
54 * Revision 2.3 90/08/07 17:58:42 rpd
55 * Added processor_set_name_array_t.
56 * [90/08/07 rpd]
57 *
58 * Revision 2.2 90/06/02 14:55:39 rpd
59 * Created for new host/processor technology.
60 * [90/03/26 23:50:00 rpd]
61 *
62 * Merge to X96
63 * [89/08/02 23:01:16 dlb]
64 *
65 * Add quantum_adj_lock to pset structure. Enclose some fields
66 * in NCPUS > 1 conditionals.
67 * [89/06/15 dlb]
68 *
69 * Add all_psets_count declaration.
70 * [89/06/09 dlb]
71 *
72 * Add processor_set_array_t.
73 * [89/06/08 dlb]
74 *
75 * Add max_priority, policies fields to processor_set structure.
76 * [89/05/12 dlb]
77 * Add load factor/average fields to processor set structure.
78 * [89/02/09 dlb]
79 *
80 * Revision 2.5 89/11/20 11:23:50 mja
81 * Put policies field under MACH_FIXPRI conditional.
82 * [89/11/10 dlb]
83 *
84 * Revision 2.4 89/10/15 02:05:13 rpd
85 * Minor cleanups.
86 *
87 * Revision 2.3 89/10/12 21:34:28 dlb
88 * Get ast_check_t from machine/ast_types.h instead of machine/ast.h
89 * [89/10/12 dlb]
90 *
91 * Revision 2.2 89/10/11 14:20:44 dlb
92 * Add remote ast check support for multiprocessors.
93 * Add quantum_adj_lock to pset structure. Enclose some fields
94 * in NCPUS > 1 conditionals.
95 * Add max_priority, policies fields to processor_set structure.
96 * Add load factor/average fields to processor set structure.
97 *
98 * 27-Sep-88 David Black (dlb) at Carnegie-Mellon University
99 * Created.
100 *
101 */
102
103 /*
104 * processor.h: Processor and processor-set definitions.
105 */
106
107 #ifndef _KERN_PROCESSOR_H_
108 #define _KERN_PROCESSOR_H_
109
110 /*
111 * Data structures for managing processors and sets of processors.
112 */
113
114 #include <cpus.h>
115 #include <mach_fixpri.h>
116 #include <mach_host.h>
117
118 #include <mach/boolean.h>
119 #include <mach/kern_return.h>
120 #include <mach/port.h>
121 #include <mach/processor_info.h>
122 #include <kern/cpu_number.h>
123 #include <kern/lock.h>
124 #include <kern/queue.h>
125 #include <kern/sched.h>
126 #include <kern/kern_types.h>
127 #include <kern/host.h>
128
129 #if NCPUS > 1
130 #include <machine/ast_types.h>
131 #endif /* NCPUS > 1 */
132
133 struct processor_set {
134 struct run_queue runq; /* runq for this set */
135 queue_head_t idle_queue; /* idle processors */
136 int idle_count; /* how many ? */
137 decl_simple_lock_data(, idle_lock) /* lock for above */
138 queue_head_t processors; /* all processors here */
139 int processor_count; /* how many ? */
140 boolean_t empty; /* true if no processors */
141 queue_head_t tasks; /* tasks assigned */
142 int task_count; /* how many */
143 queue_head_t threads; /* threads in this set */
144 int thread_count; /* how many */
145 int ref_count; /* structure ref count */
146 decl_simple_lock_data(, ref_lock) /* lock for ref count */
147 queue_chain_t all_psets; /* link for all_psets */
148 boolean_t active; /* is pset in use */
149 decl_simple_lock_data(, lock) /* lock for everything else */
150 struct ipc_port * pset_self; /* port for operations */
151 struct ipc_port * pset_name_self; /* port for information */
152 int max_priority; /* maximum priority */
153 #if MACH_FIXPRI
154 int policies; /* bit vector for policies */
155 #endif /* MACH_FIXPRI */
156 int set_quantum; /* current default quantum */
157 #if NCPUS > 1
158 int quantum_adj_index; /* runtime quantum adj. */
159 decl_simple_lock_data(, quantum_adj_lock) /* lock for above */
160 int machine_quantum[NCPUS+1]; /* ditto */
161 #endif /* NCPUS > 1 */
162 long mach_factor; /* mach_factor */
163 long load_average; /* load_average */
164 long sched_load; /* load avg for scheduler */
165 };
166
167 extern struct processor_set default_pset;
168
169 struct processor {
170 struct run_queue runq; /* local runq for this processor */
171 /* XXX want to do this round robin eventually */
172 queue_chain_t processor_queue; /* idle/assign/shutdown queue link */
173 int state; /* See below */
174 struct thread *next_thread; /* next thread to run if dispatched */
175 struct thread *idle_thread; /* this processor's idle thread. */
176 int quantum; /* quantum for current thread */
177 boolean_t first_quantum; /* first quantum in succession */
178 int last_quantum; /* last quantum assigned */
179
180 processor_set_t processor_set; /* processor set I belong to */
181 processor_set_t processor_set_next; /* set I will belong to */
182 queue_chain_t processors; /* all processors in set */
183 decl_simple_lock_data(, lock)
184 struct ipc_port *processor_self; /* port for operations */
185 int slot_num; /* machine-indep slot number */
186 #if NCPUS > 1
187 ast_check_t ast_check_data; /* for remote ast_check invocation */
188 #endif /* NCPUS > 1 */
189 /* punt id data temporarily */
190 };
191
192 extern struct processor processor_array[NCPUS];
193
194 /*
195 * Chain of all processor sets.
196 */
197 extern queue_head_t all_psets;
198 extern int all_psets_count;
199 decl_simple_lock_data(extern, all_psets_lock);
200
201 /*
202 * The lock ordering is:
203 *
204 * all_psets_lock
205 * |
206 * |
207 * V
208 * pset_lock
209 * |
210 * +-----------+---------------+-------------------+
211 * | | | |
212 * | | | |
213 * | | V V
214 * | | task_lock pset_self->ip_lock
215 * | | | |
216 * | | +-----------+---------------+ |
217 * | | | | |
218 * | V V V V
219 * | thread_lock* pset_ref_lock
220 * | |
221 * | +-------+
222 * | | |
223 * | | V
224 * | | runq_lock*
225 * | |
226 * V V
227 * processor_lock*
228 * |
229 * |
230 * V
231 * pset_idle_lock*
232 * |
233 * |
234 * V
235 * action_lock*
236 *
237 * Locks marked with "*" are taken at splsched.
238 */
239
240 /*
241 * XXX need a pointer to the master processor structure
242 */
243
244 extern processor_t master_processor;
245
246 /*
247 * NOTE: The processor->processor_set link is needed in one of the
248 * scheduler's critical paths. [Figure out where to look for another
249 * thread to run on this processor.] It is accessed without locking.
250 * The following access protocol controls this field.
251 *
252 * Read from own processor - just read.
253 * Read from another processor - lock processor structure during read.
254 * Write from own processor - lock processor structure during write.
255 * Write from another processor - NOT PERMITTED.
256 *
257 */
258
259 /*
260 * Processor state locking:
261 *
262 * Values for the processor state are defined below. If the processor
263 * is off-line or being shutdown, then it is only necessary to lock
264 * the processor to change its state. Otherwise it is only necessary
265 * to lock its processor set's idle_lock. Scheduler code will
266 * typically lock only the idle_lock, but processor manipulation code
267 * will often lock both.
268 */
269
270 #define PROCESSOR_OFF_LINE 0 /* Not in system */
271 #define PROCESSOR_RUNNING 1 /* Running normally */
272 #define PROCESSOR_IDLE 2 /* idle */
273 #define PROCESSOR_DISPATCHING 3 /* dispatching (idle -> running) */
274 #define PROCESSOR_ASSIGN 4 /* Assignment is changing */
275 #define PROCESSOR_SHUTDOWN 5 /* Being shutdown */
276
277 /*
278 * Use processor ptr array to find current processor's data structure.
279 * This replaces a multiplication (index into processor_array) with
280 * an array lookup and a memory reference. It also allows us to save
281 * space if processor numbering gets too sparse.
282 */
283
284 extern processor_t processor_ptr[NCPUS];
285
286 #define cpu_to_processor(i) (processor_ptr[i])
287
288 #define current_processor() (processor_ptr[cpu_number()])
289 #define current_processor_set() (current_processor()->processor_set)
290
291 /* Compatibility -- will go away */
292
293 #define cpu_state(slot_num) (processor_ptr[slot_num]->state)
294 #define cpu_idle(slot_num) (cpu_state(slot_num) == PROCESSOR_IDLE)
295
296 /* Useful lock macros */
297
298 #define pset_lock(pset) simple_lock(&(pset)->lock)
299 #define pset_unlock(pset) simple_unlock(&(pset)->lock)
300 #define pset_ref_lock(pset) simple_lock(&(pset)->ref_lock)
301 #define pset_ref_unlock(pset) simple_unlock(&(pset)->ref_lock)
302
303 #define processor_lock(pr) simple_lock(&(pr)->lock)
304 #define processor_unlock(pr) simple_unlock(&(pr)->lock)
305
306 typedef mach_port_t *processor_array_t;
307 typedef mach_port_t *processor_set_array_t;
308 typedef mach_port_t *processor_set_name_array_t;
309
310
311 /*
312 * Exported functions
313 */
314
315 /* Initialization */
316
317 #if MACH_HOST
318 extern void pset_sys_bootstrap(void);
319 extern void pset_sys_init(void);
320 #endif /* MACH_HOST */
321
322 /* Pset internal functions */
323
324 extern void pset_reference(processor_set_t);
325 extern void pset_deallocate(processor_set_t);
326 extern void pset_remove_processor(processor_set_t, processor_t);
327 extern void pset_add_processor(processor_set_t, processor_t);
328 extern void pset_remove_task(processor_set_t, struct task *);
329 extern void pset_add_task(processor_set_t, struct task *);
330 extern void pset_remove_thread(processor_set_t, struct thread *);
331 extern void pset_add_thread(processor_set_t, struct thread *);
332 extern void thread_change_psets(struct thread *,
333 processor_set_t, processor_set_t);
334
335 /* Processor interface */
336
337 extern kern_return_t processor_get_assignment(
338 processor_t processor,
339 processor_set_t *processor_set);
340
341 extern kern_return_t processor_info(
342 processor_t processor,
343 int flavor,
344 host_t * host,
345 processor_info_t info,
346 natural_t * count);
347
348 extern kern_return_t processor_start(
349 processor_t processor);
350
351 extern kern_return_t processor_exit(
352 processor_t processor);
353
354 extern kern_return_t processor_control(
355 processor_t processor,
356 processor_info_t info,
357 natural_t count);
358
359 /* Pset interface */
360
361 extern kern_return_t processor_set_create(
362 host_t host,
363 processor_set_t *new_set,
364 processor_set_t *new_name);
365
366 extern kern_return_t processor_set_destroy(
367 processor_set_t pset);
368
369 extern kern_return_t processor_set_info(
370 processor_set_t pset,
371 int flavor,
372 host_t *host,
373 processor_set_info_t info,
374 natural_t *count);
375
376 extern kern_return_t processor_set_max_priority(
377 processor_set_t pset,
378 int max_priority,
379 boolean_t change_threads);
380
381 extern kern_return_t processor_set_policy_enable(
382 processor_set_t pset,
383 int policy);
384
385 extern kern_return_t processor_set_policy_disable(
386 processor_set_t pset,
387 int policy,
388 boolean_t change_threads);
389
390 extern kern_return_t processor_set_tasks(
391 processor_set_t pset,
392 task_array_t *task_list,
393 natural_t *count);
394
395 extern kern_return_t processor_set_threads(
396 processor_set_t pset,
397 thread_array_t *thread_list,
398 natural_t *count);
399
400 #endif /* _KERN_PROCESSOR_H_ */
Cache object: 56d9810efe8e22c74cf46bcb59eca86a
|