ts.c revision 9ac8606f19e304e832a685ae7060cc3c284b9779
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.23 */
#include <sys/sysmacros.h>
#include <sys/priocntl.h>
#include <sys/tspriocntl.h>
#include <sys/iapriocntl.h>
#include <sys/schedctl.h>
#include <sys/tnf_probe.h>
#include <vm/seg_kmem.h>
"TS",
0
};
};
static struct modlinkage modlinkage = {
};
int
_init()
{
return (mod_install(&modlinkage));
}
int
_fini()
{
return (EBUSY); /* don't remove TS for now */
}
int
{
}
/*
* Class specific code for the time-sharing class
*/
/*
* Extern declarations for variables defined in the ts master file
*/
#define TSMAXUPRI 60
/* sleeping or running in kernel after sleep */
int ts_sleep_promote = 1;
#define TS_NEWUMDPRI(tspp) \
{ \
if (pri > ts_maxumdpri) \
else if (pri < 0) \
else \
}
/*
* The tsproc_t structures are kept in an array of circular doubly linked
* lists. A hash on the thread pointer is used to determine which list
* each thread should be placed. Each list has a dummy "head" which is
* never removed, so the list is never empty. ts_update traverses these
* lists to update the priorities of threads that have been waiting on
* the run queue.
*/
/* hash function, argument is a thread pointer */
/* iterate to the next list */
/*
* Insert thread into the appropriate tsproc list.
*/
#define TS_LIST_INSERT(tspp) \
{ \
mutex_enter(lockp); \
mutex_exit(lockp); \
}
/*
* Remove thread from tsproc list.
*/
#define TS_LIST_DELETE(tspp) \
{ \
mutex_enter(lockp); \
mutex_exit(lockp); \
}
static int ts_getclinfo(void *);
static int ts_getclpri(pcpri_t *);
static int ts_parmsin(void *);
static int ts_parmsout(void *, pc_vaparms_t *);
static int ts_vaparmsin(void *, pc_vaparms_t *);
static int ts_vaparmsout(void *, pc_vaparms_t *);
static void ts_exitclass(void *);
static void ts_nullsys();
static void ts_parmsget(kthread_t *, void *);
static void ts_preempt(kthread_t *);
static void ts_trapret(kthread_t *);
static void ts_update(void *);
static int ts_update_list(int);
extern tsdpent_t *ts_getdptbl(void);
extern pri_t *ts_getkmdpris(void);
extern pri_t td_getmaxumdpri(void);
static int ts_alloc(void **, int);
static void ts_free(void *);
static int ia_getclinfo(void *);
static int ia_parmsin(void *);
static int ia_vaparmsin(void *, pc_vaparms_t *);
static int ia_vaparmsout(void *, pc_vaparms_t *);
static void ia_parmsget(kthread_t *, void *);
static struct classfuncs ts_classfuncs = {
/* class functions */
/* thread functions */
ts_nullsys, /* stop */
ts_nullsys, /* exit */
ts_nullsys, /* active */
ts_nullsys, /* inactive */
ts_nullsys, /* set_process_group */
};
/*
* ia_classfuncs is used for interactive class threads; IA threads are stored
* on the same class list as TS threads, and most of the class functions are
* identical, but a few have different enough functionality to require their
* own functions.
*/
static struct classfuncs ia_classfuncs = {
/* class functions */
/* thread functions */
ts_nullsys, /* stop */
ts_nullsys, /* exit */
ts_nullsys, /* active */
ts_nullsys, /* inactive */
};
/*
* Time sharing class initialization. Called by dispinit() at boot time.
* We can ignore the clparmsz argument since we know that the smallest
* possible parameter buffer is big enough for us.
*/
/* ARGSUSED */
static pri_t
{
int i;
extern pri_t ts_getmaxumdpri(void);
ts_dptbl = ts_getdptbl();
ts_kmdpris = ts_getkmdpris();
/*
* Initialize the tsproc lists.
*/
for (i = 0; i < TS_LISTS; i++) {
&ts_plisthead[i];
}
/*
* We're required to return a pointer to our classfuncs
* structure and the highest global priority value we use.
*/
*clfuncspp = &ts_classfuncs;
return (ts_maxglobpri);
}
/*
* Interactive class scheduler initialization
*/
/* ARGSUSED */
{
/*
* We're required to return a pointer to our classfuncs
* structure and the highest global priority value we use.
*/
*clfuncspp = &ia_classfuncs;
return (ts_maxglobpri);
}
/*
* Get or reset the ts_dptbl values per the user's request.
*/
static int
{
int userdpsz;
int i;
if (get_udatamodel() == DATAMODEL_NATIVE) {
return (EFAULT);
}
#ifdef _SYSCALL32_IMPL
else {
/* get tsadmin struct from ILP32 caller */
return (EFAULT);
}
#endif /* _SYSCALL32_IMPL */
case TS_GETDPSIZE:
if (get_udatamodel() == DATAMODEL_NATIVE) {
return (EFAULT);
}
#ifdef _SYSCALL32_IMPL
else {
/* return tsadmin struct to ILP32 caller */
return (EFAULT);
}
#endif /* _SYSCALL32_IMPL */
break;
case TS_GETDPTBL:
tsdpsz);
return (EFAULT);
if (get_udatamodel() == DATAMODEL_NATIVE) {
return (EFAULT);
}
#ifdef _SYSCALL32_IMPL
else {
/* return tsadmin struct to ILP32 callers */
return (EFAULT);
}
#endif /* _SYSCALL32_IMPL */
break;
case TS_SETDPTBL:
/*
* We require that the requesting process has sufficient
* priveleges. We also require that the table supplied by
* the user exactly match the current ts_dptbl in size.
*/
if (secpolicy_dispadm(reqpcredp) != 0)
return (EPERM);
return (EINVAL);
}
/*
* We read the user supplied table into a temporary buffer
* where it is validated before being copied over the
* ts_dptbl.
*/
tsdpsz)) {
return (EFAULT);
}
for (i = 0; i < tsadmin.ts_ndpents; i++) {
/*
* Validate the user supplied values. All we are doing
* here is verifying that the values are within their
* allowable ranges and will not panic the system. We
* make no attempt to ensure that the resulting
* configuration makes sense or results in reasonable
* performance.
*/
if (tmpdpp[i].ts_quantum <= 0) {
return (EINVAL);
}
return (EINVAL);
}
return (EINVAL);
}
if (tmpdpp[i].ts_maxwait < 0) {
return (EINVAL);
}
return (EINVAL);
}
}
/*
* Copy the user supplied values over the current ts_dptbl
* values. The ts_globpri member is read-only so we don't
* overwrite it.
*/
for (i = 0; i < tsadmin.ts_ndpents; i++) {
}
break;
default:
return (EINVAL);
}
return (0);
}
/*
* Allocate a time-sharing class specific thread structure and
* initialize it with the parameters supplied. Also move the thread
* to specified time-sharing priority.
*/
static int
{
/* a time-sharing process */
/*
* Initialize the tsproc structure.
*/
/*
* Check to make sure caller is either privileged or the
* window system. When the window system is converted
* to using privileges, the second check can go away.
*/
secpolicy_setpriority(reqpcredp) != 0)
return (EPERM);
/*
* Belongs to IA "class", so set appropriate flags.
* Mark as 'on' so it will not be a swap victim
* while forking.
*/
} else {
}
/*
* Use default values.
*/
} else {
/*
* Use supplied values.
*/
reqtsuprilim = 0;
else {
if (tsparmsp->ts_uprilim > 0 &&
secpolicy_setpriority(reqpcredp) != 0)
return (EPERM);
}
} else {
secpolicy_setpriority(reqpcredp) != 0)
return (EPERM);
/*
* Set the user priority to the requested value
* or the upri limit, whichever is lower.
*/
if (reqtsupri > reqtsuprilim)
}
/ ts_maxupri;
}
tspp->ts_dispwait = 0;
/*
* Reset priority. Process goes to a "user mode" priority
* here regardless of whether or not it has slept since
* entering the kernel.
*/
thread_lock(t); /* get dispatcher lock on thread */
t->t_schedflag &= ~TS_RUNQMATCH;
ts_change_priority(t, tspp);
thread_unlock(t);
/*
* Link new structure into tsproc list.
*/
/*
* If this is the first time-sharing thread to occur since
* boot we set up the initial call to ts_update() here.
* Use an atomic compare-and-swap since that's easier and
* faster than a mutex (but check with an ordinary load first
* since most of the time this will already be done).
*/
return (0);
}
/*
* Free tsproc structure of thread.
*/
static void
ts_exitclass(void *procp)
{
/* Remove tsproc_t structure from list */
}
/* ARGSUSED */
static int
{
/*
*/
return (0);
}
static int
{
/*
* Initialize child's tsproc structure.
*/
thread_lock(t);
ctspp->ts_dispwait = 0;
thread_unlock(t);
/*
* Link new structure into tsproc list.
*/
return (0);
}
/*
* Child is placed at back of dispatcher queue and parent gives
* up processor so that the child runs first after the fork.
* This allows the child immediately execing to break the multiple
* use of copy on write pages with no disk home. The parent will
* get to steal them back rather than uselessly copying them.
*/
static void
{
/*
* Grab the child's p_lock before dropping pidlock to ensure
* the process does not disappear before we set it running.
*/
thread_lock(t);
tspp->ts_dispwait = 0;
ts_setrun(t);
thread_unlock(t);
swtch();
}
/*
* Get information about the time-sharing class into the buffer
* pointed to by tsinfop. The maximum configured user priority
* is the only information we supply. ts_getclinfo() is called
* for TS threads, and ia_getclinfo() is called for IA threads.
*/
static int
ts_getclinfo(void *infop)
{
return (0);
}
static int
ia_getclinfo(void *infop)
{
return (0);
}
/*
* Return the global scheduling priority ranges for the timesharing
* class in pcpri_t structure.
*/
static int
{
return (0);
}
static void
{}
/*
* Get the time-sharing parameters of the thread pointed to by
* tsprocp into the buffer pointed to by tsparmsp. ts_parmsget()
* is called for TS threads, and ia_parmsget() is called for IA
* threads.
*/
static void
{
}
static void
{
else
}
/*
* Check the validity of the time-sharing parameters in the buffer
* pointed to by tsparmsp.
* ts_parmsin() is called for TS threads, and ia_parmsin() is called
* for IA threads.
*/
static int
ts_parmsin(void *parmsp)
{
/*
* Check validity of parameters.
*/
return (EINVAL);
return (EINVAL);
return (0);
}
static int
ia_parmsin(void *parmsp)
{
return (EINVAL);
}
return (EINVAL);
}
return (0);
}
/*
* Check the validity of the time-sharing parameters in the pc_vaparms_t
* structure vaparmsp and put them in the buffer pointed to by tsparmsp.
* pc_vaparms_t contains (key, value) pairs of parameter.
* ts_vaparmsin() is called for TS threads, and ia_vaparmsin() is called
* for IA threads. ts_vaparmsin() is the variable parameter version of
* ts_parmsin() and ia_vaparmsin() is the variable parameter version of
* ia_parmsin().
*/
static int
{
int priflag = 0;
int limflag = 0;
/*
* TS_NOCHANGE (-32768) is outside of the range of values for
* ts_uprilim and ts_upri. If the structure tsparms_t is changed,
* TS_NOCHANGE should be replaced by a flag word (in the same manner
* as in rt.c).
*/
/*
* Get the varargs parameter and check validity of parameters.
*/
return (EINVAL);
case TS_KY_UPRILIM:
if (limflag++)
return (EINVAL);
return (EINVAL);
break;
case TS_KY_UPRI:
if (priflag++)
return (EINVAL);
return (EINVAL);
break;
default:
return (EINVAL);
}
}
if (vaparmsp->pc_vaparmscnt == 0) {
/*
* Use default parameters.
*/
}
return (0);
}
static int
{
int priflag = 0;
int limflag = 0;
int mflag = 0;
/*
* IA_NOCHANGE (-32768) is outside of the range of values for
* ia_uprilim, ia_upri and ia_mode. If the structure iaparms_t is
* changed, IA_NOCHANGE should be replaced by a flag word (in the
* same manner as in rt.c).
*/
/*
* Get the varargs parameter and check validity of parameters.
*/
return (EINVAL);
case IA_KY_UPRILIM:
if (limflag++)
return (EINVAL);
return (EINVAL);
break;
case IA_KY_UPRI:
if (priflag++)
return (EINVAL);
return (EINVAL);
break;
case IA_KY_MODE:
if (mflag++)
return (EINVAL);
return (EINVAL);
break;
default:
return (EINVAL);
}
}
if (vaparmsp->pc_vaparmscnt == 0) {
/*
* Use default parameters.
*/
}
return (0);
}
/*
* Nothing to do here but return success.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* Copy all selected time-sharing class parameters to the user.
* The parameters are specified by a key.
*/
static int
{
int priflag = 0;
int limflag = 0;
return (EINVAL);
case TS_KY_UPRILIM:
if (limflag++)
return (EINVAL);
return (EFAULT);
break;
case TS_KY_UPRI:
if (priflag++)
return (EINVAL);
return (EFAULT);
break;
default:
return (EINVAL);
}
}
return (0);
}
/*
* Copy all selected interactive class parameters to the user.
* The parameters are specified by a key.
*/
static int
{
int priflag = 0;
int limflag = 0;
int mflag = 0;
return (EINVAL);
case IA_KY_UPRILIM:
if (limflag++)
return (EINVAL);
return (EFAULT);
break;
case IA_KY_UPRI:
if (priflag++)
return (EINVAL);
return (EFAULT);
break;
case IA_KY_MODE:
if (mflag++)
return (EINVAL);
return (EFAULT);
break;
default:
return (EINVAL);
}
}
return (0);
}
/*
* Set the scheduling parameters of the thread pointed to by tsprocp
* to those specified in the buffer pointed to by tsparmsp.
* ts_parmsset() is called for TS threads, and ia_parmsset() is
* called for IA threads.
*/
/* ARGSUSED */
static int
{
char nice;
else
else
/*
* Make sure the user priority doesn't exceed the upri limit.
*/
if (reqtsupri > reqtsuprilim)
/*
* Basic permissions enforced by generic kernel code
* for all classes require that a thread attempting
* to change the scheduling parameters of a target
* thread be privileged or have a real or effective
* UID matching that of the target thread. We are not
* called unless these basic permission checks have
* already passed. The time-sharing class requires in
* addition that the calling thread be privileged if it
* is attempting to raise the upri limit above its current
* value This may have been checked previously but if our
* caller passed us a non-NULL credential pointer we assume
* it hasn't and we check it here.
*/
secpolicy_setpriority(reqpcredp) != 0)
return (EPERM);
/*
* Set ts_nice to the nice value corresponding to the user
* priority we are setting. Note that setting the nice field
* of the parameter struct won't affect upri or nice.
*/
return (0);
}
tspp->ts_dispwait = 0;
return (0);
}
static int
{
proc_t *p;
int sess_held;
/*
* Handle user priority changes
*/
/*
* Check permissions for changing modes.
*/
secpolicy_setpriority(reqpcredp) != 0) {
/*
* Silently fail in case this is just a priocntl
* call with upri and uprilim set to IA_NOCHANGE.
*/
return (0);
}
return (0);
}
return (0);
}
/*
* session leaders must be turned on now so all processes
* in the group controlling the tty will be turned on or off.
* if the ia_mode is off for the session leader,
* ia_set_process_group will return without setting the
* processes in the group controlling the tty on.
*/
}
sess_held = 1;
sess_held = 0;
off = 0;
} else {
on = 0;
}
"active chain:pid %d gid %d %p",
}
}
if (sess_held)
} else {
}
}
/*
* Return the global scheduling priority that would be assigned
* to a thread entering the time-sharing class with the ts_upri.
*/
static pri_t
ts_globpri(kthread_t *t)
{
if (tspri > ts_maxumdpri)
else if (tspri < 0)
tspri = 0;
}
/*
* Arrange for thread to be placed in appropriate location
* on dispatcher queue.
*
* This is called with the current thread in TS_ONPROC and locked.
*/
static void
ts_preempt(kthread_t *t)
{
#ifdef KSLICE
extern int kslice;
#endif
/*
* If preempted in the kernel, make sure the thread has
* a kernel priority if needed.
*/
THREAD_CHANGE_PRI(t, ts_kmdpris[0]);
aston(t);
}
/*
* If preempted in user-land mark the thread
* as swappable because I know it isn't holding any locks.
*/
t->t_schedflag &= ~TS_DONT_SWAP;
/*
* Check to see if we're doing "preemption control" here. If
* we are, and if the user has requested that this thread not
* be preempted, and if preemptions haven't been put off for
* too long, let the preemption happen here but try to make
* sure the thread is rescheduled as soon as possible. We do
* this by putting it on the front of the highest priority run
* queue in the TS class. If the preemption has been put off
* for too long, clear the "nopreempt" bit and let the thread
* be preempted.
*/
if (t->t_schedctl && schedctl_get_nopreempt(t)) {
/*
* If not already remembered, remember current
* priority for restoration in ts_yield().
*/
}
t->t_schedflag |= TS_DONT_SWAP;
}
schedctl_set_yield(t, 1);
setfrontdq(t);
goto done;
} else {
}
schedctl_set_nopreempt(t, 0);
/*
* Fall through and be preempted below.
*/
}
}
tspp->ts_dispwait = 0;
setbackdq(t);
setbackdq(t);
} else {
#ifdef KSLICE
if (kslice)
setbackdq(t);
else
#endif
setfrontdq(t);
}
done:
"preempt:tid %p old pri %d", t, oldpri);
}
static void
{
tspp->ts_dispwait = 0;
}
}
setfrontdq(t);
else
setbackdq(t);
} else {
if (t->t_disp_time != lbolt)
setbackdq(t);
else
setfrontdq(t);
}
}
/*
* Prepare thread for sleep. We reset the thread priority so it will
* run at the kernel priority level when it wakes up.
*/
static void
{
int flags;
ASSERT(THREAD_LOCK_HELD(t));
if (t->t_kpri_req) {
THREAD_CHANGE_PRI(t, ts_kmdpris[0]);
aston(t);
/*
* If thread has blocked in the kernel (as opposed to
* being merely preempted), recompute the user mode priority.
*/
tspp->ts_dispwait = 0;
if (DISP_MUST_SURRENDER(curthread))
if (DISP_MUST_SURRENDER(curthread))
}
"sleep:tid %p old pri %d", t, old_pri);
}
/*
* Return Values:
*
* -1 if the thread is loaded or is not eligible to be swapped in.
*
* effective priority of the specified thread based on swapout time
* and size of process (epri >= 0 , epri <= SHRT_MAX).
*/
/* ARGSUSED */
static pri_t
{
long epri = -1;
ASSERT(THREAD_LOCK_HELD(t));
/*
* We know that pri_t is a short.
* Be sure not to overrun its range.
*/
else {
/*
* Threads which have been out for a long time,
* have high user mode priority and are associated
* with a small address space are more deserving
*/
}
/*
* Scale epri so SHRT_MAX/2 represents zero priority.
*/
if (epri < 0)
epri = 0;
}
}
/*
* Return Values
* -1 if the thread isn't loaded or is not eligible to be swapped out.
*
* effective priority of the specified thread based on if the swapper
* is in softswap or hardswap mode.
*
* Softswap: Return a low effective priority for threads
* sleeping for more than maxslp secs.
*
* Hardswap: Return an effective priority such that threads
* which have been in memory for a while and are
* associated with a small address space are swapped
* in before others.
*
* (epri >= 0 , epri <= SHRT_MAX).
*/
static pri_t
{
long epri = -1;
ASSERT(THREAD_LOCK_HELD(t));
(t->t_proc_flag & TP_LWPEXIT) ||
return (-1);
/*
* We know that pri_t is a short.
* Be sure not to overrun its range.
*/
epri = 0;
} else {
}
} else {
epri = swapin_time -
} else {
}
}
/*
* Scale epri so SHRT_MAX/2 represents zero priority.
*/
if (epri < 0)
epri = 0;
}
/*
* Check for time slice expiration. If time slice has expired
* move thread to priority specified in tsdptbl for time slice expiration
* and set runrun to cause preemption.
*/
static void
{
thread_lock(t);
if (--tspp->ts_timeleft <= 0) {
/*
* If we're doing preemption control and trying to
* avoid preempting this thread, just note that
* the thread should yield soon and let it keep
* running (unless it's been a while).
*/
if (t->t_schedctl && schedctl_get_nopreempt(t)) {
kthread_t *, t);
schedctl_set_yield(t, 1);
return;
}
"schedctl TS ts_tick", /* CSTYLED */,
}
tspp->ts_dispwait = 0;
/*
* When the priority of a thread is changed,
* it may be necessary to adjust its position
* on a sleep queue or dispatch queue.
* The function thread_change_pri accomplishes
* this.
*/
if (thread_change_pri(t, new_pri, 0)) {
if ((t->t_schedflag & TS_LOAD) &&
t->t_schedflag &= ~TS_DONT_SWAP;
tspp->ts_timeleft =
} else {
cpu_surrender(t);
}
"tick:tid %p old pri %d", t, oldpri);
cpu_surrender(t);
}
}
thread_unlock_nopreempt(t); /* clock thread can't be preempted */
}
/*
* If thread is currently at a kernel mode priority (has slept)
* we assign it the appropriate user mode priority and time quantum
* here. If we are lowering the thread's priority below that of
* other runnable threads we will normally set runrun via cpu_surrender() to
* cause preemption.
*/
static void
ts_trapret(kthread_t *t)
{
ASSERT(THREAD_LOCK_HELD(t));
t->t_kpri_req = 0;
tspp->ts_dispwait = 0;
/*
* If thread has blocked in the kernel (as opposed to
* being merely preempted), recompute the user mode priority.
*/
if (DISP_MUST_SURRENDER(t))
cpu_surrender(t);
/*
* If thread has blocked in the kernel (as opposed to
* being merely preempted), recompute the user mode priority.
*/
if (DISP_MUST_SURRENDER(t))
cpu_surrender(t);
}
/*
* Swapout lwp if the swapper is waiting for this thread to
* reach a safe point.
*/
thread_unlock(t);
swapout_lwp(ttolwp(t));
thread_lock(t);
}
"trapret:tid %p old pri %d", t, old_pri);
}
/*
* Update the ts_dispwait values of all time sharing threads that
* are currently runnable at a user mode priority and bump the priority
* if ts_dispwait exceeds ts_maxwait. Called once per second via
* timeout which we reset here.
*
* There are several lists of time sharing threads broken up by a hash on
* the thread pointer. Each list has its own lock. This avoids blocking
* all ts_enterclass, ts_fork, and ts_exitclass operations while ts_update
* runs. ts_update traverses each list in turn.
*
* If multiple threads have their priorities updated to the same value,
* the system implicitly favors the one that is updated first (since it
* winds up first on the run queue). To avoid this unfairness, the
* traversal of threads starts at the list indicated by a marker. When
* threads in more than one list have their priorities updated, the marker
* is moved. This changes the order the threads will be placed on the run
* queue the next time ts_update is called and preserves fairness over the
* long run. The marker doesn't need to be protected by a lock since it's
* only accessed by ts_update, which is inherently single-threaded (only
* one instance can be running at a time).
*/
static void
{
int i;
int new_marker = -1;
static int ts_update_marker;
/*
* Start with the ts_update_marker list, then do the rest.
*/
i = ts_update_marker;
do {
/*
* If this is the first list after the current marker to
* have threads with priorities updated, advance the marker
* to this list for the next time ts_update runs.
*/
i != ts_update_marker) {
new_marker = i;
}
} while ((i = TS_LIST_NEXT(i)) != ts_update_marker);
/* advance marker for next ts_update call */
if (new_marker != -1)
}
/*
* Updates priority for a list of threads. Returns 1 if the priority of
* one of the threads was actually updated, 0 if none were for various
* reasons (thread is no longer in the TS or IA class, isn't runnable,
* hasn't waited long enough, has the preemption control no-preempt bit
* set, etc.)
*/
static int
ts_update_list(int i)
{
int updated = 0;
mutex_enter(&ts_list_lock[i]);
/*
* Lock the thread and verify state.
*/
/*
* Skip the thread if it is no longer in the TS (or IA) class.
*/
goto next;
tspp->ts_dispwait++;
goto next;
goto next;
goto next;
!ts_sleep_promote)) {
goto next;
}
tspp->ts_dispwait = 0;
updated = 1;
/*
* Only dequeue it if needs to move; otherwise it should
* just round-robin here.
*/
}
next:
}
mutex_exit(&ts_list_lock[i]);
return (updated);
}
/*
* Processes waking up go to the back of their queue. We don't
* need to assign a time quantum here because thread is still
* at a kernel mode priority and the time slicing is not done
* for threads running in the kernel after sleeping. The proper
* time quantum will be assigned by ts_trapret before the thread
* returns to user mode.
*/
static void
{
ASSERT(THREAD_LOCK_HELD(t));
setfrontdq(t);
else
setbackdq(t);
} else if (t->t_kpri_req) {
/*
* Give thread a priority boost if we were asked.
*/
THREAD_CHANGE_PRI(t, ts_kmdpris[0]);
setbackdq(t);
aston(t);
} else {
tspp->ts_timeleft =
tspp->ts_dispwait = 0;
}
setfrontdq(t);
else
setbackdq(t);
} else {
if (t->t_disp_time != lbolt)
setbackdq(t);
else
setfrontdq(t);
}
}
}
/*
* When a thread yields, put it on the back of the run queue.
*/
static void
{
ASSERT(THREAD_LOCK_HELD(t));
/*
* Clear the preemption control "yield" bit since the user is
* doing a yield.
*/
if (t->t_schedctl)
schedctl_set_yield(t, 0);
/*
* If ts_preempt() artifically increased the thread's priority
* to avoid preemption, restore the original priority now.
*/
}
if (tspp->ts_timeleft <= 0) {
/*
* Time slice was artificially extended to avoid
* preemption, so pretend we're preempting it now.
*/
tspp->ts_dispwait = 0;
}
setbackdq(t);
}
/*
* Increment the nice value of the specified thread by incr and
* return the new value in *retvalp.
*/
static int
{
int newnice;
/* If there's no change to priority, just return current setting */
if (incr == 0) {
if (retvalp) {
}
return (0);
}
secpolicy_setpriority(cr) != 0)
return (EPERM);
/*
* Specifying a nice increment greater than the upper limit of
* 2 * NZERO - 1 will result in the thread's nice value being
* set to the upper limit. We check for this before computing
* the new value because otherwise we could get overflow
* if a privileged process specified some ridiculous increment.
*/
else if (newnice < 0)
newnice = 0;
/*
* Reset the uprilim and upri values of the thread.
* Call ts_parmsset even if thread is interactive since we're
* not changing mode.
*/
/*
* Although ts_parmsset already reset ts_nice it may
* not have been set to precisely the value calculated above
* because ts_parmsset determines the nice value from the
* user priority and we may have truncated during the integer
* conversion from nice value to user priority and back.
* We reset ts_nice to the value we calculated above.
*/
if (retvalp)
return (0);
}
/*
* ia_set_process_group marks foreground processes as interactive
* and background processes as non-interactive iff the session
* leader is interactive. This routine is called from two places:
* strioctl:SPGRP when a new process group gets
* control of the tty.
* ia_parmsset-when the process in question is a session leader.
* ia_set_process_group assumes that pidlock is held by the caller,
* either strioctl or priocntlsys. If the caller is priocntlsys
* (via ia_parmsset) then the p_lock of the session leader is held
* and the code needs to be careful about acquiring other p_locks.
*/
static void
{
int plocked = 0;
/*
* see if the session leader is interactive AND
* if it is currently "on" AND controlling a tty
* iff it is then make the processes in the foreground
* group interactive and the processes in the background
* group non-interactive.
*/
return;
}
return;
}
return;
}
/*
* XXX do all the threads in the leader
*/
return;
}
/*
* session leaders that are not interactive need not have
* any processing done for them. They are typically shells
* that do not have focus and are changing the process group
* attatched to the tty, e.g. a process that is exiting
*/
return;
}
/*
* If we're already holding the leader's p_lock, we should use
* mutex_tryenter instead of mutex_enter to avoid deadlocks from
* lock ordering violations.
*/
plocked = 1;
if (fg_pgid == 0)
goto skip;
/*
* now look for all processes in the foreground group and
* make them interactive
*/
/*
* if the process is SIDL it's begin forked, ignore it
*/
continue;
}
/*
* not implicitly as happens to other members of
* the process group.
*/
continue;
}
"group on:proc %p", fg);
if (plocked) {
continue;
} else {
}
continue;
}
do {
/*
* if this thread is not interactive continue
*/
continue;
}
continue;
}
tspp->ts_dispwait = 0;
}
skip:
if (bg_pgid == 0)
return;
continue;
}
/*
* sesssion leaders must be turned off explicitly
* not implicitly as happens to other members of
* the process group.
*/
continue;
}
"group off:proc %p", bg);
if (plocked) {
continue;
} else {
}
continue;
}
do {
/*
* if this thread is not interactive continue
*/
continue;
}
continue;
}
tspp->ts_dispwait = 0;
}
}
static void
{
ASSERT(THREAD_LOCK_HELD(t));
/* curthread is always onproc */
THREAD_CHANGE_PRI(t, new_pri);
if (t == cp->cpu_dispthread)
if (DISP_MUST_SURRENDER(t)) {
cpu_surrender(t);
} else {
tspp->ts_timeleft =
}
} else {
int frontq;
/*
* When the priority of a thread is changed,
* it may be necessary to adjust its position
* on a sleep queue or dispatch queue.
* The function thread_change_pri accomplishes
* this.
*/
/*
* The thread was on a run queue. Reset
* its CPU timeleft from the quantum
* associated with the new priority.
*/
tspp->ts_timeleft =
} else {
}
}
}
static int
{
void *bufp;
return (ENOMEM);
} else {
*p = bufp;
return (0);
}
}
static void
{
if (bufp)
}