FreeBSD/sys/kern/sched_4bsd.c
/*
 * Select threads to run.  Note that running threads still consume a
 * slot.
 */
Select threads to run.  Note that running threads still consume a
slot.
Select threads to run . Note that running threads still consume a slot .
struct thread *
sched_choose(void)
{
	struct thread *td;
	struct runq *rq;
	mtx_assert(&sched_lock,  MA_OWNED);
#ifdef SMP
	struct thread *tdcpu;
	rq = &runq;
	td = runq_choose_fuzz(&runq, runq_fuzz);
	tdcpu = runq_choose(&runq_pcpu[PCPU_GET(cpuid)]);
	if (td == NULL ||
	    (tdcpu != NULL &&
	     tdcpu->td_priority < td->td_priority)) {
		CTR2(KTR_RUNQ, "choosing td %p from pcpu runq %d", tdcpu,
		     PCPU_GET(cpuid));
		td = tdcpu;
		rq = &runq_pcpu[PCPU_GET(cpuid)];
	} else {
		CTR1(KTR_RUNQ, "choosing td_sched %p from main runq", td);
	}
#else
	rq = &runq;
	td = runq_choose(&runq);
#endif
	if (td) {
#ifdef SMP
		if (td == tdcpu)
			runq_length[PCPU_GET(cpuid)]--;
#endif
		runq_remove(rq, td);
		td->td_flags |= TDF_DIDRUN;
		KASSERT(td->td_flags & TDF_INMEM,
		    ("sched_choose: thread swapped out"));
		return (td);
	}
	return (PCPU_GET(idlethread));
}
struct thread * sched_choose ( void ) { struct thread * td ; struct runq * rq ; mtx_assert ( & sched_lock , MA_OWNED ) ; #ifdef SMP struct thread * tdcpu ; rq = & runq ; td = runq_choose_fuzz ( & runq , runq_fuzz ) ; tdcpu = runq_choose ( & runq_pcpu [ PCPU_GET ( cpuid ) ] ) ; if ( td == NULL || ( tdcpu != NULL && tdcpu -> td_priority < td -> td_priority ) ) { CTR2 ( KTR_RUNQ , " " , tdcpu , PCPU_GET ( cpuid ) ) ; td = tdcpu ; rq = & runq_pcpu [ PCPU_GET ( cpuid ) ] ; } else { CTR1 ( KTR_RUNQ , " " , td ) ; } #else rq = & runq ; td = runq_choose ( & runq ) ; #endif if ( td ) { #ifdef SMP if ( td == tdcpu ) runq_length [ PCPU_GET ( cpuid ) ] -- ; #endif runq_remove ( rq , td ) ; td -> td_flags |= TDF_DIDRUN ; KASSERT ( td -> td_flags & TDF_INMEM , ( " " ) ) ; return ( td ) ; } return ( PCPU_GET ( idlethread ) ) ; }
Select threads to run.
Select threads to run .