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.
28 .Dd September 24, 2004
38 .Nm kthread_suspend_check
43 .Fn kproc_start "const void *udata"
45 .Fn kproc_shutdown "void *arg" "int howto"
47 .Fn kthread_create "void (*func)(void *)" "void *arg" "struct proc **newpp" "int flags" "int pages" "const char *fmt" "..."
49 .Fn kthread_exit "int ecode"
51 .Fn kthread_resume "struct proc *p"
53 .Fn kthread_suspend "struct proc *p" "int timo"
55 .Fn kthread_suspend_check "struct proc *p"
61 daemons such as bufdaemon, pagedaemon, vmdaemon, and the syncer and is intended
66 argument is actually a pointer to a
68 which describes the kernel thread that should be created:
69 .Bd -literal -offset indent
73 struct proc **global_procpp;
77 The structure members are used by
80 .Bl -tag -width "global_procpp" -offset indent
82 String to be used for the name of the process.
83 This string will be copied into the
85 member of the new process'
88 The main function for this kernel process to run.
92 pointer that should be updated to point to the newly created process' process
101 function is used to create a kernel thread.
102 The new thread shares its address space with process 0, the swapper process,
103 and runs in kernel mode only.
106 argument specifies the function that the thread should execute.
109 argument is an arbitrary pointer that is passed in as the only argument to
111 when it is called by the new process.
116 pointer that is to be updated to point to the newly created process.
122 argument specifies a set of flags as described in
126 argument specifies the size of the new kernel thread's stack in pages.
127 If 0 is used, the default kernel stack size is allocated.
128 The rest of the arguments form a
130 argument list that is used to build the name of the new thread and is stored
133 member of the new thread's
138 function is used to terminate kernel threads.
139 It should be called by the main function of the kernel thread rather than
140 letting the main function return to its caller.
143 argument specifies the exit status of the thread.
144 While exiting, the function
146 will initiate a call to
148 on the thread handle.
152 .Fn kthread_suspend ,
154 .Fn kthread_suspend_check
155 functions are used to suspend and resume a kernel thread.
156 During the main loop of its execution, a kernel thread that wishes to allow
157 itself to be suspended should call
158 .Fn kthread_suspend_check
161 as the only argument.
162 This function checks to see if the kernel thread has been asked to suspend.
165 until it is told to resume.
166 Once it has been told to resume it will return allowing execution of the
167 kernel thread to continue.
168 The other two functions are used to notify a kernel thread of a suspend or
172 argument points to the
174 of the kernel thread to suspend or resume.
176 .Fn kthread_suspend ,
179 argument specifies a timeout to wait for the kernel thread to acknowledge the
180 suspend request and suspend itself.
184 function is meant to be registered as a shutdown event for kernel threads that
185 need to be suspended voluntarily during system shutdown so as not to interfere
186 with system shutdown activities.
187 The actual suspension of the kernel thread is done with
188 .Fn kthread_suspend .
195 functions return zero on success and non-zero on failure.
197 This example demonstrates the use of a
198 .Li struct kproc_desc
203 .Fn kthread_suspend_check
207 .Bd -literal -offset indent
208 static struct proc *bufdaemonproc;
210 static struct kproc_desc buf_kp = {
215 SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kproc_start,
223 * This process needs to be suspended prior to shutdown sync.
225 EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown,
226 bufdaemonproc, SHUTDOWN_PRI_LAST);
229 kthread_suspend_check(bufdaemonproc);
239 functions will fail if:
244 argument does not reference a kernel thread.
249 function will fail if:
252 The system-imposed limit on the total
253 number of processes under execution would be exceeded.
254 The limit is given by the
261 flag was specified in the
273 function first appeared in
280 .Fn kthread_suspend ,
282 .Fn kthread_suspend_check
283 functions were introduced in
290 .Fn kthread_suspend ,
292 .Fn kthread_suspend_check
298 .Fn kproc_suspend_loop ,