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