SCHEDULER(9)

NAME
scheduler, resetpriority, roundrobin, rqinit, schedclock, schedcpu, setrunnable, updatepri - thread scheduling sub-system

SYNOPSIS
#include <sys/sched.h>
#include <sys/lwp.h>
#include <sys/proc.h>
void
resetpriority(struct lwp *l);
void
roundrobin(struct cpu_info *ci);
void
schedclock(struct lwp *l);
void
schedcpu(void *arg);
void
setrunnable(struct lwp *l);
void
updatepri(struct lwp *l);

DESCRIPTION

The NetBSD thread scheduling sub-system employs a “multilevel feedback queues” algorithm, favouring interactive, short-runnig threads to CPU-bound ones.

resetpriority() recomputes the priority of a thread running in user mode. If the resulting priority is higher than that of the current thread, a reschedule is arranged.

roundrobin() gets called from hardclock(9) every 100ms to force a switch between equal priority threads.

The runqueues are initialized through rqinit(), called from init_main() at system startup.

The priority of the current thread is adjusted through schedclock(). The priority of a thread gets worse as it accumulates CPU time.

The schedcpu() function recomputes the priorities of all threads every Hz ticks.

The setrunnable() function changes a thread's state to be runnable. If the thread is in memory, it is placed on the proper runqueue, according to its priority. Otherwise the swapper is awaked.

The updatepri() function recalculates the priority of a thread after it has been sleeping.

CODE REFERENCES
This section describes places within the NetBSD source tree where actual code implementing the scheduler can be found. All pathnames are relative to /usr/src.

The scheduler subsystem is implemented within the file sys/kern/kern_synch.c.

SEE ALSO
SCHED_LOCK(9), hardclock(9), mi_switch(9), setrunqueue(9), userret(9)