|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1991,1990,1989 Carnegie Mellon University.
4: * Copyright (c) 1993,1994 The University of Utah and
5: * the Computer Systems Laboratory (CSL).
6: * All rights reserved.
7: *
8: * Permission to use, copy, modify and distribute this software and its
9: * documentation is hereby granted, provided that both the copyright
10: * notice and this permission notice appear in all copies of the
11: * software, derivative works or modified versions, and any portions
12: * thereof, and that both notices appear in supporting documentation.
13: *
14: * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF
15: * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY
16: * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
17: * THIS SOFTWARE.
18: *
19: * Carnegie Mellon requests users of this software to return to
20: *
21: * Software Distribution Coordinator or [email protected]
22: * School of Computer Science
23: * Carnegie Mellon University
24: * Pittsburgh PA 15213-3890
25: *
26: * any improvements or extensions that they make and grant Carnegie Mellon
27: * the rights to redistribute these changes.
28: */
29: /*
30: * processor.h: Processor and processor-set definitions.
31: */
32:
33: #ifndef _KERN_PROCESSOR_H_
34: #define _KERN_PROCESSOR_H_
35:
36: /*
37: * Data structures for managing processors and sets of processors.
38: */
39:
40: #include <mach/boolean.h>
41: #include <mach/kern_return.h>
42: #include <mach/port.h>
43: #include <mach/processor_info.h>
44: #include <kern/cpu_number.h>
45: #include <kern/lock.h>
46: #include <kern/queue.h>
47: #include <kern/sched.h>
48: #include <kern/kern_types.h>
49: #include <kern/host.h>
50:
51: #if NCPUS > 1
52: #include <machine/ast_types.h>
53: #endif /* NCPUS > 1 */
54:
55: struct processor_set {
56: struct run_queue runq; /* runq for this set */
57: queue_head_t idle_queue; /* idle processors */
58: int idle_count; /* how many ? */
59: decl_simple_lock_data(, idle_lock) /* lock for above */
60: queue_head_t processors; /* all processors here */
61: int processor_count; /* how many ? */
62: boolean_t empty; /* true if no processors */
63: queue_head_t tasks; /* tasks assigned */
64: int task_count; /* how many */
65: queue_head_t threads; /* threads in this set */
66: int thread_count; /* how many */
67: int ref_count; /* structure ref count */
68: decl_simple_lock_data(, ref_lock) /* lock for ref count */
69: queue_chain_t all_psets; /* link for all_psets */
70: boolean_t active; /* is pset in use */
71: decl_simple_lock_data(, lock) /* lock for everything else */
72: struct ipc_port * pset_self; /* port for operations */
73: struct ipc_port * pset_name_self; /* port for information */
74: int max_priority; /* maximum priority */
75: #if MACH_FIXPRI
76: int policies; /* bit vector for policies */
77: #endif /* MACH_FIXPRI */
78: int set_quantum; /* current default quantum */
79: #if NCPUS > 1
80: int quantum_adj_index; /* runtime quantum adj. */
81: decl_simple_lock_data(, quantum_adj_lock) /* lock for above */
82: int machine_quantum[NCPUS+1]; /* ditto */
83: #endif /* NCPUS > 1 */
84: long mach_factor; /* mach_factor */
85: long load_average; /* load_average */
86: long sched_load; /* load avg for scheduler */
87: };
88: extern struct processor_set default_pset;
89:
90: struct processor {
91: struct run_queue runq; /* local runq for this processor */
92: /* XXX want to do this round robin eventually */
93: queue_chain_t processor_queue; /* idle/assign/shutdown queue link */
94: int state; /* See below */
95: struct thread *next_thread; /* next thread to run if dispatched */
96: struct thread *idle_thread; /* this processor's idle thread. */
97: int quantum; /* quantum for current thread */
98: boolean_t first_quantum; /* first quantum in succession */
99: int last_quantum; /* last quantum assigned */
100:
101: processor_set_t processor_set; /* processor set I belong to */
102: processor_set_t processor_set_next; /* set I will belong to */
103: queue_chain_t processors; /* all processors in set */
104: decl_simple_lock_data(, lock)
105: struct ipc_port *processor_self; /* port for operations */
106: int slot_num; /* machine-indep slot number */
107: #if NCPUS > 1
108: ast_check_t ast_check_data; /* for remote ast_check invocation */
109: #endif /* NCPUS > 1 */
110: /* punt id data temporarily */
111: };
112: typedef struct processor Processor;
113: extern struct processor processor_array[NCPUS];
114:
115: /*
116: * Chain of all processor sets.
117: */
118: extern queue_head_t all_psets;
119: extern int all_psets_count;
120: decl_simple_lock_data(extern, all_psets_lock);
121:
122: /*
123: * The lock ordering is:
124: *
125: * all_psets_lock
126: * |
127: * |
128: * V
129: * pset_lock
130: * |
131: * +-----------+---------------+-------------------+
132: * | | | |
133: * | | | |
134: * | | V V
135: * | | task_lock pset_self->ip_lock
136: * | | | |
137: * | | +-----------+---------------+ |
138: * | | | | |
139: * | V V V V
140: * | thread_lock* pset_ref_lock
141: * | |
142: * | +-------+
143: * | | |
144: * | | V
145: * | | runq_lock*
146: * | |
147: * V V
148: * processor_lock*
149: * |
150: * |
151: * V
152: * pset_idle_lock*
153: * |
154: * |
155: * V
156: * action_lock*
157: *
158: * Locks marked with "*" are taken at splsched.
159: */
160:
161: /*
162: * XXX need a pointer to the master processor structure
163: */
164:
165: extern processor_t master_processor;
166:
167: /*
168: * NOTE: The processor->processor_set link is needed in one of the
169: * scheduler's critical paths. [Figure out where to look for another
170: * thread to run on this processor.] It is accessed without locking.
171: * The following access protocol controls this field.
172: *
173: * Read from own processor - just read.
174: * Read from another processor - lock processor structure during read.
175: * Write from own processor - lock processor structure during write.
176: * Write from another processor - NOT PERMITTED.
177: *
178: */
179:
180: /*
181: * Processor state locking:
182: *
183: * Values for the processor state are defined below. If the processor
184: * is off-line or being shutdown, then it is only necessary to lock
185: * the processor to change its state. Otherwise it is only necessary
186: * to lock its processor set's idle_lock. Scheduler code will
187: * typically lock only the idle_lock, but processor manipulation code
188: * will often lock both.
189: */
190:
191: #define PROCESSOR_OFF_LINE 0 /* Not in system */
192: #define PROCESSOR_RUNNING 1 /* Running normally */
193: #define PROCESSOR_IDLE 2 /* idle */
194: #define PROCESSOR_DISPATCHING 3 /* dispatching (idle -> running) */
195: #define PROCESSOR_ASSIGN 4 /* Assignment is changing */
196: #define PROCESSOR_SHUTDOWN 5 /* Being shutdown */
197:
198: /*
199: * Use processor ptr array to find current processor's data structure.
200: * This replaces a multiplication (index into processor_array) with
201: * an array lookup and a memory reference. It also allows us to save
202: * space if processor numbering gets too sparse.
203: */
204:
205: extern processor_t processor_ptr[NCPUS];
206:
207: #define cpu_to_processor(i) (processor_ptr[i])
208:
209: #define current_processor() (processor_ptr[cpu_number()])
210: #define current_processor_set() (current_processor()->processor_set)
211:
212: /* Compatibility -- will go away */
213:
214: #define cpu_state(slot_num) (processor_ptr[slot_num]->state)
215: #define cpu_idle(slot_num) (cpu_state(slot_num) == PROCESSOR_IDLE)
216:
217: /* Useful lock macros */
218:
219: #define pset_lock(pset) simple_lock(&(pset)->lock)
220: #define pset_unlock(pset) simple_unlock(&(pset)->lock)
221: #define pset_ref_lock(pset) simple_lock(&(pset)->ref_lock)
222: #define pset_ref_unlock(pset) simple_unlock(&(pset)->ref_lock)
223:
224: #define processor_lock(pr) simple_lock(&(pr)->lock)
225: #define processor_unlock(pr) simple_unlock(&(pr)->lock)
226:
227: typedef mach_port_t *processor_array_t;
228: typedef mach_port_t *processor_set_array_t;
229: typedef mach_port_t *processor_set_name_array_t;
230:
231:
232: /*
233: * Exported functions
234: */
235:
236: /* Initialization */
237:
238: #ifdef KERNEL
239: #if MACH_HOST
240: extern void pset_sys_init(void);
241: #endif /* MACH_HOST */
242:
243: /* Pset internal functions */
244:
1.1.1.2 ! root 245: extern void pset_sys_bootstrap(void);
1.1 root 246: extern void pset_reference(processor_set_t);
247: extern void pset_deallocate(processor_set_t);
248: extern void pset_remove_processor(processor_set_t, processor_t);
249: extern void pset_add_processor(processor_set_t, processor_t);
250: extern void pset_remove_task(processor_set_t, struct task *);
251: extern void pset_add_task(processor_set_t, struct task *);
252: extern void pset_remove_thread(processor_set_t, struct thread *);
253: extern void pset_add_thread(processor_set_t, struct thread *);
254: extern void thread_change_psets(struct thread *,
255: processor_set_t, processor_set_t);
256:
257: /* Processor interface */
258:
259: extern kern_return_t processor_get_assignment(
260: processor_t processor,
261: processor_set_t *processor_set);
262:
263: extern kern_return_t processor_info(
264: processor_t processor,
265: int flavor,
266: host_t * host,
267: processor_info_t info,
268: natural_t * count);
269:
270: extern kern_return_t processor_start(
271: processor_t processor);
272:
273: extern kern_return_t processor_exit(
274: processor_t processor);
275:
276: extern kern_return_t processor_control(
277: processor_t processor,
278: processor_info_t info,
279: natural_t count);
280:
281: /* Pset interface */
282:
283: extern kern_return_t processor_set_create(
284: host_t host,
285: processor_set_t *new_set,
286: processor_set_t *new_name);
287:
288: extern kern_return_t processor_set_destroy(
289: processor_set_t pset);
290:
291: extern kern_return_t processor_set_info(
292: processor_set_t pset,
293: int flavor,
294: host_t *host,
295: processor_set_info_t info,
296: natural_t *count);
297:
298: extern kern_return_t processor_set_max_priority(
299: processor_set_t pset,
300: int max_priority,
301: boolean_t change_threads);
302:
303: extern kern_return_t processor_set_policy_enable(
304: processor_set_t pset,
305: int policy);
306:
307: extern kern_return_t processor_set_policy_disable(
308: processor_set_t pset,
309: int policy,
310: boolean_t change_threads);
311:
312: extern kern_return_t processor_set_tasks(
313: processor_set_t pset,
314: task_array_t *task_list,
315: natural_t *count);
316:
317: extern kern_return_t processor_set_threads(
318: processor_set_t pset,
319: thread_array_t *thread_list,
320: natural_t *count);
321: #endif
322:
323: #endif /* _KERN_PROCESSOR_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.