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. .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
.\" All rights reserved. .\" All rights reserved.
.\" .\"
.\" This code is derived from software contributed to The NetBSD Foundation .\" 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 .\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions .\" 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 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE. .\" POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd September 21, 2002 .Dd December 2, 2006
.Dt SCHEDULER 9 .Dt SCHEDULER 9
.Os .Os
.Sh NAME .Sh NAME
.Nm scheduler .Nm scheduler ,
.Nd process scheduling subsystem .Nm resetpriority ,
.Nm roundrobin ,
.Nm rqinit ,
.Nm schedclock ,
.Nm schedcpu ,
.Nm setrunnable ,
.Nm updatepri
.Nd thread scheduling sub-system
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/sched.h .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 .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 .Pp
.Nx Ns 's The
scheduler algorithm is based on .Nx
.Dq multilevel feedback queues . thread scheduling sub-system employs a
All processes that are runnable are assigned a scheduling priority .Dq multilevel feedback queues
that determines in which run queue they are placed. algorithm, favouring interactive, short-runnig threads to
The currently running process does not exist on a run queue. CPU-bound ones.
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.
.Pp .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 .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 .Pp
When a process other than the currently running process attains a .Fn roundrobin
higher scheduling priority, the system notices this in gets called from
.Fn resetpriority .Xr hardclock 9
and schedules a context switch to the higher-priority process to occur every 100ms to force a switch between equal priority threads.
on return to user mode.
.Pp .Pp
A blocked process exists on the sleep queue and is not affected by the The runqueues are initialized through
scheduling behaviour discussed above. .Fn rqinit ,
However, each second 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 .Fn schedcpu
updates the time each process has been on the sleep queue. function recomputes the priorities of all threads every Hz
The system recomputes a process's CPU utilization estimate in 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 .Fn updatepri
when it is awakened and has been sleeping for longer than 1 second. function recalculates the priority of a thread after it has been
When the process is placed on the run queue by sleeping.
.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.
.Sh CODE REFERENCES .Sh CODE REFERENCES
This section describes places within the This section describes places within the
.Nx .Nx