FreeBSD/sys/kern/sched_ule.c
/*
 * This is the core of the interactivity algorithm.  Determines a score based
 * on past behavior.  It is the ratio of sleep time to run time scaled to
 * a [0, 100] integer.  This is the voluntary sleep time of a process, which
 * differs from the cpu usage because it does not account for time spent
 * waiting on a run-queue.  Would be prettier if we had floating point.
 *
 * When a thread's sleep time is greater than its run time the
 * calculation is:
 *
 *                           scaling factor 
 * interactivity score =  ---------------------
 *                        sleep time / run time
 *
 *
 * When a thread's run time is greater than its sleep time the
 * calculation is:
 *
 *                           scaling factor 
 * interactivity score =  ---------------------    + scaling factor
 *                        run time / sleep time
 */
This is the core of the interactivity algorithm.  Determines a score based
on past behavior.  It is the ratio of sleep time to run time scaled to
a [0, 100] integer.  This is the voluntary sleep time of a process, which
differs from the cpu usage because it does not account for time spent
waiting on a run-queue.  Would be prettier if we had floating point.

When a thread's sleep time is greater than its run time the
calculation is.

scaling factor
interactivity score
sleep time / run time

When a thread's run time is greater than its sleep time the
calculation is.

scaling factor
interactivity score =      + scaling factor
run time / sleep time
This is the core of the interactivity algorithm . Determines a score based on past behavior . It is the ratio of sleep time to run time scaled to a [ 0 100 ] integer . This is the voluntary sleep time of a process which differs from the cpu usage because it does not account for time spent waiting on a run - queue . Would be prettier if we had floating point . When a thread ' s sleep time is greater than its run time the calculation is . scaling factor interactivity score sleep time / run time When a thread ' s run time is greater than its sleep time the calculation is . scaling factor interactivity score = + scaling factor run time / sleep time
static int
sched_interact_score(struct thread *td)
{
	struct td_sched *ts;
	int div;
	ts = td_get_sched(td);
	if (sched_interact <= SCHED_INTERACT_HALF &&
		ts->ts_runtime >= ts->ts_slptime)
			return (SCHED_INTERACT_HALF);
	if (ts->ts_runtime > ts->ts_slptime) {
		div = max(1, ts->ts_runtime / SCHED_INTERACT_HALF);
		return (SCHED_INTERACT_HALF +
		    (SCHED_INTERACT_HALF - (ts->ts_slptime / div)));
	}
	if (ts->ts_slptime > ts->ts_runtime) {
		div = max(1, ts->ts_slptime / SCHED_INTERACT_HALF);
		return (ts->ts_runtime / div);
	}
	if (ts->ts_runtime)
		return (SCHED_INTERACT_HALF);
	return (0);
}
static int sched_interact_score ( struct thread * td ) { struct td_sched * ts ; int div ; ts = td_get_sched ( td ) ; if ( sched_interact <= SCHED_INTERACT_HALF && ts -> ts_runtime >= ts -> ts_slptime ) return ( SCHED_INTERACT_HALF ) ; if ( ts -> ts_runtime > ts -> ts_slptime ) { div = max ( 1 , ts -> ts_runtime / SCHED_INTERACT_HALF ) ; return ( SCHED_INTERACT_HALF + ( SCHED_INTERACT_HALF - ( ts -> ts_slptime / div ) ) ) ; } if ( ts -> ts_slptime > ts -> ts_runtime ) { div = max ( 1 , ts -> ts_slptime / SCHED_INTERACT_HALF ) ; return ( ts -> ts_runtime / div ) ; } if ( ts -> ts_runtime ) return ( SCHED_INTERACT_HALF ) ; return ( 0 ) ; }
This is the core of the interactivity algorithm.
This is the core of the interactivity algorithm .
/*
	 * The score is only needed if this is likely to be an interactive
	 * task.  Don't go through the expense of computing it if there's
	 * no chance.
	 */ /* runtime == slptime */ /*
	 * This can happen if slptime and runtime are 0.
	 */