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