Update to describe current API (only), and not duplicate that can be

found elsewhere. (And which will appear in the NetBSD Internals Guide
soonish).

Submitted by Daniel Sieger <dsieger@TechFak.Uni-Bielefeld.DE>,
OK'd by martin@ and  yamt@
This commit is contained in:
hubertf 2006-12-04 15:36:23 +00:00
parent 4fe0853ea1
commit e135fa8ee4
1 changed files with 62 additions and 65 deletions

View File

@ -1,10 +1,10 @@
.\" $NetBSD: scheduler.9,v 1.3 2003/04/16 13:35:33 wiz Exp $
.\" $NetBSD: scheduler.9,v 1.4 2006/12/04 15:36:23 hubertf Exp $
.\"
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Gregory McGarry.
.\" by Gregory McGarry and Daniel Sieger.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -34,82 +34,79 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd September 21, 2002
.Dd December 2, 2006
.Dt SCHEDULER 9
.Os
.Sh NAME
.Nm scheduler
.Nd process scheduling subsystem
.Nm scheduler ,
.Nm resetpriority ,
.Nm roundrobin ,
.Nm rqinit ,
.Nm schedclock ,
.Nm schedcpu ,
.Nm setrunnable ,
.Nm updatepri
.Nd thread scheduling sub-system
.Sh SYNOPSIS
.In sys/sched.h
.In sys/lwp.h
.In sys/proc.h
.Ft void
.Fn resetpriority "struct lwp *l"
.Ft void
.Fn roundrobin "struct cpu_info *ci"
.Ft void
.Fn schedclock "struct lwp *l"
.Ft void
.Fn schedcpu "void *arg"
.Ft void
.Fn setrunnable "struct lwp *l"
.Ft void
.Fn updatepri "struct lwp *l"
.Sh DESCRIPTION
.Bf -symbolic
This page documents the default
.Dq time-sharing
scheduler in
.Nx .
It is likely that in the future a new scheduler subsystem will be
developed which will allow new scheduling algorithms to be
implemented.
.Ef
.Pp
.Nx Ns 's
scheduler algorithm is based on
.Dq multilevel feedback queues .
All processes that are runnable are assigned a scheduling priority
that determines in which run queue they are placed.
The currently running process does not exist on a run queue.
In selecting a new process to run, the system scans the run queues
from highest to lowest priority and chooses the first process on the
first non-empty queue.
If multiple processes reside on a queue, the system runs them round
robin in the order found on the queue.
If a process uses up the time slice allocated to it, it is placed at
the end of the queue from which it came, and the process at the front of
the queue is selected to run.
The
.Nx
thread scheduling sub-system employs a
.Dq multilevel feedback queues
algorithm, favouring interactive, short-runnig threads to
CPU-bound ones.
.Pp
The system adjusts the scheduling priority of a process dynamically to
reflect resource requirements (being blocked) and the CPU utilization
consumed by the process.
Processes are moved between run queues based on changes in their
scheduling priority (hence the word feedback in the name).
.Pp
The process CPU utilization is incremented in
.Fn hardclock
each time that the system clock ticks and the process is found to be
executing.
CPU utilization is adjusted once per second in
.Fn schedcpu
via a digital decay filter.
Each time a process accumulates four ticks in its CPU utilization,
.Fn schedclock
invokes
.Fn resetpriority
to recalculate the process's scheduling priority.
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.
.Pp
When a process other than the currently running process attains a
higher scheduling priority, the system notices this in
.Fn resetpriority
and schedules a context switch to the higher-priority process to occur
on return to user mode.
.Fn roundrobin
gets called from
.Xr hardclock 9
every 100ms to force a switch between equal priority threads.
.Pp
A blocked process exists on the sleep queue and is not affected by the
scheduling behaviour discussed above.
However, each second
The runqueues are initialized through
.Fn rqinit ,
called from
.Fn init_main
at system startup.
.Pp
The priority of the current thread is adjusted through
.Fn schedclock .
The priority of a thread gets worse as it accumulates CPU time.
.Pp
The
.Fn schedcpu
updates the time each process has been on the sleep queue.
The system recomputes a process's CPU utilization estimate in
function recomputes the priorities of all threads every Hz
ticks.
.Pp
The
.Fn 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.
.Pp
The
.Fn updatepri
when it is awakened and has been sleeping for longer than 1 second.
When the process is placed on the run queue by
.Fn setrunnable ,
.Fn resetpriority
is invoked to recalculate the process's scheduling priority.
.Pp
The system tailors this short-term scheduling algorithm to favor
interactive jobs by raising the scheduling priority of processes that
are blocked waiting for I/O for one or more seconds, and by lowering the
priority of processes that accumulate significant amounts of CPU time.
function recalculates the priority of a thread after it has been
sleeping.
.Sh CODE REFERENCES
This section describes places within the
.Nx