1.\" $NetBSD: sched_4bsd.9,v 1.2 2007/07/15 21:33:12 wiz Exp $ 2.\" 3.\" Copyright (c) 2002 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Gregory McGarry and Daniel Sieger. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd July 14, 2007 38.Dt SCHED_4BSD 9 39.Os 40.Sh NAME 41.Nm sched_4bsd 42.Nd The 4.4BSD thread scheduler 43.Sh SYNOPSIS 44.In sys/sched.h 45.Ft void 46.Fn resetpriority "lwp_t *l" 47.Ft void 48.Fn sched_tick "struct cpu_info *ci" 49.Ft void 50.Fn sched_schedclock "lwp_t *l" 51.Ft void 52.Fn sched_pstats_hook "struct proc *p" "int minslp" 53.Ft void 54.Fn sched_setrunnable "lwp_t *l" 55.Ft void 56.Fn updatepri "lwp_t *l" 57.Sh DESCRIPTION 58The 59.Nx 60thread scheduling sub-system employs a 61.Dq multilevel feedback queues 62algorithm, favouring interactive, short-running threads to 63CPU-bound ones. 64.Pp 65.Fn resetpriority 66recomputes the priority of a thread running in user mode. 67If the resulting priority is higher than that of the 68current thread, a reschedule is arranged. 69.Pp 70.Fn sched_tick 71gets called from 72.Xr hardclock 9 73every 100ms to force a switch between equal priority threads. 74.Pp 75The priority of the current thread is adjusted through 76.Fn sched_schedclock . 77The priority of a thread gets worse as it accumulates CPU time. 78.Pp 79.Fn sched_pstats_hook 80gets called from 81.Fn sched_pstats 82every Hz ticks in order to recompute the priorities of all threads. 83.Pp 84.Fn sched_setrunnable 85checks if an LWP has slept for more than one second. 86If so, its priority is updated by 87.Fn updatepri . 88.Sh CODE REFERENCES 89This section describes places within the 90.Nx 91source tree where actual code implementing the scheduler can be found. 92All pathnames are relative to 93.Pa /usr/src . 94.Pp 95The 4.4BSD scheduler subsystem is implemented within the file 96.Pa sys/kern/sched_4bsd.c . 97.Sh SEE ALSO 98.Xr csf 9 , 99.Xr hardclock 9 , 100.Xr mi_switch 9 , 101.Xr userret 9 102.Rs 103.%A Marshall Kirk McKusick 104.%A Keith Bostic 105.%A Michael J. Karels 106.%A John S. Quarterman 107.%B "The Design and Implementation of the 4.4BSD Operating System" 108.%I "Addison Wesley" 109.%D 1996 110.Re 111