124 lines
3.9 KiB
Groff
124 lines
3.9 KiB
Groff
.\" $NetBSD: scheduler.9,v 1.7 2006/12/23 09:21:10 wiz 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 and Daniel Sieger.
|
|
.\"
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
.\" modification, are permitted provided that the following conditions
|
|
.\" are met:
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
.\" must display the following acknowledgement:
|
|
.\" This product includes software developed by the NetBSD
|
|
.\" Foundation, Inc. and its contributors.
|
|
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
.\" contributors may be used to endorse or promote products derived
|
|
.\" from this software without specific prior written permission.
|
|
.\"
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
|
.\"
|
|
.Dd December 2, 2006
|
|
.Dt SCHEDULER 9
|
|
.Os
|
|
.Sh NAME
|
|
.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
|
|
The
|
|
.Nx
|
|
thread scheduling sub-system employs a
|
|
.Dq multilevel feedback queues
|
|
algorithm, favouring interactive, short-running threads to
|
|
CPU-bound ones.
|
|
.Pp
|
|
.Fn 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.
|
|
.Pp
|
|
.Fn roundrobin
|
|
gets called from
|
|
.Xr hardclock 9
|
|
every 100ms to force a switch between equal priority threads.
|
|
.Pp
|
|
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
|
|
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 awakened.
|
|
.Pp
|
|
The
|
|
.Fn updatepri
|
|
function recalculates the priority of a thread after it has been
|
|
sleeping.
|
|
.Sh CODE REFERENCES
|
|
This section describes places within the
|
|
.Nx
|
|
source tree where actual code implementing the scheduler can be found.
|
|
All pathnames are relative to
|
|
.Pa /usr/src .
|
|
.Pp
|
|
The scheduler subsystem is implemented within the file
|
|
.Pa sys/kern/kern_synch.c .
|
|
.Sh SEE ALSO
|
|
.Xr SCHED_LOCK 9 ,
|
|
.Xr hardclock 9 ,
|
|
.Xr mi_switch 9 ,
|
|
.Xr setrunqueue 9 ,
|
|
.Xr userret 9
|