]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
b0d623f7 | 2 | * Copyright (c) 2000-2009 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | ||
59 | /* | |
91447636 | 60 | * processor.h: Processor and processor-related definitions. |
1c79356b A |
61 | */ |
62 | ||
63 | #ifndef _KERN_PROCESSOR_H_ | |
64 | #define _KERN_PROCESSOR_H_ | |
65 | ||
1c79356b A |
66 | #include <mach/boolean.h> |
67 | #include <mach/kern_return.h> | |
68 | #include <kern/kern_types.h> | |
69 | ||
91447636 | 70 | #include <sys/cdefs.h> |
1c79356b | 71 | |
9bccf70c | 72 | #ifdef MACH_KERNEL_PRIVATE |
1c79356b | 73 | |
1c79356b | 74 | #include <mach/mach_types.h> |
91447636 | 75 | #include <kern/ast.h> |
1c79356b | 76 | #include <kern/cpu_number.h> |
3e170ce0 | 77 | #include <kern/smp.h> |
fe8ab488 A |
78 | #include <kern/simple_lock.h> |
79 | #include <kern/locks.h> | |
1c79356b A |
80 | #include <kern/queue.h> |
81 | #include <kern/sched.h> | |
fe8ab488 | 82 | #include <mach/sfi_class.h> |
91447636 | 83 | #include <kern/processor_data.h> |
1c79356b | 84 | |
1c79356b | 85 | struct processor_set { |
9bccf70c | 86 | queue_head_t active_queue; /* active processors */ |
2d21ac55 | 87 | queue_head_t idle_queue; /* idle processors */ |
fe8ab488 | 88 | queue_head_t idle_secondary_queue; /* idle secondary processors */ |
9bccf70c | 89 | |
6d2010ae | 90 | int online_processor_count; |
9bccf70c | 91 | |
b7266188 A |
92 | int cpu_set_low, cpu_set_hi; |
93 | int cpu_set_count; | |
94 | ||
3e170ce0 | 95 | #if __SMP__ |
2d21ac55 | 96 | decl_simple_lock_data(,sched_lock) /* lock for above */ |
3e170ce0 | 97 | #endif |
9bccf70c | 98 | |
fe8ab488 | 99 | #if defined(CONFIG_SCHED_TRADITIONAL) || defined(CONFIG_SCHED_MULTIQ) |
6d2010ae | 100 | struct run_queue pset_runq; /* runq for this processor set */ |
fe8ab488 A |
101 | #endif |
102 | ||
103 | #if defined(CONFIG_SCHED_TRADITIONAL) | |
6d2010ae A |
104 | int pset_runq_bound_count; |
105 | /* # of threads in runq bound to any processor in pset */ | |
106 | #endif | |
fe8ab488 | 107 | |
39236c6e | 108 | /* CPUs that have been sent an unacknowledged remote AST for scheduling purposes */ |
3e170ce0 A |
109 | uint64_t pending_AST_cpu_mask; |
110 | #if defined(CONFIG_SCHED_DEFERRED_AST) | |
111 | /* | |
112 | * A seperate mask, for ASTs that we may be able to cancel. This is dependent on | |
113 | * some level of support for requesting an AST on a processor, and then quashing | |
114 | * that request later. | |
115 | * | |
116 | * The purpose of this field (and the associated codepaths) is to infer when we | |
117 | * no longer need a processor that is DISPATCHING to come up, and to prevent it | |
118 | * from coming out of IDLE if possible. This should serve to decrease the number | |
119 | * of spurious ASTs in the system, and let processors spend longer periods in | |
120 | * IDLE. | |
121 | */ | |
122 | uint64_t pending_deferred_AST_cpu_mask; | |
123 | #endif | |
39236c6e | 124 | |
9bccf70c A |
125 | struct ipc_port * pset_self; /* port for operations */ |
126 | struct ipc_port * pset_name_self; /* port for information */ | |
127 | ||
2d21ac55 A |
128 | processor_set_t pset_list; /* chain of associated psets */ |
129 | pset_node_t node; | |
130 | }; | |
131 | ||
132 | extern struct processor_set pset0; | |
9bccf70c | 133 | |
2d21ac55 A |
134 | struct pset_node { |
135 | processor_set_t psets; /* list of associated psets */ | |
91447636 | 136 | |
2d21ac55 A |
137 | pset_node_t nodes; /* list of associated subnodes */ |
138 | pset_node_t node_list; /* chain of associated nodes */ | |
139 | ||
140 | pset_node_t parent; | |
1c79356b A |
141 | }; |
142 | ||
2d21ac55 A |
143 | extern struct pset_node pset_node0; |
144 | ||
6d2010ae | 145 | extern queue_head_t tasks, terminated_tasks, threads; /* Terminated tasks are ONLY for stackshot */ |
39236c6e | 146 | extern int tasks_count, terminated_tasks_count, threads_count; |
b0d623f7 A |
147 | decl_lck_mtx_data(extern,tasks_threads_lock) |
148 | ||
1c79356b | 149 | struct processor { |
91447636 | 150 | queue_chain_t processor_queue;/* idle/active queue link, |
9bccf70c | 151 | * MUST remain the first element */ |
1c79356b | 152 | int state; /* See below */ |
fe8ab488 | 153 | boolean_t is_SMT; |
3e170ce0 | 154 | boolean_t is_recommended; |
55e303ae A |
155 | struct thread |
156 | *active_thread, /* thread running on processor */ | |
91447636 | 157 | *next_thread, /* next thread when dispatched */ |
1c79356b | 158 | *idle_thread; /* this processor's idle thread. */ |
55e303ae | 159 | |
2d21ac55 | 160 | processor_set_t processor_set; /* assigned set */ |
55e303ae A |
161 | |
162 | int current_pri; /* priority of current thread */ | |
6d2010ae | 163 | sched_mode_t current_thmode; /* sched mode of current thread */ |
fe8ab488 | 164 | sfi_class_id_t current_sfi_class; /* SFI class of current thread */ |
b0d623f7 | 165 | int cpu_id; /* platform numeric id */ |
55e303ae | 166 | |
0b4e3aa0 | 167 | timer_call_data_t quantum_timer; /* timer for quantum expiration */ |
0b4e3aa0 A |
168 | uint64_t quantum_end; /* time when current quantum ends */ |
169 | uint64_t last_dispatch; /* time of last dispatch */ | |
1c79356b | 170 | |
55e303ae | 171 | uint64_t deadline; /* current deadline */ |
3e170ce0 | 172 | boolean_t first_timeslice; /* has the quantum expired since context switch */ |
55e303ae | 173 | |
fe8ab488 | 174 | #if defined(CONFIG_SCHED_TRADITIONAL) || defined(CONFIG_SCHED_MULTIQ) |
2d21ac55 | 175 | struct run_queue runq; /* runq for this processor */ |
fe8ab488 A |
176 | #endif |
177 | ||
178 | #if defined(CONFIG_SCHED_TRADITIONAL) | |
6d2010ae A |
179 | int runq_bound_count; /* # of threads bound to this processor */ |
180 | #endif | |
181 | #if defined(CONFIG_SCHED_GRRR) | |
182 | struct grrr_run_queue grrr_runq; /* Group Ratio Round-Robin runq */ | |
183 | #endif | |
9bccf70c | 184 | |
fe8ab488 A |
185 | processor_t processor_primary; /* pointer to primary processor for |
186 | * secondary SMT processors, or a pointer | |
187 | * to ourselves for primaries or non-SMT */ | |
188 | processor_t processor_secondary; | |
91447636 | 189 | struct ipc_port * processor_self; /* port for operations */ |
2d21ac55 | 190 | |
91447636 A |
191 | processor_t processor_list; /* all existing processors */ |
192 | processor_data_t processor_data; /* per-processor data */ | |
1c79356b A |
193 | }; |
194 | ||
91447636 A |
195 | extern processor_t processor_list; |
196 | extern unsigned int processor_count; | |
197 | decl_simple_lock_data(extern,processor_list_lock) | |
9bccf70c | 198 | |
c910b4d9 A |
199 | extern uint32_t processor_avail_count; |
200 | ||
201 | extern processor_t master_processor; | |
1c79356b | 202 | |
6d2010ae A |
203 | extern boolean_t sched_stats_active; |
204 | ||
1c79356b | 205 | /* |
2d21ac55 A |
206 | * Processor state is accessed by locking the scheduling lock |
207 | * for the assigned processor set. | |
fe8ab488 A |
208 | * |
209 | * -------------------- SHUTDOWN | |
210 | * / ^ ^ | |
211 | * _/ | \ | |
212 | * OFF_LINE ---> START ---> RUNNING ---> IDLE ---> DISPATCHING | |
213 | * \_________________^ ^ ^______/ / | |
214 | * \__________________/ | |
215 | * | |
216 | * Most of these state transitions are externally driven as a | |
217 | * a directive (for instance telling an IDLE processor to start | |
218 | * coming out of the idle state to run a thread). However these | |
219 | * are typically paired with a handshake by the processor itself | |
220 | * to indicate that it has completed a transition of indeterminate | |
221 | * length (for example, the DISPATCHING->RUNNING or START->RUNNING | |
222 | * transitions must occur on the processor itself). | |
223 | * | |
224 | * The boot processor has some special cases, and skips the START state, | |
225 | * since it has already bootstrapped and is ready to context switch threads. | |
226 | * | |
227 | * When a processor is in DISPATCHING or RUNNING state, the current_pri, | |
228 | * current_thmode, and deadline fields should be set, so that other | |
229 | * processors can evaluate if it is an appropriate candidate for preemption. | |
3e170ce0 A |
230 | */ |
231 | #if defined(CONFIG_SCHED_DEFERRED_AST) | |
232 | /* | |
233 | * -------------------- SHUTDOWN | |
234 | * / ^ ^ | |
235 | * _/ | \ | |
236 | * OFF_LINE ---> START ---> RUNNING ---> IDLE ---> DISPATCHING | |
237 | * \_________________^ ^ ^______/ ^_____ / / | |
238 | * \__________________/ | |
239 | * | |
240 | * A DISPATCHING processor may be put back into IDLE, if another | |
241 | * processor determines that the target processor will have nothing to do | |
242 | * upon reaching the RUNNING state. This is racy, but if the target | |
243 | * responds and becomes RUNNING, it will not break the processor state | |
244 | * machine. | |
245 | * | |
246 | * This change allows us to cancel an outstanding signal/AST on a processor | |
247 | * (if such an operation is supported through hardware or software), and | |
248 | * push the processor back into the IDLE state as a power optimization. | |
249 | */ | |
250 | #endif | |
251 | ||
55e303ae | 252 | #define PROCESSOR_OFF_LINE 0 /* Not available */ |
2d21ac55 A |
253 | #define PROCESSOR_SHUTDOWN 1 /* Going off-line */ |
254 | #define PROCESSOR_START 2 /* Being started */ | |
fe8ab488 | 255 | /* 3 Formerly Inactive (unavailable) */ |
c910b4d9 A |
256 | #define PROCESSOR_IDLE 4 /* Idle (available) */ |
257 | #define PROCESSOR_DISPATCHING 5 /* Dispatching (idle -> active) */ | |
258 | #define PROCESSOR_RUNNING 6 /* Normal execution */ | |
1c79356b | 259 | |
91447636 | 260 | extern processor_t current_processor(void); |
1c79356b | 261 | |
3e170ce0 | 262 | /* Lock macros, always acquired and released with interrupts disabled (splsched()) */ |
2d21ac55 | 263 | |
3e170ce0 | 264 | #if __SMP__ |
2d21ac55 A |
265 | #define pset_lock(p) simple_lock(&(p)->sched_lock) |
266 | #define pset_unlock(p) simple_unlock(&(p)->sched_lock) | |
267 | #define pset_lock_init(p) simple_lock_init(&(p)->sched_lock, 0) | |
3e170ce0 A |
268 | #else |
269 | #define pset_lock(p) do { (void)p; } while(0) | |
270 | #define pset_unlock(p) do { (void)p; } while(0) | |
271 | #define pset_lock_init(p) do { (void)p; } while(0) | |
272 | #endif | |
2d21ac55 | 273 | |
39236c6e | 274 | extern void processor_bootstrap(void); |
91447636 A |
275 | |
276 | extern void processor_init( | |
277 | processor_t processor, | |
b0d623f7 | 278 | int cpu_id, |
39236c6e | 279 | processor_set_t processor_set); |
1c79356b | 280 | |
fe8ab488 | 281 | extern void processor_set_primary( |
b0d623f7 A |
282 | processor_t processor, |
283 | processor_t primary); | |
284 | ||
1c79356b | 285 | extern kern_return_t processor_shutdown( |
55e303ae | 286 | processor_t processor); |
1c79356b | 287 | |
2d21ac55 A |
288 | extern void processor_queue_shutdown( |
289 | processor_t processor); | |
1c79356b | 290 | |
2d21ac55 A |
291 | extern processor_set_t processor_pset( |
292 | processor_t processor); | |
1c79356b | 293 | |
2d21ac55 | 294 | extern pset_node_t pset_node_root(void); |
1c79356b | 295 | |
2d21ac55 A |
296 | extern processor_set_t pset_create( |
297 | pset_node_t node); | |
1c79356b | 298 | |
2d21ac55 | 299 | extern void pset_init( |
55e303ae | 300 | processor_set_t pset, |
39236c6e | 301 | pset_node_t node); |
1c79356b A |
302 | |
303 | extern kern_return_t processor_info_count( | |
55e303ae A |
304 | processor_flavor_t flavor, |
305 | mach_msg_type_number_t *count); | |
9bccf70c | 306 | |
2d21ac55 A |
307 | #define pset_deallocate(x) |
308 | #define pset_reference(x) | |
309 | ||
b7266188 A |
310 | extern void machine_run_count( |
311 | uint32_t count); | |
312 | ||
b7266188 A |
313 | extern processor_t machine_choose_processor( |
314 | processor_set_t pset, | |
315 | processor_t processor); | |
c910b4d9 | 316 | |
fe8ab488 A |
317 | #define next_pset(p) (((p)->pset_list != PROCESSOR_SET_NULL)? (p)->pset_list: (p)->node->psets) |
318 | ||
3e170ce0 A |
319 | #define PSET_THING_TASK 0 |
320 | #define PSET_THING_THREAD 1 | |
321 | ||
322 | extern kern_return_t processor_set_things( | |
323 | processor_set_t pset, | |
324 | void **thing_list, | |
325 | mach_msg_type_number_t *count, | |
326 | int type); | |
327 | ||
2d21ac55 | 328 | #else /* MACH_KERNEL_PRIVATE */ |
1c79356b | 329 | |
91447636 | 330 | __BEGIN_DECLS |
9bccf70c A |
331 | |
332 | extern void pset_deallocate( | |
55e303ae | 333 | processor_set_t pset); |
9bccf70c A |
334 | |
335 | extern void pset_reference( | |
55e303ae | 336 | processor_set_t pset); |
9bccf70c | 337 | |
91447636 A |
338 | __END_DECLS |
339 | ||
2d21ac55 A |
340 | #endif /* MACH_KERNEL_PRIVATE */ |
341 | ||
fe8ab488 A |
342 | #ifdef KERNEL_PRIVATE |
343 | __BEGIN_DECLS | |
344 | extern processor_t cpu_to_processor(int cpu); | |
345 | __END_DECLS | |
346 | ||
347 | #endif /* KERNEL_PRIVATE */ | |
348 | ||
1c79356b | 349 | #endif /* _KERN_PROCESSOR_H_ */ |