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