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"
47 .Fn kthread_exit "void"
49 .Fn kthread_resume "struct thread *td"
51 .Fn kthread_suspend "struct thread *td" "int timo"
53 .Fn kthread_suspend_check "struct thread *td"
57 .Fa "void (*func)(void *)" "void *arg" "struct proc *procp"
58 .Fa "struct thread **newtdpp" "int flags" "int pages"
59 .Fa "const char *fmt" ...
63 .Fa "void (*func)(void *)" "void *arg"
64 .Fa "struct proc **procptr" "struct thread **tdptr"
65 .Fa "int flags" "int pages" "char * procname" "const char *fmt" "..."
72 functions was renamed to be the
75 as they were previously misnamed
76 and actually produced kernel processes.
79 functions was added to produce
84 man page for more information on the renamed calls.
86 .Fn kproc_kthread_add 9
87 function appears in both pages as its functionality is split.
94 .Nm bufdaemon , pagedaemon , vmdaemon ,
102 argument is actually a pointer to a
103 .Vt "struct kthread_desc"
104 which describes the kernel thread that should be created:
105 .Bd -literal -offset indent
106 struct kthread_desc {
109 struct thread **global_threadpp;
113 The structure members are used by
116 .Bl -tag -width ".Va global_threadpp" -offset indent
118 String to be used for the name of the thread.
119 This string will be copied into the
121 member of the new threads'
122 .Vt "struct thread" .
124 The main function for this kernel thread to run.
125 .It Va global_threadpp
128 pointer that should be updated to point to the newly created thread's
134 The thread will be a subthread of
141 function is used to create a kernel thread.
142 The new thread runs in kernel mode only.
143 It is added to the process specified by the
145 argument, or if that is
151 argument specifies the function that the thread should execute.
154 argument is an arbitrary pointer that is passed in as the only argument to
156 when it is called by the new thread.
161 pointer that is to be updated to point to the newly created thread.
167 argument may be set to
169 to leave the thread in a stopped state.
175 argument specifies the size of the new kernel thread's stack in pages.
176 If 0 is used, the default kernel stack size is allocated.
177 The rest of the arguments form a
179 argument list that is used to build the name of the new thread and is stored
182 member of the new thread's
183 .Vt "struct thread" .
186 .Fn kproc_kthread_add
187 function is much like the
189 function above except that if the kproc does not already
190 exist, it is created.
191 This function is better documented in the
197 function is used to terminate kernel threads.
198 It should be called by the main function of the kernel thread rather than
199 letting the main function return to its caller.
200 .\" XXX "int ecode" argument isn't documented.
204 .Fn kthread_suspend ,
206 .Fn kthread_suspend_check
207 functions are used to suspend and resume a kernel thread.
208 During the main loop of its execution, a kernel thread that wishes to allow
209 itself to be suspended should call
210 .Fn kthread_suspend_check
213 as the only argument.
214 This function checks to see if the kernel thread has been asked to suspend.
217 until it is told to resume.
218 Once it has been told to resume it will return allowing execution of the
219 kernel thread to continue.
220 The other two functions are used to notify a kernel thread of a suspend or
224 argument points to the
226 of the kernel thread to suspend or resume.
228 .Fn kthread_suspend ,
231 argument specifies a timeout to wait for the kernel thread to acknowledge the
232 suspend request and suspend itself.
236 function is meant to be registered as a shutdown event for kernel threads that
237 need to be suspended voluntarily during system shutdown so as not to interfere
238 with system shutdown activities.
239 The actual suspension of the kernel thread is done with
240 .Fn kthread_suspend .
247 functions return zero on success and non-zero on failure.
249 This example demonstrates the use of a
250 .Vt "struct kthread_desc"
253 .Fn kthread_shutdown ,
255 .Fn kthread_suspend_check
259 .Bd -literal -offset indent
260 static struct thread *bufdaemonthread;
262 static struct kthread_desc buf_kp = {
267 SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kthread_start,
275 * This process needs to be suspended prior to shutdown sync.
277 EVENTHANDLER_REGISTER(shutdown_pre_sync, kthread_shutdown,
278 bufdaemonthread, SHUTDOWN_PRI_LAST);
281 kthread_suspend_check(bufdaemonthread);
291 functions will fail if:
296 argument does not reference a kernel thread.
301 function will fail if:
304 Memory for a thread's stack could not be allocated.
313 function first appeared in
315 where it created a whole process.
316 It was converted to create threads in
319 .Fn kthread_shutdown ,
322 .Fn kthread_suspend ,
324 .Fn kthread_suspend_check
325 functions were introduced in
327 and were converted to threads in
335 The old functionality of creating a kernel process was renamed
341 .Fn kthread_shutdown ,
343 .Fn kthread_suspend ,
345 .Fn kthread_suspend_check
351 .Fn kproc_suspend_loop ,