2 * Copyright (c) 1999 Peter Wemm <peter@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/kern/kern_kthread.c,v 1.5.2.3 2001/12/25 01:51:14 dillon Exp $
27 * $DragonFly: src/sys/kern/kern_kthread.c,v 1.9 2003/07/19 21:14:38 dillon Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/kthread.h>
34 #include <sys/ptrace.h>
35 #include <sys/resourcevar.h>
36 #include <sys/signalvar.h>
37 #include <sys/unistd.h>
40 #include <machine/stdarg.h>
43 * Start a kernel process. This is called after a fork() call in
44 * mi_startup() in the file kern/init_main.c.
46 * This function is used to start "internal" daemons and intended
47 * to be called from SYSINIT().
53 const struct kproc_desc *kp = udata;
56 error = kthread_create((void (*)(void *))kp->func, NULL,
57 kp->global_threadpp, kp->arg0);
58 lwkt_setpri(*kp->global_threadpp, TDPRI_KERN_DAEMON);
60 panic("kproc_start: %s: error %d", kp->arg0, error);
64 * Advise a kernel process to suspend (or resume) in its main loop.
65 * Participation is voluntary.
68 suspend_kproc(struct thread *td, int timo)
70 if (td->td_proc == NULL) {
71 td->td_flags |= TDF_STOPREQ; /* request thread pause */
73 while (td->td_flags & TDF_STOPREQ) {
74 int error = tsleep(td, 0, "suspkp", timo);
75 if (error == EWOULDBLOCK)
78 td->td_flags &= ~TDF_STOPREQ;
81 return(EINVAL); /* not a kernel thread */
86 kproc_suspend_loop(void)
88 struct thread *td = curthread;
90 if (td->td_flags & TDF_STOPREQ) {
91 td->td_flags &= ~TDF_STOPREQ;
92 while ((td->td_flags & TDF_WAKEREQ) == 0) {
94 tsleep(td, 0, "kpsusp", 0);
96 td->td_flags &= ~TDF_WAKEREQ;