]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/processor.h
xnu-1486.2.11.tar.gz
[apple/xnu.git] / osfmk / kern / processor.h
1 /*
2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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 /*
60 * processor.h: Processor and processor-related definitions.
61 */
62
63 #ifndef _KERN_PROCESSOR_H_
64 #define _KERN_PROCESSOR_H_
65
66 #include <mach/boolean.h>
67 #include <mach/kern_return.h>
68 #include <kern/kern_types.h>
69
70 #include <sys/cdefs.h>
71
72 #ifdef MACH_KERNEL_PRIVATE
73
74 #include <mach/mach_types.h>
75 #include <kern/ast.h>
76 #include <kern/cpu_number.h>
77 #include <kern/lock.h>
78 #include <kern/queue.h>
79 #include <kern/sched.h>
80 #include <kern/processor_data.h>
81
82 #include <machine/ast_types.h>
83
84 struct processor_set {
85 queue_head_t active_queue; /* active processors */
86 queue_head_t idle_queue; /* idle processors */
87
88 processor_t low_pri, low_count;
89
90 int processor_count;
91
92 decl_simple_lock_data(,sched_lock) /* lock for above */
93
94 struct ipc_port * pset_self; /* port for operations */
95 struct ipc_port * pset_name_self; /* port for information */
96
97 processor_set_t pset_list; /* chain of associated psets */
98 pset_node_t node;
99 };
100
101 extern struct processor_set pset0;
102
103 struct pset_node {
104 processor_set_t psets; /* list of associated psets */
105
106 pset_node_t nodes; /* list of associated subnodes */
107 pset_node_t node_list; /* chain of associated nodes */
108
109 pset_node_t parent;
110 };
111
112 extern struct pset_node pset_node0;
113
114 extern queue_head_t tasks, threads;
115 extern int tasks_count, threads_count;
116 decl_lck_mtx_data(extern,tasks_threads_lock)
117
118 struct processor_meta {
119 queue_head_t idle_queue;
120 processor_t primary;
121 };
122
123 typedef struct processor_meta *processor_meta_t;
124 #define PROCESSOR_META_NULL ((processor_meta_t) 0)
125
126 struct processor {
127 queue_chain_t processor_queue;/* idle/active queue link,
128 * MUST remain the first element */
129 int state; /* See below */
130 struct thread
131 *active_thread, /* thread running on processor */
132 *next_thread, /* next thread when dispatched */
133 *idle_thread; /* this processor's idle thread. */
134
135 processor_set_t processor_set; /* assigned set */
136
137 int current_pri; /* priority of current thread */
138 int cpu_id; /* platform numeric id */
139
140 timer_call_data_t quantum_timer; /* timer for quantum expiration */
141 uint64_t quantum_end; /* time when current quantum ends */
142 uint64_t last_dispatch; /* time of last dispatch */
143
144 uint64_t deadline; /* current deadline */
145 int timeslice; /* quanta before timeslice ends */
146
147 struct run_queue runq; /* runq for this processor */
148 processor_meta_t processor_meta;
149
150 struct ipc_port * processor_self; /* port for operations */
151
152 processor_t processor_list; /* all existing processors */
153 processor_data_t processor_data; /* per-processor data */
154 };
155
156 extern processor_t processor_list;
157 extern unsigned int processor_count;
158 decl_simple_lock_data(extern,processor_list_lock)
159
160 extern uint32_t processor_avail_count;
161
162 extern processor_t master_processor;
163
164 /*
165 * Processor state is accessed by locking the scheduling lock
166 * for the assigned processor set.
167 */
168 #define PROCESSOR_OFF_LINE 0 /* Not available */
169 #define PROCESSOR_SHUTDOWN 1 /* Going off-line */
170 #define PROCESSOR_START 2 /* Being started */
171 #define PROCESSOR_INACTIVE 3 /* Inactive (unavailable) */
172 #define PROCESSOR_IDLE 4 /* Idle (available) */
173 #define PROCESSOR_DISPATCHING 5 /* Dispatching (idle -> active) */
174 #define PROCESSOR_RUNNING 6 /* Normal execution */
175
176 extern processor_t current_processor(void);
177
178 extern processor_t cpu_to_processor(
179 int cpu);
180
181 /* Lock macros */
182
183 #define pset_lock(p) simple_lock(&(p)->sched_lock)
184 #define pset_unlock(p) simple_unlock(&(p)->sched_lock)
185 #define pset_lock_init(p) simple_lock_init(&(p)->sched_lock, 0)
186
187 /* Update hints */
188
189 #define pset_pri_hint(ps, p, pri) \
190 MACRO_BEGIN \
191 if ((p) != (ps)->low_pri) { \
192 if ((pri) < (ps)->low_pri->current_pri) \
193 (ps)->low_pri = (p); \
194 else \
195 if ((ps)->low_pri->state < PROCESSOR_IDLE) \
196 (ps)->low_pri = (p); \
197 } \
198 MACRO_END
199
200 #define pset_count_hint(ps, p, cnt) \
201 MACRO_BEGIN \
202 if ((p) != (ps)->low_count) { \
203 if ((cnt) < (ps)->low_count->runq.count) \
204 (ps)->low_count = (p); \
205 else \
206 if ((ps)->low_count->state < PROCESSOR_IDLE) \
207 (ps)->low_count = (p); \
208 } \
209 MACRO_END
210
211 extern void processor_bootstrap(void) __attribute__((section("__TEXT, initcode")));
212
213 extern void processor_init(
214 processor_t processor,
215 int cpu_id,
216 processor_set_t processor_set) __attribute__((section("__TEXT, initcode")));
217
218 extern void processor_meta_init(
219 processor_t processor,
220 processor_t primary);
221
222 extern kern_return_t processor_shutdown(
223 processor_t processor);
224
225 extern void processor_queue_shutdown(
226 processor_t processor);
227
228 extern processor_set_t processor_pset(
229 processor_t processor);
230
231 extern pset_node_t pset_node_root(void);
232
233 extern processor_set_t pset_create(
234 pset_node_t node);
235
236 extern void pset_init(
237 processor_set_t pset,
238 pset_node_t node) __attribute__((section("__TEXT, initcode")));
239
240 extern kern_return_t processor_info_count(
241 processor_flavor_t flavor,
242 mach_msg_type_number_t *count);
243
244 #define pset_deallocate(x)
245 #define pset_reference(x)
246
247 extern void machine_run_count(
248 uint32_t count);
249
250 extern boolean_t machine_cpu_is_inactive(
251 int cpu_id);
252
253 #else /* MACH_KERNEL_PRIVATE */
254
255 __BEGIN_DECLS
256
257 extern void pset_deallocate(
258 processor_set_t pset);
259
260 extern void pset_reference(
261 processor_set_t pset);
262
263 __END_DECLS
264
265 #endif /* MACH_KERNEL_PRIVATE */
266
267 #endif /* _KERN_PROCESSOR_H_ */