]>
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 A |
76 | #include <kern/cpu_number.h> |
77 | #include <kern/lock.h> | |
78 | #include <kern/queue.h> | |
79 | #include <kern/sched.h> | |
91447636 | 80 | #include <kern/processor_data.h> |
1c79356b | 81 | |
1c79356b | 82 | #include <machine/ast_types.h> |
1c79356b A |
83 | |
84 | struct processor_set { | |
9bccf70c | 85 | queue_head_t active_queue; /* active processors */ |
2d21ac55 | 86 | queue_head_t idle_queue; /* idle processors */ |
9bccf70c | 87 | |
c910b4d9 | 88 | processor_t low_pri, low_count; |
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 | ||
2d21ac55 | 95 | decl_simple_lock_data(,sched_lock) /* lock for above */ |
9bccf70c | 96 | |
6d2010ae A |
97 | #if defined(CONFIG_SCHED_TRADITIONAL) || defined(CONFIG_SCHED_FIXEDPRIORITY) |
98 | struct run_queue pset_runq; /* runq for this processor set */ | |
99 | int pset_runq_bound_count; | |
100 | /* # of threads in runq bound to any processor in pset */ | |
101 | #endif | |
39236c6e A |
102 | |
103 | /* CPUs that have been sent an unacknowledged remote AST for scheduling purposes */ | |
104 | uint32_t pending_AST_cpu_mask; | |
105 | ||
9bccf70c A |
106 | struct ipc_port * pset_self; /* port for operations */ |
107 | struct ipc_port * pset_name_self; /* port for information */ | |
108 | ||
2d21ac55 A |
109 | processor_set_t pset_list; /* chain of associated psets */ |
110 | pset_node_t node; | |
111 | }; | |
112 | ||
113 | extern struct processor_set pset0; | |
9bccf70c | 114 | |
2d21ac55 A |
115 | struct pset_node { |
116 | processor_set_t psets; /* list of associated psets */ | |
91447636 | 117 | |
2d21ac55 A |
118 | pset_node_t nodes; /* list of associated subnodes */ |
119 | pset_node_t node_list; /* chain of associated nodes */ | |
120 | ||
121 | pset_node_t parent; | |
1c79356b A |
122 | }; |
123 | ||
2d21ac55 A |
124 | extern struct pset_node pset_node0; |
125 | ||
6d2010ae | 126 | extern queue_head_t tasks, terminated_tasks, threads; /* Terminated tasks are ONLY for stackshot */ |
39236c6e | 127 | extern int tasks_count, terminated_tasks_count, threads_count; |
b0d623f7 A |
128 | decl_lck_mtx_data(extern,tasks_threads_lock) |
129 | ||
130 | struct processor_meta { | |
131 | queue_head_t idle_queue; | |
132 | processor_t primary; | |
133 | }; | |
134 | ||
135 | typedef struct processor_meta *processor_meta_t; | |
136 | #define PROCESSOR_META_NULL ((processor_meta_t) 0) | |
91447636 | 137 | |
1c79356b | 138 | struct processor { |
91447636 | 139 | queue_chain_t processor_queue;/* idle/active queue link, |
9bccf70c | 140 | * MUST remain the first element */ |
1c79356b | 141 | int state; /* See below */ |
55e303ae A |
142 | struct thread |
143 | *active_thread, /* thread running on processor */ | |
91447636 | 144 | *next_thread, /* next thread when dispatched */ |
1c79356b | 145 | *idle_thread; /* this processor's idle thread. */ |
55e303ae | 146 | |
2d21ac55 | 147 | processor_set_t processor_set; /* assigned set */ |
55e303ae A |
148 | |
149 | int current_pri; /* priority of current thread */ | |
6d2010ae | 150 | sched_mode_t current_thmode; /* sched mode of current thread */ |
b0d623f7 | 151 | int cpu_id; /* platform numeric id */ |
55e303ae | 152 | |
0b4e3aa0 | 153 | timer_call_data_t quantum_timer; /* timer for quantum expiration */ |
0b4e3aa0 A |
154 | uint64_t quantum_end; /* time when current quantum ends */ |
155 | uint64_t last_dispatch; /* time of last dispatch */ | |
1c79356b | 156 | |
55e303ae | 157 | uint64_t deadline; /* current deadline */ |
2d21ac55 | 158 | int timeslice; /* quanta before timeslice ends */ |
55e303ae | 159 | |
6d2010ae | 160 | #if defined(CONFIG_SCHED_TRADITIONAL) || defined(CONFIG_SCHED_FIXEDPRIORITY) |
2d21ac55 | 161 | struct run_queue runq; /* runq for this processor */ |
6d2010ae A |
162 | int runq_bound_count; /* # of threads bound to this processor */ |
163 | #endif | |
164 | #if defined(CONFIG_SCHED_GRRR) | |
165 | struct grrr_run_queue grrr_runq; /* Group Ratio Round-Robin runq */ | |
166 | #endif | |
b0d623f7 | 167 | processor_meta_t processor_meta; |
9bccf70c | 168 | |
91447636 | 169 | struct ipc_port * processor_self; /* port for operations */ |
2d21ac55 | 170 | |
91447636 A |
171 | processor_t processor_list; /* all existing processors */ |
172 | processor_data_t processor_data; /* per-processor data */ | |
1c79356b A |
173 | }; |
174 | ||
91447636 A |
175 | extern processor_t processor_list; |
176 | extern unsigned int processor_count; | |
177 | decl_simple_lock_data(extern,processor_list_lock) | |
9bccf70c | 178 | |
c910b4d9 A |
179 | extern uint32_t processor_avail_count; |
180 | ||
181 | extern processor_t master_processor; | |
1c79356b | 182 | |
6d2010ae A |
183 | extern boolean_t sched_stats_active; |
184 | ||
1c79356b | 185 | /* |
2d21ac55 A |
186 | * Processor state is accessed by locking the scheduling lock |
187 | * for the assigned processor set. | |
1c79356b | 188 | */ |
55e303ae | 189 | #define PROCESSOR_OFF_LINE 0 /* Not available */ |
2d21ac55 A |
190 | #define PROCESSOR_SHUTDOWN 1 /* Going off-line */ |
191 | #define PROCESSOR_START 2 /* Being started */ | |
c910b4d9 A |
192 | #define PROCESSOR_INACTIVE 3 /* Inactive (unavailable) */ |
193 | #define PROCESSOR_IDLE 4 /* Idle (available) */ | |
194 | #define PROCESSOR_DISPATCHING 5 /* Dispatching (idle -> active) */ | |
195 | #define PROCESSOR_RUNNING 6 /* Normal execution */ | |
1c79356b | 196 | |
91447636 | 197 | extern processor_t current_processor(void); |
1c79356b | 198 | |
91447636 A |
199 | extern processor_t cpu_to_processor( |
200 | int cpu); | |
1c79356b | 201 | |
2d21ac55 A |
202 | /* Lock macros */ |
203 | ||
204 | #define pset_lock(p) simple_lock(&(p)->sched_lock) | |
205 | #define pset_unlock(p) simple_unlock(&(p)->sched_lock) | |
206 | #define pset_lock_init(p) simple_lock_init(&(p)->sched_lock, 0) | |
207 | ||
2d21ac55 A |
208 | /* Update hints */ |
209 | ||
cf7d32b8 A |
210 | #define pset_pri_hint(ps, p, pri) \ |
211 | MACRO_BEGIN \ | |
212 | if ((p) != (ps)->low_pri) { \ | |
213 | if ((pri) < (ps)->low_pri->current_pri) \ | |
214 | (ps)->low_pri = (p); \ | |
c910b4d9 A |
215 | else \ |
216 | if ((ps)->low_pri->state < PROCESSOR_IDLE) \ | |
217 | (ps)->low_pri = (p); \ | |
218 | } \ | |
219 | MACRO_END | |
220 | ||
221 | #define pset_count_hint(ps, p, cnt) \ | |
222 | MACRO_BEGIN \ | |
223 | if ((p) != (ps)->low_count) { \ | |
6d2010ae | 224 | if ((cnt) < SCHED(processor_runq_count)((ps)->low_count)) \ |
c910b4d9 A |
225 | (ps)->low_count = (p); \ |
226 | else \ | |
227 | if ((ps)->low_count->state < PROCESSOR_IDLE) \ | |
228 | (ps)->low_count = (p); \ | |
cf7d32b8 | 229 | } \ |
2d21ac55 A |
230 | MACRO_END |
231 | ||
6d2010ae A |
232 | #define pset_pri_init_hint(ps, p) \ |
233 | MACRO_BEGIN \ | |
234 | (ps)->low_pri = (p); \ | |
235 | MACRO_END | |
236 | ||
237 | #define pset_count_init_hint(ps, p) \ | |
238 | MACRO_BEGIN \ | |
239 | (ps)->low_count = (p); \ | |
240 | MACRO_END | |
241 | ||
242 | ||
39236c6e | 243 | extern void processor_bootstrap(void); |
91447636 A |
244 | |
245 | extern void processor_init( | |
246 | processor_t processor, | |
b0d623f7 | 247 | int cpu_id, |
39236c6e | 248 | processor_set_t processor_set); |
1c79356b | 249 | |
b0d623f7 A |
250 | extern void processor_meta_init( |
251 | processor_t processor, | |
252 | processor_t primary); | |
253 | ||
1c79356b | 254 | extern kern_return_t processor_shutdown( |
55e303ae | 255 | processor_t processor); |
1c79356b | 256 | |
2d21ac55 A |
257 | extern void processor_queue_shutdown( |
258 | processor_t processor); | |
1c79356b | 259 | |
2d21ac55 A |
260 | extern processor_set_t processor_pset( |
261 | processor_t processor); | |
1c79356b | 262 | |
2d21ac55 | 263 | extern pset_node_t pset_node_root(void); |
1c79356b | 264 | |
2d21ac55 A |
265 | extern processor_set_t pset_create( |
266 | pset_node_t node); | |
1c79356b | 267 | |
2d21ac55 | 268 | extern void pset_init( |
55e303ae | 269 | processor_set_t pset, |
39236c6e | 270 | pset_node_t node); |
1c79356b A |
271 | |
272 | extern kern_return_t processor_info_count( | |
55e303ae A |
273 | processor_flavor_t flavor, |
274 | mach_msg_type_number_t *count); | |
9bccf70c | 275 | |
2d21ac55 A |
276 | #define pset_deallocate(x) |
277 | #define pset_reference(x) | |
278 | ||
b7266188 A |
279 | extern void machine_run_count( |
280 | uint32_t count); | |
281 | ||
282 | extern boolean_t machine_processor_is_inactive( | |
283 | processor_t processor); | |
c910b4d9 | 284 | |
b7266188 A |
285 | extern processor_t machine_choose_processor( |
286 | processor_set_t pset, | |
287 | processor_t processor); | |
c910b4d9 | 288 | |
2d21ac55 | 289 | #else /* MACH_KERNEL_PRIVATE */ |
1c79356b | 290 | |
91447636 | 291 | __BEGIN_DECLS |
9bccf70c A |
292 | |
293 | extern void pset_deallocate( | |
55e303ae | 294 | processor_set_t pset); |
9bccf70c A |
295 | |
296 | extern void pset_reference( | |
55e303ae | 297 | processor_set_t pset); |
9bccf70c | 298 | |
91447636 A |
299 | __END_DECLS |
300 | ||
2d21ac55 A |
301 | #endif /* MACH_KERNEL_PRIVATE */ |
302 | ||
1c79356b | 303 | #endif /* _KERN_PROCESSOR_H_ */ |