]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 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 A |
86 | queue_head_t idle_queue; /* idle processors */ |
87 | int idle_count; | |
9bccf70c | 88 | |
2d21ac55 A |
89 | processor_t low_hint; |
90 | processor_t high_hint; | |
9bccf70c | 91 | |
2d21ac55 | 92 | int processor_count; |
9bccf70c | 93 | |
2d21ac55 | 94 | decl_simple_lock_data(,sched_lock) /* lock for above */ |
9bccf70c A |
95 | |
96 | struct ipc_port * pset_self; /* port for operations */ | |
97 | struct ipc_port * pset_name_self; /* port for information */ | |
98 | ||
2d21ac55 A |
99 | processor_set_t pset_list; /* chain of associated psets */ |
100 | pset_node_t node; | |
101 | }; | |
102 | ||
103 | extern struct processor_set pset0; | |
9bccf70c | 104 | |
2d21ac55 A |
105 | struct pset_node { |
106 | processor_set_t psets; /* list of associated psets */ | |
91447636 | 107 | |
2d21ac55 A |
108 | pset_node_t nodes; /* list of associated subnodes */ |
109 | pset_node_t node_list; /* chain of associated nodes */ | |
110 | ||
111 | pset_node_t parent; | |
1c79356b A |
112 | }; |
113 | ||
2d21ac55 A |
114 | extern struct pset_node pset_node0; |
115 | ||
116 | extern queue_head_t tasks, threads; | |
117 | extern int tasks_count, threads_count; | |
118 | decl_mutex_data(extern,tasks_threads_lock) | |
91447636 | 119 | |
1c79356b | 120 | struct processor { |
91447636 | 121 | queue_chain_t processor_queue;/* idle/active queue link, |
9bccf70c | 122 | * MUST remain the first element */ |
1c79356b | 123 | int state; /* See below */ |
55e303ae A |
124 | struct thread |
125 | *active_thread, /* thread running on processor */ | |
91447636 | 126 | *next_thread, /* next thread when dispatched */ |
1c79356b | 127 | *idle_thread; /* this processor's idle thread. */ |
55e303ae | 128 | |
2d21ac55 | 129 | processor_set_t processor_set; /* assigned set */ |
55e303ae A |
130 | |
131 | int current_pri; /* priority of current thread */ | |
132 | ||
0b4e3aa0 | 133 | timer_call_data_t quantum_timer; /* timer for quantum expiration */ |
0b4e3aa0 A |
134 | uint64_t quantum_end; /* time when current quantum ends */ |
135 | uint64_t last_dispatch; /* time of last dispatch */ | |
1c79356b | 136 | |
55e303ae | 137 | uint64_t deadline; /* current deadline */ |
2d21ac55 | 138 | int timeslice; /* quanta before timeslice ends */ |
55e303ae | 139 | |
2d21ac55 | 140 | struct run_queue runq; /* runq for this processor */ |
9bccf70c | 141 | |
91447636 | 142 | struct ipc_port * processor_self; /* port for operations */ |
2d21ac55 A |
143 | decl_simple_lock_data(,lock) |
144 | ||
91447636 A |
145 | processor_t processor_list; /* all existing processors */ |
146 | processor_data_t processor_data; /* per-processor data */ | |
1c79356b A |
147 | }; |
148 | ||
91447636 A |
149 | extern processor_t processor_list; |
150 | extern unsigned int processor_count; | |
151 | decl_simple_lock_data(extern,processor_list_lock) | |
9bccf70c | 152 | |
91447636 | 153 | extern processor_t master_processor; |
1c79356b A |
154 | |
155 | /* | |
2d21ac55 A |
156 | * Processor state is accessed by locking the scheduling lock |
157 | * for the assigned processor set. | |
1c79356b | 158 | */ |
55e303ae | 159 | #define PROCESSOR_OFF_LINE 0 /* Not available */ |
2d21ac55 A |
160 | #define PROCESSOR_SHUTDOWN 1 /* Going off-line */ |
161 | #define PROCESSOR_START 2 /* Being started */ | |
162 | #define PROCESSOR_IDLE 3 /* Idle */ | |
163 | #define PROCESSOR_DISPATCHING 4 /* Dispatching (idle -> running) */ | |
164 | #define PROCESSOR_RUNNING 5 /* Normal execution */ | |
1c79356b | 165 | |
91447636 | 166 | extern processor_t current_processor(void); |
1c79356b | 167 | |
91447636 A |
168 | extern processor_t cpu_to_processor( |
169 | int cpu); | |
1c79356b | 170 | |
2d21ac55 A |
171 | /* Lock macros */ |
172 | ||
173 | #define pset_lock(p) simple_lock(&(p)->sched_lock) | |
174 | #define pset_unlock(p) simple_unlock(&(p)->sched_lock) | |
175 | #define pset_lock_init(p) simple_lock_init(&(p)->sched_lock, 0) | |
176 | ||
177 | #define processor_lock(p) simple_lock(&(p)->lock) | |
178 | #define processor_unlock(p) simple_unlock(&(p)->lock) | |
179 | #define processor_lock_init(p) simple_lock_init(&(p)->lock, 0) | |
180 | ||
181 | /* Update hints */ | |
182 | ||
183 | #define pset_hint_low(ps, p) \ | |
184 | MACRO_BEGIN \ | |
185 | if ((ps)->low_hint != PROCESSOR_NULL) { \ | |
186 | if ((p) != (ps)->low_hint) { \ | |
187 | if ((p)->runq.count < (ps)->low_hint->runq.count) \ | |
188 | (ps)->low_hint = (p); \ | |
189 | } \ | |
190 | } \ | |
191 | else \ | |
192 | (ps)->low_hint = (p); \ | |
193 | MACRO_END | |
194 | ||
195 | #define pset_hint_high(ps, p) \ | |
196 | MACRO_BEGIN \ | |
197 | if ((ps)->high_hint != PROCESSOR_NULL) { \ | |
198 | if ((p) != (ps)->high_hint) { \ | |
199 | if ((p)->runq.count > (ps)->high_hint->runq.count) \ | |
200 | (ps)->high_hint = (p); \ | |
201 | } \ | |
202 | } \ | |
203 | else \ | |
204 | (ps)->high_hint = (p); \ | |
205 | MACRO_END | |
206 | ||
207 | extern void processor_bootstrap(void) __attribute__((section("__TEXT, initcode"))); | |
91447636 A |
208 | |
209 | extern void processor_init( | |
210 | processor_t processor, | |
2d21ac55 A |
211 | int slot_num, |
212 | processor_set_t processor_set) __attribute__((section("__TEXT, initcode"))); | |
1c79356b | 213 | |
1c79356b | 214 | extern kern_return_t processor_shutdown( |
55e303ae | 215 | processor_t processor); |
1c79356b | 216 | |
2d21ac55 A |
217 | extern void processor_queue_shutdown( |
218 | processor_t processor); | |
1c79356b | 219 | |
2d21ac55 A |
220 | extern processor_set_t processor_pset( |
221 | processor_t processor); | |
1c79356b | 222 | |
2d21ac55 | 223 | extern pset_node_t pset_node_root(void); |
1c79356b | 224 | |
2d21ac55 A |
225 | extern processor_set_t pset_create( |
226 | pset_node_t node); | |
1c79356b | 227 | |
2d21ac55 | 228 | extern void pset_init( |
55e303ae | 229 | processor_set_t pset, |
2d21ac55 | 230 | pset_node_t node) __attribute__((section("__TEXT, initcode"))); |
1c79356b A |
231 | |
232 | extern kern_return_t processor_info_count( | |
55e303ae A |
233 | processor_flavor_t flavor, |
234 | mach_msg_type_number_t *count); | |
9bccf70c | 235 | |
2d21ac55 A |
236 | #define pset_deallocate(x) |
237 | #define pset_reference(x) | |
238 | ||
239 | #else /* MACH_KERNEL_PRIVATE */ | |
1c79356b | 240 | |
91447636 | 241 | __BEGIN_DECLS |
9bccf70c A |
242 | |
243 | extern void pset_deallocate( | |
55e303ae | 244 | processor_set_t pset); |
9bccf70c A |
245 | |
246 | extern void pset_reference( | |
55e303ae | 247 | processor_set_t pset); |
9bccf70c | 248 | |
91447636 A |
249 | __END_DECLS |
250 | ||
2d21ac55 A |
251 | #endif /* MACH_KERNEL_PRIVATE */ |
252 | ||
253 | #ifdef XNU_KERNEL_PRIVATE | |
254 | ||
255 | extern uint32_t processor_avail_count; | |
256 | ||
257 | #endif | |
1c79356b | 258 | #endif /* _KERN_PROCESSOR_H_ */ |