FreeBSD/sys/kern/sched_4bsd.c
/*
 * We adjust the priority of the current process.  The priority of a
 * process gets worse as it accumulates CPU time.  The cpu usage
 * estimator (ts_estcpu) is increased here.  resetpriority() will
 * compute a different priority each time ts_estcpu increases by
 * INVERSE_ESTCPU_WEIGHT (until PRI_MAX_TIMESHARE is reached).  The
 * cpu usage estimator ramps up quite quickly when the process is
 * running (linearly), and decays away exponentially, at a rate which
 * is proportionally slower when the system is busy.  The basic
 * principle is that the system will 90% forget that the process used
 * a lot of CPU time in 5 * loadav seconds.  This causes the system to
 * favor processes which haven't run much recently, and to round-robin
 * among other processes.
 */
We adjust the priority of the current process.  The priority of a
process gets worse as it accumulates CPU time.  The cpu usage
estimator (ts_estcpu) is increased here.  resetpriority() will
compute a different priority each time ts_estcpu increases by
INVERSE_ESTCPU_WEIGHT (until PRI_MAX_TIMESHARE is reached).  The
cpu usage estimator ramps up quite quickly when the process is
running (linearly), and decays away exponentially, at a rate which
is proportionally slower when the system is busy.  The basic
principle is that the system will 90% forget that the process used
a lot of CPU time in 5 * loadav seconds.  This causes the system to
favor processes which haven't run much recently, and to round-robin
among other processes.
We adjust the priority of the current process . The priority of a process gets worse as it accumulates CPU time . The cpu usage estimator ( ts_estcpu ) is increased here . resetpriority () will compute a different priority each time ts_estcpu increases by INVERSE_ESTCPU_WEIGHT ( until PRI_MAX_TIMESHARE is reached ) . The cpu usage estimator ramps up quite quickly when the process is running ( linearly ) and decays away exponentially at a rate which is proportionally slower when the system is busy . The basic principle is that the system will 90% forget that the process used a lot of CPU time in 5 * loadav seconds . This causes the system to favor processes which haven ' t run much recently and to round - robin among other processes .
void
sched_clock(struct thread *td)
{
	struct pcpuidlestat *stat;
	struct td_sched *ts;
	THREAD_LOCK_ASSERT(td, MA_OWNED);
	ts = td_get_sched(td);
	ts->ts_cpticks++;
	ts->ts_estcpu = ESTCPULIM(ts->ts_estcpu + 1);
	if ((ts->ts_estcpu % INVERSE_ESTCPU_WEIGHT) == 0) {
		resetpriority(td);
		resetpriority_thread(td);
	}
	if (!TD_IS_IDLETHREAD(td) && --ts->ts_slice <= 0) {
		ts->ts_slice = sched_slice;
		td->td_flags |= TDF_NEEDRESCHED | TDF_SLICEEND;
	}
	stat = DPCPU_PTR(idlestat);
	stat->oldidlecalls = stat->idlecalls;
	stat->idlecalls = 0;
}
void sched_clock ( struct thread * td ) { struct pcpuidlestat * stat ; struct td_sched * ts ; THREAD_LOCK_ASSERT ( td , MA_OWNED ) ; ts = td_get_sched ( td ) ; ts -> ts_cpticks ++ ; ts -> ts_estcpu = ESTCPULIM ( ts -> ts_estcpu + 1 ) ; if ( ( ts -> ts_estcpu % INVERSE_ESTCPU_WEIGHT ) == 0 ) { resetpriority ( td ) ; resetpriority_thread ( td ) ; } if ( ! TD_IS_IDLETHREAD ( td ) && -- ts -> ts_slice <= 0 ) { ts -> ts_slice = sched_slice ; td -> td_flags |= TDF_NEEDRESCHED | TDF_SLICEEND ; } stat = DPCPU_PTR ( idlestat ) ; stat -> oldidlecalls = stat -> idlecalls ; stat -> idlecalls = 0 ; }
We adjust the priority of the current process.
We adjust the priority of the current process .
/*
	 * Force a context switch if the current thread has used up a full
	 * time slice (default is 100ms).
	 */