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/thread.h
+++ new/usr/src/uts/common/sys/thread.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 2010 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * Copyright 2018 Joyent, Inc.
29 29 */
30 30
31 31 #ifndef _SYS_THREAD_H
32 32 #define _SYS_THREAD_H
33 33
34 34
35 35 #include <sys/types.h>
36 36 #include <sys/t_lock.h>
37 37 #include <sys/klwp.h>
38 38 #include <sys/time.h>
39 39 #include <sys/signal.h>
40 40 #include <sys/kcpc.h>
41 41 #if defined(__GNUC__) && defined(_ASM_INLINES) && defined(_KERNEL)
42 42 #include <asm/thread.h>
43 43 #endif
44 44
45 45 #ifdef __cplusplus
46 46 extern "C" {
47 47 #endif
48 48
49 49 /*
50 50 * The thread object, its states, and the methods by which it
51 51 * is accessed.
52 52 */
53 53
54 54 /*
55 55 * Values that t_state may assume. Note that t_state cannot have more
56 56 * than one of these flags set at a time.
57 57 */
58 58 #define TS_FREE 0x00 /* Thread at loose ends */
59 59 #define TS_SLEEP 0x01 /* Awaiting an event */
60 60 #define TS_RUN 0x02 /* Runnable, but not yet on a processor */
61 61 #define TS_ONPROC 0x04 /* Thread is being run on a processor */
62 62 #define TS_ZOMB 0x08 /* Thread has died but hasn't been reaped */
63 63 #define TS_STOPPED 0x10 /* Stopped, initial state */
64 64 #define TS_WAIT 0x20 /* Waiting to become runnable */
65 65
66 66 typedef struct ctxop {
67 67 void (*save_op)(void *); /* function to invoke to save context */
68 68 void (*restore_op)(void *); /* function to invoke to restore ctx */
69 69 void (*fork_op)(void *, void *); /* invoke to fork context */
70 70 void (*lwp_create_op)(void *, void *); /* lwp_create context */
71 71 void (*exit_op)(void *); /* invoked during {thread,lwp}_exit() */
72 72 void (*free_op)(void *, int); /* function which frees the context */
73 73 void *arg; /* argument to above functions, ctx pointer */
74 74 struct ctxop *next; /* next context ops */
75 75 } ctxop_t;
76 76
77 77 /*
78 78 * The active file descriptor table.
79 79 * Each member of a_fd[] not equalling -1 represents an active fd.
80 80 * The structure is initialized on first use; all zeros means uninitialized.
81 81 */
82 82 typedef struct {
83 83 kmutex_t a_fdlock; /* protects a_fd and a_nfd */
84 84 int *a_fd; /* pointer to list of fds */
85 85 int a_nfd; /* number of entries in *a_fd */
86 86 int a_stale; /* one of the active fds is being closed */
87 87 int a_buf[2]; /* buffer to which a_fd initially refers */
88 88 } afd_t;
89 89
90 90 /*
91 91 * An lwpchan provides uniqueness when sleeping on user-level
92 92 * synchronization primitives. The lc_wchan member is used
93 93 * for sleeping on kernel synchronization primitives.
94 94 */
95 95 typedef struct {
96 96 caddr_t lc_wchan0;
97 97 caddr_t lc_wchan;
98 98 } lwpchan_t;
99 99
100 100 typedef struct _kthread *kthread_id_t;
101 101
102 102 struct turnstile;
103 103 struct panic_trap_info;
104 104 struct upimutex;
105 105 struct kproject;
106 106 struct on_trap_data;
107 107 struct waitq;
108 108 struct _kcpc_ctx;
109 109 struct _kcpc_set;
110 110
111 111 /* Definition for kernel thread identifier type */
112 112 typedef uint64_t kt_did_t;
113 113
114 114 typedef struct _kthread {
115 115 struct _kthread *t_link; /* dispq, sleepq, and free queue link */
116 116
117 117 caddr_t t_stk; /* base of stack (kernel sp value to use) */
118 118 void (*t_startpc)(void); /* PC where thread started */
119 119 struct cpu *t_bound_cpu; /* cpu bound to, or NULL if not bound */
120 120 short t_affinitycnt; /* nesting level of kernel affinity-setting */
121 121 short t_bind_cpu; /* user-specified CPU binding (-1 if none) */
122 122 ushort_t t_flag; /* modified only by current thread */
123 123 ushort_t t_proc_flag; /* modified holding ttproc(t)->p_lock */
124 124 ushort_t t_schedflag; /* modified holding thread_lock(t) */
125 125 volatile char t_preempt; /* don't preempt thread if set */
126 126 volatile char t_preempt_lk;
127 127 uint_t t_state; /* thread state (protected by thread_lock) */
128 128 pri_t t_pri; /* assigned thread priority */
129 129 pri_t t_epri; /* inherited thread priority */
130 130 pri_t t_cpri; /* thread scheduling class priority */
131 131 char t_writer; /* sleeping in lwp_rwlock_lock(RW_WRITE_LOCK) */
132 132 uchar_t t_bindflag; /* CPU and pset binding type */
133 133 label_t t_pcb; /* pcb, save area when switching */
134 134 lwpchan_t t_lwpchan; /* reason for blocking */
135 135 #define t_wchan0 t_lwpchan.lc_wchan0
136 136 #define t_wchan t_lwpchan.lc_wchan
137 137 struct _sobj_ops *t_sobj_ops;
138 138 id_t t_cid; /* scheduling class id */
139 139 struct thread_ops *t_clfuncs; /* scheduling class ops vector */
140 140 void *t_cldata; /* per scheduling class specific data */
141 141 ctxop_t *t_ctx; /* thread context */
142 142 uintptr_t t_lofault; /* ret pc for failed page faults */
143 143 label_t *t_onfault; /* on_fault() setjmp buf */
144 144 struct on_trap_data *t_ontrap; /* on_trap() protection data */
145 145 caddr_t t_swap; /* the bottom of the stack, if from segkp */
146 146 lock_t t_lock; /* used to resume() a thread */
147 147 uint8_t t_lockstat; /* set while thread is in lockstat code */
148 148 uint8_t t_pil; /* interrupt thread PIL */
149 149 disp_lock_t t_pi_lock; /* lock protecting t_prioinv list */
150 150 char t_nomigrate; /* do not migrate if set */
151 151 struct cpu *t_cpu; /* CPU that thread last ran on */
152 152 struct cpu *t_weakbound_cpu; /* cpu weakly bound to */
153 153 struct lgrp_ld *t_lpl; /* load average for home lgroup */
154 154 void *t_lgrp_reserv[2]; /* reserved for future */
155 155 struct _kthread *t_intr; /* interrupted (pinned) thread */
156 156 uint64_t t_intr_start; /* timestamp when time slice began */
157 157 kt_did_t t_did; /* thread id for kernel debuggers */
158 158 caddr_t t_tnf_tpdp; /* Trace facility data pointer */
159 159 struct _kcpc_ctx *t_cpc_ctx; /* performance counter context */
160 160 struct _kcpc_set *t_cpc_set; /* set this thread has bound */
161 161
162 162 /*
163 163 * non swappable part of the lwp state.
164 164 */
165 165 id_t t_tid; /* lwp's id */
166 166 id_t t_waitfor; /* target lwp id in lwp_wait() */
167 167 struct sigqueue *t_sigqueue; /* queue of siginfo structs */
168 168 k_sigset_t t_sig; /* signals pending to this process */
169 169 k_sigset_t t_extsig; /* signals sent from another contract */
170 170 k_sigset_t t_hold; /* hold signal bit mask */
171 171 k_sigset_t t_sigwait; /* sigtimedwait/sigfd accepting these */
172 172 struct _kthread *t_forw; /* process's forward thread link */
173 173 struct _kthread *t_back; /* process's backward thread link */
174 174 struct _kthread *t_thlink; /* tid (lwpid) lookup hash link */
175 175 klwp_t *t_lwp; /* thread's lwp pointer */
176 176 struct proc *t_procp; /* proc pointer */
177 177 struct t_audit_data *t_audit_data; /* per thread audit data */
178 178 struct _kthread *t_next; /* doubly linked list of all threads */
179 179 struct _kthread *t_prev;
180 180 ushort_t t_whystop; /* reason for stopping */
181 181 ushort_t t_whatstop; /* more detailed reason */
182 182 int t_dslot; /* index in proc's thread directory */
183 183 struct pollstate *t_pollstate; /* state used during poll(2) */
184 184 struct pollcache *t_pollcache; /* to pass a pcache ptr by /dev/poll */
185 185 struct cred *t_cred; /* pointer to current cred */
186 186 time_t t_start; /* start time, seconds since epoch */
187 187 clock_t t_lbolt; /* lbolt at last clock_tick() */
188 188 hrtime_t t_stoptime; /* timestamp at stop() */
189 189 uint_t t_pctcpu; /* %cpu at last clock_tick(), binary */
190 190 /* point at right of high-order bit */
191 191 short t_sysnum; /* system call number */
192 192 kcondvar_t t_delay_cv;
193 193 kmutex_t t_delay_lock;
194 194
195 195 /*
196 196 * Pointer to the dispatcher lock protecting t_state and state-related
197 197 * flags. This pointer can change during waits on the lock, so
198 198 * it should be grabbed only by thread_lock().
199 199 */
200 200 disp_lock_t *t_lockp; /* pointer to the dispatcher lock */
201 201 ushort_t t_oldspl; /* spl level before dispatcher locked */
202 202 volatile char t_pre_sys; /* pre-syscall work needed */
203 203 lock_t t_lock_flush; /* for lock_mutex_flush() impl */
204 204 struct _disp *t_disp_queue; /* run queue for chosen CPU */
205 205 clock_t t_disp_time; /* last time this thread was running */
206 206 uint_t t_kpri_req; /* kernel priority required */
207 207
208 208 /*
209 209 * Post-syscall / post-trap flags.
210 210 * No lock is required to set these.
211 211 * These must be cleared only by the thread itself.
212 212 *
213 213 * t_astflag indicates that some post-trap processing is required,
214 214 * possibly a signal or a preemption. The thread will not
215 215 * return to user with this set.
216 216 * t_post_sys indicates that some unusualy post-system call
217 217 * handling is required, such as an error or tracing.
218 218 * t_sig_check indicates that some condition in ISSIG() must be
219 219 * checked, but doesn't prevent returning to user.
220 220 * t_post_sys_ast is a way of checking whether any of these three
221 221 * flags are set.
222 222 */
223 223 union __tu {
224 224 struct __ts {
225 225 volatile char _t_astflag; /* AST requested */
226 226 volatile char _t_sig_check; /* ISSIG required */
227 227 volatile char _t_post_sys; /* post_syscall req */
228 228 volatile char _t_trapret; /* call CL_TRAPRET */
229 229 } _ts;
230 230 volatile int _t_post_sys_ast; /* OR of these flags */
231 231 } _tu;
232 232 #define t_astflag _tu._ts._t_astflag
233 233 #define t_sig_check _tu._ts._t_sig_check
234 234 #define t_post_sys _tu._ts._t_post_sys
235 235 #define t_trapret _tu._ts._t_trapret
236 236 #define t_post_sys_ast _tu._t_post_sys_ast
237 237
238 238 /*
239 239 * Real time microstate profiling.
240 240 */
241 241 /* possible 4-byte filler */
242 242 hrtime_t t_waitrq; /* timestamp for run queue wait time */
243 243 int t_mstate; /* current microstate */
244 244 struct rprof {
245 245 int rp_anystate; /* set if any state non-zero */
246 246 uint_t rp_state[NMSTATES]; /* mstate profiling counts */
247 247 } *t_rprof;
248 248
249 249 /*
250 250 * There is a turnstile inserted into the list below for
251 251 * every priority inverted synchronization object that
252 252 * this thread holds.
253 253 */
254 254
255 255 struct turnstile *t_prioinv;
256 256
257 257 /*
258 258 * Pointer to the turnstile attached to the synchronization
259 259 * object where this thread is blocked.
260 260 */
261 261
262 262 struct turnstile *t_ts;
263 263
264 264 /*
265 265 * kernel thread specific data
266 266 * Borrowed from userland implementation of POSIX tsd
267 267 */
268 268 struct tsd_thread {
269 269 struct tsd_thread *ts_next; /* threads with TSD */
270 270 struct tsd_thread *ts_prev; /* threads with TSD */
271 271 uint_t ts_nkeys; /* entries in value array */
272 272 void **ts_value; /* array of value/key */
273 273 } *t_tsd;
274 274
275 275 clock_t t_stime; /* time stamp used by the swapper */
276 276 struct door_data *t_door; /* door invocation data */
277 277 kmutex_t *t_plockp; /* pointer to process's p_lock */
278 278
279 279 struct sc_shared *t_schedctl; /* scheduler activations shared data */
280 280 uintptr_t t_sc_uaddr; /* user-level address of shared data */
281 281
282 282 struct cpupart *t_cpupart; /* partition containing thread */
283 283 int t_bind_pset; /* processor set binding */
284 284
285 285 struct copyops *t_copyops; /* copy in/out ops vector */
286 286
287 287 caddr_t t_stkbase; /* base of the the stack */
288 288 struct page *t_red_pp; /* if non-NULL, redzone is mapped */
289 289
290 290 afd_t t_activefd; /* active file descriptor table */
291 291
292 292 struct _kthread *t_priforw; /* sleepq per-priority sublist */
293 293 struct _kthread *t_priback;
294 294
295 295 struct sleepq *t_sleepq; /* sleep queue thread is waiting on */
296 296 struct panic_trap_info *t_panic_trap; /* saved data from fatal trap */
297 297 int *t_lgrp_affinity; /* lgroup affinity */
298 298 struct upimutex *t_upimutex; /* list of upimutexes owned by thread */
299 299 uint32_t t_nupinest; /* number of nested held upi mutexes */
300 300 struct kproject *t_proj; /* project containing this thread */
301 301 uint8_t t_unpark; /* modified holding t_delay_lock */
302 302 uint8_t t_release; /* lwp_release() waked up the thread */
303 303 uint8_t t_hatdepth; /* depth of recursive hat_memloads */
304 304 uint8_t t_xpvcntr; /* see xen_block_migrate() */
305 305 kcondvar_t t_joincv; /* cv used to wait for thread exit */
306 306 void *t_taskq; /* for threads belonging to taskq */
307 307 hrtime_t t_anttime; /* most recent time anticipatory load */
308 308 /* was added to an lgroup's load */
309 309 /* on this thread's behalf */
310 310 char *t_pdmsg; /* privilege debugging message */
311 311
312 312 uint_t t_predcache; /* DTrace predicate cache */
313 313 hrtime_t t_dtrace_vtime; /* DTrace virtual time */
314 314 hrtime_t t_dtrace_start; /* DTrace slice start time */
315 315
316 316 uint8_t t_dtrace_stop; /* indicates a DTrace-desired stop */
317 317 uint8_t t_dtrace_sig; /* signal sent via DTrace's raise() */
318 318
319 319 union __tdu {
320 320 struct __tds {
321 321 uint8_t _t_dtrace_on; /* hit a fasttrap tracepoint */
322 322 uint8_t _t_dtrace_step; /* about to return to kernel */
323 323 uint8_t _t_dtrace_ret; /* handling a return probe */
324 324 uint8_t _t_dtrace_ast; /* saved ast flag */
325 325 #ifdef __amd64
326 326 uint8_t _t_dtrace_reg; /* modified register */
327 327 #endif
328 328 } _tds;
329 329 ulong_t _t_dtrace_ft; /* bitwise or of these flags */
330 330 } _tdu;
331 331 #define t_dtrace_ft _tdu._t_dtrace_ft
332 332 #define t_dtrace_on _tdu._tds._t_dtrace_on
333 333 #define t_dtrace_step _tdu._tds._t_dtrace_step
334 334 #define t_dtrace_ret _tdu._tds._t_dtrace_ret
335 335 #define t_dtrace_ast _tdu._tds._t_dtrace_ast
336 336 #ifdef __amd64
337 337 #define t_dtrace_reg _tdu._tds._t_dtrace_reg
338 338 #endif
339 339
340 340 uintptr_t t_dtrace_pc; /* DTrace saved pc from fasttrap */
341 341 uintptr_t t_dtrace_npc; /* DTrace next pc from fasttrap */
342 342 uintptr_t t_dtrace_scrpc; /* DTrace per-thread scratch location */
343 343 uintptr_t t_dtrace_astpc; /* DTrace return sequence location */
↓ open down ↓ |
343 lines elided |
↑ open up ↑ |
344 344 #ifdef __amd64
345 345 uint64_t t_dtrace_regv; /* DTrace saved reg from fasttrap */
346 346 uint64_t t_useracc; /* SMAP state saved across swtch() */
347 347 #endif
348 348 hrtime_t t_hrtime; /* high-res last time on cpu */
349 349 kmutex_t t_ctx_lock; /* protects t_ctx in removectx() */
350 350 struct waitq *t_waitq; /* wait queue */
351 351 kmutex_t t_wait_mutex; /* used in CV wait functions */
352 352
353 353 char *t_name; /* thread name */
354 +
355 + uint64_t t_unsafe; /* unsafe to run with HT VCPU thread */
354 356 } kthread_t;
355 357
356 358 /*
357 359 * Thread flag (t_flag) definitions.
358 360 * These flags must be changed only for the current thread,
359 361 * and not during preemption code, since the code being
360 362 * preempted could be modifying the flags.
361 363 *
362 364 * For the most part these flags do not need locking.
363 365 * The following flags will only be changed while the thread_lock is held,
364 366 * to give assurrance that they are consistent with t_state:
365 367 * T_WAKEABLE
366 368 */
367 369 #define T_INTR_THREAD 0x0001 /* thread is an interrupt thread */
368 370 #define T_WAKEABLE 0x0002 /* thread is blocked, signals enabled */
369 371 #define T_TOMASK 0x0004 /* use lwp_sigoldmask on return from signal */
370 372 #define T_TALLOCSTK 0x0008 /* thread structure allocated from stk */
371 373 #define T_FORKALL 0x0010 /* thread was cloned by forkall() */
372 374 #define T_WOULDBLOCK 0x0020 /* for lockfs */
373 375 #define T_DONTBLOCK 0x0040 /* for lockfs */
374 376 #define T_DONTPEND 0x0080 /* for lockfs */
375 377 #define T_SYS_PROF 0x0100 /* profiling on for duration of system call */
376 378 #define T_WAITCVSEM 0x0200 /* waiting for a lwp_cv or lwp_sema on sleepq */
377 379 #define T_WATCHPT 0x0400 /* thread undergoing a watchpoint emulation */
378 380 #define T_PANIC 0x0800 /* thread initiated a system panic */
379 381 #define T_LWPREUSE 0x1000 /* stack and LWP can be reused */
380 382 #define T_CAPTURING 0x2000 /* thread is in page capture logic */
381 383 #define T_VFPARENT 0x4000 /* thread is vfork parent, must call vfwait */
382 384 #define T_DONTDTRACE 0x8000 /* disable DTrace probes */
383 385
384 386 /*
385 387 * Flags in t_proc_flag.
386 388 * These flags must be modified only when holding the p_lock
387 389 * for the associated process.
388 390 */
389 391 #define TP_DAEMON 0x0001 /* this is an LWP_DAEMON lwp */
390 392 #define TP_HOLDLWP 0x0002 /* hold thread's lwp */
391 393 #define TP_TWAIT 0x0004 /* wait to be freed by lwp_wait() */
392 394 #define TP_LWPEXIT 0x0008 /* lwp has exited */
393 395 #define TP_PRSTOP 0x0010 /* thread is being stopped via /proc */
394 396 #define TP_CHKPT 0x0020 /* thread is being stopped via CPR checkpoint */
395 397 #define TP_EXITLWP 0x0040 /* terminate this lwp */
396 398 #define TP_PRVSTOP 0x0080 /* thread is virtually stopped via /proc */
397 399 #define TP_MSACCT 0x0100 /* collect micro-state accounting information */
398 400 #define TP_STOPPING 0x0200 /* thread is executing stop() */
399 401 #define TP_WATCHPT 0x0400 /* process has watchpoints in effect */
400 402 #define TP_PAUSE 0x0800 /* process is being stopped via pauselwps() */
401 403 #define TP_CHANGEBIND 0x1000 /* thread has a new cpu/cpupart binding */
402 404 #define TP_ZTHREAD 0x2000 /* this is a kernel thread for a zone */
403 405 #define TP_WATCHSTOP 0x4000 /* thread is stopping via holdwatch() */
404 406
405 407 /*
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
406 408 * Thread scheduler flag (t_schedflag) definitions.
407 409 * The thread must be locked via thread_lock() or equiv. to change these.
408 410 */
409 411 #define TS_LOAD 0x0001 /* thread is in memory */
410 412 #define TS_DONT_SWAP 0x0002 /* thread/lwp should not be swapped */
411 413 #define TS_SWAPENQ 0x0004 /* swap thread when it reaches a safe point */
412 414 #define TS_ON_SWAPQ 0x0008 /* thread is on the swap queue */
413 415 #define TS_SIGNALLED 0x0010 /* thread was awakened by cv_signal() */
414 416 #define TS_PROJWAITQ 0x0020 /* thread is on its project's waitq */
415 417 #define TS_ZONEWAITQ 0x0040 /* thread is on its zone's waitq */
418 +#define TS_VCPU 0x0080 /* thread will enter guest context */
416 419 #define TS_CSTART 0x0100 /* setrun() by continuelwps() */
417 420 #define TS_UNPAUSE 0x0200 /* setrun() by unpauselwps() */
418 421 #define TS_XSTART 0x0400 /* setrun() by SIGCONT */
419 422 #define TS_PSTART 0x0800 /* setrun() by /proc */
420 423 #define TS_RESUME 0x1000 /* setrun() by CPR resume process */
421 424 #define TS_CREATE 0x2000 /* setrun() by syslwp_create() */
422 425 #define TS_RUNQMATCH 0x4000 /* exact run queue balancing by setbackdq() */
423 426 #define TS_ALLSTART \
424 427 (TS_CSTART|TS_UNPAUSE|TS_XSTART|TS_PSTART|TS_RESUME|TS_CREATE)
425 428 #define TS_ANYWAITQ (TS_PROJWAITQ|TS_ZONEWAITQ)
426 429
427 430 /*
428 431 * Thread binding types
429 432 */
430 433 #define TB_ALLHARD 0
431 434 #define TB_CPU_SOFT 0x01 /* soft binding to CPU */
432 435 #define TB_PSET_SOFT 0x02 /* soft binding to pset */
433 436
434 437 #define TB_CPU_SOFT_SET(t) ((t)->t_bindflag |= TB_CPU_SOFT)
435 438 #define TB_CPU_HARD_SET(t) ((t)->t_bindflag &= ~TB_CPU_SOFT)
436 439 #define TB_PSET_SOFT_SET(t) ((t)->t_bindflag |= TB_PSET_SOFT)
437 440 #define TB_PSET_HARD_SET(t) ((t)->t_bindflag &= ~TB_PSET_SOFT)
438 441 #define TB_CPU_IS_SOFT(t) ((t)->t_bindflag & TB_CPU_SOFT)
439 442 #define TB_CPU_IS_HARD(t) (!TB_CPU_IS_SOFT(t))
440 443 #define TB_PSET_IS_SOFT(t) ((t)->t_bindflag & TB_PSET_SOFT)
441 444
442 445 /*
443 446 * No locking needed for AST field.
444 447 */
445 448 #define aston(t) ((t)->t_astflag = 1)
446 449 #define astoff(t) ((t)->t_astflag = 0)
447 450
448 451 /* True if thread is stopped on an event of interest */
449 452 #define ISTOPPED(t) ((t)->t_state == TS_STOPPED && \
450 453 !((t)->t_schedflag & TS_PSTART))
451 454
452 455 /* True if thread is asleep and wakeable */
453 456 #define ISWAKEABLE(t) (((t)->t_state == TS_SLEEP && \
454 457 ((t)->t_flag & T_WAKEABLE)))
455 458
456 459 /* True if thread is on the wait queue */
457 460 #define ISWAITING(t) ((t)->t_state == TS_WAIT)
458 461
459 462 /* similar to ISTOPPED except the event of interest is CPR */
460 463 #define CPR_ISTOPPED(t) ((t)->t_state == TS_STOPPED && \
461 464 !((t)->t_schedflag & TS_RESUME))
462 465
463 466 /*
464 467 * True if thread is virtually stopped (is or was asleep in
465 468 * one of the lwp_*() system calls and marked to stop by /proc.)
466 469 */
467 470 #define VSTOPPED(t) ((t)->t_proc_flag & TP_PRVSTOP)
468 471
469 472 /* similar to VSTOPPED except the point of interest is CPR */
470 473 #define CPR_VSTOPPED(t) \
471 474 ((t)->t_state == TS_SLEEP && \
472 475 (t)->t_wchan0 != NULL && \
473 476 ((t)->t_flag & T_WAKEABLE) && \
474 477 ((t)->t_proc_flag & TP_CHKPT))
475 478
476 479 /* True if thread has been stopped by hold*() or was created stopped */
477 480 #define SUSPENDED(t) ((t)->t_state == TS_STOPPED && \
478 481 ((t)->t_schedflag & (TS_CSTART|TS_UNPAUSE)) != (TS_CSTART|TS_UNPAUSE))
479 482
480 483 /* True if thread possesses an inherited priority */
481 484 #define INHERITED(t) ((t)->t_epri != 0)
482 485
483 486 /* The dispatch priority of a thread */
484 487 #define DISP_PRIO(t) ((t)->t_epri > (t)->t_pri ? (t)->t_epri : (t)->t_pri)
485 488
486 489 /* The assigned priority of a thread */
487 490 #define ASSIGNED_PRIO(t) ((t)->t_pri)
488 491
489 492 /*
490 493 * Macros to determine whether a thread can be swapped.
491 494 * If t_lock is held, the thread is either on a processor or being swapped.
492 495 */
493 496 #define SWAP_OK(t) (!LOCK_HELD(&(t)->t_lock))
494 497
495 498 /*
496 499 * proctot(x)
497 500 * convert a proc pointer to a thread pointer. this only works with
498 501 * procs that have only one lwp.
499 502 *
500 503 * proctolwp(x)
501 504 * convert a proc pointer to a lwp pointer. this only works with
502 505 * procs that have only one lwp.
503 506 *
504 507 * ttolwp(x)
505 508 * convert a thread pointer to its lwp pointer.
506 509 *
507 510 * ttoproc(x)
508 511 * convert a thread pointer to its proc pointer.
509 512 *
510 513 * ttoproj(x)
511 514 * convert a thread pointer to its project pointer.
512 515 *
513 516 * ttozone(x)
514 517 * convert a thread pointer to its zone pointer.
515 518 *
516 519 * lwptot(x)
517 520 * convert a lwp pointer to its thread pointer.
518 521 *
519 522 * lwptoproc(x)
520 523 * convert a lwp to its proc pointer.
521 524 */
522 525 #define proctot(x) ((x)->p_tlist)
523 526 #define proctolwp(x) ((x)->p_tlist->t_lwp)
524 527 #define ttolwp(x) ((x)->t_lwp)
525 528 #define ttoproc(x) ((x)->t_procp)
526 529 #define ttoproj(x) ((x)->t_proj)
527 530 #define ttozone(x) ((x)->t_procp->p_zone)
528 531 #define lwptot(x) ((x)->lwp_thread)
529 532 #define lwptoproc(x) ((x)->lwp_procp)
530 533
531 534 #define t_pc t_pcb.val[0]
532 535 #define t_sp t_pcb.val[1]
533 536
534 537 #ifdef _KERNEL
535 538
536 539 extern kthread_t *threadp(void); /* inline, returns thread pointer */
537 540 #define curthread (threadp()) /* current thread pointer */
538 541 #define curproc (ttoproc(curthread)) /* current process pointer */
539 542 #define curproj (ttoproj(curthread)) /* current project pointer */
540 543 #define curzone (curproc->p_zone) /* current zone pointer */
541 544
542 545 extern struct _kthread t0; /* the scheduler thread */
543 546 extern kmutex_t pidlock; /* global process lock */
544 547
545 548 /*
546 549 * thread_free_lock is used by the tick accounting thread to keep a thread
547 550 * from being freed while it is being examined.
548 551 *
549 552 * Thread structures are 32-byte aligned structures. That is why we use the
550 553 * following formula.
551 554 */
552 555 #define THREAD_FREE_BITS 10
553 556 #define THREAD_FREE_NUM (1 << THREAD_FREE_BITS)
554 557 #define THREAD_FREE_MASK (THREAD_FREE_NUM - 1)
555 558 #define THREAD_FREE_1 PTR24_LSB
556 559 #define THREAD_FREE_2 (PTR24_LSB + THREAD_FREE_BITS)
557 560 #define THREAD_FREE_SHIFT(t) \
558 561 (((ulong_t)(t) >> THREAD_FREE_1) ^ ((ulong_t)(t) >> THREAD_FREE_2))
559 562 #define THREAD_FREE_HASH(t) (THREAD_FREE_SHIFT(t) & THREAD_FREE_MASK)
560 563
561 564 typedef struct thread_free_lock {
562 565 kmutex_t tf_lock;
563 566 uchar_t tf_pad[64 - sizeof (kmutex_t)];
564 567 } thread_free_lock_t;
565 568
566 569 extern void thread_free_prevent(kthread_t *);
567 570 extern void thread_free_allow(kthread_t *);
568 571
569 572 /*
570 573 * Routines to change the priority and effective priority
571 574 * of a thread-locked thread, whatever its state.
572 575 */
573 576 extern int thread_change_pri(kthread_t *t, pri_t disp_pri, int front);
574 577 extern void thread_change_epri(kthread_t *t, pri_t disp_pri);
575 578
576 579 /*
577 580 * Routines that manipulate the dispatcher lock for the thread.
578 581 * The locking heirarchy is as follows:
579 582 * cpu_lock > sleepq locks > run queue locks
580 583 */
581 584 void thread_transition(kthread_t *); /* move to transition lock */
582 585 void thread_stop(kthread_t *); /* move to stop lock */
583 586 void thread_lock(kthread_t *); /* lock thread and its queue */
584 587 void thread_lock_high(kthread_t *); /* lock thread and its queue */
585 588 void thread_onproc(kthread_t *, struct cpu *); /* set onproc state lock */
586 589
587 590 #define thread_unlock(t) disp_lock_exit((t)->t_lockp)
588 591 #define thread_unlock_high(t) disp_lock_exit_high((t)->t_lockp)
589 592 #define thread_unlock_nopreempt(t) disp_lock_exit_nopreempt((t)->t_lockp)
590 593
591 594 #define THREAD_LOCK_HELD(t) (DISP_LOCK_HELD((t)->t_lockp))
592 595
593 596 extern disp_lock_t transition_lock; /* lock protecting transiting threads */
594 597 extern disp_lock_t stop_lock; /* lock protecting stopped threads */
595 598
596 599 caddr_t thread_stk_init(caddr_t); /* init thread stack */
597 600
598 601 int thread_setname(kthread_t *, const char *);
599 602 int thread_vsetname(kthread_t *, const char *, ...);
600 603
601 604 extern int default_binding_mode;
602 605
603 606 #endif /* _KERNEL */
604 607
605 608 #define THREAD_NAME_MAX 32 /* includes terminating NUL */
606 609
607 610 /*
608 611 * Macros to indicate that the thread holds resources that could be critical
609 612 * to other kernel threads, so this thread needs to have kernel priority
610 613 * if it blocks or is preempted. Note that this is not necessary if the
611 614 * resource is a mutex or a writer lock because of priority inheritance.
612 615 *
613 616 * The only way one thread may legally manipulate another thread's t_kpri_req
614 617 * is to hold the target thread's thread lock while that thread is asleep.
615 618 * (The rwlock code does this to implement direct handoff to waiting readers.)
616 619 */
617 620 #define THREAD_KPRI_REQUEST() (curthread->t_kpri_req++)
618 621 #define THREAD_KPRI_RELEASE() (curthread->t_kpri_req--)
619 622 #define THREAD_KPRI_RELEASE_N(n) (curthread->t_kpri_req -= (n))
620 623
621 624 /*
622 625 * Macro to change a thread's priority.
623 626 */
624 627 #define THREAD_CHANGE_PRI(t, pri) { \
625 628 pri_t __new_pri = (pri); \
626 629 DTRACE_SCHED2(change__pri, kthread_t *, (t), pri_t, __new_pri); \
627 630 (t)->t_pri = __new_pri; \
628 631 schedctl_set_cidpri(t); \
629 632 }
630 633
631 634 /*
632 635 * Macro to indicate that a thread's priority is about to be changed.
633 636 */
634 637 #define THREAD_WILLCHANGE_PRI(t, pri) { \
635 638 DTRACE_SCHED2(change__pri, kthread_t *, (t), pri_t, (pri)); \
636 639 }
637 640
638 641 /*
639 642 * Macros to change thread state and the associated lock.
640 643 */
641 644 #define THREAD_SET_STATE(tp, state, lp) \
642 645 ((tp)->t_state = state, (tp)->t_lockp = lp)
643 646
644 647 /*
645 648 * Point it at the transition lock, which is always held.
646 649 * The previosly held lock is dropped.
647 650 */
648 651 #define THREAD_TRANSITION(tp) thread_transition(tp);
649 652 /*
650 653 * Set the thread's lock to be the transition lock, without dropping
651 654 * previosly held lock.
652 655 */
653 656 #define THREAD_TRANSITION_NOLOCK(tp) ((tp)->t_lockp = &transition_lock)
654 657
655 658 /*
656 659 * Put thread in run state, and set the lock pointer to the dispatcher queue
657 660 * lock pointer provided. This lock should be held.
658 661 */
659 662 #define THREAD_RUN(tp, lp) THREAD_SET_STATE(tp, TS_RUN, lp)
660 663
661 664 /*
662 665 * Put thread in wait state, and set the lock pointer to the wait queue
663 666 * lock pointer provided. This lock should be held.
664 667 */
665 668 #define THREAD_WAIT(tp, lp) THREAD_SET_STATE(tp, TS_WAIT, lp)
666 669
667 670 /*
668 671 * Put thread in run state, and set the lock pointer to the dispatcher queue
669 672 * lock pointer provided (i.e., the "swapped_lock"). This lock should be held.
670 673 */
671 674 #define THREAD_SWAP(tp, lp) THREAD_SET_STATE(tp, TS_RUN, lp)
672 675
673 676 /*
674 677 * Put the thread in zombie state and set the lock pointer to NULL.
675 678 * The NULL will catch anything that tries to lock a zombie.
676 679 */
677 680 #define THREAD_ZOMB(tp) THREAD_SET_STATE(tp, TS_ZOMB, NULL)
678 681
679 682 /*
680 683 * Set the thread into ONPROC state, and point the lock at the CPUs
681 684 * lock for the onproc thread(s). This lock should be held, so the
682 685 * thread deoes not become unlocked, since these stores can be reordered.
683 686 */
684 687 #define THREAD_ONPROC(tp, cpu) \
685 688 THREAD_SET_STATE(tp, TS_ONPROC, &(cpu)->cpu_thread_lock)
686 689
687 690 /*
688 691 * Set the thread into the TS_SLEEP state, and set the lock pointer to
689 692 * to some sleep queue's lock. The new lock should already be held.
690 693 */
691 694 #define THREAD_SLEEP(tp, lp) { \
692 695 disp_lock_t *tlp; \
693 696 tlp = (tp)->t_lockp; \
694 697 THREAD_SET_STATE(tp, TS_SLEEP, lp); \
695 698 disp_lock_exit_high(tlp); \
696 699 }
697 700
698 701 /*
699 702 * Interrupt threads are created in TS_FREE state, and their lock
700 703 * points at the associated CPU's lock.
701 704 */
702 705 #define THREAD_FREEINTR(tp, cpu) \
703 706 THREAD_SET_STATE(tp, TS_FREE, &(cpu)->cpu_thread_lock)
704 707
705 708 /* if tunable kmem_stackinfo is set, fill kthread stack with a pattern */
706 709 #define KMEM_STKINFO_PATTERN 0xbadcbadcbadcbadcULL
707 710
708 711 /*
709 712 * If tunable kmem_stackinfo is set, log the latest KMEM_LOG_STK_USAGE_SIZE
710 713 * dead kthreads that used their kernel stack the most.
711 714 */
712 715 #define KMEM_STKINFO_LOG_SIZE 16
713 716
714 717 /* kthread name (cmd/lwpid) string size in the stackinfo log */
715 718 #define KMEM_STKINFO_STR_SIZE 64
716 719
717 720 /*
718 721 * stackinfo logged data.
719 722 */
720 723 typedef struct kmem_stkinfo {
721 724 caddr_t kthread; /* kthread pointer */
722 725 caddr_t t_startpc; /* where kthread started */
723 726 caddr_t start; /* kthread stack start address */
724 727 size_t stksz; /* kthread stack size */
725 728 size_t percent; /* kthread stack high water mark */
726 729 id_t t_tid; /* kthread id */
727 730 char cmd[KMEM_STKINFO_STR_SIZE]; /* kthread name (cmd/lwpid) */
728 731 } kmem_stkinfo_t;
729 732
730 733 #ifdef __cplusplus
731 734 }
732 735 #endif
733 736
734 737 #endif /* _SYS_THREAD_H */
↓ open down ↓ |
309 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX