/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
*/
#include <sys/sysmacros.h>
#include <sys/resource.h>
#include <vm/seg_kmem.h>
#include <sys/machlock.h>
#include <sys/turnstile.h>
#include <sys/cpc_impl.h>
#include <sys/schedctl.h>
/*
* allthreads is only for use by kmem_readers. All kernel loops can use
*/
/* protects tick thread from reaper */
extern int nthread;
/* System Scheduling classes. */
/* Default mode for thread binding to CPUs and processor sets */
/*
*/
/*
* default_stksize overrides lwp_default_stksize if it is set.
*/
int default_stksize;
int lwp_default_stksize;
/*
* forward declarations for internal thread specific data (tsd)
*/
void thread_reaper(void);
/* forward declarations for stackinfo feature */
static void stkinfo_begin(kthread_t *);
static void stkinfo_end(kthread_t *);
/*ARGSUSED*/
static int
{
return (0);
}
/*ARGSUSED*/
static void
{
}
void
thread_init(void)
{
extern char sys_name[];
extern void idle();
int i;
for (i = 0; i < THREAD_FREE_NUM; i++) {
}
/*
* "struct _klwp" includes a "struct pcb", which includes a
* "struct fpu", which needs to be 64-byte aligned on amd64
*/
#else
/*
* Allocate thread structures from static_arena. This prevents
* issues where a thread tries to relocate its own thread
* structure and touches it after the mapping has been suspended.
*/
#endif
sizeof (turnstile_t), 0,
label_init();
cred_init();
/*
* Initialize various resource management facilities.
*/
rctl_init();
cpucaps_init();
/*
* Zone_init() should be called before project_init() so that project ID
* for the first project is initialized correctly.
*/
zone_init();
project_init();
brand_init();
kiconv_init();
task_init();
tcache_init();
pool_init();
/*
* Originally, we had two parameters to set default stack
* size: one for lwp's (lwp_default_stksize), and one for
* kernel-only threads (DEFAULTSTKSZ, a.k.a. _defaultstksz).
* Now we have a third parameter that overrides both if it is
* set to a legal stack size, called default_stksize.
*/
if (default_stksize == 0) {
} else if (default_stksize % PAGESIZE != 0 ||
(int)DEFAULTSTKSZ);
} else {
}
if (lwp_default_stksize == 0) {
} else if (lwp_default_stksize % PAGESIZE != 0 ||
}
/*
* Set up the first CPU's idle thread.
* It runs whenever the CPU has nothing worthwhile to do.
*/
/*
* Registering a thread in the callback table is usually
* done in the initialization code of the thread. In this
* case, we do it right after thread creation to avoid
* blocking idle thread while registering itself. It also
* avoids the possibility of reregistration in case a CPU
* restarts its idle thread.
*/
/*
* Create the thread_reaper daemon. From this point on, exited
* threads will get reaped.
*/
/*
* Finish initializing the kernel memory allocator now that
* thread_create() is available.
*/
}
/*
* Create a thread.
*
* thread_create() blocks for memory if necessary. It never fails.
*
* If stk is NULL, the thread is created at the base of the stack
* and cannot be swapped.
*/
void (*proc)(),
void *arg,
int state,
{
kthread_t *t;
extern struct classfuncs sys_classfuncs;
/*
* Every thread keeps a turnstile around in case it needs to block.
* The only reason the turnstile is not simply part of the thread
* structure is that we may have to break the association whenever
* more than one thread blocks on a given synchronization object.
* From a memory-management standpoint, turnstiles are like the
* "attached mblks" that hang off dblks in the streams allocator.
*/
/*
* alloc both thread and stack in segkp chunk
*/
if (stksize < default_stksize)
if (stksize == default_stksize) {
} else {
}
/*
* The machine-dependent mutex code may require that
* thread pointers (since they may be used for mutex owner
* fields) have certain alignment requirements.
* PTR24_ALIGN is the size of the alignment quanta.
* XXX - assumes stack grows toward low addresses.
*/
" too small to hold thread.");
#ifdef STACK_GROWTH_DOWN
if (audit_active)
#else /* stack grows to larger addresses */
#endif /* STACK_GROWTH_DOWN */
t->t_flag |= T_TALLOCSTK;
} else {
if (audit_active)
/*
* Initialize t_stk to the kernel stack pointer to use
* upon entry to the kernel
*/
#ifdef STACK_GROWTH_DOWN
#else
#endif /* STACK_GROWTH_DOWN */
}
if (kmem_stackinfo != 0) {
stkinfo_begin(t);
}
/*
* p_cred could be NULL if it thread_create is called before cred_init
* is called in main.
*/
t->t_start = gethrestime_sec();
t->t_stime = ddi_get_lbolt();
t->t_bind_cpu = PBIND_NONE;
t->t_bind_pset = PS_NONE;
t->t_anttime = 0;
t->t_hatdepth = 0;
#ifndef NPROBE
/* Kernel probe */
#endif /* NPROBE */
LOCK_INIT_CLEAR(&t->t_lock);
/*
* Callers who give us a NULL proc must do their own
* stack initialization. e.g. lwp_create()
*/
}
/*
* Put a hold on project0. If this thread is actually in a
* different project, then t_proj will be changed later in
* lwp_create(). All kernel-only threads must be in project 0.
*/
nthread++;
/*
* Add the thread to the list of all threads, and initialize
* its t_cpu pointer. We need to block preemption since
* cpu_offline walks the thread list looking for threads
* with t_cpu pointing to the CPU being offlined. We want
* to make sure that the list is consistent and that if t_cpu
* is set, the thread is on the list.
*/
/*
* Threads should never have a NULL t_cpu pointer so assign it
* here. If the thread is being created with state TS_RUN a
* better CPU may be chosen when it is placed on the run queue.
*
* We need to keep kernel preemption disabled when setting all
* three fields to keep them in sync. Also, always create in
* the default partition since that's where kernel threads go
* (if this isn't a kernel thread, t_cpupart will be changed
* in lwp_create before setting the thread runnable).
*/
t->t_cpupart = &cp_default;
/*
* For now, affiliate this thread with the root lgroup.
* Since the kernel does not (presently) allocate its memory
* in a locality aware fashion, the root is an appropriate home.
* If this thread is later associated with an lwp, it will have
* it's lgroup re-assigned at that time.
*/
/*
* Inherit the current cpu. If this cpu isn't part of the chosen
* lgroup, a new cpu will be chosen by cpu_choose when the thread
* is ready to run.
*/
else
/*
* Initialize thread state and the dispatcher lock pointer.
* Need to hold onto pidlock to block allthreads walkers until
* the state is set.
*/
switch (state) {
case TS_RUN:
CL_SETRUN(t);
thread_unlock(t);
break;
case TS_ONPROC:
THREAD_ONPROC(t, t->t_cpu);
break;
case TS_FREE:
/*
* Free state will be used for intr threads.
* The interrupt routine must set the thread dispatcher
* lock pointer (t_lockp) if starting on a CPU
* other than the current one.
*/
THREAD_FREEINTR(t, CPU);
break;
case TS_STOPPED:
break;
default: /* TS_SLEEP, TS_ZOMB or TS_TRANS */
}
return (t);
}
/*
* Move thread to project0 and take care of project reference counters.
*/
void
{
thread_lock(t);
thread_unlock(t);
(void) project_hold(proj0p);
}
}
void
thread_exit(void)
{
if ((t->t_proc_flag & TP_ZTHREAD) != 0)
tsd_exit(); /* Clean up this thread's TSD */
kcpc_passivate(); /* clean up performance counter state */
/*
* No kernel thread should have called poll() without arranging
* calling pollcleanup() here.
*/
if (t->t_door)
door_slam(); /* in case thread did an upcall */
#ifndef NPROBE
/* Kernel probe */
if (t->t_tnf_tpdp)
#endif /* NPROBE */
thread_rele(t);
t->t_preempt++;
/*
* remove thread from the all threads list so that
* death-row can use the same pointers.
*/
exitctx(t);
if (kmem_stackinfo != 0) {
stkinfo_end(t);
}
swtch_from_zombie(); /* give up the CPU */
/* NOTREACHED */
}
/*
* Check to see if the specified thread is active (defined as being on
* the thread list). This is certainly a slow way to do this; if there's
* ever a reason to speed it up, we could maintain a hash table of active
* threads indexed by their t_did.
*/
static kthread_t *
{
kthread_t *t;
break;
}
return (t);
else
return (NULL);
}
/*
* Wait for specified thread to exit. Returns immediately if the thread
* could not be found, meaning that it has either already exited or never
* existed.
*/
void
{
kthread_t *t;
/*
* Make sure we check that the thread is on the thread list
* before blocking on it; otherwise we could end up blocking on
* a cv that's already been freed. In other words, don't cache
* the thread pointer across calls to cv_wait.
*
* The choice of loop invariant means that whenever a thread
* is taken off the allthreads list, a cv_broadcast must be
* performed on that thread's t_joincv to wake up any waiters.
* The broadcast doesn't have to happen right away, but it
* shouldn't be postponed indefinitely (e.g., by doing it in
* thread_free which may only be executed when the deathrow
* queue is processed.
*/
while (t = did_to_thread(tid))
}
void
{
}
void
{
mutex_exit(lp);
}
static void
{
mutex_exit(lp);
}
void
{
t->t_pri = 0;
t->t_pc = 0;
t->t_sp = 0;
t->t_cred = 0;
}
if (t->t_pdmsg) {
}
if (audit_active)
#ifndef NPROBE
if (t->t_tnf_tpdp)
tnf_thread_free(t);
#endif /* NPROBE */
if (t->t_cldata) {
}
}
if (lwp)
lwp_freeregs(lwp, 0);
if (t->t_ctx)
freectx(t, 0);
if (lwp)
lock_clear(&t->t_lock);
if (t->t_ts->ts_waiters > 0)
panic("thread_free: turnstile still active");
free_afd(&t->t_activefd);
/*
* Barrier for the tick accounting code. The tick accounting code
* holds this lock to keep the thread from going away while it's
* looking at it.
*/
project_rele(ttoproj(t));
nthread--;
/*
* Free thread, lwp and stack. This needs to be done carefully, since
* if T_TALLOCSTK is set, the thread is part of the stack.
*/
if (swap) {
}
if (lwp) {
}
if (!allocstk) {
}
}
/*
* Removes threads associated with the given zone from a deathrow queue.
* tp is a pointer to the head of the deathrow queue, and countp is a
* pointer to the current deathrow count. Returns a linked list of
* threads removed from the list.
*/
static kthread_t *
{
(*countp)--;
} else {
}
}
return (list);
}
static void
{
while (t != NULL) {
thread_free(t);
t = next;
}
}
/* ARGSUSED */
static void
{
kthread_t *t, *l;
/*
* Pull threads and lwps associated with zone off deathrow lists.
*/
/*
* Guard against race condition in mutex_owner_running:
* thread=owner(mutex)
* <interrupt>
* thread exits mutex
* thread exits
* thread reaped
* thread struct freed
* cpu = thread->t_cpu <- BAD POINTER DEREFERENCE.
* A cross call to all cpus will cause the interrupt handler
* to reset the PC if it is in mutex_owner_running, refreshing
* stale thread pointers.
*/
mutex_sync(); /* sync with mutex code */
/*
* Reap threads
*/
thread_reap_list(t);
/*
* Reap lwps
*/
thread_reap_list(l);
}
/*
* cleanup zombie threads that are on deathrow.
*/
void
{
kthread_t *t, *l;
/*
* Register callback to clean up threads when zone is destroyed.
*/
for (;;) {
}
/*
* mutex_sync() needs to be called when reaping, but
* not too often. We limit reaping rate to once
* per second. Reaplimit is max rate at which threads can
* be freed. Does not impact thread destruction/creation.
*/
t = thread_deathrow;
l = lwp_deathrow;
lwp_deathrow = NULL;
thread_reapcnt = 0;
lwp_reapcnt = 0;
/*
* Guard against race condition in mutex_owner_running:
* thread=owner(mutex)
* <interrupt>
* thread exits mutex
* thread exits
* thread reaped
* thread struct freed
* cpu = thread->t_cpu <- BAD POINTER DEREFERENCE.
* A cross call to all cpus will cause the interrupt handler
* to reset the PC if it is in mutex_owner_running, refreshing
* stale thread pointers.
*/
mutex_sync(); /* sync with mutex code */
/*
* Reap threads
*/
thread_reap_list(t);
/*
* Reap lwps
*/
thread_reap_list(l);
}
}
/*
* This is called by lwpcreate, etc.() to put a lwp_deathrow thread onto
* thread_deathrow. The thread's state is changed already TS_FREE to indicate
* that is reapable. The thread already holds the reaplock, and was already
* freed.
*/
void
{
t->t_forw = thread_deathrow;
thread_deathrow = t;
}
/*
* This is called by resume() to put a zombie thread onto deathrow.
* The thread's state is changed to TS_FREE to indicate that is reapable.
* This is called from the idle thread so it must not block - just spin.
*/
void
{
/*
* lwp_deathrow contains threads with lwp linkage and
* swappable thread stacks which have the default stacksize.
* These threads' lwps and stacks may be reused by lwp_create().
*
* Anything else goes on thread_deathrow(), where it will eventually
* be thread_free()d.
*/
if (t->t_flag & T_LWPREUSE) {
t->t_forw = lwp_deathrow;
lwp_deathrow = t;
lwp_reapcnt++;
} else {
t->t_forw = thread_deathrow;
thread_deathrow = t;
}
lock_clear(&t->t_lock);
/*
* Before we return, we need to grab and drop the thread lock for
* the dead thread. At this point, the current thread is the idle
* thread, and the dead thread's CPU lock points to the current
* CPU -- and we must grab and drop the lock to synchronize with
* a racing thread walking a blocking chain that the zombie thread
* was recently in. By this point, that blocking chain is (by
* definition) stale: the dead thread is not holding any locks, and
* is therefore not in any blocking chains -- but if we do not regrab
* our lock before freeing the dead thread's data structures, the
* thread walking the (stale) blocking chain will die on memory
* corruption when it attempts to drop the dead thread's lock. We
* only need do this once because there is no way for the dead thread
* to ever again be on a blocking chain: once we have grabbed and
* dropped the thread lock, we are guaranteed that anyone that could
* have seen this thread in a blocking chain can no longer see it.
*/
thread_lock(t);
thread_unlock(t);
}
/*
* Install thread context ops for the current thread.
*/
void
kthread_t *t,
void *arg,
void (*save)(void *),
void (*restore)(void *),
void (*fork)(void *, void *),
void (*lwp_create)(void *, void *),
void (*exit)(void *),
void (*free)(void *, int))
{
}
/*
* Remove the thread context ops from a thread.
*/
int
kthread_t *t,
void *arg,
void (*save)(void *),
void (*restore)(void *),
void (*fork)(void *, void *),
void (*lwp_create)(void *, void *),
void (*exit)(void *),
void (*free)(void *, int))
{
/*
* The incoming kthread_t (which is the thread for which the
* context ops will be removed) should be one of the following:
*
* a) the current thread,
*
* b) a thread of a process that's being forked (SIDL),
*
* c) a thread that belongs to the same process as the current
* thread and for which the current thread is the agent thread,
*
* d) a thread that is TS_STOPPED which is indicative of it
* being (if curthread is not an agent) a thread being created
* as part of an lwp creation.
*/
/*
* Serialize modifications to t->t_ctx to prevent the agent thread
* and the target thread from racing with each other during lwp exit.
*/
mutex_enter(&t->t_ctx_lock);
if (prev_ctx)
else
mutex_exit(&t->t_ctx_lock);
return (1);
}
}
mutex_exit(&t->t_ctx_lock);
return (0);
}
void
{
}
void
{
}
void
{
}
/*
* Note that this operator is only invoked via the _lwp_create
* system call. The system may have other reasons to create lwps
* e.g. the agent lwp or the doors unreferenced lwp.
*/
void
{
}
/*
* exitctx is called from thread_exit() and lwp_exit() to perform any actions
* routine is not intended to deal with freeing memory; freectx() is used for
* that purpose during thread_free(). This routine is provided to allow for
* clean-up that can't wait until thread_free().
*/
void
{
}
/*
* freectx is called from thread_free() and exec() to get
* rid of old thread context ops.
*/
void
{
}
}
/*
* freectx_ctx is called from lwp_create() when lwp is reused from
* lwp_deathrow and its thread structure is added to thread_deathrow.
* The thread structure to which this ctx was attached may be already
* freed by the thread reaper so free_op implementations shouldn't rely
* on thread structure to which this ctx was attached still being around.
*/
void
{
do {
}
/*
* Set the thread running; arrange for it to be swapped in if necessary.
*/
void
{
ASSERT(THREAD_LOCK_HELD(t));
/*
* Take off sleep queue.
*/
SOBJ_UNSLEEP(t->t_sobj_ops, t);
/*
* Already on dispatcher queue.
*/
return;
waitq_setrun(t);
} else if (t->t_state == TS_STOPPED) {
/*
* All of the sending of SIGCONT (TC_XSTART) and /proc
* (TC_PSTART) and lwp_continue() (TC_CSTART) must have
* requested that the thread be run.
* Just calling setrun() is not sufficient to set a stopped
* thread running. TP_TXSTART is always set if the thread
* is not stopped by a jobcontrol stop signal.
* TP_TPSTART is always set if /proc is not controlling it.
* TP_TCSTART is always set if lwp_suspend() didn't stop it.
* The thread won't be stopped unless one of these
* three mechanisms did it.
*
* These flags must be set before calling setrun_locked(t).
* They can't be passed as arguments because the streams
* code calls setrun() indirectly and the mechanism for
* doing so admits only one argument. Note that the
* thread must be locked in order to change t_schedflags.
*/
return;
/*
* Process is no longer stopped (a thread is running).
*/
t->t_whystop = 0;
t->t_whatstop = 0;
/*
* Strictly speaking, we do not have to clear these
* flags here; they are cleared on entry to stop().
* However, they are confusing when doing kernel
* debugging or when they are revealed by ps(1).
*/
t->t_schedflag &= ~TS_ALLSTART;
THREAD_TRANSITION(t); /* drop stopped-thread lock */
/*
* Let the class put the process on the dispatcher queue.
*/
CL_SETRUN(t);
}
}
void
{
thread_lock(t);
setrun_locked(t);
thread_unlock(t);
}
/*
* Unpin an interrupted thread.
* When an interrupt occurs, the interrupt is handled on the stack
* of an interrupt thread, taken from a pool linked to the CPU structure.
*
* When swtch() is switching away from an interrupt thread because it
* blocked or was preempted, this routine is called to complete the
* saving of the interrupted thread state, and returns the interrupted
* thread pointer so it may be resumed.
*
* Called by swtch() only at high spl.
*/
{
int i; /* interrupt level */
extern int intr_passivate();
/*
* Get state from interrupt thread for the one
* it interrupted.
*/
i = intr_passivate(t, itp);
"intr_passivate:level %d curthread %p (%T) ithread %p (%T)",
/*
* Dissociate the current thread from the interrupted thread's LWP.
*/
/*
* Interrupt handlers above the level that spinlocks block must
* not block.
*/
#if DEBUG
if (i < 0 || i > LOCK_LEVEL)
#endif
/*
* Compute the CPU's base interrupt level based on the active
* interrupts.
*/
set_base_spl();
return (itp);
}
/*
* Create and initialize an interrupt thread.
* Returns non-zero on error.
* Called at spl7() or better.
*/
void
{
/*
* Set the thread in the TS_FREE state. The state will change
* to TS_ONPROC only while the interrupt is active. Think of these
* as being on a private free list for the CPU. Being TS_FREE keeps
* inactive interrupt threads out of debugger thread lists.
*
* We cannot call thread_create with TS_FREE because of the current
* checks there for ONPROC. Fix this when thread_create takes flags.
*/
/*
* Nobody should ever reference the credentials of an interrupt
* thread so make it NULL to catch any such references.
*/
/*
* Don't make a user-requested binding on this thread so that
* the processor can be offlined.
*/
#endif
/*
* Link onto CPU's interrupt pool.
*/
}
/*
* TSD -- THREAD SPECIFIC DATA
*/
/* per-key destructor funcs */
static void (**tsd_destructor)(void *);
/* list of tsd_thread's */
/*
* Default destructor
* Needed because NULL destructor means that the key is unused
*/
/* ARGSUSED */
void
{}
/*
* Create a key (index into per thread array)
* Locks out tsd_create, tsd_destroy, and tsd_exit
* May allocate memory with lock held
*/
void
{
int i;
/*
* if key is allocated, do nothing
*/
if (*keyp) {
return;
}
/*
* find an unused key
*/
if (destructor == NULL)
for (i = 0; i < tsd_nkeys; ++i)
if (tsd_destructor[i] == NULL)
break;
/*
* if no unused keys, increase the size of the destructor array
*/
if (i == tsd_nkeys) {
nkeys = 1;
(void (**)(void *))tsd_realloc((void *)tsd_destructor,
}
/*
* allocate the next available unused key
*/
tsd_destructor[i] = destructor;
*keyp = i + 1;
}
/*
* Destroy a key -- this is for unloadable modules
*
* Assumes that the caller is preventing tsd_set and tsd_get
* Locks out tsd_create, tsd_destroy, and tsd_exit
* May free memory with lock held
*/
void
{
/*
* protect the key namespace and our destructor lists
*/
*keyp = 0;
/*
* if the key is valid
*/
if (key != 0) {
/*
* for every thread with TSD, call key's destructor
*/
/*
* no TSD for key in this thread
*/
continue;
/*
* call destructor for key
*/
/*
* reset value for key
*/
}
/*
* actually free the key (NULL destructor == unused)
*/
tsd_destructor[k] = NULL;
}
}
/*
* Quickly return the per thread value that was stored with the specified key
* Assumes the caller is protecting key from tsd_create and tsd_destroy
*/
void *
{
}
/*
* Set a per thread value indexed with the specified key
*/
int
{
}
/*
* Like tsd_get(), except that the agent lwp can get the tsd of
* another thread in the same process (the agent thread only runs when the
* process is completely stopped by /proc), or syslwp is creating a new lwp.
*/
void *
{
return (NULL);
}
/*
* Like tsd_set(), except that the agent lwp can set the tsd of
* another thread in the same process, or syslwp can set the tsd
* of a thread it's in the middle of creating.
*
* Assumes the caller is protecting key from tsd_create and tsd_destroy
* May lock out tsd_destroy (and tsd_create), may allocate memory with
* lock held
*/
int
{
if (key == 0)
return (EINVAL);
return (0);
}
/*
* lock out tsd_destroy()
*/
/*
* Link onto list of threads with TSD
*/
}
/*
* Allocate thread local storage and set the value for key
*/
key * sizeof (void *));
return (0);
}
/*
* Return the per thread value that was stored with the specified key
* If necessary, create the key and the value
* Assumes the caller is protecting *keyp from tsd_destroy
*/
void *
{
void *value;
return (value);
if (key == 0)
return (value);
}
/*
* Called from thread_exit() to run the destructor function for each tsd
* Locks out tsd_create and tsd_destroy
* Assumes that the destructor *DOES NOT* use tsd
*/
void
tsd_exit(void)
{
int i;
return;
return;
}
/*
* lock out tsd_create and tsd_destroy, call
* the destructor, and mark the value as destroyed.
*/
}
/*
* remove from linked list of threads with TSD
*/
/*
* free up the TSD
*/
}
/*
* realloc
*/
static void *
{
void *new;
if (old) {
}
return (new);
}
/*
* Return non-zero if an interrupt is being serviced.
*/
int
{
int onintr = 0;
/* Are we an interrupt thread */
return (1);
/* Are we servicing a high level interrupt? */
if (CPU_ON_INTR(CPU)) {
}
return (onintr);
}
/*
* Change the dispatch priority of a thread in the system.
* Used when raising or lowering a thread's priority.
* (E.g., priority inheritance)
*
* Since threads are queued according to their priority, we
* we must check the thread's state to determine whether it
* is on a queue somewhere. If it is, we've got to:
*
* o Dequeue the thread.
* o Change its effective priority.
* o Enqueue the thread.
*
* Assumptions: The thread whose priority we wish to change
* must be locked before we call thread_change_(e)pri().
* The thread_change(e)pri() function doesn't drop the thread
* lock--that must be done by its caller.
*/
void
{
ASSERT(THREAD_LOCK_HELD(t));
/*
* If the inherited priority hasn't actually changed,
* just return.
*/
return;
/*
* If it's not on a queue, change the priority with impunity.
*/
if (t == cp->cpu_dispthread)
}
/*
* Take the thread out of its sleep queue.
* Change the inherited priority.
* Re-enqueue the thread.
* Each synchronization object exports a function
* to do this in an appropriate manner.
*/
/*
* Re-enqueue a thread on the wait queue if its
* effective priority needs to change.
*/
waitq_change_pri(t, disp_pri);
} else {
/*
* The thread is on a run queue.
* Note: setbackdq() may not put the thread
* back on the same run queue where it originally
* resided.
*/
(void) dispdeq(t);
setbackdq(t);
}
}
/*
* Function: Change the t_pri field of a thread.
* Side Effects: Adjust the thread ordering on a run queue
* or sleep queue, if necessary.
* Returns: 1 if the thread was on a run queue, else 0.
*/
int
{
int on_rq = 0;
ASSERT(THREAD_LOCK_HELD(t));
/*
* If it's not on a queue, change the priority with impunity.
*/
if (t == cp->cpu_dispthread)
}
/*
* If the priority has changed, take the thread out of
* its sleep queue and change the priority.
* Re-enqueue the thread.
* Each synchronization object exports a function
* to do this in an appropriate manner.
*/
/*
* Re-enqueue a thread on the wait queue if its
* priority needs to change.
*/
waitq_change_pri(t, disp_pri);
} else {
/*
* The thread is on a run queue.
* Note: setbackdq() may not put the thread
* back on the same run queue where it originally
* resided.
*
* We still requeue the thread even if the priority
* is unchanged to preserve round-robin (and other)
* effects between threads of the same priority.
*/
if (front) {
setfrontdq(t);
} else {
setbackdq(t);
}
}
return (on_rq);
}
/*
* Tunable kmem_stackinfo is set, fill the kernel thread stack with a
* specific pattern.
*/
static void
{
/*
* Stack grows up or down, see thread_create(),
* compute stack memory area start and end (start < end).
*/
/* stack grows down */
} else {
/* stack grows up */
}
/*
* Stackinfo pattern size is 8 bytes. Ensure proper 8 bytes
* alignement for start and end in stack area boundaries
*/
}
/* negative or stack size > 1 meg, assume bogus */
return;
}
/* fill stack area with a pattern (instead of zeros) */
*ptr++ = KMEM_STKINFO_PATTERN;
}
}
/*
* Tunable kmem_stackinfo is set, create stackinfo log if doesn't already exist,
* compute the percentage of kernel stack really used, and set in the log
* if it's the latest highest percentage.
*/
static void
{
uint_t i;
/* create the stackinfo log, if doesn't already exist */
if (kmem_stkinfo_log == NULL) {
(sizeof (kmem_stkinfo_t)), KM_NOSLEEP);
if (kmem_stkinfo_log == NULL) {
return;
}
}
/*
* Stack grows up or down, see thread_create(),
* compute stack memory area start and end (start < end).
*/
/* stack grows down */
} else {
/* stack grows up */
}
/* stack size as found in kthread_t */
/*
* Stackinfo pattern size is 8 bytes. Ensure proper 8 bytes
* alignement for start and end in stack area boundaries
*/
}
/* negative or stack size > 1 meg, assume bogus */
return;
}
/* search until no pattern in the stack */
/* stack grows down */
/*
* 6 longs are pushed on stack, see thread_load(). Skip
* them, so if kthread has never run, percent is zero.
* 8 bytes alignement is preserved for a 32 bit kernel,
* 6 x 4 = 24, 24 is a multiple of 8.
*
*/
end -= (6 * sizeof (long));
#endif
if (*ptr != KMEM_STKINFO_PATTERN) {
break;
}
ptr++;
}
} else {
/* stack grows up */
ptr--;
if (*ptr != KMEM_STKINFO_PATTERN) {
break;
}
ptr--;
}
}
if (percent == 0) {
return;
}
/*
* The log is full and already contains the highest values
*/
return;
}
/* keep a log of the highest used stack */
for (i = 0; i < KMEM_STKINFO_LOG_SIZE; i++) {
if (kmem_stkinfo_log[i].percent == 0) {
index = i;
full++;
break;
}
if (smallest == 0) {
index = i;
continue;
}
index = i;
}
}
if (t->t_tid != 0) {
if (stksz >= KMEM_STKINFO_STR_SIZE) {
} else {
stksz += 1;
}
}
if (percent < smallest_percent) {
}
}
}
/*
* Tunable kmem_stackinfo is set, compute stack utilization percentage.
*/
static size_t
{
size_t s;
/* stack grows down */
return (0);
}
return (100);
}
} else {
/* stack grows up */
return (0);
}
return (100);
}
}
if (percent > 100) {
percent = 100;
}
return (percent);
}