FreeBSD/sys/kern/sched_ule.c
/*
 * This routine enforces a maximum limit on the amount of scheduling history
 * kept.  It is called after either the slptime or runtime is adjusted.  This
 * function is ugly due to integer math.
 */
This routine enforces a maximum limit on the amount of scheduling history
kept.  It is called after either the slptime or runtime is adjusted.  This
function is ugly due to integer math.
This routine enforces a maximum limit on the amount of scheduling history kept . It is called after either the slptime or runtime is adjusted . This function is ugly due to integer math .
static void
sched_interact_update(struct thread *td)
{
	struct td_sched *ts;
	u_int sum;
	ts = td_get_sched(td);
	sum = ts->ts_runtime + ts->ts_slptime;
	if (sum < SCHED_SLP_RUN_MAX)
		return;
	if (sum > SCHED_SLP_RUN_MAX * 2) {
		if (ts->ts_runtime > ts->ts_slptime) {
			ts->ts_runtime = SCHED_SLP_RUN_MAX;
			ts->ts_slptime = 1;
		} else {
			ts->ts_slptime = SCHED_SLP_RUN_MAX;
			ts->ts_runtime = 1;
		}
		return;
	}
	if (sum > (SCHED_SLP_RUN_MAX / 5) * 6) {
		ts->ts_runtime /= 2;
		ts->ts_slptime /= 2;
		return;
	}
	ts->ts_runtime = (ts->ts_runtime / 5) * 4;
	ts->ts_slptime = (ts->ts_slptime / 5) * 4;
}
static void sched_interact_update ( struct thread * td ) { struct td_sched * ts ; u_int sum ; ts = td_get_sched ( td ) ; sum = ts -> ts_runtime + ts -> ts_slptime ; if ( sum < SCHED_SLP_RUN_MAX ) return ; if ( sum > SCHED_SLP_RUN_MAX * 2 ) { if ( ts -> ts_runtime > ts -> ts_slptime ) { ts -> ts_runtime = SCHED_SLP_RUN_MAX ; ts -> ts_slptime = 1 ; } else { ts -> ts_slptime = SCHED_SLP_RUN_MAX ; ts -> ts_runtime = 1 ; } return ; } if ( sum > ( SCHED_SLP_RUN_MAX / 5 ) * 6 ) { ts -> ts_runtime /= 2 ; ts -> ts_slptime /= 2 ; return ; } ts -> ts_runtime = ( ts -> ts_runtime / 5 ) * 4 ; ts -> ts_slptime = ( ts -> ts_slptime / 5 ) * 4 ; }
This routine enforces a maximum limit on the amount of scheduling history
 kept.
This routine enforces a maximum limit on the amount of scheduling history kept .
/*
	 * This only happens from two places:
	 * 1) We have added an unusual amount of run time from fork_exit.
	 * 2) We have added an unusual amount of sleep time from sched_sleep().
	 */ /*
	 * If we have exceeded by more than 1/5th then the algorithm below
	 * will not bring us back into range.  Dividing by two here forces
	 * us into the range of [4/5 * SCHED_INTERACT_MAX, SCHED_INTERACT_MAX]
	 */