1 .\" $NetBSD: csf.9,v 1.5 2009/03/15 14:05:18 joerg Exp $
3 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
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.
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.
37 common scheduler framework
41 .Fn sched_rqinit "void"
43 .Fn sched_setup "void"
45 .Fn sched_cpuattach "struct cpu_info *"
47 .Fn sched_tick "struct cpu_info *"
49 .Fn sched_schedclock "lwp_t *"
51 .Fn sched_curcpu_runnable_p "void"
53 .Fn sched_nextlwp "void"
55 .Fn sched_enqueue "lwp_t *" "bool"
57 .Fn sched_dequeue "lwp_t *"
59 .Fn sched_nice "struct proc *" "int"
61 .Fn sched_proc_fork "struct proc *" "struct proc *"
63 .Fn sched_proc_exit "struct proc *" "struct proc *"
65 .Fn sched_lwp_fork "lwp_t *"
67 .Fn sched_lwp_exit "lwp_t *"
69 .Fn sched_setrunnable "lwp_t *"
71 .Fn sched_print_runqueue "void (*pr)(const char *, ...)"
73 .Fn sched_pstats_hook "struct proc *" "int"
75 .Fn sched_pstats "void *arg"
77 .Fn sched_kpri "lwp_t *"
79 .Fn resched_cpu "lwp_t *"
83 .Fn schedclock "lwp_t *"
88 provides a modular and self-contained interface for
89 implementing different thread scheduling algorithms.
90 The different schedulers can be selected at compile-time.
91 Currently, the schedulers available are
93 the traditional 4.4BSD thread scheduler, and
95 which implements a SVR4/Solaris like apporach.
97 The interface is divided into two parts: A set of functions each
98 scheduler needs to implement and common functions used by all
100 .Sh Scheduler-specific functions
101 The following functions have to be implemented by the individual
103 .Ss Scheduler initialization
104 .Bl -tag -width compact
105 .It Ft void Fn sched_cpuattach "struct cpu_info *"
106 Per-CPU scheduler initialization routine.
107 .It Ft void Fn sched_rqinit "void"
108 Initialize the scheduler's runqueue data structures.
109 .It Ft void Fn sched_setup "void"
110 Setup initial scheduling parameters and kick off timeout driven
113 .Ss Runqueue handling
114 Runqueue handling is completely internal to the scheduler.
115 Other parts of the kernel should access runqueues only through the
117 .Bl -tag -width compact
118 .It Ft void Fn sched_enqueue "lwp_t *" "bool"
119 Place an LWP within the scheduler's runqueue structures.
120 .It Ft void Fn sched_dequeue "lwp_t *"
121 Remove an LWP from the scheduler's runqueue structures.
122 .It Ft lwp_t * Fn sched_nextlwp "void"
123 Return the LWP that should run the CPU next.
124 .It Ft bool Fn sched_curcpu_runnable_p "void"
125 Indicate if there is a runnable LWP for the current CPU.
126 .It Ft void Fn sched_print_runqueue "void (*pr)(const char *, ...)"
127 Print runqueues in DDB.
129 .Ss Core scheduler functions
130 .Bl -tag -width compact
131 .It Ft void Fn sched_tick "struct cpu_info *"
132 Periodically called from
134 Determines if a reschedule is necessary, if the running LWP has
136 .It Ft void Fn sched_schedclock "lwp_t *"
137 Periodically called from
139 in order to handle priority adjustment.
141 .Ss Priority adjustment
142 .Bl -tag -width compact
143 .It Ft void Fn sched_nice "struct proc *, int"
144 Recalculate the process priority according to its nice value.
146 .Ss General helper functions
147 .Bl -tag -width compact
148 .It Ft void Fn sched_proc_fork "struct proc *" "struct proc *"
149 Inherit the scheduling history of the parent process after
151 .It Ft void Fn sched_proc_exit "struct proc *" "struct proc *"
152 Charge back a processes parent for its resource usage.
153 .It Ft void Fn sched_lwp_fork "lwp_t *"
154 LWP-specific version of the above
155 .It Ft void Fn sched_lwp_exit "lwp_t *"
156 LWP-specific version of the above
157 .It Ft void Fn sched_setrunnable "lwp_t *"
158 Scheduler-specific actions for
160 .It Ft void Fn sched_pstats_hook "struct proc *" "int"
161 Scheduler-specific actions for
164 .Sh Common scheduler functions
165 .Bl -tag -width compact
166 .It Ft pri_t Fn sched_kpri "lwp_t *"
167 Scale a priority level to a kernel priority level, usually for an LWP
168 that is about to sleep.
169 .It Ft void Fn sched_pstats "void *"
170 Update process statistics and check CPU resource allocation.
171 .It Ft inline void Fn resched_cpu "lwp_t *"
172 Arrange for a reschedule.
173 .It Ft void Fn setrunnable "lwp_t *"
174 Change process state to be runnable, placing it on a runqueue if it
175 is in memory, awakening the swapper otherwise.
176 .It Ft void Fn schedclock "lwp_t *"
178 Periodically called from
180 .It Ft void Fn sched_init "void"
181 Initialize callout for
185 to initialize any other scheduler-specific data.
188 This section describes places within the
190 source tree where actual code implementing the scheduler can be found.
191 All pathnames are relative to
196 programming interface is defined within the file
197 .Pa sys/sys/sched.h .
199 Functions common to all scheduler implementations are in
200 .Pa sys/kern/kern_synch.c .
202 The traditional 4.4BSD scheduler is implemented in
203 .Pa sys/kern/sched_4bsd.c .
205 The M2 scheduler is implemented in
206 .Pa sys/kern/sched_m2.c .
222 .Aq dsieger@NetBSD.org .