cpuvar.h revision 1.1.1.2.44.1 1 1.1 darran /*
2 1.1 darran * CDDL HEADER START
3 1.1 darran *
4 1.1 darran * The contents of this file are subject to the terms of the
5 1.1 darran * Common Development and Distribution License (the "License").
6 1.1 darran * You may not use this file except in compliance with the License.
7 1.1 darran *
8 1.1 darran * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 1.1 darran * or http://www.opensolaris.org/os/licensing.
10 1.1 darran * See the License for the specific language governing permissions
11 1.1 darran * and limitations under the License.
12 1.1 darran *
13 1.1 darran * When distributing Covered Code, include this CDDL HEADER in each
14 1.1 darran * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 1.1 darran * If applicable, add the following below this CDDL HEADER, with the
16 1.1 darran * fields enclosed by brackets "[]" replaced with your own identifying
17 1.1 darran * information: Portions Copyright [yyyy] [name of copyright owner]
18 1.1 darran *
19 1.1 darran * CDDL HEADER END
20 1.1 darran */
21 1.1 darran
22 1.1 darran /*
23 1.1.1.2.44.1 pgoyette * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 1.1.1.2.44.1 pgoyette * Copyright 2014 Igor Kozhukhov <ikozhukhov (at) gmail.com>.
25 1.1 darran */
26 1.1 darran
27 1.1 darran #ifndef _SYS_CPUVAR_H
28 1.1 darran #define _SYS_CPUVAR_H
29 1.1 darran
30 1.1 darran #include <sys/thread.h>
31 1.1 darran #include <sys/sysinfo.h> /* has cpu_stat_t definition */
32 1.1 darran #include <sys/disp.h>
33 1.1 darran #include <sys/processor.h>
34 1.1 darran
35 1.1.1.2.44.1 pgoyette #include <sys/loadavg.h>
36 1.1 darran #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
37 1.1 darran #include <sys/machcpuvar.h>
38 1.1 darran #endif
39 1.1 darran
40 1.1 darran #include <sys/types.h>
41 1.1 darran #include <sys/file.h>
42 1.1 darran #include <sys/bitmap.h>
43 1.1 darran #include <sys/rwlock.h>
44 1.1 darran #include <sys/msacct.h>
45 1.1 darran #if defined(__GNUC__) && defined(_ASM_INLINES) && defined(_KERNEL) && \
46 1.1 darran (defined(__i386) || defined(__amd64))
47 1.1 darran #include <asm/cpuvar.h>
48 1.1 darran #endif
49 1.1 darran
50 1.1 darran #ifdef __cplusplus
51 1.1 darran extern "C" {
52 1.1 darran #endif
53 1.1 darran
54 1.1 darran struct squeue_set_s;
55 1.1 darran
56 1.1 darran #define CPU_CACHE_COHERENCE_SIZE 64
57 1.1 darran
58 1.1 darran /*
59 1.1 darran * For fast event tracing.
60 1.1 darran */
61 1.1 darran struct ftrace_record;
62 1.1 darran typedef struct ftrace_data {
63 1.1 darran int ftd_state; /* ftrace flags */
64 1.1 darran kmutex_t ftd_unused; /* ftrace buffer lock, unused */
65 1.1 darran struct ftrace_record *ftd_cur; /* current record */
66 1.1 darran struct ftrace_record *ftd_first; /* first record */
67 1.1 darran struct ftrace_record *ftd_last; /* last record */
68 1.1 darran } ftrace_data_t;
69 1.1 darran
70 1.1 darran struct cyc_cpu;
71 1.1 darran struct nvlist;
72 1.1 darran
73 1.1 darran /*
74 1.1 darran * Per-CPU data.
75 1.1 darran *
76 1.1 darran * Be careful adding new members: if they are not the same in all modules (e.g.
77 1.1 darran * change size depending on a #define), CTF uniquification can fail to work
78 1.1 darran * properly. Furthermore, this is transitive in that it applies recursively to
79 1.1 darran * all types pointed to by cpu_t.
80 1.1 darran */
81 1.1 darran typedef struct cpu {
82 1.1 darran processorid_t cpu_id; /* CPU number */
83 1.1 darran processorid_t cpu_seqid; /* sequential CPU id (0..ncpus-1) */
84 1.1 darran volatile cpu_flag_t cpu_flags; /* flags indicating CPU state */
85 1.1 darran struct cpu *cpu_self; /* pointer to itself */
86 1.1 darran kthread_t *cpu_thread; /* current thread */
87 1.1 darran kthread_t *cpu_idle_thread; /* idle thread for this CPU */
88 1.1 darran kthread_t *cpu_pause_thread; /* pause thread for this CPU */
89 1.1 darran klwp_id_t cpu_lwp; /* current lwp (if any) */
90 1.1 darran klwp_id_t cpu_fpowner; /* currently loaded fpu owner */
91 1.1 darran struct cpupart *cpu_part; /* partition with this CPU */
92 1.1 darran struct lgrp_ld *cpu_lpl; /* pointer to this cpu's load */
93 1.1 darran int cpu_cache_offset; /* see kmem.c for details */
94 1.1 darran
95 1.1 darran /*
96 1.1 darran * Links to other CPUs. It is safe to walk these lists if
97 1.1 darran * one of the following is true:
98 1.1 darran * - cpu_lock held
99 1.1 darran * - preemption disabled via kpreempt_disable
100 1.1 darran * - PIL >= DISP_LEVEL
101 1.1 darran * - acting thread is an interrupt thread
102 1.1 darran * - all other CPUs are paused
103 1.1 darran */
104 1.1 darran struct cpu *cpu_next; /* next existing CPU */
105 1.1 darran struct cpu *cpu_prev; /* prev existing CPU */
106 1.1 darran struct cpu *cpu_next_onln; /* next online (enabled) CPU */
107 1.1 darran struct cpu *cpu_prev_onln; /* prev online (enabled) CPU */
108 1.1 darran struct cpu *cpu_next_part; /* next CPU in partition */
109 1.1 darran struct cpu *cpu_prev_part; /* prev CPU in partition */
110 1.1 darran struct cpu *cpu_next_lgrp; /* next CPU in latency group */
111 1.1 darran struct cpu *cpu_prev_lgrp; /* prev CPU in latency group */
112 1.1 darran struct cpu *cpu_next_lpl; /* next CPU in lgrp partition */
113 1.1 darran struct cpu *cpu_prev_lpl;
114 1.1 darran
115 1.1 darran struct cpu_pg *cpu_pg; /* cpu's processor groups */
116 1.1 darran
117 1.1 darran void *cpu_reserved[4]; /* reserved for future use */
118 1.1 darran
119 1.1 darran /*
120 1.1 darran * Scheduling variables.
121 1.1 darran */
122 1.1 darran disp_t *cpu_disp; /* dispatch queue data */
123 1.1 darran /*
124 1.1 darran * Note that cpu_disp is set before the CPU is added to the system
125 1.1 darran * and is never modified. Hence, no additional locking is needed
126 1.1 darran * beyond what's necessary to access the cpu_t structure.
127 1.1 darran */
128 1.1 darran char cpu_runrun; /* scheduling flag - set to preempt */
129 1.1 darran char cpu_kprunrun; /* force kernel preemption */
130 1.1 darran pri_t cpu_chosen_level; /* priority at which cpu */
131 1.1 darran /* was chosen for scheduling */
132 1.1 darran kthread_t *cpu_dispthread; /* thread selected for dispatch */
133 1.1 darran disp_lock_t cpu_thread_lock; /* dispatcher lock on current thread */
134 1.1 darran uint8_t cpu_disp_flags; /* flags used by dispatcher */
135 1.1 darran /*
136 1.1 darran * The following field is updated when ever the cpu_dispthread
137 1.1 darran * changes. Also in places, where the current thread(cpu_dispthread)
138 1.1 darran * priority changes. This is used in disp_lowpri_cpu()
139 1.1 darran */
140 1.1 darran pri_t cpu_dispatch_pri; /* priority of cpu_dispthread */
141 1.1 darran clock_t cpu_last_swtch; /* last time switched to new thread */
142 1.1 darran
143 1.1 darran /*
144 1.1 darran * Interrupt data.
145 1.1 darran */
146 1.1 darran caddr_t cpu_intr_stack; /* interrupt stack */
147 1.1 darran kthread_t *cpu_intr_thread; /* interrupt thread list */
148 1.1 darran uint_t cpu_intr_actv; /* interrupt levels active (bitmask) */
149 1.1 darran int cpu_base_spl; /* priority for highest rupt active */
150 1.1 darran
151 1.1 darran /*
152 1.1 darran * Statistics.
153 1.1 darran */
154 1.1 darran cpu_stats_t cpu_stats; /* per-CPU statistics */
155 1.1 darran struct kstat *cpu_info_kstat; /* kstat for cpu info */
156 1.1 darran
157 1.1 darran uintptr_t cpu_profile_pc; /* kernel PC in profile interrupt */
158 1.1 darran uintptr_t cpu_profile_upc; /* user PC in profile interrupt */
159 1.1 darran uintptr_t cpu_profile_pil; /* PIL when profile interrupted */
160 1.1 darran
161 1.1 darran ftrace_data_t cpu_ftrace; /* per cpu ftrace data */
162 1.1 darran
163 1.1.1.2 haad clock_t cpu_deadman_counter; /* used by deadman() */
164 1.1 darran uint_t cpu_deadman_countdown; /* used by deadman() */
165 1.1 darran
166 1.1 darran kmutex_t cpu_cpc_ctxlock; /* protects context for idle thread */
167 1.1 darran kcpc_ctx_t *cpu_cpc_ctx; /* performance counter context */
168 1.1 darran
169 1.1 darran /*
170 1.1 darran * Configuration information for the processor_info system call.
171 1.1 darran */
172 1.1 darran processor_info_t cpu_type_info; /* config info */
173 1.1 darran time_t cpu_state_begin; /* when CPU entered current state */
174 1.1 darran char cpu_cpr_flags; /* CPR related info */
175 1.1 darran struct cyc_cpu *cpu_cyclic; /* per cpu cyclic subsystem data */
176 1.1 darran struct squeue_set_s *cpu_squeue_set; /* per cpu squeue set */
177 1.1 darran struct nvlist *cpu_props; /* pool-related properties */
178 1.1 darran
179 1.1 darran krwlock_t cpu_ft_lock; /* DTrace: fasttrap lock */
180 1.1 darran uintptr_t cpu_dtrace_caller; /* DTrace: caller, if any */
181 1.1 darran hrtime_t cpu_dtrace_chillmark; /* DTrace: chill mark time */
182 1.1 darran hrtime_t cpu_dtrace_chilled; /* DTrace: total chill time */
183 1.1 darran volatile uint16_t cpu_mstate; /* cpu microstate */
184 1.1 darran volatile uint16_t cpu_mstate_gen; /* generation counter */
185 1.1 darran volatile hrtime_t cpu_mstate_start; /* cpu microstate start time */
186 1.1 darran volatile hrtime_t cpu_acct[NCMSTATES]; /* cpu microstate data */
187 1.1 darran hrtime_t cpu_intracct[NCMSTATES]; /* interrupt mstate data */
188 1.1 darran hrtime_t cpu_waitrq; /* cpu run-queue wait time */
189 1.1 darran struct loadavg_s cpu_loadavg; /* loadavg info for this cpu */
190 1.1 darran
191 1.1 darran char *cpu_idstr; /* for printing and debugging */
192 1.1 darran char *cpu_brandstr; /* for printing */
193 1.1 darran
194 1.1 darran /*
195 1.1 darran * Sum of all device interrupt weights that are currently directed at
196 1.1 darran * this cpu. Cleared at start of interrupt redistribution.
197 1.1 darran */
198 1.1 darran int32_t cpu_intr_weight;
199 1.1 darran void *cpu_vm_data;
200 1.1 darran
201 1.1 darran struct cpu_physid *cpu_physid; /* physical associations */
202 1.1 darran
203 1.1 darran uint64_t cpu_curr_clock; /* current clock freq in Hz */
204 1.1 darran char *cpu_supp_freqs; /* supported freqs in Hz */
205 1.1 darran
206 1.1.1.2 haad uintptr_t cpu_cpcprofile_pc; /* kernel PC in cpc interrupt */
207 1.1.1.2 haad uintptr_t cpu_cpcprofile_upc; /* user PC in cpc interrupt */
208 1.1.1.2 haad
209 1.1 darran /*
210 1.1 darran * Interrupt load factor used by dispatcher & softcall
211 1.1 darran */
212 1.1 darran hrtime_t cpu_intrlast; /* total interrupt time (nsec) */
213 1.1 darran int cpu_intrload; /* interrupt load factor (0-99%) */
214 1.1 darran
215 1.1.1.2 haad uint_t cpu_rotor; /* for cheap pseudo-random numbers */
216 1.1.1.2 haad
217 1.1.1.2 haad struct cu_cpu_info *cpu_cu_info; /* capacity & util. info */
218 1.1.1.2 haad
219 1.1.1.2 haad /*
220 1.1.1.2 haad * cpu_generation is updated whenever CPU goes on-line or off-line.
221 1.1.1.2 haad * Updates to cpu_generation are protected by cpu_lock.
222 1.1.1.2 haad *
223 1.1.1.2 haad * See CPU_NEW_GENERATION() macro below.
224 1.1.1.2 haad */
225 1.1.1.2 haad volatile uint_t cpu_generation; /* tracking on/off-line */
226 1.1.1.2 haad
227 1.1 darran /*
228 1.1 darran * New members must be added /before/ this member, as the CTF tools
229 1.1 darran * rely on this being the last field before cpu_m, so they can
230 1.1 darran * correctly calculate the offset when synthetically adding the cpu_m
231 1.1 darran * member in objects that do not have it. This fixup is required for
232 1.1 darran * uniquification to work correctly.
233 1.1 darran */
234 1.1 darran uintptr_t cpu_m_pad;
235 1.1 darran
236 1.1 darran #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
237 1.1 darran struct machcpu cpu_m; /* per architecture info */
238 1.1 darran #endif
239 1.1 darran } cpu_t;
240 1.1 darran
241 1.1 darran /*
242 1.1 darran * The cpu_core structure consists of per-CPU state available in any context.
243 1.1 darran * On some architectures, this may mean that the page(s) containing the
244 1.1 darran * NCPU-sized array of cpu_core structures must be locked in the TLB -- it
245 1.1 darran * is up to the platform to assure that this is performed properly. Note that
246 1.1 darran * the structure is sized to avoid false sharing.
247 1.1 darran */
248 1.1.1.2 haad #define CPUC_SIZE (sizeof (uint16_t) + sizeof (uint8_t) + \
249 1.1.1.2 haad sizeof (uintptr_t) + sizeof (kmutex_t))
250 1.1 darran #define CPUC_PADSIZE CPU_CACHE_COHERENCE_SIZE - CPUC_SIZE
251 1.1 darran
252 1.1 darran typedef struct cpu_core {
253 1.1 darran uint16_t cpuc_dtrace_flags; /* DTrace flags */
254 1.1.1.2 haad uint8_t cpuc_dcpc_intr_state; /* DCPC provider intr state */
255 1.1 darran uint8_t cpuc_pad[CPUC_PADSIZE]; /* padding */
256 1.1 darran uintptr_t cpuc_dtrace_illval; /* DTrace illegal value */
257 1.1 darran kmutex_t cpuc_pid_lock; /* DTrace pid provider lock */
258 1.1 darran } cpu_core_t;
259 1.1 darran
260 1.1 darran #ifdef _KERNEL
261 1.1 darran extern cpu_core_t cpu_core[];
262 1.1 darran #endif /* _KERNEL */
263 1.1 darran
264 1.1 darran /*
265 1.1 darran * CPU_ON_INTR() macro. Returns non-zero if currently on interrupt stack.
266 1.1 darran * Note that this isn't a test for a high PIL. For example, cpu_intr_actv
267 1.1 darran * does not get updated when we go through sys_trap from TL>0 at high PIL.
268 1.1 darran * getpil() should be used instead to check for PIL levels.
269 1.1 darran */
270 1.1 darran #define CPU_ON_INTR(cpup) ((cpup)->cpu_intr_actv >> (LOCK_LEVEL + 1))
271 1.1 darran
272 1.1.1.2 haad /*
273 1.1.1.2 haad * Check to see if an interrupt thread might be active at a given ipl.
274 1.1.1.2 haad * If so return true.
275 1.1.1.2 haad * We must be conservative--it is ok to give a false yes, but a false no
276 1.1.1.2 haad * will cause disaster. (But if the situation changes after we check it is
277 1.1.1.2 haad * ok--the caller is trying to ensure that an interrupt routine has been
278 1.1.1.2 haad * exited).
279 1.1.1.2 haad * This is used when trying to remove an interrupt handler from an autovector
280 1.1.1.2 haad * list in avintr.c.
281 1.1.1.2 haad */
282 1.1.1.2 haad #define INTR_ACTIVE(cpup, level) \
283 1.1.1.2 haad ((level) <= LOCK_LEVEL ? \
284 1.1.1.2 haad ((cpup)->cpu_intr_actv & (1 << (level))) : (CPU_ON_INTR(cpup)))
285 1.1.1.2 haad
286 1.1.1.2 haad /*
287 1.1.1.2 haad * CPU_PSEUDO_RANDOM() returns a per CPU value that changes each time one
288 1.1.1.2 haad * looks at it. It's meant as a cheap mechanism to be incorporated in routines
289 1.1.1.2 haad * wanting to avoid biasing, but where true randomness isn't needed (just
290 1.1.1.2 haad * something that changes).
291 1.1.1.2 haad */
292 1.1.1.2 haad #define CPU_PSEUDO_RANDOM() (CPU->cpu_rotor++)
293 1.1.1.2 haad
294 1.1 darran #if defined(_KERNEL) || defined(_KMEMUSER)
295 1.1 darran
296 1.1 darran #define INTR_STACK_SIZE MAX(DEFAULTSTKSZ, PAGESIZE)
297 1.1 darran
298 1.1 darran /* MEMBERS PROTECTED BY "atomicity": cpu_flags */
299 1.1 darran
300 1.1 darran /*
301 1.1 darran * Flags in the CPU structure.
302 1.1 darran *
303 1.1 darran * These are protected by cpu_lock (except during creation).
304 1.1 darran *
305 1.1 darran * Offlined-CPUs have three stages of being offline:
306 1.1 darran *
307 1.1 darran * CPU_ENABLE indicates that the CPU is participating in I/O interrupts
308 1.1 darran * that can be directed at a number of different CPUs. If CPU_ENABLE
309 1.1 darran * is off, the CPU will not be given interrupts that can be sent elsewhere,
310 1.1 darran * but will still get interrupts from devices associated with that CPU only,
311 1.1 darran * and from other CPUs.
312 1.1 darran *
313 1.1 darran * CPU_OFFLINE indicates that the dispatcher should not allow any threads
314 1.1 darran * other than interrupt threads to run on that CPU. A CPU will not have
315 1.1 darran * CPU_OFFLINE set if there are any bound threads (besides interrupts).
316 1.1 darran *
317 1.1 darran * CPU_QUIESCED is set if p_offline was able to completely turn idle the
318 1.1 darran * CPU and it will not have to run interrupt threads. In this case it'll
319 1.1 darran * stay in the idle loop until CPU_QUIESCED is turned off.
320 1.1 darran *
321 1.1 darran * CPU_FROZEN is used only by CPR to mark CPUs that have been successfully
322 1.1 darran * suspended (in the suspend path), or have yet to be resumed (in the resume
323 1.1 darran * case).
324 1.1 darran *
325 1.1 darran * On some platforms CPUs can be individually powered off.
326 1.1 darran * The following flags are set for powered off CPUs: CPU_QUIESCED,
327 1.1 darran * CPU_OFFLINE, and CPU_POWEROFF. The following flags are cleared:
328 1.1 darran * CPU_RUNNING, CPU_READY, CPU_EXISTS, and CPU_ENABLE.
329 1.1 darran */
330 1.1 darran #define CPU_RUNNING 0x001 /* CPU running */
331 1.1 darran #define CPU_READY 0x002 /* CPU ready for cross-calls */
332 1.1 darran #define CPU_QUIESCED 0x004 /* CPU will stay in idle */
333 1.1 darran #define CPU_EXISTS 0x008 /* CPU is configured */
334 1.1 darran #define CPU_ENABLE 0x010 /* CPU enabled for interrupts */
335 1.1 darran #define CPU_OFFLINE 0x020 /* CPU offline via p_online */
336 1.1 darran #define CPU_POWEROFF 0x040 /* CPU is powered off */
337 1.1 darran #define CPU_FROZEN 0x080 /* CPU is frozen via CPR suspend */
338 1.1 darran #define CPU_SPARE 0x100 /* CPU offline available for use */
339 1.1 darran #define CPU_FAULTED 0x200 /* CPU offline diagnosed faulty */
340 1.1 darran
341 1.1 darran #define FMT_CPU_FLAGS \
342 1.1 darran "\20\12fault\11spare\10frozen" \
343 1.1 darran "\7poweroff\6offline\5enable\4exist\3quiesced\2ready\1run"
344 1.1 darran
345 1.1 darran #define CPU_ACTIVE(cpu) (((cpu)->cpu_flags & CPU_OFFLINE) == 0)
346 1.1 darran
347 1.1 darran /*
348 1.1 darran * Flags for cpu_offline(), cpu_faulted(), and cpu_spare().
349 1.1 darran */
350 1.1 darran #define CPU_FORCED 0x0001 /* Force CPU offline */
351 1.1 darran
352 1.1 darran /*
353 1.1 darran * DTrace flags.
354 1.1 darran */
355 1.1 darran #define CPU_DTRACE_NOFAULT 0x0001 /* Don't fault */
356 1.1 darran #define CPU_DTRACE_DROP 0x0002 /* Drop this ECB */
357 1.1 darran #define CPU_DTRACE_BADADDR 0x0004 /* DTrace fault: bad address */
358 1.1 darran #define CPU_DTRACE_BADALIGN 0x0008 /* DTrace fault: bad alignment */
359 1.1 darran #define CPU_DTRACE_DIVZERO 0x0010 /* DTrace fault: divide by zero */
360 1.1 darran #define CPU_DTRACE_ILLOP 0x0020 /* DTrace fault: illegal operation */
361 1.1 darran #define CPU_DTRACE_NOSCRATCH 0x0040 /* DTrace fault: out of scratch */
362 1.1 darran #define CPU_DTRACE_KPRIV 0x0080 /* DTrace fault: bad kernel access */
363 1.1 darran #define CPU_DTRACE_UPRIV 0x0100 /* DTrace fault: bad user access */
364 1.1 darran #define CPU_DTRACE_TUPOFLOW 0x0200 /* DTrace fault: tuple stack overflow */
365 1.1 darran #if defined(__sparc)
366 1.1 darran #define CPU_DTRACE_FAKERESTORE 0x0400 /* pid provider hint to getreg */
367 1.1 darran #endif
368 1.1 darran #define CPU_DTRACE_ENTRY 0x0800 /* pid provider hint to ustack() */
369 1.1 darran #define CPU_DTRACE_BADSTACK 0x1000 /* DTrace fault: bad stack */
370 1.1 darran
371 1.1 darran #define CPU_DTRACE_FAULT (CPU_DTRACE_BADADDR | CPU_DTRACE_BADALIGN | \
372 1.1 darran CPU_DTRACE_DIVZERO | CPU_DTRACE_ILLOP | \
373 1.1 darran CPU_DTRACE_NOSCRATCH | CPU_DTRACE_KPRIV | \
374 1.1 darran CPU_DTRACE_UPRIV | CPU_DTRACE_TUPOFLOW | \
375 1.1 darran CPU_DTRACE_BADSTACK)
376 1.1 darran #define CPU_DTRACE_ERROR (CPU_DTRACE_FAULT | CPU_DTRACE_DROP)
377 1.1 darran
378 1.1 darran /*
379 1.1 darran * Dispatcher flags
380 1.1 darran * These flags must be changed only by the current CPU.
381 1.1 darran */
382 1.1 darran #define CPU_DISP_DONTSTEAL 0x01 /* CPU undergoing context swtch */
383 1.1 darran #define CPU_DISP_HALTED 0x02 /* CPU halted waiting for interrupt */
384 1.1 darran
385 1.1 darran #endif /* _KERNEL || _KMEMUSER */
386 1.1 darran
387 1.1 darran #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
388 1.1 darran
389 1.1 darran /*
390 1.1 darran * Macros for manipulating sets of CPUs as a bitmap. Note that this
391 1.1 darran * bitmap may vary in size depending on the maximum CPU id a specific
392 1.1 darran * platform supports. This may be different than the number of CPUs
393 1.1 darran * the platform supports, since CPU ids can be sparse. We define two
394 1.1 darran * sets of macros; one for platforms where the maximum CPU id is less
395 1.1 darran * than the number of bits in a single word (32 in a 32-bit kernel,
396 1.1 darran * 64 in a 64-bit kernel), and one for platforms that require bitmaps
397 1.1 darran * of more than one word.
398 1.1 darran */
399 1.1 darran
400 1.1 darran #define CPUSET_WORDS BT_BITOUL(NCPU)
401 1.1 darran #define CPUSET_NOTINSET ((uint_t)-1)
402 1.1 darran
403 1.1 darran #if CPUSET_WORDS > 1
404 1.1 darran
405 1.1 darran typedef struct cpuset {
406 1.1 darran ulong_t cpub[CPUSET_WORDS];
407 1.1 darran } cpuset_t;
408 1.1 darran
409 1.1 darran /*
410 1.1 darran * Private functions for manipulating cpusets that do not fit in a
411 1.1 darran * single word. These should not be used directly; instead the
412 1.1 darran * CPUSET_* macros should be used so the code will be portable
413 1.1 darran * across different definitions of NCPU.
414 1.1 darran */
415 1.1 darran extern void cpuset_all(cpuset_t *);
416 1.1 darran extern void cpuset_all_but(cpuset_t *, uint_t);
417 1.1 darran extern int cpuset_isnull(cpuset_t *);
418 1.1 darran extern int cpuset_cmp(cpuset_t *, cpuset_t *);
419 1.1 darran extern void cpuset_only(cpuset_t *, uint_t);
420 1.1 darran extern uint_t cpuset_find(cpuset_t *);
421 1.1 darran extern void cpuset_bounds(cpuset_t *, uint_t *, uint_t *);
422 1.1 darran
423 1.1 darran #define CPUSET_ALL(set) cpuset_all(&(set))
424 1.1 darran #define CPUSET_ALL_BUT(set, cpu) cpuset_all_but(&(set), cpu)
425 1.1 darran #define CPUSET_ONLY(set, cpu) cpuset_only(&(set), cpu)
426 1.1 darran #define CPU_IN_SET(set, cpu) BT_TEST((set).cpub, cpu)
427 1.1 darran #define CPUSET_ADD(set, cpu) BT_SET((set).cpub, cpu)
428 1.1 darran #define CPUSET_DEL(set, cpu) BT_CLEAR((set).cpub, cpu)
429 1.1 darran #define CPUSET_ISNULL(set) cpuset_isnull(&(set))
430 1.1 darran #define CPUSET_ISEQUAL(set1, set2) cpuset_cmp(&(set1), &(set2))
431 1.1 darran
432 1.1 darran /*
433 1.1 darran * Find one CPU in the cpuset.
434 1.1 darran * Sets "cpu" to the id of the found CPU, or CPUSET_NOTINSET if no cpu
435 1.1 darran * could be found. (i.e. empty set)
436 1.1 darran */
437 1.1 darran #define CPUSET_FIND(set, cpu) { \
438 1.1 darran cpu = cpuset_find(&(set)); \
439 1.1 darran }
440 1.1 darran
441 1.1 darran /*
442 1.1 darran * Determine the smallest and largest CPU id in the set. Returns
443 1.1 darran * CPUSET_NOTINSET in smallest and largest when set is empty.
444 1.1 darran */
445 1.1 darran #define CPUSET_BOUNDS(set, smallest, largest) { \
446 1.1 darran cpuset_bounds(&(set), &(smallest), &(largest)); \
447 1.1 darran }
448 1.1 darran
449 1.1 darran /*
450 1.1 darran * Atomic cpuset operations
451 1.1 darran * These are safe to use for concurrent cpuset manipulations.
452 1.1 darran * "xdel" and "xadd" are exclusive operations, that set "result" to "0"
453 1.1 darran * if the add or del was successful, or "-1" if not successful.
454 1.1 darran * (e.g. attempting to add a cpu to a cpuset that's already there, or
455 1.1 darran * deleting a cpu that's not in the cpuset)
456 1.1 darran */
457 1.1 darran
458 1.1 darran #define CPUSET_ATOMIC_DEL(set, cpu) BT_ATOMIC_CLEAR((set).cpub, (cpu))
459 1.1 darran #define CPUSET_ATOMIC_ADD(set, cpu) BT_ATOMIC_SET((set).cpub, (cpu))
460 1.1 darran
461 1.1 darran #define CPUSET_ATOMIC_XADD(set, cpu, result) \
462 1.1 darran BT_ATOMIC_SET_EXCL((set).cpub, cpu, result)
463 1.1 darran
464 1.1 darran #define CPUSET_ATOMIC_XDEL(set, cpu, result) \
465 1.1 darran BT_ATOMIC_CLEAR_EXCL((set).cpub, cpu, result)
466 1.1 darran
467 1.1 darran
468 1.1 darran #define CPUSET_OR(set1, set2) { \
469 1.1 darran int _i; \
470 1.1 darran for (_i = 0; _i < CPUSET_WORDS; _i++) \
471 1.1 darran (set1).cpub[_i] |= (set2).cpub[_i]; \
472 1.1 darran }
473 1.1 darran
474 1.1 darran #define CPUSET_XOR(set1, set2) { \
475 1.1 darran int _i; \
476 1.1 darran for (_i = 0; _i < CPUSET_WORDS; _i++) \
477 1.1 darran (set1).cpub[_i] ^= (set2).cpub[_i]; \
478 1.1 darran }
479 1.1 darran
480 1.1 darran #define CPUSET_AND(set1, set2) { \
481 1.1 darran int _i; \
482 1.1 darran for (_i = 0; _i < CPUSET_WORDS; _i++) \
483 1.1 darran (set1).cpub[_i] &= (set2).cpub[_i]; \
484 1.1 darran }
485 1.1 darran
486 1.1 darran #define CPUSET_ZERO(set) { \
487 1.1 darran int _i; \
488 1.1 darran for (_i = 0; _i < CPUSET_WORDS; _i++) \
489 1.1 darran (set).cpub[_i] = 0; \
490 1.1 darran }
491 1.1 darran
492 1.1 darran #elif CPUSET_WORDS == 1
493 1.1 darran
494 1.1 darran typedef ulong_t cpuset_t; /* a set of CPUs */
495 1.1 darran
496 1.1 darran #define CPUSET(cpu) (1UL << (cpu))
497 1.1 darran
498 1.1 darran #define CPUSET_ALL(set) ((void)((set) = ~0UL))
499 1.1 darran #define CPUSET_ALL_BUT(set, cpu) ((void)((set) = ~CPUSET(cpu)))
500 1.1 darran #define CPUSET_ONLY(set, cpu) ((void)((set) = CPUSET(cpu)))
501 1.1 darran #define CPU_IN_SET(set, cpu) ((set) & CPUSET(cpu))
502 1.1 darran #define CPUSET_ADD(set, cpu) ((void)((set) |= CPUSET(cpu)))
503 1.1 darran #define CPUSET_DEL(set, cpu) ((void)((set) &= ~CPUSET(cpu)))
504 1.1 darran #define CPUSET_ISNULL(set) ((set) == 0)
505 1.1 darran #define CPUSET_ISEQUAL(set1, set2) ((set1) == (set2))
506 1.1 darran #define CPUSET_OR(set1, set2) ((void)((set1) |= (set2)))
507 1.1 darran #define CPUSET_XOR(set1, set2) ((void)((set1) ^= (set2)))
508 1.1 darran #define CPUSET_AND(set1, set2) ((void)((set1) &= (set2)))
509 1.1 darran #define CPUSET_ZERO(set) ((void)((set) = 0))
510 1.1 darran
511 1.1 darran #define CPUSET_FIND(set, cpu) { \
512 1.1 darran cpu = (uint_t)(lowbit(set) - 1); \
513 1.1 darran }
514 1.1 darran
515 1.1 darran #define CPUSET_BOUNDS(set, smallest, largest) { \
516 1.1 darran smallest = (uint_t)(lowbit(set) - 1); \
517 1.1 darran largest = (uint_t)(highbit(set) - 1); \
518 1.1 darran }
519 1.1 darran
520 1.1.1.2.44.1 pgoyette #define CPUSET_ATOMIC_DEL(set, cpu) atomic_and_ulong(&(set), ~CPUSET(cpu))
521 1.1.1.2.44.1 pgoyette #define CPUSET_ATOMIC_ADD(set, cpu) atomic_or_ulong(&(set), CPUSET(cpu))
522 1.1 darran
523 1.1 darran #define CPUSET_ATOMIC_XADD(set, cpu, result) \
524 1.1 darran { result = atomic_set_long_excl(&(set), (cpu)); }
525 1.1 darran
526 1.1 darran #define CPUSET_ATOMIC_XDEL(set, cpu, result) \
527 1.1 darran { result = atomic_clear_long_excl(&(set), (cpu)); }
528 1.1 darran
529 1.1 darran #else /* CPUSET_WORDS <= 0 */
530 1.1 darran
531 1.1 darran #error NCPU is undefined or invalid
532 1.1 darran
533 1.1 darran #endif /* CPUSET_WORDS */
534 1.1 darran
535 1.1 darran extern cpuset_t cpu_seqid_inuse;
536 1.1 darran
537 1.1 darran #endif /* (_KERNEL || _KMEMUSER) && _MACHDEP */
538 1.1 darran
539 1.1 darran #define CPU_CPR_OFFLINE 0x0
540 1.1 darran #define CPU_CPR_ONLINE 0x1
541 1.1 darran #define CPU_CPR_IS_OFFLINE(cpu) (((cpu)->cpu_cpr_flags & CPU_CPR_ONLINE) == 0)
542 1.1 darran #define CPU_CPR_IS_ONLINE(cpu) ((cpu)->cpu_cpr_flags & CPU_CPR_ONLINE)
543 1.1 darran #define CPU_SET_CPR_FLAGS(cpu, flag) ((cpu)->cpu_cpr_flags |= flag)
544 1.1 darran
545 1.1 darran #if defined(_KERNEL) || defined(_KMEMUSER)
546 1.1 darran
547 1.1 darran extern struct cpu *cpu[]; /* indexed by CPU number */
548 1.1.1.2 haad extern struct cpu **cpu_seq; /* indexed by sequential CPU id */
549 1.1 darran extern cpu_t *cpu_list; /* list of CPUs */
550 1.1 darran extern cpu_t *cpu_active; /* list of active CPUs */
551 1.1 darran extern int ncpus; /* number of CPUs present */
552 1.1 darran extern int ncpus_online; /* number of CPUs not quiesced */
553 1.1 darran extern int max_ncpus; /* max present before ncpus is known */
554 1.1 darran extern int boot_max_ncpus; /* like max_ncpus but for real */
555 1.1 darran extern int boot_ncpus; /* # cpus present @ boot */
556 1.1 darran extern processorid_t max_cpuid; /* maximum CPU number */
557 1.1 darran extern struct cpu *cpu_inmotion; /* offline or partition move target */
558 1.1 darran extern cpu_t *clock_cpu_list;
559 1.1.1.2.44.1 pgoyette extern processorid_t max_cpu_seqid_ever; /* maximum seqid ever given */
560 1.1 darran
561 1.1 darran #if defined(__i386) || defined(__amd64)
562 1.1 darran extern struct cpu *curcpup(void);
563 1.1 darran #define CPU (curcpup()) /* Pointer to current CPU */
564 1.1 darran #else
565 1.1 darran #define CPU (curthread->t_cpu) /* Pointer to current CPU */
566 1.1 darran #endif
567 1.1 darran
568 1.1 darran /*
569 1.1 darran * CPU_CURRENT indicates to thread_affinity_set to use CPU->cpu_id
570 1.1 darran * as the target and to grab cpu_lock instead of requiring the caller
571 1.1 darran * to grab it.
572 1.1 darran */
573 1.1 darran #define CPU_CURRENT -3
574 1.1 darran
575 1.1 darran /*
576 1.1 darran * Per-CPU statistics
577 1.1 darran *
578 1.1 darran * cpu_stats_t contains numerous system and VM-related statistics, in the form
579 1.1 darran * of gauges or monotonically-increasing event occurrence counts.
580 1.1 darran */
581 1.1 darran
582 1.1 darran #define CPU_STATS_ENTER_K() kpreempt_disable()
583 1.1 darran #define CPU_STATS_EXIT_K() kpreempt_enable()
584 1.1 darran
585 1.1 darran #define CPU_STATS_ADD_K(class, stat, amount) \
586 1.1 darran { kpreempt_disable(); /* keep from switching CPUs */\
587 1.1 darran CPU_STATS_ADDQ(CPU, class, stat, amount); \
588 1.1 darran kpreempt_enable(); \
589 1.1 darran }
590 1.1 darran
591 1.1 darran #define CPU_STATS_ADDQ(cp, class, stat, amount) { \
592 1.1 darran extern void __dtrace_probe___cpu_##class##info_##stat(uint_t, \
593 1.1 darran uint64_t *, cpu_t *); \
594 1.1 darran uint64_t *stataddr = &((cp)->cpu_stats.class.stat); \
595 1.1 darran __dtrace_probe___cpu_##class##info_##stat((amount), \
596 1.1 darran stataddr, cp); \
597 1.1 darran *(stataddr) += (amount); \
598 1.1 darran }
599 1.1 darran
600 1.1 darran #define CPU_STATS(cp, stat) \
601 1.1 darran ((cp)->cpu_stats.stat)
602 1.1 darran
603 1.1.1.2 haad /*
604 1.1.1.2 haad * Increment CPU generation value.
605 1.1.1.2 haad * This macro should be called whenever CPU goes on-line or off-line.
606 1.1.1.2 haad * Updates to cpu_generation should be protected by cpu_lock.
607 1.1.1.2 haad */
608 1.1.1.2 haad #define CPU_NEW_GENERATION(cp) ((cp)->cpu_generation++)
609 1.1.1.2 haad
610 1.1 darran #endif /* _KERNEL || _KMEMUSER */
611 1.1 darran
612 1.1 darran /*
613 1.1 darran * CPU support routines.
614 1.1 darran */
615 1.1 darran #if defined(_KERNEL) && defined(__STDC__) /* not for genassym.c */
616 1.1 darran
617 1.1 darran struct zone;
618 1.1 darran
619 1.1 darran void cpu_list_init(cpu_t *);
620 1.1 darran void cpu_add_unit(cpu_t *);
621 1.1 darran void cpu_del_unit(int cpuid);
622 1.1 darran void cpu_add_active(cpu_t *);
623 1.1 darran void cpu_kstat_init(cpu_t *);
624 1.1 darran void cpu_visibility_add(cpu_t *, struct zone *);
625 1.1 darran void cpu_visibility_remove(cpu_t *, struct zone *);
626 1.1 darran void cpu_visibility_configure(cpu_t *, struct zone *);
627 1.1 darran void cpu_visibility_unconfigure(cpu_t *, struct zone *);
628 1.1 darran void cpu_visibility_online(cpu_t *, struct zone *);
629 1.1 darran void cpu_visibility_offline(cpu_t *, struct zone *);
630 1.1 darran void cpu_create_intrstat(cpu_t *);
631 1.1 darran void cpu_delete_intrstat(cpu_t *);
632 1.1 darran int cpu_kstat_intrstat_update(kstat_t *, int);
633 1.1 darran void cpu_intr_swtch_enter(kthread_t *);
634 1.1 darran void cpu_intr_swtch_exit(kthread_t *);
635 1.1 darran
636 1.1 darran void mbox_lock_init(void); /* initialize cross-call locks */
637 1.1 darran void mbox_init(int cpun); /* initialize cross-calls */
638 1.1 darran void poke_cpu(int cpun); /* interrupt another CPU (to preempt) */
639 1.1 darran
640 1.1 darran /*
641 1.1 darran * values for safe_list. Pause state that CPUs are in.
642 1.1 darran */
643 1.1 darran #define PAUSE_IDLE 0 /* normal state */
644 1.1 darran #define PAUSE_READY 1 /* paused thread ready to spl */
645 1.1 darran #define PAUSE_WAIT 2 /* paused thread is spl-ed high */
646 1.1 darran #define PAUSE_DIE 3 /* tell pause thread to leave */
647 1.1 darran #define PAUSE_DEAD 4 /* pause thread has left */
648 1.1 darran
649 1.1 darran void mach_cpu_pause(volatile char *);
650 1.1 darran
651 1.1.1.2.44.1 pgoyette void pause_cpus(cpu_t *off_cp, void *(*func)(void *));
652 1.1 darran void start_cpus(void);
653 1.1 darran int cpus_paused(void);
654 1.1 darran
655 1.1 darran void cpu_pause_init(void);
656 1.1 darran cpu_t *cpu_get(processorid_t cpun); /* get the CPU struct associated */
657 1.1 darran
658 1.1 darran int cpu_online(cpu_t *cp); /* take cpu online */
659 1.1 darran int cpu_offline(cpu_t *cp, int flags); /* take cpu offline */
660 1.1 darran int cpu_spare(cpu_t *cp, int flags); /* take cpu to spare */
661 1.1 darran int cpu_faulted(cpu_t *cp, int flags); /* take cpu to faulted */
662 1.1 darran int cpu_poweron(cpu_t *cp); /* take powered-off cpu to offline */
663 1.1 darran int cpu_poweroff(cpu_t *cp); /* take offline cpu to powered-off */
664 1.1 darran
665 1.1 darran cpu_t *cpu_intr_next(cpu_t *cp); /* get next online CPU taking intrs */
666 1.1 darran int cpu_intr_count(cpu_t *cp); /* count # of CPUs handling intrs */
667 1.1 darran int cpu_intr_on(cpu_t *cp); /* CPU taking I/O interrupts? */
668 1.1 darran void cpu_intr_enable(cpu_t *cp); /* enable I/O interrupts */
669 1.1 darran int cpu_intr_disable(cpu_t *cp); /* disable I/O interrupts */
670 1.1 darran void cpu_intr_alloc(cpu_t *cp, int n); /* allocate interrupt threads */
671 1.1 darran
672 1.1 darran /*
673 1.1 darran * Routines for checking CPU states.
674 1.1 darran */
675 1.1 darran int cpu_is_online(cpu_t *); /* check if CPU is online */
676 1.1 darran int cpu_is_nointr(cpu_t *); /* check if CPU can service intrs */
677 1.1 darran int cpu_is_active(cpu_t *); /* check if CPU can run threads */
678 1.1 darran int cpu_is_offline(cpu_t *); /* check if CPU is offline */
679 1.1 darran int cpu_is_poweredoff(cpu_t *); /* check if CPU is powered off */
680 1.1 darran
681 1.1 darran int cpu_flagged_online(cpu_flag_t); /* flags show CPU is online */
682 1.1 darran int cpu_flagged_nointr(cpu_flag_t); /* flags show CPU not handling intrs */
683 1.1 darran int cpu_flagged_active(cpu_flag_t); /* flags show CPU scheduling threads */
684 1.1 darran int cpu_flagged_offline(cpu_flag_t); /* flags show CPU is offline */
685 1.1 darran int cpu_flagged_poweredoff(cpu_flag_t); /* flags show CPU is powered off */
686 1.1 darran
687 1.1 darran /*
688 1.1 darran * The processor_info(2) state of a CPU is a simplified representation suitable
689 1.1 darran * for use by an application program. Kernel subsystems should utilize the
690 1.1 darran * internal per-CPU state as given by the cpu_flags member of the cpu structure,
691 1.1 darran * as this information may include platform- or architecture-specific state
692 1.1 darran * critical to a subsystem's disposition of a particular CPU.
693 1.1 darran */
694 1.1 darran void cpu_set_state(cpu_t *); /* record/timestamp current state */
695 1.1 darran int cpu_get_state(cpu_t *); /* get current cpu state */
696 1.1 darran const char *cpu_get_state_str(cpu_t *); /* get current cpu state as string */
697 1.1 darran
698 1.1 darran
699 1.1.1.2 haad void cpu_set_curr_clock(uint64_t); /* indicate the current CPU's freq */
700 1.1 darran void cpu_set_supp_freqs(cpu_t *, const char *); /* set the CPU supported */
701 1.1 darran /* frequencies */
702 1.1 darran
703 1.1 darran int cpu_configure(int);
704 1.1 darran int cpu_unconfigure(int);
705 1.1 darran void cpu_destroy_bound_threads(cpu_t *cp);
706 1.1 darran
707 1.1 darran extern int cpu_bind_thread(kthread_t *tp, processorid_t bind,
708 1.1 darran processorid_t *obind, int *error);
709 1.1 darran extern int cpu_unbind(processorid_t cpu_id, boolean_t force);
710 1.1 darran extern void thread_affinity_set(kthread_t *t, int cpu_id);
711 1.1 darran extern void thread_affinity_clear(kthread_t *t);
712 1.1 darran extern void affinity_set(int cpu_id);
713 1.1 darran extern void affinity_clear(void);
714 1.1 darran extern void init_cpu_mstate(struct cpu *, int);
715 1.1 darran extern void term_cpu_mstate(struct cpu *);
716 1.1 darran extern void new_cpu_mstate(int, hrtime_t);
717 1.1 darran extern void get_cpu_mstate(struct cpu *, hrtime_t *);
718 1.1 darran extern void thread_nomigrate(void);
719 1.1 darran extern void thread_allowmigrate(void);
720 1.1 darran extern void weakbinding_stop(void);
721 1.1 darran extern void weakbinding_start(void);
722 1.1 darran
723 1.1 darran /*
724 1.1 darran * The following routines affect the CPUs participation in interrupt processing,
725 1.1 darran * if that is applicable on the architecture. This only affects interrupts
726 1.1 darran * which aren't directed at the processor (not cross calls).
727 1.1 darran *
728 1.1 darran * cpu_disable_intr returns non-zero if interrupts were previously enabled.
729 1.1 darran */
730 1.1 darran int cpu_disable_intr(struct cpu *cp); /* stop issuing interrupts to cpu */
731 1.1 darran void cpu_enable_intr(struct cpu *cp); /* start issuing interrupts to cpu */
732 1.1 darran
733 1.1 darran /*
734 1.1 darran * The mutex cpu_lock protects cpu_flags for all CPUs, as well as the ncpus
735 1.1 darran * and ncpus_online counts.
736 1.1 darran */
737 1.1 darran extern kmutex_t cpu_lock; /* lock protecting CPU data */
738 1.1 darran
739 1.1.1.2 haad /*
740 1.1.1.2 haad * CPU state change events
741 1.1.1.2 haad *
742 1.1.1.2 haad * Various subsystems need to know when CPUs change their state. They get this
743 1.1.1.2 haad * information by registering CPU state change callbacks using
744 1.1.1.2 haad * register_cpu_setup_func(). Whenever any CPU changes its state, the callback
745 1.1.1.2 haad * function is called. The callback function is passed three arguments:
746 1.1.1.2 haad *
747 1.1.1.2 haad * Event, described by cpu_setup_t
748 1.1.1.2 haad * CPU ID
749 1.1.1.2 haad * Transparent pointer passed when registering the callback
750 1.1.1.2 haad *
751 1.1.1.2 haad * The callback function is called with cpu_lock held. The return value from the
752 1.1.1.2 haad * callback function is usually ignored, except for CPU_CONFIG and CPU_UNCONFIG
753 1.1.1.2 haad * events. For these two events, non-zero return value indicates a failure and
754 1.1.1.2 haad * prevents successful completion of the operation.
755 1.1.1.2 haad *
756 1.1.1.2 haad * New events may be added in the future. Callback functions should ignore any
757 1.1.1.2 haad * events that they do not understand.
758 1.1.1.2 haad *
759 1.1.1.2 haad * The following events provide notification callbacks:
760 1.1.1.2 haad *
761 1.1.1.2 haad * CPU_INIT A new CPU is started and added to the list of active CPUs
762 1.1.1.2 haad * This event is only used during boot
763 1.1.1.2 haad *
764 1.1.1.2 haad * CPU_CONFIG A newly inserted CPU is prepared for starting running code
765 1.1.1.2 haad * This event is called by DR code
766 1.1.1.2 haad *
767 1.1.1.2 haad * CPU_UNCONFIG CPU has been powered off and needs cleanup
768 1.1.1.2 haad * This event is called by DR code
769 1.1.1.2 haad *
770 1.1.1.2 haad * CPU_ON CPU is enabled but does not run anything yet
771 1.1.1.2 haad *
772 1.1.1.2 haad * CPU_INTR_ON CPU is enabled and has interrupts enabled
773 1.1.1.2 haad *
774 1.1.1.2 haad * CPU_OFF CPU is going offline but can still run threads
775 1.1.1.2 haad *
776 1.1.1.2 haad * CPU_CPUPART_OUT CPU is going to move out of its partition
777 1.1.1.2 haad *
778 1.1.1.2 haad * CPU_CPUPART_IN CPU is going to move to a new partition
779 1.1.1.2 haad *
780 1.1.1.2 haad * CPU_SETUP CPU is set up during boot and can run threads
781 1.1.1.2 haad */
782 1.1 darran typedef enum {
783 1.1 darran CPU_INIT,
784 1.1 darran CPU_CONFIG,
785 1.1 darran CPU_UNCONFIG,
786 1.1 darran CPU_ON,
787 1.1 darran CPU_OFF,
788 1.1 darran CPU_CPUPART_IN,
789 1.1.1.2 haad CPU_CPUPART_OUT,
790 1.1.1.2 haad CPU_SETUP,
791 1.1.1.2 haad CPU_INTR_ON
792 1.1 darran } cpu_setup_t;
793 1.1 darran
794 1.1 darran typedef int cpu_setup_func_t(cpu_setup_t, int, void *);
795 1.1 darran
796 1.1 darran /*
797 1.1 darran * Routines used to register interest in cpu's being added to or removed
798 1.1 darran * from the system.
799 1.1 darran */
800 1.1 darran extern void register_cpu_setup_func(cpu_setup_func_t *, void *);
801 1.1 darran extern void unregister_cpu_setup_func(cpu_setup_func_t *, void *);
802 1.1 darran extern void cpu_state_change_notify(int, cpu_setup_t);
803 1.1 darran
804 1.1 darran /*
805 1.1.1.2 haad * Call specified function on the given CPU
806 1.1.1.2 haad */
807 1.1.1.2 haad typedef void (*cpu_call_func_t)(uintptr_t, uintptr_t);
808 1.1.1.2 haad extern void cpu_call(cpu_t *, cpu_call_func_t, uintptr_t, uintptr_t);
809 1.1.1.2 haad
810 1.1.1.2 haad
811 1.1.1.2 haad /*
812 1.1 darran * Create various strings that describe the given CPU for the
813 1.1 darran * processor_info system call and configuration-related kstats.
814 1.1 darran */
815 1.1 darran #define CPU_IDSTRLEN 100
816 1.1 darran
817 1.1 darran extern void init_cpu_info(struct cpu *);
818 1.1 darran extern void populate_idstr(struct cpu *);
819 1.1 darran extern void cpu_vm_data_init(struct cpu *);
820 1.1 darran extern void cpu_vm_data_destroy(struct cpu *);
821 1.1 darran
822 1.1 darran #endif /* _KERNEL */
823 1.1 darran
824 1.1 darran #ifdef __cplusplus
825 1.1 darran }
826 1.1 darran #endif
827 1.1 darran
828 1.1 darran #endif /* _SYS_CPUVAR_H */
829