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