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