Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Move proc0 initialization from main() in init_main.c and...



details:   https://anonhg.NetBSD.org/src/rev/b73d1b1e0981
branches:  trunk
changeset: 583414:b73d1b1e0981
user:      junyoung <junyoung%NetBSD.org@localhost>
date:      Fri Aug 05 11:03:18 2005 +0000

description:
Move proc0 initialization from main() in init_main.c and proc0_insert() in
kern_proc.c into a new function proc0_init() in kern_proc.c, as suggested
on tech-kern@ days ago.

diffstat:

 sys/kern/init_main.c |  120 +++-----------------------------
 sys/kern/kern_proc.c |  186 ++++++++++++++++++++++++++++++++++++++++----------
 sys/sys/proc.h       |    4 +-
 3 files changed, 162 insertions(+), 148 deletions(-)

diffs (truncated from 435 to 300 lines):

diff -r c675f315e867 -r b73d1b1e0981 sys/kern/init_main.c
--- a/sys/kern/init_main.c      Fri Aug 05 11:00:31 2005 +0000
+++ b/sys/kern/init_main.c      Fri Aug 05 11:03:18 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_main.c,v 1.250 2005/07/16 22:47:18 christos Exp $ */
+/*     $NetBSD: init_main.c,v 1.251 2005/08/05 11:03:18 junyoung Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.250 2005/07/16 22:47:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.251 2005/08/05 11:03:18 junyoung Exp $");
 
 #include "fs_nfs.h"
 #include "opt_nfsserver.h"
@@ -172,28 +172,15 @@
 #include <net/if.h>
 #include <net/raw_cb.h>
 
-/* Components of the first process -- never freed. */
-struct session session0;
-struct pgrp pgrp0;
-struct proc proc0;
-struct lwp lwp0;
-struct pcred cred0;
-struct filedesc0 filedesc0;
-struct cwdinfo cwdi0;
-struct plimit limit0;
-struct pstats pstat0;
-struct vmspace vmspace0;
-struct sigacts sigacts0;
+extern struct proc proc0;
+extern struct lwp lwp0;
+extern struct cwdinfo cwdi0;
+
 #ifndef curlwp
 struct lwp *curlwp = &lwp0;
 #endif
 struct proc *initproc;
 
-int    nofile = NOFILE;
-int    maxuprc = MAXUPRC;
-int    cmask = CMASK;
-extern struct user *proc0paddr;
-
 struct vnode *rootvp, *swapdev_vp;
 int    boothowto;
 int    cold = 1;                       /* still working on startup */
@@ -206,8 +193,6 @@
 static void start_init(void *);
 void main(void);
 
-extern const struct emul emul_netbsd;  /* defined in kern_exec.c */
-
 /*
  * System startup; initialize the world, create process 0, mount root
  * filesystem, and fork to create init and pagedaemon.  Most of the
@@ -221,8 +206,6 @@
        struct proc *p;
        struct pdevinit *pdev;
        int s, error;
-       u_int i;
-       rlim_t lim;
        extern struct pdevinit pdevinit[];
        extern void schedcpu(void *);
 #if defined(NFSSERVER) || defined(NFS)
@@ -298,82 +281,11 @@
        lkm_init();
 #endif
 
-       /*
-        * Create process 0 (the swapper).
-        */
-       p = &proc0;
-       proc0_insert(p, l, &pgrp0, &session0);
-
-       /*
-        * Set P_NOCLDWAIT so that kernel threads are reparented to
-        * init(8) when they exit.  init(8) can easily wait them out
-        * for us.
-        */
-       p->p_flag = P_SYSTEM | P_NOCLDWAIT;
-       p->p_stat = SACTIVE;
-       p->p_nice = NZERO;
-       p->p_emul = &emul_netbsd;
-#ifdef __HAVE_SYSCALL_INTERN
-       (*p->p_emul->e_syscall_intern)(p);
-#endif
-       strncpy(p->p_comm, "swapper", MAXCOMLEN);
-
-       l->l_flag = L_INMEM;
-       l->l_stat = LSONPROC;
-       p->p_nrlwps = 1;
-
-       callout_init(&l->l_tsleep_ch);
-
-       /* Create credentials. */
-       cred0.p_refcnt = 1;
-       p->p_cred = &cred0;
-       p->p_ucred = crget();
-       p->p_ucred->cr_ngroups = 1;     /* group 0 */
-
-       /* Create the file descriptor table. */
-       p->p_fd = &filedesc0.fd_fd;
-       fdinit1(&filedesc0);
+       /* Initialize signal-related data structures. */
+       signal_init();
 
