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.
38 .Nm kproc_suspend_check
39 .Nd "kernel processes"
43 .Fn kproc_start "const void *udata"
45 .Fn kproc_shutdown "void *arg" "int howto"
48 .Fa "void (*func)(void *)" "void *arg" "struct proc **newpp"
49 .Fa "int flags" "int pages"
50 .Fa "const char *fmt" ...
53 .Fn kproc_exit "int ecode"
55 .Fn kproc_resume "struct proc *p"
57 .Fn kproc_suspend "struct proc *p" "int timo"
59 .Fn kproc_suspend_check "struct proc *p"
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 kproc_desc"
82 which describes the kernel process that should be created:
83 .Bd -literal -offset indent
87 struct proc **global_procpp;
91 The structure members are used by
94 .Bl -tag -width ".Va global_procpp" -offset indent
96 String to be used for the name of the process.
97 This string will be copied into the
99 member of the new process'
102 The main function for this kernel process to run.
106 pointer that should be updated to point to the newly created process' process
115 function is used to create a kernel process.
116 The new process shares its address space with process 0, the
119 and runs in kernel mode only.
122 argument specifies the function that the process should execute.
125 argument is an arbitrary pointer that is passed in as the only argument to
127 when it is called by the new process.
132 pointer that is to be updated to point to the newly created process.
138 argument specifies a set of flags as described in
142 argument specifies the size of the new kernel process's stack in pages.
143 If 0 is used, the default kernel stack size is allocated.
144 The rest of the arguments form a
146 argument list that is used to build the name of the new process and is stored
149 member of the new process's
154 function is used to terminate kernel processes.
155 It should be called by the main function of the kernel process rather than
156 letting the main function return to its caller.
159 argument specifies the exit status of the process.
160 While exiting, the function
162 will initiate a call to
164 on the process handle.
170 .Fn kproc_suspend_check
171 functions are used to suspend and resume a kernel process.
172 During the main loop of its execution, a kernel process that wishes to allow
173 itself to be suspended should call
174 .Fn kproc_suspend_check
177 as the only argument.
178 This function checks to see if the kernel process has been asked to suspend.
181 until it is told to resume.
182 Once it has been told to resume it will return allowing execution of the
183 kernel process to continue.
184 The other two functions are used to notify a kernel process of a suspend or
188 argument points to the
190 of the kernel process to suspend or resume.
195 argument specifies a timeout to wait for the kernel process to acknowledge the
196 suspend request and suspend itself.
200 function is meant to be registered as a shutdown event for kernel processes that
201 need to be suspended voluntarily during system shutdown so as not to interfere
202 with system shutdown activities.
203 The actual suspension of the kernel process is done with
207 .Fn kproc_kthread_add
208 function is much like the
210 function above except that if the kproc already exists,
211 then only a new thread (see
213 is created on the existing process.
216 argument specifies the function that the process should execute.
219 argument is an arbitrary pointer that is passed in as the only argument to
221 when it is called by the new process.
226 pointer that is the location to be updated with the new proc pointer
227 if a new process is created, or if not
229 must contain the process pointer for the already exisiting process.
230 If this argument points to
232 then a new process is created and the field updated.
237 pointer that is the location to be updated with the new thread pointer.
240 argument specifies a set of flags as described in
244 argument specifies the size of the new kernel thread's stack in pages.
245 If 0 is used, the default kernel stack size is allocated.
246 The procname argument is the name the new process should be given if it needs to be created.
249 a printf style format specifier but a simple string.
250 The rest of the arguments form a
252 argument list that is used to build the name of the new thread and is stored
255 member of the new thread's
256 .Vt "struct thread" .
263 functions return zero on success and non-zero on failure.
265 This example demonstrates the use of a
266 .Vt "struct kproc_desc"
271 .Fn kproc_suspend_check
275 .Bd -literal -offset indent
276 static struct proc *bufdaemonproc;
278 static struct kproc_desc buf_kp = {
283 SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kproc_start,
291 * This process needs to be suspended prior to shutdown sync.
293 EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown,
294 bufdaemonproc, SHUTDOWN_PRI_LAST);
297 kproc_suspend_check(bufdaemonproc);
307 functions will fail if:
312 argument does not reference a kernel process.
317 function will fail if:
320 The system-imposed limit on the total
321 number of processes under execution would be exceeded.
322 The limit is given by the
329 flag was specified in the
342 function first appeared in
351 .Fn kproc_suspend_check
352 functions were introduced in
361 .Fn kproc_suspend_check
367 .Fn kproc_suspend_loop ,
369 Originally they had the names
373 when real kthreads became available.