FreeBSD/sys/kern/sched_ule.c
/*
 * Handle a stathz tick.  This is really only relevant for timeshare
 * threads.
 */
Handle a stathz tick.  This is really only relevant for timeshare
threads.
Handle a stathz tick . This is really only relevant for timeshare threads .
void
sched_clock(struct thread *td)
{
	struct tdq *tdq;
	struct td_sched *ts;
	THREAD_LOCK_ASSERT(td, MA_OWNED);
	tdq = TDQ_SELF();
#ifdef SMP
	if (balance_tdq == tdq) {
		if (balance_ticks && --balance_ticks == 0)
			sched_balance();
	}
#endif
	tdq->tdq_oldswitchcnt = tdq->tdq_switchcnt;
	tdq->tdq_switchcnt = tdq->tdq_load;
	if (tdq->tdq_idx == tdq->tdq_ridx) {
		tdq->tdq_idx = (tdq->tdq_idx + 1) % RQ_NQS;
		if (TAILQ_EMPTY(&tdq->tdq_timeshare.rq_queues[tdq->tdq_ridx]))
			tdq->tdq_ridx = tdq->tdq_idx;
	}
	ts = td_get_sched(td);
	sched_pctcpu_update(ts, 1);
	if (td->td_pri_class & PRI_FIFO_BIT)
		return;
	if (PRI_BASE(td->td_pri_class) == PRI_TIMESHARE) {
		td_get_sched(td)->ts_runtime += tickincr;
		sched_interact_update(td);
		sched_priority(td);
	}
	if (!TD_IS_IDLETHREAD(td) && ++ts->ts_slice >= tdq_slice(tdq)) {
		ts->ts_slice = 0;
		td->td_flags |= TDF_NEEDRESCHED | TDF_SLICEEND;
	}
}
void sched_clock ( struct thread * td ) { struct tdq * tdq ; struct td_sched * ts ; THREAD_LOCK_ASSERT ( td , MA_OWNED ) ; tdq = TDQ_SELF ( ) ; #ifdef SMP if ( balance_tdq == tdq ) { if ( balance_ticks && -- balance_ticks == 0 ) sched_balance ( ) ; } #endif tdq -> tdq_oldswitchcnt = tdq -> tdq_switchcnt ; tdq -> tdq_switchcnt = tdq -> tdq_load ; if ( tdq -> tdq_idx == tdq -> tdq_ridx ) { tdq -> tdq_idx = ( tdq -> tdq_idx + 1 ) % RQ_NQS ; if ( TAILQ_EMPTY ( & tdq -> tdq_timeshare . rq_queues [ tdq -> tdq_ridx ] ) ) tdq -> tdq_ridx = tdq -> tdq_idx ; } ts = td_get_sched ( td ) ; sched_pctcpu_update ( ts , 1 ) ; if ( td -> td_pri_class & PRI_FIFO_BIT ) return ; if ( PRI_BASE ( td -> td_pri_class ) == PRI_TIMESHARE ) { td_get_sched ( td ) -> ts_runtime += tickincr ; sched_interact_update ( td ) ; sched_priority ( td ) ; } if ( ! TD_IS_IDLETHREAD ( td ) && ++ ts -> ts_slice >= tdq_slice ( tdq ) ) { ts -> ts_slice = 0 ; td -> td_flags |= TDF_NEEDRESCHED | TDF_SLICEEND ; } }
Handle a stathz tick.
Handle a stathz tick .
/*
	 * We run the long term load balancer infrequently on the first cpu.
	 */ /*
	 * Save the old switch count so we have a record of the last ticks
	 * activity.   Initialize the new switch count based on our load.
	 * If there is some activity seed it to reflect that.
	 */ /*
	 * Advance the insert index once for each tick to ensure that all
	 * threads get a chance to run.
	 */ /*
		 * We used a tick; charge it to the thread so
		 * that we can compute our interactivity.
		 */ /*
	 * Force a context switch if the current thread has used up a full
	 * time slice (default is 100ms).
	 */