-       /* Create the CWD info. */
-       p->p_cwdi = &cwdi0;
-       cwdi0.cwdi_cmask = cmask;
-       cwdi0.cwdi_refcnt = 1;
-       simple_lock_init(&cwdi0.cwdi_slock);
-
-       /* Create the limits structures. */
-       p->p_limit = &limit0;
-       simple_lock_init(&limit0.p_slock);
-       for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
-               limit0.pl_rlimit[i].rlim_cur =
-                   limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
-
-       limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = maxfiles;
-       limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur =
-           maxfiles < nofile ? maxfiles : nofile;
-
-       limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
-       limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur =
-           maxproc < maxuprc ? maxproc : maxuprc;
-
-       lim = ptoa(uvmexp.free);
-       limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
-       limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
-       limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
-       limit0.pl_corename = defcorename;
-       limit0.p_refcnt = 1;
-
-       /*
-        * Initialize proc0's vmspace, which uses the kernel pmap.
-        * All kernel processes (which never have user space mappings)
-        * share proc0's vmspace, and thus, the kernel pmap.
-        */
-       uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
-           trunc_page(VM_MAX_ADDRESS));
-       p->p_vmspace = &vmspace0;
-
-       l->l_addr = proc0paddr;                         /* XXX */
-
-       p->p_stats = &pstat0;
+       /* Create process 0 (the swapper). */
+       proc0_init();
 
        /*
         * Charge root for one process.
@@ -382,9 +294,6 @@
 
        rqinit();
 
-       /* Configure virtual memory system, set vm rlimits. */
-       uvm_init_limits(p);
-
        /* Initialize the file systems. */
 #if defined(NFSSERVER) || defined(NFS)
        nfs_init();                     /* initialize server/shared data */
@@ -436,7 +345,7 @@
           */
        veriexec_init_fp_ops();
 #endif
-       
+
        /* Attach pseudo-devices. */
        for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++)
                (*pdev->pdev_attach)(pdev->pdev_count);
@@ -467,13 +376,6 @@
 #ifdef SYSTRACE
        systrace_init();
 #endif
-       /*
-        * Initialize signal-related data structures, and signal state
-        * for proc0.
-        */
-       signal_init();
-       p->p_sigacts = &sigacts0;
-       siginit(p);
 
        /* Kick off timeout driven events by calling first time. */
        schedcpu(NULL);
diff -r c675f315e867 -r b73d1b1e0981 sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c      Fri Aug 05 11:00:31 2005 +0000
+++ b/sys/kern/kern_proc.c      Fri Aug 05 11:03:18 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_proc.c,v 1.80 2004/10/03 22:26:35 yamt Exp $      */
+/*     $NetBSD: kern_proc.c,v 1.81 2005/08/05 11:03:18 junyoung Exp $  */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.80 2004/10/03 22:26:35 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.81 2005/08/05 11:03:18 junyoung Exp $");
 
 #include "opt_kstack.h"
 
@@ -93,6 +93,9 @@
 #include <sys/ras.h>
 #include <sys/sa.h>
 #include <sys/savar.h>
+#include <sys/filedesc.h>
+
+#include <uvm/uvm.h>
 #include <uvm/uvm_extern.h>
 
 /*
@@ -155,6 +158,27 @@
 static uint next_free_pt, last_free_pt;
 static pid_t pid_max = PID_MAX;                /* largest value we allocate */
 
+/* Components of the first process -- never freed. */
+struct session session0;
+struct pgrp pgrp0;
+struct proc proc0;
+struct lwp lwp0;
+struct pcred cred0;
+struct filedesc0 filedesc0;
+struct cwdinfo cwdi0;
+struct plimit limit0;
+struct pstats pstat0;
+struct vmspace vmspace0;
+struct sigacts sigacts0;
+
+extern struct user *proc0paddr;
+
+extern const struct emul emul_netbsd;  /* defined in kern_exec.c */
+
+int nofile = NOFILE;
+int maxuprc = MAXUPRC;
+int cmask = CMASK;
+
 POOL_INIT(proc_pool, sizeof(struct proc), 0, 0, 0, "procpl",
     &pool_allocator_nointr);
 POOL_INIT(lwp_pool, sizeof(struct lwp), 0, 0, 0, "lwppl",
@@ -243,6 +267,129 @@
 }
 
 /*
+ * Initialize process 0.
+ */
+void
+proc0_init(void)
+{
+       struct proc *p;
+       struct pgrp *pg;
+       struct session *sess;
+       struct lwp *l;
+       int s;
+       u_int i;
+       rlim_t lim;
+
+       p = &proc0;
+       pg = &pgrp0;
+       sess = &session0;
+       l = &lwp0;
+
+       simple_lock_init(&p->p_lock);
+       LIST_INIT(&p->p_lwps);
+       LIST_INSERT_HEAD(&p->p_lwps, l, l_sibling);
+       p->p_nlwps = 1;
+       simple_lock_init(&p->p_sigctx.ps_silock);
+       CIRCLEQ_INIT(&p->p_sigctx.ps_siginfo);
+
+       s = proclist_lock_write();
+
+       pid_table[0].pt_proc = p;
+       LIST_INSERT_HEAD(&allproc, p, p_list);
+       LIST_INSERT_HEAD(&alllwp, l, l_list);
+
+       p->p_pgrp = pg;
+       pid_table[0].pt_pgrp = pg;
+       LIST_INIT(&pg->pg_members);
+       LIST_INSERT_HEAD(&pg->pg_members, p, p_pglist);
+
+       pg->pg_session = sess;
+       sess->s_count = 1;
+       sess->s_sid = 0;
+       sess->s_leader = p;
+
+       proclist_unlock_write(s);
+
+       /*
+        * Set P_NOCLDWAIT so that kernel threads are reparented to
+        * init(8) when they exit.  init(8) can easily wait them out
+        * for us.
+        */
+       p->p_flag = P_SYSTEM | P_NOCLDWAIT;
+       p->p_stat = SACTIVE;
+       p->p_nice = NZERO;



Home | Main Index | Thread Index | Old Index