2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
54 * processor.h: Processor and processor-set definitions.
57 #ifndef _KERN_PROCESSOR_H_
58 #define _KERN_PROCESSOR_H_
61 * Data structures for managing processors and sets of processors.
63 #include <mach/boolean.h>
64 #include <mach/kern_return.h>
65 #include <kern/kern_types.h>
67 extern struct processor_set default_pset
;
68 extern processor_t master_processor
;
70 #ifdef MACH_KERNEL_PRIVATE
73 #include <mach_host.h>
75 #include <mach/mach_types.h>
76 #include <kern/cpu_number.h>
77 #include <kern/lock.h>
78 #include <kern/queue.h>
79 #include <kern/sched.h>
82 #include <machine/ast_types.h>
83 #endif /* NCPUS > 1 */
85 struct processor_set
{
86 struct run_queue runq
; /* runq for this set */
87 queue_head_t idle_queue
; /* idle processors */
88 int idle_count
; /* how many ? */
89 decl_simple_lock_data(,idle_lock
) /* lock for above */
90 queue_head_t processors
; /* all processors here */
91 int processor_count
;/* how many ? */
92 decl_simple_lock_data(,processors_lock
) /* lock for above */
93 queue_head_t tasks
; /* tasks assigned */
94 int task_count
; /* how many */
95 queue_head_t threads
; /* threads in this set */
96 int thread_count
; /* how many */
97 int ref_count
; /* structure ref count */
98 boolean_t active
; /* is pset in use */
99 decl_mutex_data(, lock
) /* lock for everything else */
100 struct ipc_port
* pset_self
; /* port for operations */
101 struct ipc_port
* pset_name_self
; /* port for information */
102 int max_priority
; /* maximum priority */
103 int policies
; /* bit vector for policies */
104 int set_quantum
; /* current default quantum */
106 int quantum_adj_index
; /* runtime quantum adj. */
107 decl_simple_lock_data(,quantum_adj_lock
) /* lock for above */
108 int machine_quantum
[NCPUS
+1]; /* ditto */
109 #endif /* NCPUS > 1 */
110 integer_t mach_factor
; /* mach_factor */
111 integer_t load_average
; /* load_average */
112 long sched_load
; /* load avg for scheduler */
113 policy_t policy_default
; /* per set default */
114 policy_base_data_t policy_base
; /* base attributes */
115 policy_limit_data_t policy_limit
; /* limit attributes */
119 struct run_queue runq
; /* local runq for this processor */
120 queue_chain_t processor_queue
;/* idle/assign/shutdown queue link */
121 int state
; /* See below */
122 struct thread_shuttle
123 *next_thread
, /* next thread to run if dispatched */
124 *idle_thread
; /* this processor's idle thread. */
125 int quantum
; /* quantum for current thread */
126 boolean_t first_quantum
; /* first quantum in succession */
127 int last_quantum
; /* last quantum assigned */
129 processor_set_t processor_set
; /* processor set I belong to */
130 processor_set_t processor_set_next
; /* set I will belong to */
131 queue_chain_t processors
; /* all processors in set */
132 decl_simple_lock_data(,lock
)
133 struct ipc_port
*processor_self
;/* port for operations */
134 int slot_num
; /* machine-indep slot number */
136 ast_check_t ast_check_data
; /* for remote ast_check invocation */
137 queue_chain_t softclock_queue
;/* cpus handling softclocks */
138 #endif /* NCPUS > 1 */
139 /* punt id data temporarily */
142 extern struct processor processor_array
[NCPUS
];
145 * NOTE: The processor->processor_set link is needed in one of the
146 * scheduler's critical paths. [Figure out where to look for another
147 * thread to run on this processor.] It is accessed without locking.
148 * The following access protocol controls this field.
150 * Read from own processor - just read.
151 * Read from another processor - lock processor structure during read.
152 * Write from own processor - lock processor structure during write.
153 * Write from another processor - NOT PERMITTED.
158 * Processor state locking:
160 * Values for the processor state are defined below. If the processor
161 * is off-line or being shutdown, then it is only necessary to lock
162 * the processor to change its state. Otherwise it is only necessary
163 * to lock its processor set's idle_lock. Scheduler code will
164 * typically lock only the idle_lock, but processor manipulation code
165 * will often lock both.
168 #define PROCESSOR_OFF_LINE 0 /* Not in system */
169 #define PROCESSOR_RUNNING 1 /* Running a normal thread */
170 #define PROCESSOR_IDLE 2 /* idle */
171 #define PROCESSOR_DISPATCHING 3 /* dispatching (idle -> running) */
172 #define PROCESSOR_ASSIGN 4 /* Assignment is changing */
173 #define PROCESSOR_SHUTDOWN 5 /* Being shutdown */
174 #define PROCESSOR_START 6 /* Being start */
177 * Use processor ptr array to find current processor's data structure.
178 * This replaces a multiplication (index into processor_array) with
179 * an array lookup and a memory reference. It also allows us to save
180 * space if processor numbering gets too sparse.
183 extern processor_t processor_ptr
[NCPUS
];
185 #define cpu_to_processor(i) (processor_ptr[i])
187 #define current_processor() (processor_ptr[cpu_number()])
188 #define current_processor_set() (current_processor()->processor_set)
190 /* Compatibility -- will go away */
192 #define cpu_state(slot_num) (processor_ptr[slot_num]->state)
193 #define cpu_idle(slot_num) (cpu_state(slot_num) == PROCESSOR_IDLE)
195 /* Useful lock macros */
197 #define pset_lock(pset) mutex_lock(&(pset)->lock)
198 #define pset_lock_try(pset) mutex_try(&(pset)->lock)
199 #define pset_unlock(pset) mutex_unlock(&(pset)->lock)
201 #define processor_lock(pr) simple_lock(&(pr)->lock)
202 #define processor_unlock(pr) simple_unlock(&(pr)->lock)
205 extern void pset_sys_bootstrap(void);
207 /* Implemented by MD layer */
212 extern kern_return_t
processor_shutdown(
213 processor_t processor
);
215 extern void pset_remove_processor(
216 processor_set_t pset
,
217 processor_t processor
);
219 extern void pset_add_processor(
220 processor_set_t pset
,
221 processor_t processor
);
223 extern void pset_remove_task(
224 processor_set_t pset
,
227 extern void pset_add_task(
228 processor_set_t pset
,
231 extern void pset_remove_thread(
232 processor_set_t pset
,
235 extern void pset_add_thread(
236 processor_set_t pset
,
239 extern void thread_change_psets(
241 processor_set_t old_pset
,
242 processor_set_t new_pset
);
244 extern void pset_deallocate(
245 processor_set_t pset
);
247 extern void pset_reference(
248 processor_set_t pset
);
250 extern kern_return_t
processor_assign(
251 processor_t processor
,
252 processor_set_t new_pset
,
255 extern kern_return_t
processor_info_count(
256 processor_flavor_t flavor
,
257 mach_msg_type_number_t
*count
);
258 #endif /* MACH_KERNEL_PRIVATE */
260 extern kern_return_t
processor_start(
261 processor_t processor
);
263 extern kern_return_t
processor_exit(
264 processor_t processor
);
266 #endif /* _KERN_PROCESSOR_H_ */