1.\" $NetBSD: sched_4bsd.9,v 1.9 2019/04/09 13:53:52 sevan 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.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd April 9, 2019 31.Dt SCHED_4BSD 9 32.Os 33.Sh NAME 34.Nm sched_4bsd 35.Nd The 4.4BSD thread scheduler 36.Sh SYNOPSIS 37.In sys/sched.h 38.Ft void 39.Fn resetpriority "lwp_t *l" 40.Ft void 41.Fn sched_tick "struct cpu_info *ci" 42.Ft void 43.Fn sched_schedclock "lwp_t *l" 44.Ft void 45.Fn sched_pstats_hook "struct proc *p" "int minslp" 46.Ft void 47.Fn sched_setrunnable "lwp_t *l" 48.Ft void 49.Fn updatepri "lwp_t *l" 50.Sh DESCRIPTION 51The traditional 52.Bx 4.4 53scheduler employs a 54.Dq multilevel feedback queues 55algorithm, favouring interactive, short-running threads to 56CPU-bound ones. 57.Pp 58.Fn resetpriority 59recomputes the priority of a thread running in user mode. 60If the resulting priority is higher than that of the 61current thread, a reschedule is arranged. 62.Pp 63.Fn sched_tick 64gets called from 65.Xr hardclock 9 66every 100ms to force a switch between equal priority threads. 67.Pp 68The priority of the current thread is adjusted through 69.Fn sched_schedclock . 70The priority of a thread gets worse as it accumulates CPU time. 71.Pp 72.Fn sched_pstats_hook 73gets called from 74.Fn sched_pstats 75every Hz ticks in order to recompute the priorities of all threads. 76.Pp 77.Fn sched_setrunnable 78checks if an LWP has slept for more than one second. 79If so, its priority is updated by 80.Fn updatepri . 81.Sh EXAMPLES 82To determine the scheduler currently in use 83.Bd -literal -offset indent 84$ sysctl kern.sched.name 85kern.sched.name = 4.4BSD 86.Ed 87.Sh CODE REFERENCES 88The 89.Bx 4.4 90scheduler subsystem is implemented within the file 91.Pa sys/kern/sched_4bsd.c . 92.Sh SEE ALSO 93.Xr csf 9 , 94.Xr hardclock 9 , 95.Xr mi_switch 9 , 96.Xr sched_m2 9 , 97.Xr userret 9 98.Rs 99.%A Marshall Kirk McKusick 100.%A Keith Bostic 101.%A Michael J. Karels 102.%A John S. Quarterman 103.%B "The Design and Implementation of the 4.4BSD Operating System" 104.%I "Addison Wesley" 105.%D 1996 106.Re 107