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