]>
Commit | Line | Data |
---|---|---|
1c79356b A |
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 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 Software.Distribution@CS.CMU.EDU | |
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 | /* | |
54 | * processor.h: Processor and processor-set definitions. | |
55 | */ | |
56 | ||
57 | #ifndef _KERN_PROCESSOR_H_ | |
58 | #define _KERN_PROCESSOR_H_ | |
59 | ||
60 | /* | |
61 | * Data structures for managing processors and sets of processors. | |
62 | */ | |
63 | #include <mach/boolean.h> | |
64 | #include <mach/kern_return.h> | |
65 | #include <kern/kern_types.h> | |
66 | ||
67 | extern struct processor_set default_pset; | |
68 | extern processor_t master_processor; | |
69 | ||
70 | #ifdef MACH_KERNEL_PRIVATE | |
71 | ||
72 | #include <cpus.h> | |
1c79356b A |
73 | |
74 | #include <mach/mach_types.h> | |
75 | #include <kern/cpu_number.h> | |
76 | #include <kern/lock.h> | |
77 | #include <kern/queue.h> | |
78 | #include <kern/sched.h> | |
79 | ||
1c79356b | 80 | #include <machine/ast_types.h> |
1c79356b A |
81 | |
82 | struct processor_set { | |
83 | struct run_queue runq; /* runq for this set */ | |
84 | queue_head_t idle_queue; /* idle processors */ | |
85 | int idle_count; /* how many ? */ | |
86 | decl_simple_lock_data(,idle_lock) /* lock for above */ | |
87 | queue_head_t processors; /* all processors here */ | |
88 | int processor_count;/* how many ? */ | |
89 | decl_simple_lock_data(,processors_lock) /* lock for above */ | |
90 | queue_head_t tasks; /* tasks assigned */ | |
91 | int task_count; /* how many */ | |
92 | queue_head_t threads; /* threads in this set */ | |
93 | int thread_count; /* how many */ | |
94 | int ref_count; /* structure ref count */ | |
95 | boolean_t active; /* is pset in use */ | |
96 | decl_mutex_data(, lock) /* lock for everything else */ | |
97 | struct ipc_port * pset_self; /* port for operations */ | |
98 | struct ipc_port * pset_name_self; /* port for information */ | |
0b4e3aa0 A |
99 | int set_quanta; /* timeslice quanta for timesharing */ |
100 | int machine_quanta[NCPUS+1]; | |
1c79356b A |
101 | integer_t mach_factor; /* mach_factor */ |
102 | integer_t load_average; /* load_average */ | |
103 | long sched_load; /* load avg for scheduler */ | |
1c79356b A |
104 | }; |
105 | ||
106 | struct processor { | |
107 | struct run_queue runq; /* local runq for this processor */ | |
108 | queue_chain_t processor_queue;/* idle/assign/shutdown queue link */ | |
109 | int state; /* See below */ | |
110 | struct thread_shuttle | |
111 | *next_thread, /* next thread to run if dispatched */ | |
112 | *idle_thread; /* this processor's idle thread. */ | |
0b4e3aa0 A |
113 | timer_call_data_t quantum_timer; /* timer for quantum expiration */ |
114 | int slice_quanta; /* quanta before timeslice ends */ | |
115 | uint64_t quantum_end; /* time when current quantum ends */ | |
116 | uint64_t last_dispatch; /* time of last dispatch */ | |
1c79356b A |
117 | |
118 | processor_set_t processor_set; /* processor set I belong to */ | |
119 | processor_set_t processor_set_next; /* set I will belong to */ | |
120 | queue_chain_t processors; /* all processors in set */ | |
121 | decl_simple_lock_data(,lock) | |
122 | struct ipc_port *processor_self;/* port for operations */ | |
123 | int slot_num; /* machine-indep slot number */ | |
1c79356b A |
124 | }; |
125 | ||
126 | extern struct processor processor_array[NCPUS]; | |
127 | ||
128 | /* | |
129 | * NOTE: The processor->processor_set link is needed in one of the | |
130 | * scheduler's critical paths. [Figure out where to look for another | |
131 | * thread to run on this processor.] It is accessed without locking. | |
132 | * The following access protocol controls this field. | |
133 | * | |
134 | * Read from own processor - just read. | |
135 | * Read from another processor - lock processor structure during read. | |
136 | * Write from own processor - lock processor structure during write. | |
137 | * Write from another processor - NOT PERMITTED. | |
138 | * | |
139 | */ | |
140 | ||
141 | /* | |
142 | * Processor state locking: | |
143 | * | |
144 | * Values for the processor state are defined below. If the processor | |
145 | * is off-line or being shutdown, then it is only necessary to lock | |
146 | * the processor to change its state. Otherwise it is only necessary | |
147 | * to lock its processor set's idle_lock. Scheduler code will | |
148 | * typically lock only the idle_lock, but processor manipulation code | |
149 | * will often lock both. | |
150 | */ | |
151 | ||
152 | #define PROCESSOR_OFF_LINE 0 /* Not in system */ | |
153 | #define PROCESSOR_RUNNING 1 /* Running a normal thread */ | |
154 | #define PROCESSOR_IDLE 2 /* idle */ | |
155 | #define PROCESSOR_DISPATCHING 3 /* dispatching (idle -> running) */ | |
156 | #define PROCESSOR_ASSIGN 4 /* Assignment is changing */ | |
157 | #define PROCESSOR_SHUTDOWN 5 /* Being shutdown */ | |
158 | #define PROCESSOR_START 6 /* Being start */ | |
159 | ||
160 | /* | |
161 | * Use processor ptr array to find current processor's data structure. | |
162 | * This replaces a multiplication (index into processor_array) with | |
163 | * an array lookup and a memory reference. It also allows us to save | |
164 | * space if processor numbering gets too sparse. | |
165 | */ | |
166 | ||
167 | extern processor_t processor_ptr[NCPUS]; | |
168 | ||
169 | #define cpu_to_processor(i) (processor_ptr[i]) | |
170 | ||
171 | #define current_processor() (processor_ptr[cpu_number()]) | |
172 | #define current_processor_set() (current_processor()->processor_set) | |
173 | ||
174 | /* Compatibility -- will go away */ | |
175 | ||
176 | #define cpu_state(slot_num) (processor_ptr[slot_num]->state) | |
177 | #define cpu_idle(slot_num) (cpu_state(slot_num) == PROCESSOR_IDLE) | |
178 | ||
179 | /* Useful lock macros */ | |
180 | ||
181 | #define pset_lock(pset) mutex_lock(&(pset)->lock) | |
182 | #define pset_lock_try(pset) mutex_try(&(pset)->lock) | |
183 | #define pset_unlock(pset) mutex_unlock(&(pset)->lock) | |
184 | ||
185 | #define processor_lock(pr) simple_lock(&(pr)->lock) | |
186 | #define processor_unlock(pr) simple_unlock(&(pr)->lock) | |
187 | ||
188 | ||
189 | extern void pset_sys_bootstrap(void); | |
190 | ||
191 | /* Implemented by MD layer */ | |
192 | ||
193 | extern void cpu_up( | |
194 | int cpu); | |
195 | ||
196 | extern kern_return_t processor_shutdown( | |
197 | processor_t processor); | |
198 | ||
199 | extern void pset_remove_processor( | |
200 | processor_set_t pset, | |
201 | processor_t processor); | |
202 | ||
203 | extern void pset_add_processor( | |
204 | processor_set_t pset, | |
205 | processor_t processor); | |
206 | ||
207 | extern void pset_remove_task( | |
208 | processor_set_t pset, | |
209 | task_t task); | |
210 | ||
211 | extern void pset_add_task( | |
212 | processor_set_t pset, | |
213 | task_t task); | |
214 | ||
215 | extern void pset_remove_thread( | |
216 | processor_set_t pset, | |
217 | thread_t thread); | |
218 | ||
219 | extern void pset_add_thread( | |
220 | processor_set_t pset, | |
221 | thread_t thread); | |
222 | ||
223 | extern void thread_change_psets( | |
224 | thread_t thread, | |
225 | processor_set_t old_pset, | |
226 | processor_set_t new_pset); | |
227 | ||
228 | extern void pset_deallocate( | |
229 | processor_set_t pset); | |
230 | ||
231 | extern void pset_reference( | |
232 | processor_set_t pset); | |
233 | ||
234 | extern kern_return_t processor_assign( | |
235 | processor_t processor, | |
236 | processor_set_t new_pset, | |
237 | boolean_t wait); | |
238 | ||
239 | extern kern_return_t processor_info_count( | |
240 | processor_flavor_t flavor, | |
241 | mach_msg_type_number_t *count); | |
242 | #endif /* MACH_KERNEL_PRIVATE */ | |
243 | ||
244 | extern kern_return_t processor_start( | |
245 | processor_t processor); | |
246 | ||
247 | extern kern_return_t processor_exit( | |
248 | processor_t processor); | |
249 | ||
250 | #endif /* _KERN_PROCESSOR_H_ */ |