FreeBSD/sys/kern/sched_ule.c
/*
 * Scale the scheduling priority according to the "interactivity" of this
 * process.
 */
Scale the scheduling priority according to the "interactivity" of this
process.
Scale the scheduling priority according to the " interactivity " of this process .
static void
sched_priority(struct thread *td)
{
	int score;
	int pri;
	if (PRI_BASE(td->td_pri_class) != PRI_TIMESHARE)
		return;
	score = imax(0, sched_interact_score(td) + td->td_proc->p_nice);
	if (score < sched_interact) {
		pri = PRI_MIN_INTERACT;
		pri += ((PRI_MAX_INTERACT - PRI_MIN_INTERACT + 1) /
		    sched_interact) * score;
		KASSERT(pri >= PRI_MIN_INTERACT && pri <= PRI_MAX_INTERACT,
		    ("sched_priority: invalid interactive priority %d score %d",
		    pri, score));
	} else {
		pri = SCHED_PRI_MIN;
		if (td_get_sched(td)->ts_ticks)
			pri += min(SCHED_PRI_TICKS(td_get_sched(td)),
			    SCHED_PRI_RANGE - 1);
		pri += SCHED_PRI_NICE(td->td_proc->p_nice);
		KASSERT(pri >= PRI_MIN_BATCH && pri <= PRI_MAX_BATCH,
		    ("sched_priority: invalid priority %d: nice %d, " 
		    "ticks %d ftick %d ltick %d tick pri %d",
		    pri, td->td_proc->p_nice, td_get_sched(td)->ts_ticks,
		    td_get_sched(td)->ts_ftick, td_get_sched(td)->ts_ltick,
		    SCHED_PRI_TICKS(td_get_sched(td))));
	}
	sched_user_prio(td, pri);
	return;
}
static void sched_priority ( struct thread * td ) { int score ; int pri ; if ( PRI_BASE ( td -> td_pri_class ) != PRI_TIMESHARE ) return ; score = imax ( 0 , sched_interact_score ( td ) + td -> td_proc -> p_nice ) ; if ( score < sched_interact ) { pri = PRI_MIN_INTERACT ; pri += ( ( PRI_MAX_INTERACT - PRI_MIN_INTERACT + 1 ) / sched_interact ) * score ; KASSERT ( pri >= PRI_MIN_INTERACT && pri <= PRI_MAX_INTERACT , ( " " , pri , score ) ) ; } else { pri = SCHED_PRI_MIN ; if ( td_get_sched ( td ) -> ts_ticks ) pri += min ( SCHED_PRI_TICKS ( td_get_sched ( td ) ) , SCHED_PRI_RANGE - 1 ) ; pri += SCHED_PRI_NICE ( td -> td_proc -> p_nice ) ; KASSERT ( pri >= PRI_MIN_BATCH && pri <= PRI_MAX_BATCH , ( " " " " , pri , td -> td_proc -> p_nice , td_get_sched ( td ) -> ts_ticks , td_get_sched ( td ) -> ts_ftick , td_get_sched ( td ) -> ts_ltick , SCHED_PRI_TICKS ( td_get_sched ( td ) ) ) ) ; } sched_user_prio ( td , pri ) ; return ; }
Scale the scheduling priority according to the "interactivity" of this
 process.
Scale the scheduling priority according to the " interactivity " of this process .
/*
	 * If the score is interactive we place the thread in the realtime
	 * queue with a priority that is less than kernel and interrupt
	 * priorities.  These threads are not subject to nice restrictions.
	 *
	 * Scores greater than this are placed on the normal timeshare queue
	 * where the priority is partially decided by the most recent cpu
	 * utilization and the rest is decided by nice value.
	 *
	 * The nice value of the process has a linear effect on the calculated
	 * score.  Negative nice values make it easier for a thread to be
	 * considered interactive.
	 */