17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55a64ecfaStrevtom * Common Development and Distribution License (the "License"). 65a64ecfaStrevtom * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 218d186f16Sraf 227c478bd9Sstevel@tonic-gate /* 2391f917c7SMadhavan Venkataraman * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_THREAD_H 287c478bd9Sstevel@tonic-gate #define _SYS_THREAD_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 337c478bd9Sstevel@tonic-gate #include <sys/klwp.h> 347c478bd9Sstevel@tonic-gate #include <sys/time.h> 357c478bd9Sstevel@tonic-gate #include <sys/signal.h> 367c478bd9Sstevel@tonic-gate #include <sys/kcpc.h> 377c478bd9Sstevel@tonic-gate #if defined(__GNUC__) && defined(_ASM_INLINES) && defined(_KERNEL) 387c478bd9Sstevel@tonic-gate #include <asm/thread.h> 397c478bd9Sstevel@tonic-gate #endif 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #ifdef __cplusplus 427c478bd9Sstevel@tonic-gate extern "C" { 437c478bd9Sstevel@tonic-gate #endif 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * The thread object, its states, and the methods by which it 477c478bd9Sstevel@tonic-gate * is accessed. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * Values that t_state may assume. Note that t_state cannot have more 527c478bd9Sstevel@tonic-gate * than one of these flags set at a time. 537c478bd9Sstevel@tonic-gate */ 547c478bd9Sstevel@tonic-gate #define TS_FREE 0x00 /* Thread at loose ends */ 557c478bd9Sstevel@tonic-gate #define TS_SLEEP 0x01 /* Awaiting an event */ 567c478bd9Sstevel@tonic-gate #define TS_RUN 0x02 /* Runnable, but not yet on a processor */ 577c478bd9Sstevel@tonic-gate #define TS_ONPROC 0x04 /* Thread is being run on a processor */ 587c478bd9Sstevel@tonic-gate #define TS_ZOMB 0x08 /* Thread has died but hasn't been reaped */ 597c478bd9Sstevel@tonic-gate #define TS_STOPPED 0x10 /* Stopped, initial state */ 60c97ad5cdSakolb #define TS_WAIT 0x20 /* Waiting to become runnable */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate typedef struct ctxop { 637c478bd9Sstevel@tonic-gate void (*save_op)(void *); /* function to invoke to save context */ 647c478bd9Sstevel@tonic-gate void (*restore_op)(void *); /* function to invoke to restore ctx */ 657c478bd9Sstevel@tonic-gate void (*fork_op)(void *, void *); /* invoke to fork context */ 667c478bd9Sstevel@tonic-gate void (*lwp_create_op)(void *, void *); /* lwp_create context */ 677c478bd9Sstevel@tonic-gate void (*exit_op)(void *); /* invoked during {thread,lwp}_exit() */ 687c478bd9Sstevel@tonic-gate void (*free_op)(void *, int); /* function which frees the context */ 697c478bd9Sstevel@tonic-gate void *arg; /* argument to above functions, ctx pointer */ 707c478bd9Sstevel@tonic-gate struct ctxop *next; /* next context ops */ 717c478bd9Sstevel@tonic-gate } ctxop_t; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * The active file descriptor table. 757c478bd9Sstevel@tonic-gate * Each member of a_fd[] not equalling -1 represents an active fd. 767c478bd9Sstevel@tonic-gate * The structure is initialized on first use; all zeros means uninitialized. 777c478bd9Sstevel@tonic-gate */ 78236317e1SRoger A. Faulkner typedef struct { 79236317e1SRoger A. Faulkner kmutex_t a_fdlock; /* protects a_fd and a_nfd */ 807c478bd9Sstevel@tonic-gate int *a_fd; /* pointer to list of fds */ 81236317e1SRoger A. Faulkner int a_nfd; /* number of entries in *a_fd */ 82236317e1SRoger A. Faulkner int a_stale; /* one of the active fds is being closed */ 83236317e1SRoger A. Faulkner int a_buf[2]; /* buffer to which a_fd initially refers */ 847c478bd9Sstevel@tonic-gate } afd_t; 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * An lwpchan provides uniqueness when sleeping on user-level 887c478bd9Sstevel@tonic-gate * synchronization primitives. The lc_wchan member is used 897c478bd9Sstevel@tonic-gate * for sleeping on kernel synchronization primitives. 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate typedef struct { 927c478bd9Sstevel@tonic-gate caddr_t lc_wchan0; 937c478bd9Sstevel@tonic-gate caddr_t lc_wchan; 947c478bd9Sstevel@tonic-gate } lwpchan_t; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate typedef struct _kthread *kthread_id_t; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate struct turnstile; 99843e1988Sjohnlev struct panic_trap_info; 1007c478bd9Sstevel@tonic-gate struct upimutex; 1017c478bd9Sstevel@tonic-gate struct kproject; 1027c478bd9Sstevel@tonic-gate struct on_trap_data; 103c97ad5cdSakolb struct waitq; 1044568bee7Strevtom struct _kcpc_ctx; 1054568bee7Strevtom struct _kcpc_set; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* Definition for kernel thread identifier type */ 1087c478bd9Sstevel@tonic-gate typedef uint64_t kt_did_t; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate typedef struct _kthread { 1117c478bd9Sstevel@tonic-gate struct _kthread *t_link; /* dispq, sleepq, and free queue link */ 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate caddr_t t_stk; /* base of stack (kernel sp value to use) */ 1147c478bd9Sstevel@tonic-gate void (*t_startpc)(void); /* PC where thread started */ 1157c478bd9Sstevel@tonic-gate struct cpu *t_bound_cpu; /* cpu bound to, or NULL if not bound */ 1167c478bd9Sstevel@tonic-gate short t_affinitycnt; /* nesting level of kernel affinity-setting */ 1177c478bd9Sstevel@tonic-gate short t_bind_cpu; /* user-specified CPU binding (-1 if none) */ 1187c478bd9Sstevel@tonic-gate ushort_t t_flag; /* modified only by current thread */ 1197c478bd9Sstevel@tonic-gate ushort_t t_proc_flag; /* modified holding ttproc(t)->p_lock */ 1207c478bd9Sstevel@tonic-gate ushort_t t_schedflag; /* modified holding thread_lock(t) */ 1217c478bd9Sstevel@tonic-gate volatile char t_preempt; /* don't preempt thread if set */ 1227c478bd9Sstevel@tonic-gate volatile char t_preempt_lk; 1237c478bd9Sstevel@tonic-gate uint_t t_state; /* thread state (protected by thread_lock) */ 1247c478bd9Sstevel@tonic-gate pri_t t_pri; /* assigned thread priority */ 1257c478bd9Sstevel@tonic-gate pri_t t_epri; /* inherited thread priority */ 126d4204c85Sraf pri_t t_cpri; /* thread scheduling class priority */ 1277c478bd9Sstevel@tonic-gate char t_writer; /* sleeping in lwp_rwlock_lock(RW_WRITE_LOCK) */ 1280b70c467Sakolb uchar_t t_bindflag; /* CPU and pset binding type */ 1297c478bd9Sstevel@tonic-gate label_t t_pcb; /* pcb, save area when switching */ 1307c478bd9Sstevel@tonic-gate lwpchan_t t_lwpchan; /* reason for blocking */ 1317c478bd9Sstevel@tonic-gate #define t_wchan0 t_lwpchan.lc_wchan0 1327c478bd9Sstevel@tonic-gate #define t_wchan t_lwpchan.lc_wchan 1337c478bd9Sstevel@tonic-gate struct _sobj_ops *t_sobj_ops; 1347c478bd9Sstevel@tonic-gate id_t t_cid; /* scheduling class id */ 1357c478bd9Sstevel@tonic-gate struct thread_ops *t_clfuncs; /* scheduling class ops vector */ 1367c478bd9Sstevel@tonic-gate void *t_cldata; /* per scheduling class specific data */ 1377c478bd9Sstevel@tonic-gate ctxop_t *t_ctx; /* thread context */ 1387c478bd9Sstevel@tonic-gate uintptr_t t_lofault; /* ret pc for failed page faults */ 1397c478bd9Sstevel@tonic-gate label_t *t_onfault; /* on_fault() setjmp buf */ 1407c478bd9Sstevel@tonic-gate struct on_trap_data *t_ontrap; /* on_trap() protection data */ 141d32efdadSJonathan Adams caddr_t t_swap; /* the bottom of the stack, if from segkp */ 1427c478bd9Sstevel@tonic-gate lock_t t_lock; /* used to resume() a thread */ 1437c478bd9Sstevel@tonic-gate uint8_t t_lockstat; /* set while thread is in lockstat code */ 1447c478bd9Sstevel@tonic-gate uint8_t t_pil; /* interrupt thread PIL */ 1457c478bd9Sstevel@tonic-gate disp_lock_t t_pi_lock; /* lock protecting t_prioinv list */ 1467c478bd9Sstevel@tonic-gate char t_nomigrate; /* do not migrate if set */ 1477c478bd9Sstevel@tonic-gate struct cpu *t_cpu; /* CPU that thread last ran on */ 1487c478bd9Sstevel@tonic-gate struct cpu *t_weakbound_cpu; /* cpu weakly bound to */ 1497c478bd9Sstevel@tonic-gate struct lgrp_ld *t_lpl; /* load average for home lgroup */ 1507c478bd9Sstevel@tonic-gate void *t_lgrp_reserv[2]; /* reserved for future */ 1517c478bd9Sstevel@tonic-gate struct _kthread *t_intr; /* interrupted (pinned) thread */ 1527c478bd9Sstevel@tonic-gate uint64_t t_intr_start; /* timestamp when time slice began */ 1537c478bd9Sstevel@tonic-gate kt_did_t t_did; /* thread id for kernel debuggers */ 1547c478bd9Sstevel@tonic-gate caddr_t t_tnf_tpdp; /* Trace facility data pointer */ 1554568bee7Strevtom struct _kcpc_ctx *t_cpc_ctx; /* performance counter context */ 1564568bee7Strevtom struct _kcpc_set *t_cpc_set; /* set this thread has bound */ 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* 1597c478bd9Sstevel@tonic-gate * non swappable part of the lwp state. 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate id_t t_tid; /* lwp's id */ 1627c478bd9Sstevel@tonic-gate id_t t_waitfor; /* target lwp id in lwp_wait() */ 1637c478bd9Sstevel@tonic-gate struct sigqueue *t_sigqueue; /* queue of siginfo structs */ 1647c478bd9Sstevel@tonic-gate k_sigset_t t_sig; /* signals pending to this process */ 1657c478bd9Sstevel@tonic-gate k_sigset_t t_extsig; /* signals sent from another contract */ 1667c478bd9Sstevel@tonic-gate k_sigset_t t_hold; /* hold signal bit mask */ 167*3d729aecSJerry Jelinek k_sigset_t t_sigwait; /* sigtimedwait/sigfd accepting these */ 1687c478bd9Sstevel@tonic-gate struct _kthread *t_forw; /* process's forward thread link */ 1697c478bd9Sstevel@tonic-gate struct _kthread *t_back; /* process's backward thread link */ 1707c478bd9Sstevel@tonic-gate struct _kthread *t_thlink; /* tid (lwpid) lookup hash link */ 1717c478bd9Sstevel@tonic-gate klwp_t *t_lwp; /* thread's lwp pointer */ 1727c478bd9Sstevel@tonic-gate struct proc *t_procp; /* proc pointer */ 1737c478bd9Sstevel@tonic-gate struct t_audit_data *t_audit_data; /* per thread audit data */ 1747c478bd9Sstevel@tonic-gate struct _kthread *t_next; /* doubly linked list of all threads */ 1757c478bd9Sstevel@tonic-gate struct _kthread *t_prev; 1767c478bd9Sstevel@tonic-gate ushort_t t_whystop; /* reason for stopping */ 1777c478bd9Sstevel@tonic-gate ushort_t t_whatstop; /* more detailed reason */ 1787c478bd9Sstevel@tonic-gate int t_dslot; /* index in proc's thread directory */ 1797c478bd9Sstevel@tonic-gate struct pollstate *t_pollstate; /* state used during poll(2) */ 1807c478bd9Sstevel@tonic-gate struct pollcache *t_pollcache; /* to pass a pcache ptr by /dev/poll */ 1817c478bd9Sstevel@tonic-gate struct cred *t_cred; /* pointer to current cred */ 1827c478bd9Sstevel@tonic-gate time_t t_start; /* start time, seconds since epoch */ 1837c478bd9Sstevel@tonic-gate clock_t t_lbolt; /* lbolt at last clock_tick() */ 1847c478bd9Sstevel@tonic-gate hrtime_t t_stoptime; /* timestamp at stop() */ 1857c478bd9Sstevel@tonic-gate uint_t t_pctcpu; /* %cpu at last clock_tick(), binary */ 1867c478bd9Sstevel@tonic-gate /* point at right of high-order bit */ 1877c478bd9Sstevel@tonic-gate short t_sysnum; /* system call number */ 1887c478bd9Sstevel@tonic-gate kcondvar_t t_delay_cv; 1897c478bd9Sstevel@tonic-gate kmutex_t t_delay_lock; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * Pointer to the dispatcher lock protecting t_state and state-related 1937c478bd9Sstevel@tonic-gate * flags. This pointer can change during waits on the lock, so 1947c478bd9Sstevel@tonic-gate * it should be grabbed only by thread_lock(). 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate disp_lock_t *t_lockp; /* pointer to the dispatcher lock */ 1977c478bd9Sstevel@tonic-gate ushort_t t_oldspl; /* spl level before dispatcher locked */ 1987c478bd9Sstevel@tonic-gate volatile char t_pre_sys; /* pre-syscall work needed */ 1997c478bd9Sstevel@tonic-gate lock_t t_lock_flush; /* for lock_mutex_flush() impl */ 2007c478bd9Sstevel@tonic-gate struct _disp *t_disp_queue; /* run queue for chosen CPU */ 2017c478bd9Sstevel@tonic-gate clock_t t_disp_time; /* last time this thread was running */ 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate /* 2047c478bd9Sstevel@tonic-gate * Post-syscall / post-trap flags. 2057c478bd9Sstevel@tonic-gate * No lock is required to set these. 2067c478bd9Sstevel@tonic-gate * These must be cleared only by the thread itself. 2077c478bd9Sstevel@tonic-gate * 2087c478bd9Sstevel@tonic-gate * t_astflag indicates that some post-trap processing is required, 2097c478bd9Sstevel@tonic-gate * possibly a signal or a preemption. The thread will not 2107c478bd9Sstevel@tonic-gate * return to user with this set. 2117c478bd9Sstevel@tonic-gate * t_post_sys indicates that some unusualy post-system call 2127c478bd9Sstevel@tonic-gate * handling is required, such as an error or tracing. 2137c478bd9Sstevel@tonic-gate * t_sig_check indicates that some condition in ISSIG() must be 2147c478bd9Sstevel@tonic-gate * checked, but doesn't prevent returning to user. 2157c478bd9Sstevel@tonic-gate * t_post_sys_ast is a way of checking whether any of these three 2167c478bd9Sstevel@tonic-gate * flags are set. 2177c478bd9Sstevel@tonic-gate */ 2187c478bd9Sstevel@tonic-gate union __tu { 2197c478bd9Sstevel@tonic-gate struct __ts { 2207c478bd9Sstevel@tonic-gate volatile char _t_astflag; /* AST requested */ 2217c478bd9Sstevel@tonic-gate volatile char _t_sig_check; /* ISSIG required */ 2227c478bd9Sstevel@tonic-gate volatile char _t_post_sys; /* post_syscall req */ 2237c478bd9Sstevel@tonic-gate volatile char _t_trapret; /* call CL_TRAPRET */ 2247c478bd9Sstevel@tonic-gate } _ts; 2257c478bd9Sstevel@tonic-gate volatile int _t_post_sys_ast; /* OR of these flags */ 2267c478bd9Sstevel@tonic-gate } _tu; 2277c478bd9Sstevel@tonic-gate #define t_astflag _tu._ts._t_astflag 2287c478bd9Sstevel@tonic-gate #define t_sig_check _tu._ts._t_sig_check 2297c478bd9Sstevel@tonic-gate #define t_post_sys _tu._ts._t_post_sys 2307c478bd9Sstevel@tonic-gate #define t_trapret _tu._ts._t_trapret 2317c478bd9Sstevel@tonic-gate #define t_post_sys_ast _tu._t_post_sys_ast 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate /* 2347c478bd9Sstevel@tonic-gate * Real time microstate profiling. 2357c478bd9Sstevel@tonic-gate */ 2367c478bd9Sstevel@tonic-gate /* possible 4-byte filler */ 2377c478bd9Sstevel@tonic-gate hrtime_t t_waitrq; /* timestamp for run queue wait time */ 2387c478bd9Sstevel@tonic-gate int t_mstate; /* current microstate */ 2397c478bd9Sstevel@tonic-gate struct rprof { 2407c478bd9Sstevel@tonic-gate int rp_anystate; /* set if any state non-zero */ 2417c478bd9Sstevel@tonic-gate uint_t rp_state[NMSTATES]; /* mstate profiling counts */ 2427c478bd9Sstevel@tonic-gate } *t_rprof; 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate /* 2457c478bd9Sstevel@tonic-gate * There is a turnstile inserted into the list below for 2467c478bd9Sstevel@tonic-gate * every priority inverted synchronization object that 2477c478bd9Sstevel@tonic-gate * this thread holds. 2487c478bd9Sstevel@tonic-gate */ 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate struct turnstile *t_prioinv; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate /* 2537c478bd9Sstevel@tonic-gate * Pointer to the turnstile attached to the synchronization 2547c478bd9Sstevel@tonic-gate * object where this thread is blocked. 2557c478bd9Sstevel@tonic-gate */ 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate struct turnstile *t_ts; 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate /* 2607c478bd9Sstevel@tonic-gate * kernel thread specific data 2617c478bd9Sstevel@tonic-gate * Borrowed from userland implementation of POSIX tsd 2627c478bd9Sstevel@tonic-gate */ 2637c478bd9Sstevel@tonic-gate struct tsd_thread { 2647c478bd9Sstevel@tonic-gate struct tsd_thread *ts_next; /* threads with TSD */ 2657c478bd9Sstevel@tonic-gate struct tsd_thread *ts_prev; /* threads with TSD */ 2667c478bd9Sstevel@tonic-gate uint_t ts_nkeys; /* entries in value array */ 2677c478bd9Sstevel@tonic-gate void **ts_value; /* array of value/key */ 2687c478bd9Sstevel@tonic-gate } *t_tsd; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate clock_t t_stime; /* time stamp used by the swapper */ 2717c478bd9Sstevel@tonic-gate struct door_data *t_door; /* door invocation data */ 2727c478bd9Sstevel@tonic-gate kmutex_t *t_plockp; /* pointer to process's p_lock */ 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate struct sc_shared *t_schedctl; /* scheduler activations shared data */ 2757c478bd9Sstevel@tonic-gate uintptr_t t_sc_uaddr; /* user-level address of shared data */ 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate struct cpupart *t_cpupart; /* partition containing thread */ 2787c478bd9Sstevel@tonic-gate int t_bind_pset; /* processor set binding */ 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate struct copyops *t_copyops; /* copy in/out ops vector */ 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate caddr_t t_stkbase; /* base of the the stack */ 2837c478bd9Sstevel@tonic-gate struct page *t_red_pp; /* if non-NULL, redzone is mapped */ 2847c478bd9Sstevel@tonic-gate 285236317e1SRoger A. Faulkner afd_t t_activefd; /* active file descriptor table */ 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate struct _kthread *t_priforw; /* sleepq per-priority sublist */ 2887c478bd9Sstevel@tonic-gate struct _kthread *t_priback; 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate struct sleepq *t_sleepq; /* sleep queue thread is waiting on */ 291843e1988Sjohnlev struct panic_trap_info *t_panic_trap; /* saved data from fatal trap */ 2927c478bd9Sstevel@tonic-gate int *t_lgrp_affinity; /* lgroup affinity */ 2937c478bd9Sstevel@tonic-gate struct upimutex *t_upimutex; /* list of upimutexes owned by thread */ 2947c478bd9Sstevel@tonic-gate uint32_t t_nupinest; /* number of nested held upi mutexes */ 2957c478bd9Sstevel@tonic-gate struct kproject *t_proj; /* project containing this thread */ 2967c478bd9Sstevel@tonic-gate uint8_t t_unpark; /* modified holding t_delay_lock */ 2977c478bd9Sstevel@tonic-gate uint8_t t_release; /* lwp_release() waked up the thread */ 2987c478bd9Sstevel@tonic-gate uint8_t t_hatdepth; /* depth of recursive hat_memloads */ 299551bc2a6Smrj uint8_t t_xpvcntr; /* see xen_block_migrate() */ 3007c478bd9Sstevel@tonic-gate kcondvar_t t_joincv; /* cv used to wait for thread exit */ 3017c478bd9Sstevel@tonic-gate void *t_taskq; /* for threads belonging to taskq */ 3027c478bd9Sstevel@tonic-gate hrtime_t t_anttime; /* most recent time anticipatory load */ 3037c478bd9Sstevel@tonic-gate /* was added to an lgroup's load */ 3047c478bd9Sstevel@tonic-gate /* on this thread's behalf */ 3057c478bd9Sstevel@tonic-gate char *t_pdmsg; /* privilege debugging message */ 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate uint_t t_predcache; /* DTrace predicate cache */ 3087c478bd9Sstevel@tonic-gate hrtime_t t_dtrace_vtime; /* DTrace virtual time */ 3097c478bd9Sstevel@tonic-gate hrtime_t t_dtrace_start; /* DTrace slice start time */ 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate uint8_t t_dtrace_stop; /* indicates a DTrace-desired stop */ 3127c478bd9Sstevel@tonic-gate uint8_t t_dtrace_sig; /* signal sent via DTrace's raise() */ 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate union __tdu { 3157c478bd9Sstevel@tonic-gate struct __tds { 3167c478bd9Sstevel@tonic-gate uint8_t _t_dtrace_on; /* hit a fasttrap tracepoint */ 3177c478bd9Sstevel@tonic-gate uint8_t _t_dtrace_step; /* about to return to kernel */ 3187c478bd9Sstevel@tonic-gate uint8_t _t_dtrace_ret; /* handling a return probe */ 3197c478bd9Sstevel@tonic-gate uint8_t _t_dtrace_ast; /* saved ast flag */ 3207c478bd9Sstevel@tonic-gate #ifdef __amd64 3217c478bd9Sstevel@tonic-gate uint8_t _t_dtrace_reg; /* modified register */ 3227c478bd9Sstevel@tonic-gate #endif 3237c478bd9Sstevel@tonic-gate } _tds; 3247c478bd9Sstevel@tonic-gate ulong_t _t_dtrace_ft; /* bitwise or of these flags */ 3257c478bd9Sstevel@tonic-gate } _tdu; 3267c478bd9Sstevel@tonic-gate #define t_dtrace_ft _tdu._t_dtrace_ft 3277c478bd9Sstevel@tonic-gate #define t_dtrace_on _tdu._tds._t_dtrace_on 3287c478bd9Sstevel@tonic-gate #define t_dtrace_step _tdu._tds._t_dtrace_step 3297c478bd9Sstevel@tonic-gate #define t_dtrace_ret _tdu._tds._t_dtrace_ret 3307c478bd9Sstevel@tonic-gate #define t_dtrace_ast _tdu._tds._t_dtrace_ast 3317c478bd9Sstevel@tonic-gate #ifdef __amd64 3327c478bd9Sstevel@tonic-gate #define t_dtrace_reg _tdu._tds._t_dtrace_reg 3337c478bd9Sstevel@tonic-gate #endif 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate uintptr_t t_dtrace_pc; /* DTrace saved pc from fasttrap */ 3367c478bd9Sstevel@tonic-gate uintptr_t t_dtrace_npc; /* DTrace next pc from fasttrap */ 3377c478bd9Sstevel@tonic-gate uintptr_t t_dtrace_scrpc; /* DTrace per-thread scratch location */ 3387c478bd9Sstevel@tonic-gate uintptr_t t_dtrace_astpc; /* DTrace return sequence location */ 3397c478bd9Sstevel@tonic-gate #ifdef __amd64 3407c478bd9Sstevel@tonic-gate uint64_t t_dtrace_regv; /* DTrace saved reg from fasttrap */ 3417c478bd9Sstevel@tonic-gate #endif 3427c478bd9Sstevel@tonic-gate hrtime_t t_hrtime; /* high-res last time on cpu */ 3435a64ecfaStrevtom kmutex_t t_ctx_lock; /* protects t_ctx in removectx() */ 344c97ad5cdSakolb struct waitq *t_waitq; /* wait queue */ 345454ab202SMadhavan Venkataraman kmutex_t t_wait_mutex; /* used in CV wait functions */ 3467c478bd9Sstevel@tonic-gate } kthread_t; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate /* 3497c478bd9Sstevel@tonic-gate * Thread flag (t_flag) definitions. 3507c478bd9Sstevel@tonic-gate * These flags must be changed only for the current thread, 3517c478bd9Sstevel@tonic-gate * and not during preemption code, since the code being 3527c478bd9Sstevel@tonic-gate * preempted could be modifying the flags. 3537c478bd9Sstevel@tonic-gate * 3547c478bd9Sstevel@tonic-gate * For the most part these flags do not need locking. 3557c478bd9Sstevel@tonic-gate * The following flags will only be changed while the thread_lock is held, 3567c478bd9Sstevel@tonic-gate * to give assurrance that they are consistent with t_state: 3577c478bd9Sstevel@tonic-gate * T_WAKEABLE 3587c478bd9Sstevel@tonic-gate */ 3597c478bd9Sstevel@tonic-gate #define T_INTR_THREAD 0x0001 /* thread is an interrupt thread */ 3607c478bd9Sstevel@tonic-gate #define T_WAKEABLE 0x0002 /* thread is blocked, signals enabled */ 3617c478bd9Sstevel@tonic-gate #define T_TOMASK 0x0004 /* use lwp_sigoldmask on return from signal */ 3627c478bd9Sstevel@tonic-gate #define T_TALLOCSTK 0x0008 /* thread structure allocated from stk */ 363c4978b50Sraf #define T_FORKALL 0x0010 /* thread was cloned by forkall() */ 3647c478bd9Sstevel@tonic-gate #define T_WOULDBLOCK 0x0020 /* for lockfs */ 3657c478bd9Sstevel@tonic-gate #define T_DONTBLOCK 0x0040 /* for lockfs */ 3667c478bd9Sstevel@tonic-gate #define T_DONTPEND 0x0080 /* for lockfs */ 3677c478bd9Sstevel@tonic-gate #define T_SYS_PROF 0x0100 /* profiling on for duration of system call */ 3687c478bd9Sstevel@tonic-gate #define T_WAITCVSEM 0x0200 /* waiting for a lwp_cv or lwp_sema on sleepq */ 3697c478bd9Sstevel@tonic-gate #define T_WATCHPT 0x0400 /* thread undergoing a watchpoint emulation */ 3707c478bd9Sstevel@tonic-gate #define T_PANIC 0x0800 /* thread initiated a system panic */ 371d32efdadSJonathan Adams #define T_LWPREUSE 0x1000 /* stack and LWP can be reused */ 3728b464eb8Smec #define T_CAPTURING 0x2000 /* thread is in page capture logic */ 3738d186f16Sraf #define T_VFPARENT 0x4000 /* thread is vfork parent, must call vfwait */ 3745cc25c11Smb158278 #define T_DONTDTRACE 0x8000 /* disable DTrace probes */ 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate /* 3777c478bd9Sstevel@tonic-gate * Flags in t_proc_flag. 3787c478bd9Sstevel@tonic-gate * These flags must be modified only when holding the p_lock 3797c478bd9Sstevel@tonic-gate * for the associated process. 3807c478bd9Sstevel@tonic-gate */ 3817c478bd9Sstevel@tonic-gate #define TP_DAEMON 0x0001 /* this is an LWP_DAEMON lwp */ 3827c478bd9Sstevel@tonic-gate #define TP_HOLDLWP 0x0002 /* hold thread's lwp */ 3837c478bd9Sstevel@tonic-gate #define TP_TWAIT 0x0004 /* wait to be freed by lwp_wait() */ 3847c478bd9Sstevel@tonic-gate #define TP_LWPEXIT 0x0008 /* lwp has exited */ 3857c478bd9Sstevel@tonic-gate #define TP_PRSTOP 0x0010 /* thread is being stopped via /proc */ 3867c478bd9Sstevel@tonic-gate #define TP_CHKPT 0x0020 /* thread is being stopped via CPR checkpoint */ 3877c478bd9Sstevel@tonic-gate #define TP_EXITLWP 0x0040 /* terminate this lwp */ 3887c478bd9Sstevel@tonic-gate #define TP_PRVSTOP 0x0080 /* thread is virtually stopped via /proc */ 3897c478bd9Sstevel@tonic-gate #define TP_MSACCT 0x0100 /* collect micro-state accounting information */ 3907c478bd9Sstevel@tonic-gate #define TP_STOPPING 0x0200 /* thread is executing stop() */ 3917c478bd9Sstevel@tonic-gate #define TP_WATCHPT 0x0400 /* process has watchpoints in effect */ 3927c478bd9Sstevel@tonic-gate #define TP_PAUSE 0x0800 /* process is being stopped via pauselwps() */ 3937c478bd9Sstevel@tonic-gate #define TP_CHANGEBIND 0x1000 /* thread has a new cpu/cpupart binding */ 3947c478bd9Sstevel@tonic-gate #define TP_ZTHREAD 0x2000 /* this is a kernel thread for a zone */ 3957c478bd9Sstevel@tonic-gate #define TP_WATCHSTOP 0x4000 /* thread is stopping via holdwatch() */ 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate /* 3987c478bd9Sstevel@tonic-gate * Thread scheduler flag (t_schedflag) definitions. 3997c478bd9Sstevel@tonic-gate * The thread must be locked via thread_lock() or equiv. to change these. 4007c478bd9Sstevel@tonic-gate */ 4017c478bd9Sstevel@tonic-gate #define TS_LOAD 0x0001 /* thread is in memory */ 4027c478bd9Sstevel@tonic-gate #define TS_DONT_SWAP 0x0002 /* thread/lwp should not be swapped */ 4037c478bd9Sstevel@tonic-gate #define TS_SWAPENQ 0x0004 /* swap thread when it reaches a safe point */ 4047c478bd9Sstevel@tonic-gate #define TS_ON_SWAPQ 0x0008 /* thread is on the swap queue */ 4057c478bd9Sstevel@tonic-gate #define TS_SIGNALLED 0x0010 /* thread was awakened by cv_signal() */ 406c97ad5cdSakolb #define TS_PROJWAITQ 0x0020 /* thread is on its project's waitq */ 407c97ad5cdSakolb #define TS_ZONEWAITQ 0x0040 /* thread is on its zone's waitq */ 4087c478bd9Sstevel@tonic-gate #define TS_CSTART 0x0100 /* setrun() by continuelwps() */ 4097c478bd9Sstevel@tonic-gate #define TS_UNPAUSE 0x0200 /* setrun() by unpauselwps() */ 4107c478bd9Sstevel@tonic-gate #define TS_XSTART 0x0400 /* setrun() by SIGCONT */ 4117c478bd9Sstevel@tonic-gate #define TS_PSTART 0x0800 /* setrun() by /proc */ 4127c478bd9Sstevel@tonic-gate #define TS_RESUME 0x1000 /* setrun() by CPR resume process */ 4137c478bd9Sstevel@tonic-gate #define TS_CREATE 0x2000 /* setrun() by syslwp_create() */ 4147c478bd9Sstevel@tonic-gate #define TS_RUNQMATCH 0x4000 /* exact run queue balancing by setbackdq() */ 4157c478bd9Sstevel@tonic-gate #define TS_ALLSTART \ 4167c478bd9Sstevel@tonic-gate (TS_CSTART|TS_UNPAUSE|TS_XSTART|TS_PSTART|TS_RESUME|TS_CREATE) 417c97ad5cdSakolb #define TS_ANYWAITQ (TS_PROJWAITQ|TS_ZONEWAITQ) 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate /* 4200b70c467Sakolb * Thread binding types 4210b70c467Sakolb */ 4220b70c467Sakolb #define TB_ALLHARD 0 4230b70c467Sakolb #define TB_CPU_SOFT 0x01 /* soft binding to CPU */ 4240b70c467Sakolb #define TB_PSET_SOFT 0x02 /* soft binding to pset */ 4250b70c467Sakolb 4260b70c467Sakolb #define TB_CPU_SOFT_SET(t) ((t)->t_bindflag |= TB_CPU_SOFT) 4270b70c467Sakolb #define TB_CPU_HARD_SET(t) ((t)->t_bindflag &= ~TB_CPU_SOFT) 4280b70c467Sakolb #define TB_PSET_SOFT_SET(t) ((t)->t_bindflag |= TB_PSET_SOFT) 4290b70c467Sakolb #define TB_PSET_HARD_SET(t) ((t)->t_bindflag &= ~TB_PSET_SOFT) 4300b70c467Sakolb #define TB_CPU_IS_SOFT(t) ((t)->t_bindflag & TB_CPU_SOFT) 4310b70c467Sakolb #define TB_CPU_IS_HARD(t) (!TB_CPU_IS_SOFT(t)) 4320b70c467Sakolb #define TB_PSET_IS_SOFT(t) ((t)->t_bindflag & TB_PSET_SOFT) 4330b70c467Sakolb 4340b70c467Sakolb /* 4357c478bd9Sstevel@tonic-gate * No locking needed for AST field. 4367c478bd9Sstevel@tonic-gate */ 4377c478bd9Sstevel@tonic-gate #define aston(t) ((t)->t_astflag = 1) 4387c478bd9Sstevel@tonic-gate #define astoff(t) ((t)->t_astflag = 0) 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate /* True if thread is stopped on an event of interest */ 4417c478bd9Sstevel@tonic-gate #define ISTOPPED(t) ((t)->t_state == TS_STOPPED && \ 4427c478bd9Sstevel@tonic-gate !((t)->t_schedflag & TS_PSTART)) 4437c478bd9Sstevel@tonic-gate 444c97ad5cdSakolb /* True if thread is asleep and wakeable */ 445c97ad5cdSakolb #define ISWAKEABLE(t) (((t)->t_state == TS_SLEEP && \ 446c97ad5cdSakolb ((t)->t_flag & T_WAKEABLE))) 447c97ad5cdSakolb 448c97ad5cdSakolb /* True if thread is on the wait queue */ 449c97ad5cdSakolb #define ISWAITING(t) ((t)->t_state == TS_WAIT) 450c97ad5cdSakolb 4517c478bd9Sstevel@tonic-gate /* similar to ISTOPPED except the event of interest is CPR */ 4527c478bd9Sstevel@tonic-gate #define CPR_ISTOPPED(t) ((t)->t_state == TS_STOPPED && \ 4537c478bd9Sstevel@tonic-gate !((t)->t_schedflag & TS_RESUME)) 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate /* 4567c478bd9Sstevel@tonic-gate * True if thread is virtually stopped (is or was asleep in 4577c478bd9Sstevel@tonic-gate * one of the lwp_*() system calls and marked to stop by /proc.) 4587c478bd9Sstevel@tonic-gate */ 4597c478bd9Sstevel@tonic-gate #define VSTOPPED(t) ((t)->t_proc_flag & TP_PRVSTOP) 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate /* similar to VSTOPPED except the point of interest is CPR */ 4627c478bd9Sstevel@tonic-gate #define CPR_VSTOPPED(t) \ 4637c478bd9Sstevel@tonic-gate ((t)->t_state == TS_SLEEP && \ 4647c478bd9Sstevel@tonic-gate (t)->t_wchan0 != NULL && \ 4657c478bd9Sstevel@tonic-gate ((t)->t_flag & T_WAKEABLE) && \ 4667c478bd9Sstevel@tonic-gate ((t)->t_proc_flag & TP_CHKPT)) 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate /* True if thread has been stopped by hold*() or was created stopped */ 4697c478bd9Sstevel@tonic-gate #define SUSPENDED(t) ((t)->t_state == TS_STOPPED && \ 4707c478bd9Sstevel@tonic-gate ((t)->t_schedflag & (TS_CSTART|TS_UNPAUSE)) != (TS_CSTART|TS_UNPAUSE)) 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate /* True if thread possesses an inherited priority */ 4737c478bd9Sstevel@tonic-gate #define INHERITED(t) ((t)->t_epri != 0) 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate /* The dispatch priority of a thread */ 4767c478bd9Sstevel@tonic-gate #define DISP_PRIO(t) ((t)->t_epri > (t)->t_pri ? (t)->t_epri : (t)->t_pri) 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate /* The assigned priority of a thread */ 4797c478bd9Sstevel@tonic-gate #define ASSIGNED_PRIO(t) ((t)->t_pri) 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate /* 4827c478bd9Sstevel@tonic-gate * Macros to determine whether a thread can be swapped. 4837c478bd9Sstevel@tonic-gate * If t_lock is held, the thread is either on a processor or being swapped. 4847c478bd9Sstevel@tonic-gate */ 4857c478bd9Sstevel@tonic-gate #define SWAP_OK(t) (!LOCK_HELD(&(t)->t_lock)) 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate /* 4887c478bd9Sstevel@tonic-gate * proctot(x) 4897c478bd9Sstevel@tonic-gate * convert a proc pointer to a thread pointer. this only works with 4907c478bd9Sstevel@tonic-gate * procs that have only one lwp. 4917c478bd9Sstevel@tonic-gate * 4927c478bd9Sstevel@tonic-gate * proctolwp(x) 4937c478bd9Sstevel@tonic-gate * convert a proc pointer to a lwp pointer. this only works with 4947c478bd9Sstevel@tonic-gate * procs that have only one lwp. 4957c478bd9Sstevel@tonic-gate * 4967c478bd9Sstevel@tonic-gate * ttolwp(x) 4977c478bd9Sstevel@tonic-gate * convert a thread pointer to its lwp pointer. 4987c478bd9Sstevel@tonic-gate * 4997c478bd9Sstevel@tonic-gate * ttoproc(x) 5007c478bd9Sstevel@tonic-gate * convert a thread pointer to its proc pointer. 5017c478bd9Sstevel@tonic-gate * 5027c478bd9Sstevel@tonic-gate * ttoproj(x) 5037c478bd9Sstevel@tonic-gate * convert a thread pointer to its project pointer. 5047c478bd9Sstevel@tonic-gate * 505c97ad5cdSakolb * ttozone(x) 506c97ad5cdSakolb * convert a thread pointer to its zone pointer. 507c97ad5cdSakolb * 5087c478bd9Sstevel@tonic-gate * lwptot(x) 5097c478bd9Sstevel@tonic-gate * convert a lwp pointer to its thread pointer. 5107c478bd9Sstevel@tonic-gate * 5117c478bd9Sstevel@tonic-gate * lwptoproc(x) 5127c478bd9Sstevel@tonic-gate * convert a lwp to its proc pointer. 5137c478bd9Sstevel@tonic-gate */ 5147c478bd9Sstevel@tonic-gate #define proctot(x) ((x)->p_tlist) 5157c478bd9Sstevel@tonic-gate #define proctolwp(x) ((x)->p_tlist->t_lwp) 5167c478bd9Sstevel@tonic-gate #define ttolwp(x) ((x)->t_lwp) 5177c478bd9Sstevel@tonic-gate #define ttoproc(x) ((x)->t_procp) 5187c478bd9Sstevel@tonic-gate #define ttoproj(x) ((x)->t_proj) 519c97ad5cdSakolb #define ttozone(x) ((x)->t_procp->p_zone) 5207c478bd9Sstevel@tonic-gate #define lwptot(x) ((x)->lwp_thread) 5217c478bd9Sstevel@tonic-gate #define lwptoproc(x) ((x)->lwp_procp) 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate #define t_pc t_pcb.val[0] 5247c478bd9Sstevel@tonic-gate #define t_sp t_pcb.val[1] 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate #ifdef _KERNEL 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate extern kthread_t *threadp(void); /* inline, returns thread pointer */ 5297c478bd9Sstevel@tonic-gate #define curthread (threadp()) /* current thread pointer */ 5307c478bd9Sstevel@tonic-gate #define curproc (ttoproc(curthread)) /* current process pointer */ 5317c478bd9Sstevel@tonic-gate #define curproj (ttoproj(curthread)) /* current project pointer */ 532c97ad5cdSakolb #define curzone (curproc->p_zone) /* current zone pointer */ 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate extern struct _kthread t0; /* the scheduler thread */ 5357c478bd9Sstevel@tonic-gate extern kmutex_t pidlock; /* global process lock */ 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate /* 5382850d85bSmv143129 * thread_free_lock is used by the tick accounting thread to keep a thread 5397c478bd9Sstevel@tonic-gate * from being freed while it is being examined. 54091f917c7SMadhavan Venkataraman * 54191f917c7SMadhavan Venkataraman * Thread structures are 32-byte aligned structures. That is why we use the 54291f917c7SMadhavan Venkataraman * following formula. 5437c478bd9Sstevel@tonic-gate */ 54491f917c7SMadhavan Venkataraman #define THREAD_FREE_BITS 10 54591f917c7SMadhavan Venkataraman #define THREAD_FREE_NUM (1 << THREAD_FREE_BITS) 5462850d85bSmv143129 #define THREAD_FREE_MASK (THREAD_FREE_NUM - 1) 54791f917c7SMadhavan Venkataraman #define THREAD_FREE_1 PTR24_LSB 54891f917c7SMadhavan Venkataraman #define THREAD_FREE_2 (PTR24_LSB + THREAD_FREE_BITS) 54991f917c7SMadhavan Venkataraman #define THREAD_FREE_SHIFT(t) \ 55091f917c7SMadhavan Venkataraman (((ulong_t)(t) >> THREAD_FREE_1) ^ ((ulong_t)(t) >> THREAD_FREE_2)) 5512850d85bSmv143129 #define THREAD_FREE_HASH(t) (THREAD_FREE_SHIFT(t) & THREAD_FREE_MASK) 5522850d85bSmv143129 5532850d85bSmv143129 typedef struct thread_free_lock { 5542850d85bSmv143129 kmutex_t tf_lock; 5552850d85bSmv143129 uchar_t tf_pad[64 - sizeof (kmutex_t)]; 5562850d85bSmv143129 } thread_free_lock_t; 5572850d85bSmv143129 5582850d85bSmv143129 extern void thread_free_prevent(kthread_t *); 5592850d85bSmv143129 extern void thread_free_allow(kthread_t *); 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate /* 5627c478bd9Sstevel@tonic-gate * Routines to change the priority and effective priority 5637c478bd9Sstevel@tonic-gate * of a thread-locked thread, whatever its state. 5647c478bd9Sstevel@tonic-gate */ 5657c478bd9Sstevel@tonic-gate extern int thread_change_pri(kthread_t *t, pri_t disp_pri, int front); 5667c478bd9Sstevel@tonic-gate extern void thread_change_epri(kthread_t *t, pri_t disp_pri); 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate /* 5697c478bd9Sstevel@tonic-gate * Routines that manipulate the dispatcher lock for the thread. 5707c478bd9Sstevel@tonic-gate * The locking heirarchy is as follows: 5717c478bd9Sstevel@tonic-gate * cpu_lock > sleepq locks > run queue locks 5727c478bd9Sstevel@tonic-gate */ 5737c478bd9Sstevel@tonic-gate void thread_transition(kthread_t *); /* move to transition lock */ 5747c478bd9Sstevel@tonic-gate void thread_stop(kthread_t *); /* move to stop lock */ 5757c478bd9Sstevel@tonic-gate void thread_lock(kthread_t *); /* lock thread and its queue */ 5767c478bd9Sstevel@tonic-gate void thread_lock_high(kthread_t *); /* lock thread and its queue */ 5777c478bd9Sstevel@tonic-gate void thread_onproc(kthread_t *, struct cpu *); /* set onproc state lock */ 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate #define thread_unlock(t) disp_lock_exit((t)->t_lockp) 5807c478bd9Sstevel@tonic-gate #define thread_unlock_high(t) disp_lock_exit_high((t)->t_lockp) 5817c478bd9Sstevel@tonic-gate #define thread_unlock_nopreempt(t) disp_lock_exit_nopreempt((t)->t_lockp) 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate #define THREAD_LOCK_HELD(t) (DISP_LOCK_HELD((t)->t_lockp)) 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate extern disp_lock_t transition_lock; /* lock protecting transiting threads */ 5867c478bd9Sstevel@tonic-gate extern disp_lock_t stop_lock; /* lock protecting stopped threads */ 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate caddr_t thread_stk_init(caddr_t); /* init thread stack */ 5897c478bd9Sstevel@tonic-gate 5900b70c467Sakolb extern int default_binding_mode; 5910b70c467Sakolb 5927c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 5937c478bd9Sstevel@tonic-gate 5947c478bd9Sstevel@tonic-gate /* 5957c478bd9Sstevel@tonic-gate * Macro to change a thread's priority. 5967c478bd9Sstevel@tonic-gate */ 5977c478bd9Sstevel@tonic-gate #define THREAD_CHANGE_PRI(t, pri) { \ 5987c478bd9Sstevel@tonic-gate pri_t __new_pri = (pri); \ 5997c478bd9Sstevel@tonic-gate DTRACE_SCHED2(change__pri, kthread_t *, (t), pri_t, __new_pri); \ 6007c478bd9Sstevel@tonic-gate (t)->t_pri = __new_pri; \ 601d4204c85Sraf schedctl_set_cidpri(t); \ 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate * Macro to indicate that a thread's priority is about to be changed. 6067c478bd9Sstevel@tonic-gate */ 6077c478bd9Sstevel@tonic-gate #define THREAD_WILLCHANGE_PRI(t, pri) { \ 6087c478bd9Sstevel@tonic-gate DTRACE_SCHED2(change__pri, kthread_t *, (t), pri_t, (pri)); \ 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate /* 6127c478bd9Sstevel@tonic-gate * Macros to change thread state and the associated lock. 6137c478bd9Sstevel@tonic-gate */ 6147c478bd9Sstevel@tonic-gate #define THREAD_SET_STATE(tp, state, lp) \ 6157c478bd9Sstevel@tonic-gate ((tp)->t_state = state, (tp)->t_lockp = lp) 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate /* 6187c478bd9Sstevel@tonic-gate * Point it at the transition lock, which is always held. 6197c478bd9Sstevel@tonic-gate * The previosly held lock is dropped. 6207c478bd9Sstevel@tonic-gate */ 6217c478bd9Sstevel@tonic-gate #define THREAD_TRANSITION(tp) thread_transition(tp); 6227c478bd9Sstevel@tonic-gate /* 6237c478bd9Sstevel@tonic-gate * Set the thread's lock to be the transition lock, without dropping 6247c478bd9Sstevel@tonic-gate * previosly held lock. 6257c478bd9Sstevel@tonic-gate */ 6267c478bd9Sstevel@tonic-gate #define THREAD_TRANSITION_NOLOCK(tp) ((tp)->t_lockp = &transition_lock) 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate /* 6297c478bd9Sstevel@tonic-gate * Put thread in run state, and set the lock pointer to the dispatcher queue 6307c478bd9Sstevel@tonic-gate * lock pointer provided. This lock should be held. 6317c478bd9Sstevel@tonic-gate */ 6327c478bd9Sstevel@tonic-gate #define THREAD_RUN(tp, lp) THREAD_SET_STATE(tp, TS_RUN, lp) 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate /* 635c97ad5cdSakolb * Put thread in wait state, and set the lock pointer to the wait queue 636c97ad5cdSakolb * lock pointer provided. This lock should be held. 637c97ad5cdSakolb */ 638c97ad5cdSakolb #define THREAD_WAIT(tp, lp) THREAD_SET_STATE(tp, TS_WAIT, lp) 639c97ad5cdSakolb 640c97ad5cdSakolb /* 6417c478bd9Sstevel@tonic-gate * Put thread in run state, and set the lock pointer to the dispatcher queue 6427c478bd9Sstevel@tonic-gate * lock pointer provided (i.e., the "swapped_lock"). This lock should be held. 6437c478bd9Sstevel@tonic-gate */ 6447c478bd9Sstevel@tonic-gate #define THREAD_SWAP(tp, lp) THREAD_SET_STATE(tp, TS_RUN, lp) 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate /* 6477c478bd9Sstevel@tonic-gate * Put the thread in zombie state and set the lock pointer to NULL. 6487c478bd9Sstevel@tonic-gate * The NULL will catch anything that tries to lock a zombie. 6497c478bd9Sstevel@tonic-gate */ 6507c478bd9Sstevel@tonic-gate #define THREAD_ZOMB(tp) THREAD_SET_STATE(tp, TS_ZOMB, NULL) 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate /* 6537c478bd9Sstevel@tonic-gate * Set the thread into ONPROC state, and point the lock at the CPUs 6547c478bd9Sstevel@tonic-gate * lock for the onproc thread(s). This lock should be held, so the 6557c478bd9Sstevel@tonic-gate * thread deoes not become unlocked, since these stores can be reordered. 6567c478bd9Sstevel@tonic-gate */ 6577c478bd9Sstevel@tonic-gate #define THREAD_ONPROC(tp, cpu) \ 6587c478bd9Sstevel@tonic-gate THREAD_SET_STATE(tp, TS_ONPROC, &(cpu)->cpu_thread_lock) 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate /* 6617c478bd9Sstevel@tonic-gate * Set the thread into the TS_SLEEP state, and set the lock pointer to 6627c478bd9Sstevel@tonic-gate * to some sleep queue's lock. The new lock should already be held. 6637c478bd9Sstevel@tonic-gate */ 6647c478bd9Sstevel@tonic-gate #define THREAD_SLEEP(tp, lp) { \ 6657c478bd9Sstevel@tonic-gate disp_lock_t *tlp; \ 6667c478bd9Sstevel@tonic-gate tlp = (tp)->t_lockp; \ 6677c478bd9Sstevel@tonic-gate THREAD_SET_STATE(tp, TS_SLEEP, lp); \ 6687c478bd9Sstevel@tonic-gate disp_lock_exit_high(tlp); \ 6697c478bd9Sstevel@tonic-gate } 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate /* 6727c478bd9Sstevel@tonic-gate * Interrupt threads are created in TS_FREE state, and their lock 6737c478bd9Sstevel@tonic-gate * points at the associated CPU's lock. 6747c478bd9Sstevel@tonic-gate */ 6757c478bd9Sstevel@tonic-gate #define THREAD_FREEINTR(tp, cpu) \ 6767c478bd9Sstevel@tonic-gate THREAD_SET_STATE(tp, TS_FREE, &(cpu)->cpu_thread_lock) 6777c478bd9Sstevel@tonic-gate 678bff31d89SPhilippe Jung /* if tunable kmem_stackinfo is set, fill kthread stack with a pattern */ 679bff31d89SPhilippe Jung #define KMEM_STKINFO_PATTERN 0xbadcbadcbadcbadcULL 680bff31d89SPhilippe Jung 681bff31d89SPhilippe Jung /* 682bff31d89SPhilippe Jung * If tunable kmem_stackinfo is set, log the latest KMEM_LOG_STK_USAGE_SIZE 683bff31d89SPhilippe Jung * dead kthreads that used their kernel stack the most. 684bff31d89SPhilippe Jung */ 685bff31d89SPhilippe Jung #define KMEM_STKINFO_LOG_SIZE 16 686bff31d89SPhilippe Jung 687bff31d89SPhilippe Jung /* kthread name (cmd/lwpid) string size in the stackinfo log */ 688bff31d89SPhilippe Jung #define KMEM_STKINFO_STR_SIZE 64 689bff31d89SPhilippe Jung 690bff31d89SPhilippe Jung /* 691bff31d89SPhilippe Jung * stackinfo logged data. 692bff31d89SPhilippe Jung */ 693bff31d89SPhilippe Jung typedef struct kmem_stkinfo { 694bff31d89SPhilippe Jung caddr_t kthread; /* kthread pointer */ 695bff31d89SPhilippe Jung caddr_t t_startpc; /* where kthread started */ 696bff31d89SPhilippe Jung caddr_t start; /* kthread stack start address */ 697bff31d89SPhilippe Jung size_t stksz; /* kthread stack size */ 698bff31d89SPhilippe Jung size_t percent; /* kthread stack high water mark */ 699bff31d89SPhilippe Jung id_t t_tid; /* kthread id */ 700bff31d89SPhilippe Jung char cmd[KMEM_STKINFO_STR_SIZE]; /* kthread name (cmd/lwpid) */ 701bff31d89SPhilippe Jung } kmem_stkinfo_t; 702bff31d89SPhilippe Jung 7037c478bd9Sstevel@tonic-gate #ifdef __cplusplus 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate #endif 7067c478bd9Sstevel@tonic-gate 7077c478bd9Sstevel@tonic-gate #endif /* _SYS_THREAD_H */ 708