Source-Changes-HG archive

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

[src/trunk]: src/sys - Count number of zombies and stopped children and reque...



details:   https://anonhg.NetBSD.org/src/rev/b39622662472
branches:  trunk
changeset: 555260:b39622662472
user:      dsl <dsl%NetBSD.org@localhost>
date:      Wed Nov 12 21:07:37 2003 +0000

description:
- Count number of zombies and stopped children and requeue them at the top
  of the sibling list so that find_stopped_child can be optimised to avoid
  traversing the entire sibling list - helps when a process has a lot of
  children.
- Modify locking in pfind() and pgfind() to that the caller can rely on the
  result being valid, allow caller to request that zombies be findable.
- Rename pfind() to p_find() to ensure we break binary compatibility.
- Remove svr4_pfind since p_find willnow do the job.
- Modify some of the SMP locking of the proc lists - signals are still stuffed.

Welcome to 1.6ZF

diffstat:

 sys/compat/svr4/svr4_misc.c       |   29 +--------
 sys/compat/svr4_32/svr4_32_misc.c |   29 +--------
 sys/kern/kern_exec.c              |    5 +-
 sys/kern/kern_exit.c              |  123 +++++++++++++++++++++++--------------
 sys/kern/kern_fork.c              |   12 ++-
 sys/kern/kern_ktrace.c            |   15 ++-
 sys/kern/kern_proc.c              |   70 ++++++++++++--------
 sys/kern/kern_sig.c               |   11 ++-
 sys/sys/param.h                   |    4 +-
 sys/sys/proc.h                    |   29 ++++++--
 10 files changed, 173 insertions(+), 154 deletions(-)

diffs (truncated from 759 to 300 lines):

diff -r 5909e546a726 -r b39622662472 sys/compat/svr4/svr4_misc.c
--- a/sys/compat/svr4/svr4_misc.c       Wed Nov 12 20:38:24 2003 +0000
+++ b/sys/compat/svr4/svr4_misc.c       Wed Nov 12 21:07:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svr4_misc.c,v 1.106 2003/06/29 22:29:47 fvdl Exp $      */
+/*     $NetBSD: svr4_misc.c,v 1.107 2003/11/12 21:07:37 dsl Exp $       */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.106 2003/06/29 22:29:47 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.107 2003/11/12 21:07:37 dsl Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -114,7 +114,7 @@
     struct svr4_statvfs *));
 static void bsd_statfs_to_svr4_statvfs64 __P((const struct statfs *,
     struct svr4_statvfs64 *));
-static struct proc *svr4_pfind __P((pid_t pid));
+#define svr4_pfind(pid) p_find((pid), PFIND_UNLOCK | PFIND_ZOMBIE)
 
 static int svr4_mknod __P((struct lwp *, register_t *, const char *,
     svr4_mode_t, svr4_dev_t));
@@ -946,29 +946,6 @@
 }
 
 
-static struct proc *
-svr4_pfind(pid)
-       pid_t pid;
-{
-       struct proc *p = NULL;
-
-       proclist_lock_read();
-
-       /* look in the live processes */
-       if ((p = pfind(pid)) != NULL)
-               goto out;
-
-       /* look in the zombies */
-       for (p = zombproc.lh_first; p != 0; p = p->p_list.le_next)
-               if (p->p_pid == pid)
-                       goto out;
-
- out:
-       proclist_unlock_read();
-       return p;
-}
-
-
 int
 svr4_sys_pgrpsys(l, v, retval)
        struct lwp *l;
diff -r 5909e546a726 -r b39622662472 sys/compat/svr4_32/svr4_32_misc.c
--- a/sys/compat/svr4_32/svr4_32_misc.c Wed Nov 12 20:38:24 2003 +0000
+++ b/sys/compat/svr4_32/svr4_32_misc.c Wed Nov 12 21:07:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svr4_32_misc.c,v 1.24 2003/10/21 09:02:50 petrov Exp $  */
+/*     $NetBSD: svr4_32_misc.c,v 1.25 2003/11/12 21:07:38 dsl Exp $     */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.24 2003/10/21 09:02:50 petrov Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.25 2003/11/12 21:07:38 dsl Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -114,7 +114,7 @@
     struct svr4_32_statvfs *));
 static void bsd_statfs_to_svr4_32_statvfs64 __P((const struct statfs *,
     struct svr4_32_statvfs64 *));
-static struct proc *svr4_32_pfind __P((pid_t pid));
+#define svr4_32_pfind(pid) p_find((pid), PFIND_UNLOCK | PFIND_ZOMBIE)
 
 static int svr4_32_mknod __P((struct lwp *, register_t *, const char *,
     svr4_32_mode_t, svr4_32_dev_t));
@@ -962,29 +962,6 @@
 }
 
 
-static struct proc *
-svr4_32_pfind(pid)
-       pid_t pid;
-{
-       struct proc *p = NULL;
-
-       proclist_lock_read();
-
-       /* look in the live processes */
-       if ((p = pfind(pid)) != NULL)
-               goto out;
-
-       /* look in the zombies */
-       for (p = zombproc.lh_first; p != 0; p = p->p_list.le_next)
-               if (p->p_pid == pid)
-                       goto out;
-
- out:
-       proclist_unlock_read();
-       return p;
-}
-
-
 int
 svr4_32_sys_pgrpsys(l, v, retval)
        struct lwp *l;
