From a68f4a7087d8695c2bfbe7ccd91558ce04a9d603 Mon Sep 17 00:00:00 2001 From: dyson Date: Fri, 12 Dec 1997 04:00:59 +0000 Subject: [PATCH] We have had support for running the kernel daemons as threads for quite a while, but forgot to do so. For now, this code supports most daemons running as kernel threads in UP kernels, and as full processes in SMP. We will soon be able to run them as threads in SMP, but not yet. --- sys/kern/init_main.c | 17 ++++++++++++++--- sys/kern/kern_fork.c | 6 ++---- sys/kern/kern_linker.c | 15 +++++++++++++-- sys/sys/kernel.h | 15 +++++++++++++-- sys/sys/proc.h | 3 ++- 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index e56531eba624..d4ea42bf7592 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -39,7 +39,7 @@ * SUCH DAMAGE. * * @(#)init_main.c 8.9 (Berkeley) 1/21/94 - * $Id: init_main.c,v 1.76 1997/11/25 07:07:41 julian Exp $ + * $Id: init_main.c,v 1.77 1997/12/06 04:11:09 sef Exp $ */ #include "opt_devfs.h" @@ -59,6 +59,7 @@ #include #include #include +#include #include @@ -194,6 +195,7 @@ main(framep) * which will not return. */ for( sipp = (struct sysinit **)sysinit_set.ls_items; *sipp; sipp++) { + if( (*sipp)->subsystem == SI_SUB_DUMMY) continue; /* skip dummy task(s)*/ @@ -204,8 +206,17 @@ main(framep) break; case SI_TYPE_KTHREAD: +#if !defined(SMP) /* kernel thread*/ - if (fork(&proc0, NULL)) + if (fork1(&proc0, RFMEM|RFFDG|RFPROC)) + panic("fork kernel thread"); + cpu_set_fork_handler(pfind(proc0.p_retval[0]), + (*sipp)->func, (*sipp)->udata); + break; +#endif + + case SI_TYPE_KPROCESS: + if (fork1(&proc0, RFFDG|RFPROC)) panic("fork kernel process"); cpu_set_fork_handler(pfind(proc0.p_retval[0]), (*sipp)->func, (*sipp)->udata); @@ -507,7 +518,7 @@ SYSINIT(retrofit, SI_SUB_ROOT_FDTAB, SI_ORDER_FIRST, xxx_vfs_root_fdtab, NULL) */ static void kthread_init __P((void *dummy)); -SYSINIT_KT(init,SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kthread_init, NULL) +SYSINIT_KP(init,SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kthread_init, NULL) extern void prepare_usermode __P((void)); diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index e7fa08932de9..df7b863c9de3 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_fork.c 8.6 (Berkeley) 4/8/94 - * $Id: kern_fork.c,v 1.48 1997/11/06 19:29:09 phk Exp $ + * $Id: kern_fork.c,v 1.49 1997/11/20 16:36:17 bde Exp $ */ #include "opt_ktrace.h" @@ -68,8 +68,6 @@ static int fast_vfork = 1; #endif SYSCTL_INT(_kern, OID_AUTO, fast_vfork, CTLFLAG_RW, &fast_vfork, 0, ""); -static int fork1 __P((struct proc *p, int flags)); - /* * These are the stuctures used to create a callout list for things to do * when forking a process @@ -121,7 +119,7 @@ rfork(p, uap) int nprocs = 1; /* process 0 */ static int nextpid = 0; -static int +int fork1(p1, flags) register struct proc *p1; int flags; diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c index ef83ab310af5..da4b19828635 100644 --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: kern_linker.c,v 1.3 1997/11/06 19:29:10 phk Exp $ + * $Id: kern_linker.c,v 1.4 1997/11/20 20:07:45 bde Exp $ */ #include @@ -37,6 +37,7 @@ #include #include #include +#include linker_file_t linker_current_file; @@ -129,8 +130,18 @@ linker_file_sysinit(linker_file_t lf) break; case SI_TYPE_KTHREAD: +#if !defined(SMP) /* kernel thread*/ - if (fork(&proc0, NULL)) + if (fork1(&proc0, RFFDG|RFPROC|RFMEM)) + panic("fork kernel thread"); + cpu_set_fork_handler(pfind(proc0.p_retval[0]), + (*sipp)->func, (*sipp)->udata); + break; +#endif + + case SI_TYPE_KPROCESS: + /* kernel thread*/ + if (fork1(&proc0, RFFDG|RFPROC)) panic("fork kernel process"); cpu_set_fork_handler(pfind(proc0.p_retval[0]), (*sipp)->func, (*sipp)->udata); diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h index 45dc867cb0a5..dcd682e382c3 100644 --- a/sys/sys/kernel.h +++ b/sys/sys/kernel.h @@ -39,7 +39,7 @@ * SUCH DAMAGE. * * @(#)kernel.h 8.3 (Berkeley) 1/21/94 - * $Id: kernel.h,v 1.34 1997/09/21 22:09:11 gibbs Exp $ + * $Id: kernel.h,v 1.35 1997/11/18 07:23:40 bde Exp $ */ #ifndef _SYS_KERNEL_H_ @@ -200,7 +200,8 @@ enum sysinit_elem_order { */ typedef enum sysinit_elem_type { SI_TYPE_DEFAULT = 0x00000000, /* No special processing*/ - SI_TYPE_KTHREAD = 0x00000001 /* start kernel thread*/ + SI_TYPE_KTHREAD = 0x00000001, /* start kernel thread*/ + SI_TYPE_KPROCESS = 0x00000002 /* start kernel process*/ } si_elem_t; @@ -245,6 +246,16 @@ struct sysinit { }; \ DATA_SET(sysinit_set,uniquifier ## _sys_init); +#define SYSINIT_KP(uniquifier, subsystem, order, func, ident) \ + static struct sysinit uniquifier ## _sys_init = { \ + subsystem, \ + order, \ + func, \ + ident, \ + SI_TYPE_KPROCESS \ + }; \ + DATA_SET(sysinit_set,uniquifier ## _sys_init); + /* * A kernel process descriptor; used to start "internal" daemons diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 2dc5c3093097..c66cd2eb8807 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)proc.h 8.15 (Berkeley) 5/19/95 - * $Id: proc.h,v 1.49 1997/11/25 07:07:48 julian Exp $ + * $Id: proc.h,v 1.50 1997/12/06 04:11:14 sef Exp $ */ #ifndef _SYS_PROC_H_ @@ -338,6 +338,7 @@ void wakeup_one __P((void *chan)); void cpu_exit __P((struct proc *)) __dead2; void exit1 __P((struct proc *, int)) __dead2; void cpu_fork __P((struct proc *, struct proc *)); +int fork1 __P((struct proc *, int)); int trace_req __P((struct proc *)); void cpu_wait __P((struct proc *)); int cpu_coredump __P((struct proc *, struct vnode *, struct ucred *));