1 .\" Copyright (c) 2000-2001
2 .\" The Regents of the University of California. All rights reserved.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 .Nm kthread_shutdown ,
38 .Nm kthread_suspend_check
43 .Fn kthread_start "const void *udata"
45 .Fn kthread_shutdown "void *arg" "int howto"
48 .Fa "void (*func)(void *)" "void *arg" "struct proc *procp"
49 .Fa "struct thread **newtdpp" "int flags" "int pages"
50 .Fa "const char *fmt" ...
53 .Fn kthread_exit "void"
55 .Fn kthread_resume "struct thread *td"
57 .Fn kthread_suspend "struct thread *td" "int timo"
59 .Fn kthread_suspend_check "struct thread *td"
62 .Fa "void (*func)(void *)" "void *arg"
63 .Fa "struct proc **procptr" "struct thread **tdptr"
64 .Fa "int flags" "int pages" "char * procname" "const char *fmt" "..."
72 .Nm bufdaemon , pagedaemon , vmdaemon ,
80 argument is actually a pointer to a
81 .Vt "struct kthread_desc"
82 which describes the kernel thread that should be created:
83 .Bd -literal -offset indent
87 struct thread **global_threadpp;
91 The structure members are used by
94 .Bl -tag -width ".Va global_threadpp" -offset indent
96 String to be used for the name of the thread.
97 This string will be copied into the
99 member of the new threads'
100 .Vt "struct thread" .
102 The main function for this kernel thread to run.
103 .It Va global_threadpp
106 pointer that should be updated to point to the newly created thread's
112 The thread will be a subthread of
119 function is used to create a kernel thread.
120 The new thread runs in kernel mode only.
121 It is added to the process specified by the
123 argument, or if that is
129 argument specifies the function that the thread should execute.
132 argument is an arbitrary pointer that is passed in as the only argument to
134 when it is called by the new thread.
139 pointer that is to be updated to point to the newly created thread.
145 argument specifies a set of flags as described in
149 argument specifies the size of the new kernel thread's stack in pages.
150 If 0 is used, the default kernel stack size is allocated.
151 The rest of the arguments form a
153 argument list that is used to build the name of the new thread and is stored
156 member of the new thread's
157 .Vt "struct thread" .
160 .Fn kproc_kthread_add
161 function is much like the
163 function above except that if the kproc does not already
164 exist, it is created.
165 This function is better documented in the
171 function is used to terminate kernel threads.
172 It should be called by the main function of the kernel thread rather than
173 letting the main function return to its caller.
174 .\" XXX "int ecode" argument isn't documented.
178 .Fn kthread_suspend ,
180 .Fn kthread_suspend_check
181 functions are used to suspend and resume a kernel thread.
182 During the main loop of its execution, a kernel thread that wishes to allow
183 itself to be suspended should call
184 .Fn kthread_suspend_check
187 as the only argument.
188 This function checks to see if the kernel thread has been asked to suspend.
191 until it is told to resume.
192 Once it has been told to resume it will return allowing execution of the
193 kernel thread to continue.
194 The other two functions are used to notify a kernel thread of a suspend or
198 argument points to the
200 of the kernel thread to suspend or resume.
202 .Fn kthread_suspend ,
205 argument specifies a timeout to wait for the kernel thread to acknowledge the
206 suspend request and suspend itself.
210 function is meant to be registered as a shutdown event for kernel threads that
211 need to be suspended voluntarily during system shutdown so as not to interfere
212 with system shutdown activities.
213 The actual suspension of the kernel thread is done with
214 .Fn kthread_suspend .
221 functions return zero on success and non-zero on failure.
223 This example demonstrates the use of a
224 .Vt "struct kthread_desc"
227 .Fn kthread_shutdown ,
229 .Fn kthread_suspend_check
233 .Bd -literal -offset indent
234 static struct thread *bufdaemonthread;
236 static struct kthread_desc buf_kp = {
241 SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kthread_start,
249 * This process needs to be suspended prior to shutdown sync.
251 EVENTHANDLER_REGISTER(shutdown_pre_sync, kthread_shutdown,
252 bufdaemonthread, SHUTDOWN_PRI_LAST);
255 kthread_suspend_check(bufdaemonthread);
265 functions will fail if:
270 argument does not reference a kernel thread.
275 function will fail if:
278 The system-imposed limit on the total
279 number of processes under execution would be exceeded.
280 The limit is given by the
287 flag was specified in the
300 function first appeared in
302 where it created a whole process.
303 It was converted to create threads in
306 .Fn kthread_shutdown ,
309 .Fn kthread_suspend ,
311 .Fn kthread_suspend_check
312 functions were introduced in
314 and were converted to threads in
322 The old functionality of creating a kernel process was renamed
328 .Fn kthread_shutdown ,
330 .Fn kthread_suspend ,
332 .Fn kthread_suspend_check
338 .Fn kproc_suspend_loop ,