diff -r 5909e546a726 -r b39622662472 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Wed Nov 12 20:38:24 2003 +0000
+++ b/sys/kern/kern_exec.c      Wed Nov 12 21:07:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.174 2003/09/15 00:33:35 christos Exp $ */
+/*     $NetBSD: kern_exec.c,v 1.175 2003/11/12 21:07:38 dsl Exp $      */
 
 /*-
  * Copyright (C) 1993, 1994, 1996 Christopher G. Demetriou
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.174 2003/09/15 00:33:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.175 2003/11/12 21:07:38 dsl Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_syscall_debug.h"
@@ -819,6 +819,7 @@
 
                sigminusset(&contsigmask, &p->p_sigctx.ps_siglist);
                SCHED_LOCK(s);
+               p->p_pptr->p_nstopchild++;
                p->p_stat = SSTOP;
                l->l_stat = LSSTOP;
                p->p_nrlwps--;
diff -r 5909e546a726 -r b39622662472 sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c      Wed Nov 12 20:38:24 2003 +0000
+++ b/sys/kern/kern_exit.c      Wed Nov 12 21:07:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exit.c,v 1.127 2003/11/06 09:30:13 dsl Exp $      */
+/*     $NetBSD: kern_exit.c,v 1.128 2003/11/12 21:07:38 dsl Exp $      */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.127 2003/11/06 09:30:13 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.128 2003/11/12 21:07:38 dsl Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_perfctrs.h"
@@ -308,6 +308,22 @@
                (*p->p_emul->e_proc_exit)(p);
 
        /*
+        * Reset p_opptr pointer of all former children which got
+        * traced by another process and were reparented. We reset
+        * it to NULL here; the trace detach code then reparents
+        * the child to initproc. We only check allproc list, since
+        * eventual former children on zombproc list won't reference
+        * p_opptr anymore.
+        */
+       s = proclist_lock_write();
+       if (p->p_flag & P_CHTRACED) {
+               LIST_FOREACH(q, &allproc, p_list) {
+                       if (q->p_opptr == p)
+                               q->p_opptr = NULL;
+               }
+       }
+
+       /*
         * Give orphaned children to init(8).
         */
        q = LIST_FIRST(&p->p_children);
@@ -336,27 +352,7 @@
                        proc_reparent(q, initproc);
                }
        }
-
-       /*
-        * Reset p_opptr pointer of all former children which got
-        * traced by another process and were reparented. We reset
-        * it to NULL here; the trace detach code then reparents
-        * the child to initproc. We only check allproc list, since
-        * eventual former children on zombproc list won't reference
-        * p_opptr anymore.
-        */
-       if (p->p_flag & P_CHTRACED) {
-               struct proc *t;
-
-               proclist_lock_read();
-
-               LIST_FOREACH(t, &allproc, p_list) {
-                       if (t->p_opptr == p)
-                               t->p_opptr = NULL;
-               }
-
-               proclist_unlock_read();
-       }
+       proclist_unlock_write(s);
 
        /*
         * Save exit status and final rusage info, adding in child rusage
@@ -501,7 +497,7 @@
         */
        LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
                l2->l_flag &= ~(L_DETACHED|L_SA);
-       
+
                if (l2->l_wchan == &l2->l_upcallstack)
                        wakeup(&l2->l_upcallstack);
 
@@ -570,7 +566,7 @@
 void
 reaper(void *arg)
 {
-       struct proc *p;
+       struct proc *p, *parent;
        struct lwp *l;
 
        KERNEL_PROC_UNLOCK(curlwp);
@@ -636,6 +632,14 @@
                        
                        /* Process is now a true zombie. */
                        p->p_stat = SZOMB;
+                       parent = p->p_pptr;
+                       parent->p_nstopchild++;
+                       if (LIST_FIRST(&parent->p_children) != p) {
+                               /* Put child where it can be found quickly */
+                               LIST_REMOVE(p, p_sibling);
+                               LIST_INSERT_HEAD(&parent->p_children,
+                                               p, p_sibling);
+                       }
                        
                        /* Wake up the parent so it can get exit status. */
                        if ((p->p_flag & P_FSTRACE) == 0 && p->p_exitsig != 0)
@@ -698,7 +702,7 @@
        /* child state must be SSTOP */
        if (SCARG(uap, status)) {
                status = W_STOPCODE(child->p_xstat);
-               return copyout(&status, SCARG(uap, status), sizeof (status));
+               return copyout(&status, SCARG(uap, status), sizeof(status));
        }
        return 0;
 }
@@ -712,15 +716,26 @@
        struct proc **child_p)
 {
        struct proc *child;
-       int c_found, error;
+       int error;
 
        for (;;) {
-               c_found = 0;
+               proclist_lock_read();
+               error = ECHILD;
                LIST_FOREACH(child, &parent->p_children, p_sibling) {
-                       if (pid != WAIT_ANY &&
-                           child->p_pid != pid &&
-                           child->p_pgid != -pid)
-                               continue;
+                       if (pid >= 0) {
+                               if (child->p_pid != pid) {
+                                       child = p_find(pid, PFIND_ZOMBIE |
+                                                               PFIND_LOCKED);
+                                       if (child == NULL
+                                           || child->p_pptr != parent) {
+                                               child = NULL;
+                                               break;
+                                       }
+                               }
+                       } else
+                               if (pid != WAIT_ANY && child->p_pgid != -pid)
+                                       /* child not in correct pgrp */
+                                       continue;
                        /*
                         * Wait for processes with p_exitsig != SIGCHLD
                         * processes only if WALTSIG is set; wait for
@@ -729,30 +744,36 @@
                         */
                        if (((options & WALLSIG) == 0) &&
                            (options & WALTSIG ? child->p_exitsig == SIGCHLD
-                                               : P_EXITSIG(child) != SIGCHLD))
+                                               : P_EXITSIG(child) != SIGCHLD)){
+                               if (child->p_pid == pid) {
+                                       child = NULL;
+                                       break;
+                               }
                                continue;
+                       }
 
-                       c_found = 1;
-                       if (child->p_stat == SZOMB &&



Home | Main Index | Thread Index | Old Index