]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/processor.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / osfmk / kern / processor.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
d7e50217 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
d7e50217
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d7e50217
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * @OSF_COPYRIGHT@
27 */
28/*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53/*
54 */
55
56/*
57 * processor.h: Processor and processor-set definitions.
58 */
59
60#ifndef _KERN_PROCESSOR_H_
61#define _KERN_PROCESSOR_H_
62
63/*
64 * Data structures for managing processors and sets of processors.
65 */
66#include <mach/boolean.h>
67#include <mach/kern_return.h>
68#include <kern/kern_types.h>
69
9bccf70c
A
70#include <sys/appleapiopts.h>
71
72#ifdef __APPLE_API_PRIVATE
1c79356b 73
9bccf70c 74#ifdef MACH_KERNEL_PRIVATE
1c79356b
A
75
76#include <cpus.h>
1c79356b
A
77
78#include <mach/mach_types.h>
79#include <kern/cpu_number.h>
80#include <kern/lock.h>
81#include <kern/queue.h>
82#include <kern/sched.h>
9bccf70c 83#include <kern/cpu_data.h>
1c79356b 84
1c79356b 85#include <machine/ast_types.h>
1c79356b
A
86
87struct processor_set {
1c79356b
A
88 queue_head_t idle_queue; /* idle processors */
89 int idle_count; /* how many ? */
9bccf70c
A
90 queue_head_t active_queue; /* active processors */
91 decl_simple_lock_data(,sched_lock) /* lock for above */
92
1c79356b
A
93 queue_head_t processors; /* all processors here */
94 int processor_count;/* how many ? */
95 decl_simple_lock_data(,processors_lock) /* lock for above */
9bccf70c
A
96
97 struct run_queue runq; /* runq for this set */
98
1c79356b
A
99 queue_head_t tasks; /* tasks assigned */
100 int task_count; /* how many */
101 queue_head_t threads; /* threads in this set */
102 int thread_count; /* how many */
103 int ref_count; /* structure ref count */
104 boolean_t active; /* is pset in use */
9bccf70c
A
105 decl_mutex_data(, lock) /* lock for above */
106
0b4e3aa0
A
107 int set_quanta; /* timeslice quanta for timesharing */
108 int machine_quanta[NCPUS+1];
9bccf70c
A
109
110 struct ipc_port * pset_self; /* port for operations */
111 struct ipc_port * pset_name_self; /* port for information */
112
113 uint32_t run_count; /* number of threads running in set */
114
1c79356b
A
115 integer_t mach_factor; /* mach_factor */
116 integer_t load_average; /* load_average */
9bccf70c 117 uint32_t sched_load; /* load avg for scheduler */
1c79356b
A
118};
119
120struct processor {
9bccf70c
A
121 queue_chain_t processor_queue;/* idle/active/action queue link,
122 * MUST remain the first element */
1c79356b 123 int state; /* See below */
9bccf70c 124 int current_pri; /* priority of current thread */
1c79356b
A
125 struct thread_shuttle
126 *next_thread, /* next thread to run if dispatched */
127 *idle_thread; /* this processor's idle thread. */
0b4e3aa0
A
128 timer_call_data_t quantum_timer; /* timer for quantum expiration */
129 int slice_quanta; /* quanta before timeslice ends */
130 uint64_t quantum_end; /* time when current quantum ends */
131 uint64_t last_dispatch; /* time of last dispatch */
1c79356b 132
9bccf70c
A
133 struct run_queue runq; /* local runq for this processor */
134
135 processor_set_t processor_set; /* current membership */
136 processor_set_t processor_set_next; /* set to join in progress */
1c79356b
A
137 queue_chain_t processors; /* all processors in set */
138 decl_simple_lock_data(,lock)
139 struct ipc_port *processor_self;/* port for operations */
9bccf70c 140 cpu_data_t *cpu_data; /* machine-dep per-cpu data */
1c79356b 141 int slot_num; /* machine-indep slot number */
1c79356b
A
142};
143
9bccf70c
A
144extern struct processor_set default_pset;
145extern processor_t master_processor;
146
1c79356b
A
147extern struct processor processor_array[NCPUS];
148
149/*
150 * NOTE: The processor->processor_set link is needed in one of the
151 * scheduler's critical paths. [Figure out where to look for another
152 * thread to run on this processor.] It is accessed without locking.
153 * The following access protocol controls this field.
154 *
155 * Read from own processor - just read.
156 * Read from another processor - lock processor structure during read.
157 * Write from own processor - lock processor structure during write.
158 * Write from another processor - NOT PERMITTED.
159 *
160 */
161
162/*
163 * Processor state locking:
164 *
165 * Values for the processor state are defined below. If the processor
166 * is off-line or being shutdown, then it is only necessary to lock
167 * the processor to change its state. Otherwise it is only necessary
9bccf70c
A
168 * to lock its processor set's sched_lock. Scheduler code will
169 * typically lock only the sched_lock, but processor manipulation code
1c79356b
A
170 * will often lock both.
171 */
172
173#define PROCESSOR_OFF_LINE 0 /* Not in system */
174#define PROCESSOR_RUNNING 1 /* Running a normal thread */
175#define PROCESSOR_IDLE 2 /* idle */
176#define PROCESSOR_DISPATCHING 3 /* dispatching (idle -> running) */
177#define PROCESSOR_ASSIGN 4 /* Assignment is changing */
178#define PROCESSOR_SHUTDOWN 5 /* Being shutdown */
179#define PROCESSOR_START 6 /* Being start */
180
181/*
182 * Use processor ptr array to find current processor's data structure.
183 * This replaces a multiplication (index into processor_array) with
184 * an array lookup and a memory reference. It also allows us to save
185 * space if processor numbering gets too sparse.
186 */
187
188extern processor_t processor_ptr[NCPUS];
189
190#define cpu_to_processor(i) (processor_ptr[i])
191
192#define current_processor() (processor_ptr[cpu_number()])
193#define current_processor_set() (current_processor()->processor_set)
194
195/* Compatibility -- will go away */
196
197#define cpu_state(slot_num) (processor_ptr[slot_num]->state)
198#define cpu_idle(slot_num) (cpu_state(slot_num) == PROCESSOR_IDLE)
199
200/* Useful lock macros */
201
202#define pset_lock(pset) mutex_lock(&(pset)->lock)
203#define pset_lock_try(pset) mutex_try(&(pset)->lock)
204#define pset_unlock(pset) mutex_unlock(&(pset)->lock)
205
206#define processor_lock(pr) simple_lock(&(pr)->lock)
207#define processor_unlock(pr) simple_unlock(&(pr)->lock)
208
1c79356b
A
209extern void pset_sys_bootstrap(void);
210
9bccf70c
A
211#define pset_quanta_update(pset) \
212MACRO_BEGIN \
213 int proc_count = (pset)->processor_count; \
214 int runq_count = (pset)->runq.count; \
215 \
216 (pset)->set_quanta = (pset)->machine_quanta[ \
217 (runq_count > proc_count)? \
218 proc_count: runq_count]; \
219MACRO_END
220
1c79356b
A
221/* Implemented by MD layer */
222
223extern void cpu_up(
224 int cpu);
225
226extern kern_return_t processor_shutdown(
227 processor_t processor);
228
229extern void pset_remove_processor(
230 processor_set_t pset,
231 processor_t processor);
232
233extern void pset_add_processor(
234 processor_set_t pset,
235 processor_t processor);
236
237extern void pset_remove_task(
238 processor_set_t pset,
239 task_t task);
240
241extern void pset_add_task(
242 processor_set_t pset,
243 task_t task);
244
245extern void pset_remove_thread(
246 processor_set_t pset,
247 thread_t thread);
248
249extern void pset_add_thread(
250 processor_set_t pset,
251 thread_t thread);
252
253extern void thread_change_psets(
254 thread_t thread,
255 processor_set_t old_pset,
256 processor_set_t new_pset);
257
1c79356b
A
258extern kern_return_t processor_assign(
259 processor_t processor,
260 processor_set_t new_pset,
261 boolean_t wait);
262
263extern kern_return_t processor_info_count(
264 processor_flavor_t flavor,
265 mach_msg_type_number_t *count);
9bccf70c
A
266
267#endif /* MACH_KERNEL_PRIVATE */
1c79356b
A
268
269extern kern_return_t processor_start(
270 processor_t processor);
271
272extern kern_return_t processor_exit(
273 processor_t processor);
274
9bccf70c
A
275#endif /* __APPLE_API_PRIVATE */
276
277extern void pset_deallocate(
278 processor_set_t pset);
279
280extern void pset_reference(
281 processor_set_t pset);
282
1c79356b 283#endif /* _KERN_PROCESSOR_H_ */