fss.c revision 8c34bbb743f69040b9eb165ea639dddb7bb91f37
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <sys/priocntl.h>
#include <sys/schedctl.h>
#include <sys/fsspriocntl.h>
#include <vm/seg_kmem.h>
#include <sys/tnf_probe.h>
/*
* FSS Data Structures:
*
* fsszone
* ----- -----
* ----- | | | |
* | |-------->| |<------->| |<---->...
* | | ----- -----
* | | ^ ^ ^
* | |--- | \ \
* ----- | | \ \
* fsspset | | \ \
* | | \ \
* | ----- ----- -----
* -->| |<--->| |<--->| |
* | | | | | |
* ----- ----- -----
* fssproj
*
*
* That is, fsspsets contain a list of fsszone's that are currently active in
* the pset, and a list of fssproj's, corresponding to projects with runnable
* threads on the pset. fssproj's in turn point to the fsszone which they
* are a member of.
*
* An fssproj_t is removed when there are no threads in it.
*
* An fsszone_t is removed when there are no projects with threads in it.
*
* Projects in a zone compete with each other for cpu time, receiving cpu
* allocation within a zone proportional to fssproj->fssp_shares
* (project.cpu-shares); at a higher level zones compete with each other,
* receiving allocation in a pset proportional to fsszone->fssz_shares
* (zone.cpu-shares). See fss_decay_usage() for the precise formula.
*/
"FSS",
0
};
extern struct mod_ops mod_schedops;
/*
* Module linkage information for the kernel.
*/
};
static struct modlinkage modlinkage = {
};
#define FSS_MAXUPRI 60
/*
* The fssproc_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 in. Each list has a dummy "head" which is never
* removed, so the list is never empty. fss_update traverses these lists to
* update the priorities of threads that have been waiting on the run queue.
*/
#define FSS_LIST_INSERT(fssproc) \
{ \
mutex_enter(lockp); \
mutex_exit(lockp); \
}
#define FSS_LIST_DELETE(fssproc) \
{ \
mutex_enter(lockp); \
mutex_exit(lockp); \
}
/*
* Decay rate percentages are based on n/128 rather than n/100 so that
* calculations can avoid having to do an integer divide by 100 (divide
* by FSS_DECAY_BASE == 128 optimizes to an arithmetic shift).
*
* FSS_DECAY_MIN = 83/128 ~= 65%
* FSS_DECAY_MAX = 108/128 ~= 85%
* FSS_DECAY_USG = 96/128 ~= 75%
*/
#define FSS_NICE_MIN 0
static int fss_nice_tick[FSS_NICE_RANGE];
static int fss_nice_decay[FSS_NICE_RANGE];
static int fss_quantum = 11;
static void fss_newpri(fssproc_t *);
static void fss_update(void *);
static int fss_update_list(int);
static int fss_getclinfo(void *);
static int fss_parmsin(void *);
static int fss_parmsout(void *, pc_vaparms_t *);
static int fss_vaparmsin(void *, pc_vaparms_t *);
static int fss_vaparmsout(void *, pc_vaparms_t *);
static int fss_getclpri(pcpri_t *);
static int fss_alloc(void **, int);
static void fss_free(void *);
static void fss_exitclass(void *);
static void fss_parmsget(kthread_t *, void *);
static void fss_active(kthread_t *);
static void fss_inactive(kthread_t *);
static void fss_trapret(kthread_t *);
static void fss_preempt(kthread_t *);
static void fss_setrun(kthread_t *);
static void fss_wakeup(kthread_t *);
static void fss_nullsys();
static struct classfuncs fss_classfuncs = {
/* class functions */
/* thread functions */
fss_nullsys, /* set_process_group */
};
int
_init()
{
return (mod_install(&modlinkage));
}
int
_fini()
{
return (EBUSY);
}
int
{
}
/*ARGSUSED*/
static int
{
return (0);
}
void *
{
void **fsslist;
int cnt;
int i;
switch (op) {
case FSS_NPSET_BUF:
break;
case FSS_NPROJ_BUF:
break;
case FSS_ONE_BUF:
cnt = 1;
break;
}
switch (type) {
case FSS_ALLOC_PROJ:
break;
case FSS_ALLOC_ZONE:
break;
}
for (i = 0; i < cnt; i++)
return (fssbuf);
}
void
{
void **fsslist;
int i;
switch (type) {
case FSS_ALLOC_PROJ:
break;
case FSS_ALLOC_ZONE:
break;
}
}
}
static fsspset_t *
{
int i;
int found = 0;
/*
* Search for the cpupart pointer in the array of fsspsets.
*/
for (i = 0; i < max_ncpus; i++) {
found = 1;
break;
}
}
if (found == 0) {
/*
* If we didn't find anything, then use the first
* available slot in the fsspsets array.
*/
for (i = 0; i < max_ncpus; i++) {
found = 1;
break;
}
}
}
return (fsspset);
}
static void
{
fsspset->fssps_maxfsspri = 0;
fsspset->fssps_shares = 0;
}
/*
* The following routine returns a pointer to the fsszone structure which
* belongs to zone "zone" and cpu partition fsspset, if such structure exists.
*/
static fsszone_t *
{
/*
* already. Try to find our zone among them.
*/
do {
return (fsszone);
}
}
return (NULL);
}
/*
* The following routine links new fsszone structure into doubly linked list of
* zones active on the specified cpu partition.
*/
static void
{
/*
* This will be the first fsszone for this fsspset
*/
} else {
/*
* Insert this fsszone to the doubly linked list.
*/
}
}
/*
* The following routine removes a single fsszone structure from the doubly
* linked list of zones active on the specified cpu partition. Note that
* global fsspsets_lock must be held in case this fsszone structure is the last
* on the above mentioned list. Also note that the fsszone structure is not
* freed here, it is the responsibility of the caller to call kmem_free for it.
*/
static void
{
/*
* This is not the last zone in the list.
*/
} else {
/*
* This was the last zone active in this cpu partition.
*/
}
}
/*
* The following routine returns a pointer to the fssproj structure
* which belongs to project kpj and cpu partition fsspset, if such structure
* exists.
*/
static fssproj_t *
{
/*
* There are projects running on this cpu partition already.
* Try to find our project among them.
*/
do {
return (fssproj);
}
}
return (NULL);
}
/*
* The following routine links new fssproj structure into doubly linked list
* of projects running on the specified cpu partition.
*/
static void
{
fsspset->fssps_nproj++;
/*
* This will be the first fssproj for this fsspset
*/
} else {
/*
* Insert this fssproj to the doubly linked list.
*/
}
fsszone->fssz_nproj++;
}
/*
* The following routine removes a single fssproj structure from the doubly
* linked list of projects running on the specified cpu partition. Note that
* global fsspsets_lock must be held in case if this fssproj structure is the
* last on the above mentioned list. Also note that the fssproj structure is
* not freed here, it is the responsibility of the caller to call kmem_free
* for it.
*/
static void
{
fsspset->fssps_nproj--;
fsszone->fssz_nproj--;
/*
* This is not the last part in the list.
*/
if (fsszone->fssz_nproj == 0)
} else {
/*
* This was the last project part running
* at this cpu partition.
*/
}
}
static void
{
ASSERT(THREAD_LOCK_HELD(t));
return;
if (--fssproj->fssp_runnable == 0) {
if (--fsszone->fssz_runnable == 0)
}
fssproc->fss_runnable = 0;
}
static void
fss_active(kthread_t *t)
{
ASSERT(THREAD_LOCK_HELD(t));
return;
}
}
/*
* Fair share scheduler initialization. Called by dispinit() at boot time.
* We can ignore clparmsz argument since we know that the smallest possible
* parameter buffer is big enough for us.
*/
/*ARGSUSED*/
static pri_t
{
int i;
fss_minglobpri = 0;
/*
* Initialize the fssproc hash table.
*/
for (i = 0; i < FSS_LISTS; i++)
&fss_listhead[i];
*clfuncspp = &fss_classfuncs;
/*
* Fill in fss_nice_tick and fss_nice_decay arrays:
* The cost of a tick is lower at positive nice values (so that it
* will not increase its project's usage as much as normal) with 50%
* drop at the maximum level and 50% increase at the minimum level.
* The fsspri decay is slower at positive nice values. fsspri values
* of processes with negative nice levels must decay faster to receive
* time slices more frequently than normal.
*/
for (i = 0; i < FSS_NICE_RANGE; i++) {
- i)) / FSS_NICE_RANGE;
fss_nice_decay[i] = FSS_DECAY_MIN +
((FSS_DECAY_MAX - FSS_DECAY_MIN) * i) /
(FSS_NICE_RANGE - 1);
}
return (fss_maxglobpri);
}
/*
* Calculate the new cpupri based on the usage, the number of shares and
* the number of active threads. Reset the tick counter for this thread.
*/
static void
{
return;
/*
* No need to change priority of exited threads.
*/
return;
/*
* Special case: threads with no shares.
*/
return;
}
/*
* fsspri += shusage * nrunnable * ticks
*/
if (fsspri < fss_maxumdpri)
/*
* The general priority formula:
*
* (fsspri * umdprirange)
* pri = maxumdpri - ------------------------
* maxfsspri
*
* If this thread's fsspri is greater than the previous largest
* fsspri, then record it as the new high and priority for this
* thread will be one (the lowest priority assigned to a thread
* that has non-zero shares).
* Note that this formula cannot produce out of bounds priority
* values; if it is changed, additional checks may need to be
* added.
*/
} else {
}
}
/*
* Decays usages of all running projects and resets their tick counters.
* Called once per second from fss_update() after updating priorities.
*/
static void
{
int psetid;
/*
* Go through all active processor sets and decay usages of projects
* running on them.
*/
continue;
}
/*
* Decay maxfsspri for this cpu partition with the
* fastest possible decay rate.
*/
if (maxfsspri < fss_maxumdpri)
do {
/*
* Decay usage for each project running on
* this cpu partition.
*/
fssproj->fssp_ticks = 0;
/*
* Readjust the project's number of shares if it has
* changed since we checked it last time.
*/
if (fssproj->fssp_runnable != 0) {
fsszone->fssz_shares -=
}
}
/*
* Readjust the zone's number of shares if it
* has changed since we checked it last time.
*/
if (fsszone->fssz_runnable != 0) {
fsspset->fssps_shares -=
fsspset->fssps_shares +=
}
}
/*
* Calculate fssp_shusage value to be used
* for fsspri increments for the next second.
*/
if (kpj_shares == 0 || zone_ext_shares == 0) {
fssproj->fssp_shusage = 0;
/*
* Project 0 in the global zone has 50%
* of its zone.
*/
} else {
/*
* Thread's priority is based on its project's
* normalized usage (shusage) value which gets
* calculated this way:
*
* pset_shares^2 zone_int_shares^2
* usage * ------------- * ------------------
* kpj_shares^2 zone_ext_shares^2
*
* Where zone_int_shares is the sum of shares
* of all active projects within the zone (and
* the pset), and zone_ext_shares is the number
* of zone shares (ie, zone.cpu-shares).
*
* If there is only one zone active on the pset
* the above reduces to:
*
* zone_int_shares^2
* shusage = usage * ---------------------
* kpj_shares^2
*
* If there's only one project active in the
* zone this formula reduces to:
*
* pset_shares^2
* shusage = usage * ----------------------
* zone_ext_shares^2
*/
fssproj->fssp_shusage /=
fssproj->fssp_shusage *=
fssproj->fssp_shusage /=
}
}
}
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 {
}
} else {
/*
* 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)) {
/*
* The thread was on a run queue.
*/
} else {
}
}
}
/*
* Update priorities of all fair-sharing threads that are currently runnable
* at a user mode priority based on the number of shares and current usage.
* Called once per second via timeout which we reset here.
*
* There are several lists of fair-sharing threads broken up by a hash on the
* thread pointer. Each list has its own lock. This avoids blocking all
* fss_enterclass, fss_fork, and fss_exitclass operations while fss_update runs.
* fss_update traverses each list in turn.
*/
static void
fss_update(void *arg)
{
int i;
int new_marker = -1;
static int fss_update_marker;
/*
* Decay and update usages for all projects.
*/
/*
* Start with the fss_update_marker list, then do the rest.
*/
i = fss_update_marker;
/*
* Go around all threads, set new priorities and decay
* per-thread CPU usages.
*/
do {
/*
* If this is the first list after the current marker to have
* threads with priorities updates, advance the marker to this
* list for the next time fss_update runs.
*/
if (fss_update_list(i) &&
new_marker = i;
} while ((i = FSS_LIST_NEXT(i)) != fss_update_marker);
/*
* Advance marker for the next fss_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 FSS class, is not runnable, has the preemption
* control no-preempt bit set, etc.)
*/
static int
fss_update_list(int i)
{
kthread_t *t;
int updated = 0;
mutex_enter(&fss_listlock[i]);
/*
* Lock the thread and verify the state.
*/
thread_lock(t);
/*
* Skip the thread if it is no longer in the FSS class or
* is running with kernel mode priority.
*/
goto next;
goto next;
goto next;
if (fssproj->fssp_shares != 0) {
/*
* Decay fsspri value.
*/
}
if (t->t_schedctl && schedctl_get_nopreempt(t))
goto next;
/*
*/
t->t_trapret = 1;
aston(t);
goto next;
}
updated = 1;
/*
* Only dequeue the thread if it needs to be moved; otherwise
* it should just round-robin here.
*/
next:
thread_unlock(t);
}
mutex_exit(&fss_listlock[i]);
return (updated);
}
/*ARGSUSED*/
static int
{
return (EFAULT);
case FSS_SETADMIN:
if (secpolicy_dispadm(reqpcredp) != 0)
return (EPERM);
return (EINVAL);
break;
case FSS_GETADMIN:
return (EFAULT);
break;
default:
return (EINVAL);
}
return (0);
}
static int
fss_getclinfo(void *infop)
{
return (0);
}
static int
fss_parmsin(void *parmsp)
{
/*
* Check validity of parameters.
*/
return (EINVAL);
return (EINVAL);
return (0);
}
/*ARGSUSED*/
static int
{
return (0);
}
static int
{
int priflag = 0;
int limflag = 0;
/*
* FSS_NOCHANGE (-32768) is outside of the range of values for
* fss_uprilim and fss_upri. If the structure fssparms_t is changed,
* FSS_NOCHANGE should be replaced by a flag word.
*/
/*
* Get the varargs parameter and check validity of parameters.
*/
return (EINVAL);
case FSS_KY_UPRILIM:
if (limflag++)
return (EINVAL);
return (EINVAL);
break;
case FSS_KY_UPRI:
if (priflag++)
return (EINVAL);
return (EINVAL);
break;
default:
return (EINVAL);
}
}
if (vaparmsp->pc_vaparmscnt == 0) {
/*
* Use default parameters.
*/
}
return (0);
}
/*
* Copy all selected fair-sharing class parameters to the user. The parameters
* are specified by a key.
*/
static int
{
int priflag = 0;
int limflag = 0;
return (EINVAL);
case FSS_KY_UPRILIM:
if (limflag++)
return (EINVAL);
return (EFAULT);
break;
case FSS_KY_UPRI:
if (priflag++)
return (EINVAL);
return (EFAULT);
break;
default:
return (EINVAL);
}
}
return (0);
}
static int
{
return (0);
}
static int
{
void *bufp;
return (ENOMEM);
} else {
*p = bufp;
return (0);
}
}
static void
{
if (bufp)
}
/*
* Thread functions
*/
static int
void *bufp)
{
int fsszone_allocated = 0;
/*
* Only root can move threads to FSS class.
*/
return (EPERM);
/*
* Initialize the fssproc structure.
*/
/*
* Use default values.
*/
} else {
/*
* Use supplied values.
*/
reqfssuprilim = 0;
} else {
if (fssparmsp->fss_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 (reqfssupri > reqfssuprilim)
}
}
/*
* Put a lock on our fsspset structure.
*/
== NULL) {
return (ENOMEM);
} else {
fsszone_allocated = 1;
}
}
== NULL) {
if (fsszone_allocated) {
}
return (ENOMEM);
} else {
}
}
fssproj->fssp_threads++;
/*
* 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);
t->t_schedflag |= TS_RUNQMATCH;
fss_active(t);
thread_unlock(t);
/*
* Link new structure into fssproc list.
*/
/*
* If this is the first fair-sharing thread to occur since boot,
* we set up the initial call to fss_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);
}
/*
* Remove fssproc_t from the list.
*/
static void
fss_exitclass(void *procp)
{
/*
* We should be either getting this thread off the deathrow or
* this thread has already moved to another scheduling class and
* we're being called with its old cldata buffer pointer. In both
* cases, the content of this buffer can not be changed while we're
* here.
*/
thread_lock(t);
/*
* We're being called as a result of the priocntl() system
* call -- someone is trying to move our thread to another
* scheduling class. We can't call fss_inactive() here
* because our thread's t_cldata pointer already points
* to another scheduling class specific data.
*/
if (fssproc->fss_runnable) {
if (--fssproj->fssp_runnable == 0) {
if (--fsszone->fssz_runnable == 0)
fsspset->fssps_shares -=
}
}
thread_unlock(t);
if (--fssproj->fssp_threads == 0) {
if (fsszone->fssz_nproj == 0)
}
} else {
/*
* We're being called from thread_free() when our thread
* is removed from the deathrow. There is nothing we need
* do here since everything should've been done earlier
* in fss_exit().
*/
thread_unlock(t);
}
}
/*ARGSUSED*/
static int
{
/*
* A thread is allowed to exit FSS only if we have sufficient
* privileges.
*/
return (EPERM);
else
return (0);
}
/*
* Initialize fair-share class specific proc structure for a child.
*/
static int
{
/*
* Initialize child's fssproc structure.
*/
cfssproc->fss_fsspri = 0;
fssproj->fssp_threads++;
/*
* Link new structure into fssproc hash table.
*/
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);
/*
* We don't want to call fss_setrun(t) here because it may call
* fss_active, which we don't need.
*/
if (t->t_disp_time != lbolt)
setbackdq(t);
else
setfrontdq(t);
thread_unlock(t);
swtch();
}
/*
* Get the fair-sharing parameters of the thread pointed to by fssprocp into
* the buffer pointed by fssparmsp.
*/
static void
{
}
/*ARGSUSED*/
static int
{
char nice;
else
else
/*
* Make sure the user priority doesn't exceed the upri limit.
*/
if (reqfssupri > reqfssuprilim)
/*
* 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 fair-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 fss_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.
*/
if (nice > FSS_NICE_MAX)
nice = FSS_NICE_MAX;
thread_lock(t);
thread_unlock(t);
return (0);
}
thread_unlock(t);
return (0);
}
/*
* The thread is being stopped.
*/
/*ARGSUSED*/
static void
{
ASSERT(THREAD_LOCK_HELD(t));
fss_inactive(t);
}
/*
* The current thread is exiting, do necessary adjustments to its project
*/
static void
{
int free = 0;
/*
* Thread t here is either a current thread (in which case we hold
* its process' p_lock), or a thread being destroyed by forklwp_fail(),
* in which case we hold pidlock and thread is no longer on the
* thread list.
*/
thread_lock(t);
if (--fssproj->fssp_runnable == 0) {
if (--fsszone->fssz_runnable == 0)
}
fssproc->fss_runnable = 0;
}
if (--fssproj->fssp_threads == 0) {
free = 1;
}
thread_unlock(t);
if (free) {
if (fsszone->fssz_nproj == 0)
}
/*
* A thread could be exiting in between clock ticks, so we need to
* calculate how much CPU time it used since it was charged last time.
*
* CPU caps are not enforced on exiting processes - it is usually
* desirable to exit as soon as possible to free resources.
*/
if (CPUCAPS_ON()) {
thread_lock(t);
thread_unlock(t);
}
}
static void
{
}
/*
* fss_swapin() returns -1 if the thread is loaded or is not eligible to be
* swapped in. Otherwise, it returns the thread's effective priority based
* on swapout time and size of process (0 <= epri <= 0 SHRT_MAX).
*/
/*ARGSUSED*/
static pri_t
{
long epri = -1;
ASSERT(THREAD_LOCK_HELD(t));
} 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 that SHRT_MAX / 2 represents zero priority.
*/
if (epri < 0)
epri = 0;
}
}
/*
* fss_swapout() returns -1 if the thread isn't loaded or is not eligible to
* be swapped out. Otherwise, it returns the thread's effective priority
* based on if the swapper is in softswap or hardswap mode.
*/
static pri_t
{
long epri = -1;
ASSERT(THREAD_LOCK_HELD(t));
if (INHERITED(t) ||
(t->t_proc_flag & TP_LWPEXIT) ||
!(t->t_schedflag & TS_LOAD) ||
!(SWAP_OK(t)))
return (-1);
epri = 0;
} else {
}
} else {
pri = fss_maxumdpri;
epri = swapin_time -
} else {
}
}
/*
* Scale epri so that SHRT_MAX / 2 represents zero priority.
*/
if (epri < 0)
epri = 0;
}
/*
* If thread is currently at a kernel mode priority (has slept) and is
* returning to the userland we assign it the appropriate user mode priority
* and time quantum here. If we're lowering the thread's priority below that
* of other runnable threads then we will set runrun via cpu_surrender() to
* cause preemption.
*/
static void
fss_trapret(kthread_t *t)
{
ASSERT(THREAD_LOCK_HELD(t));
t->t_kpri_req = 0;
/*
* If thread has blocked in the kernel
*/
if (DISP_MUST_SURRENDER(t))
cpu_surrender(t);
}
/*
* Swapout lwp if the swapper is waiting for this thread to reach
* a safe point.
*/
if (t->t_schedflag & TS_SWAPENQ) {
thread_unlock(t);
swapout_lwp(ttolwp(t));
thread_lock(t);
}
}
/*
* 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
fss_preempt(kthread_t *t)
{
/*
* If preempted in the kernel, make sure the thread has a kernel
* priority if needed.
*/
aston(t);
}
/*
* This thread may be placed on wait queue by CPU Caps. In this case we
* do not need to do anything until it is removed from the wait queue.
* Do not enforce CPU caps on threads running at a kernel priority
*/
if (CPUCAPS_ON()) {
return;
}
/*
* If preempted in user-land mark the thread as swappable because it
* cannot be holding any kernel 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 FSS 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 fss_yield().
*/
}
t->t_schedflag |= TS_DONT_SWAP;
}
schedctl_set_yield(t, 1);
setfrontdq(t);
return;
} else {
}
schedctl_set_nopreempt(t, 0);
/*
* Fall through and be preempted below.
*/
}
}
setbackdq(t);
setbackdq(t);
} else {
setfrontdq(t);
}
}
/*
* Called when a thread is waking up and is to be placed on the run queue.
*/
static void
fss_setrun(kthread_t *t)
{
fss_active(t);
/*
* If previously were running at the kernel priority then keep that
* priority and the fss_timeleft doesn't matter.
*/
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
{
ASSERT(THREAD_LOCK_HELD(t));
/*
* Account for time spent on CPU before going to sleep.
*/
fss_inactive(t);
/*
* Assign a system priority to the thread and arrange for it to be
* retained when the thread is next placed on the run queue (i.e.,
* when it wakes up) instead of being given a new pri. Also arrange
* for trapret processing as the thread leaves the system call so it
* will drop back to normal priority range.
*/
if (t->t_kpri_req) {
aston(t);
/*
* The thread has done a THREAD_KPRI_REQUEST(), slept, then
* done THREAD_KPRI_RELEASE() (so no t_kpri_req is 0 again),
* then slept again all without finishing the current system
* call so trapret won't have cleared FSSKPRI
*/
if (DISP_MUST_SURRENDER(curthread))
cpu_surrender(t);
}
}
/*
* A tick interrupt has ocurrend on a running thread. Check to see if our
* time slice has expired. We must also clear the TS_DONT_SWAP flag in
* t_schedflag if the thread is eligible to be swapped out.
*/
static void
{
/*
* It's safe to access fsspset and fssproj structures because we're
* holding our p_lock here.
*/
thread_lock(t);
}
/*
* Keep track of thread's project CPU usage. Note that projects
* get charged even when threads are running in the kernel.
* Do not surrender CPU if running in the SYS class.
*/
if (CPUCAPS_ON()) {
}
/*
* A thread's execution time for threads running in the SYS class
* is not tracked.
*/
/*
* If thread is not in kernel mode, decrement its fss_timeleft
*/
if (--fssproc->fss_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;
}
}
/*
* 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;
} else {
}
/*
* If there is a higher-priority thread which is
* waiting for a processor, then thread surrenders
* the processor.
*/
}
}
/*
* The thread used more than half of its quantum, so assume that
* it used the whole quantum.
*
* Update thread's priority just before putting it on the wait
* queue so that it gets charged for the CPU time from its
* quantum even before that quantum expires.
*/
/*
* We need to call cpu_surrender for this thread due to cpucaps
* enforcement, but fss_change_priority may have already done
* so. In this case FSSBACKQ is set and there is no need to call
* cpu-surrender again.
*/
}
if (call_cpu_surrender) {
cpu_surrender(t);
}
thread_unlock_nopreempt(t); /* clock thread can't be preempted */
}
/*
* 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 fss_trapret before the
* thread returns to user mode.
*/
static void
fss_wakeup(kthread_t *t)
{
ASSERT(THREAD_LOCK_HELD(t));
fss_active(t);
/*
* If we already have a kernel priority assigned, then we
* just use it.
*/
setbackdq(t);
} else if (t->t_kpri_req) {
/*
* Give thread a priority boost if we were asked.
*/
setbackdq(t);
aston(t);
} else {
/*
* Otherwise, we recalculate the priority.
*/
if (t->t_disp_time == lbolt) {
setfrontdq(t);
} else {
setbackdq(t);
}
}
}
/*
* fss_donice() is called when a nice(1) command is issued on the thread to
* alter the priority. The nice(1) command exists in Solaris for compatibility.
* Thread priority adjustments should be done via priocntl(1).
*/
static int
{
int newnice;
/*
* If there is no change to priority, just return current setting.
*/
if (incr == 0) {
if (retvalp)
return (0);
}
return (EPERM);
/*
* Specifying a nice increment greater than the upper limit of
* FSS_NICE_MAX (== 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 user specified some ridiculous increment.
*/
if (incr > FSS_NICE_MAX)
incr = FSS_NICE_MAX;
if (newnice > FSS_NICE_MAX)
else if (newnice < FSS_NICE_MIN)
/*
* Reset the uprilim and upri values of the thread.
*/
/*
* Although fss_parmsset already reset fss_nice it may not have been
* set to precisely the value calculated above because fss_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 fss_nice to the value we calculated
* above.
*/
if (retvalp)
return (0);
}
/*
* Return the global scheduling priority that would be assigned to a thread
* entering the fair-sharing class with the fss_upri.
*/
/*ARGSUSED*/
static pri_t
fss_globpri(kthread_t *t)
{
return (fss_maxumdpri / 2);
}
/*
* Called from the yield(2) system call when a thread is yielding (surrendering)
* the processor. The kernel thread is placed at the back of a dispatch queue.
*/
static void
{
ASSERT(THREAD_LOCK_HELD(t));
/*
* Collect CPU usage spent before yielding
*/
/*
* Clear the preemption control "yield" bit since the user is
* doing a yield.
*/
if (t->t_schedctl)
schedctl_set_yield(t, 0);
/*
* If fss_preempt() artifically increased the thread's priority
* to avoid preemption, restore the original priority now.
*/
}
if (fssproc->fss_timeleft < 0) {
/*
* Time slice was artificially extended to avoid preemption,
* so pretend we're preempting it now.
*/
}
setbackdq(t);
}
void
{
int free = 0;
int id;
return;
if (fssproj_old == NULL) {
return;
}
return;
}
/*
* If the zone for the new project is not currently active on
* the cpu partition we're on, get one of the pre-allocated
* buffers and link it in our per-pset zone list. Such buffers
* should already exist.
*/
break;
}
}
}
/*
* If our new project is not currently running
* on the cpu partition we're on, get one of the
* pre-allocated buffers and link it in our new cpu
* partition doubly linked list. Such buffers should already
* exist.
*/
break;
}
}
}
thread_lock(t);
fss_inactive(t);
if (--fssproj_old->fssp_threads == 0) {
free = 1;
}
fssproc->fss_fsspri = 0;
fss_active(t);
thread_unlock(t);
if (free) {
if (fsszone_old->fssz_nproj == 0)
}
}
void
{
int id;
return;
if (fssproj_old == NULL) {
return;
}
return;
}
break;
}
}
}
break;
}
}
}
thread_lock(t);
fss_inactive(t);
fssproc->fss_fsspri = 0;
fss_active(t);
thread_unlock(t);
if (--fssproj_old->fssp_threads == 0) {
if (fsszone_old->fssz_nproj == 0)
}
}