Pull up following revision(s) (requested by pgoyette in ticket #1979): sys/kern/kern_synch.c: revision 1.309 sys/kern/kern_exit.c: revisions 1.246, 1.247 sys/kern/kern_exec.c: revision 1.419 In execve_runproc(), update the p_waited entry for the process being moved to SSTOP state, not for its parent. (It is correct to update the parent's p_nstopchild count.) If the value is not already zero, it could prevent its parent from waiting for the process. Fixes PR kern/50298 -- When clearing out the scheduler queues during system shutdown, we move all processes to the SSTOP state. Make sure we update each process's p_waited and the parents' p_nstopchild counters to maintain consistent values. Should not make any real difference this late in the shutdown process, but we should still be consistent just in case. Fixes PR kern/50318 -- Currently, if a process is exiting and its parent has indicated no intent of reaping the process (nor any other children), the process wil get reparented to init. Since the state of the exiting process at this point is SDEAD, proc_reparent() will not update either the old or new parent's p_nstopchild counters. This change causes both old and new parents to be properly updated. Fixes PR kern/50300 -- For processes marked with PS_STOPEXIT, update the process's p_waited value, and update its parent's p_nstopchild value when marking the process's p_stat to SSTOP. The process needed to be SACTIVE to get here, so this transition represents an additional process for which the parent needs to wait. Fixes PR kern/50308diff -r1.280.4.3 -r1.280.4.4 src/sys/kern/kern_exec.c
(snj)
--- src/sys/kern/kern_exec.c 2009/04/01 21:03:04 1.280.4.3
+++ src/sys/kern/kern_exec.c 2015/11/07 20:43:23 1.280.4.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: kern_exec.c,v 1.280.4.3 2009/04/01 21:03:04 snj Exp $ */ | 1 | /* $NetBSD: kern_exec.c,v 1.280.4.4 2015/11/07 20:43:23 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -49,27 +49,27 @@ | @@ -49,27 +49,27 @@ | |||
49 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | 49 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | |
50 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 50 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
51 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 51 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
52 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 52 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
53 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 53 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
54 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 54 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
55 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 55 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
56 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 56 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
57 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 57 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
58 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 58 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
59 | */ | 59 | */ | |
60 | 60 | |||
61 | #include <sys/cdefs.h> | 61 | #include <sys/cdefs.h> | |
62 | __KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.280.4.3 2009/04/01 21:03:04 snj Exp $"); | 62 | __KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.280.4.4 2015/11/07 20:43:23 snj Exp $"); | |
63 | 63 | |||
64 | #include "opt_ktrace.h" | 64 | #include "opt_ktrace.h" | |
65 | #include "opt_syscall_debug.h" | 65 | #include "opt_syscall_debug.h" | |
66 | #include "opt_compat_netbsd.h" | 66 | #include "opt_compat_netbsd.h" | |
67 | #include "veriexec.h" | 67 | #include "veriexec.h" | |
68 | #include "opt_pax.h" | 68 | #include "opt_pax.h" | |
69 | #include "opt_sa.h" | 69 | #include "opt_sa.h" | |
70 | 70 | |||
71 | #include <sys/param.h> | 71 | #include <sys/param.h> | |
72 | #include <sys/systm.h> | 72 | #include <sys/systm.h> | |
73 | #include <sys/filedesc.h> | 73 | #include <sys/filedesc.h> | |
74 | #include <sys/kernel.h> | 74 | #include <sys/kernel.h> | |
75 | #include <sys/proc.h> | 75 | #include <sys/proc.h> | |
@@ -1094,27 +1094,27 @@ execve1(struct lwp *l, const char *path, | @@ -1094,27 +1094,27 @@ execve1(struct lwp *l, const char *path, | |||
1094 | 1094 | |||
1095 | mutex_enter(proc_lock); | 1095 | mutex_enter(proc_lock); | |
1096 | 1096 | |||
1097 | if ((p->p_slflag & (PSL_TRACED|PSL_SYSCALL)) == PSL_TRACED) { | 1097 | if ((p->p_slflag & (PSL_TRACED|PSL_SYSCALL)) == PSL_TRACED) { | |
1098 | KSI_INIT_EMPTY(&ksi); | 1098 | KSI_INIT_EMPTY(&ksi); | |
1099 | ksi.ksi_signo = SIGTRAP; | 1099 | ksi.ksi_signo = SIGTRAP; | |
1100 | ksi.ksi_lid = l->l_lid; | 1100 | ksi.ksi_lid = l->l_lid; | |
1101 | kpsignal(p, &ksi, NULL); | 1101 | kpsignal(p, &ksi, NULL); | |
1102 | } | 1102 | } | |
1103 | 1103 | |||
1104 | if (p->p_sflag & PS_STOPEXEC) { | 1104 | if (p->p_sflag & PS_STOPEXEC) { | |
1105 | KERNEL_UNLOCK_ALL(l, &l->l_biglocks); | 1105 | KERNEL_UNLOCK_ALL(l, &l->l_biglocks); | |
1106 | p->p_pptr->p_nstopchild++; | 1106 | p->p_pptr->p_nstopchild++; | |
1107 | p->p_pptr->p_waited = 0; | 1107 | p->p_waited = 0; | |
1108 | mutex_enter(p->p_lock); | 1108 | mutex_enter(p->p_lock); | |
1109 | ksiginfo_queue_init(&kq); | 1109 | ksiginfo_queue_init(&kq); | |
1110 | sigclearall(p, &contsigmask, &kq); | 1110 | sigclearall(p, &contsigmask, &kq); | |
1111 | lwp_lock(l); | 1111 | lwp_lock(l); | |
1112 | l->l_stat = LSSTOP; | 1112 | l->l_stat = LSSTOP; | |
1113 | p->p_stat = SSTOP; | 1113 | p->p_stat = SSTOP; | |
1114 | p->p_nrlwps--; | 1114 | p->p_nrlwps--; | |
1115 | mutex_exit(p->p_lock); | 1115 | mutex_exit(p->p_lock); | |
1116 | mutex_exit(proc_lock); | 1116 | mutex_exit(proc_lock); | |
1117 | mi_switch(l); | 1117 | mi_switch(l); | |
1118 | ksiginfo_queue_drain(&kq); | 1118 | ksiginfo_queue_drain(&kq); | |
1119 | KERNEL_LOCK(l->l_biglocks, l); | 1119 | KERNEL_LOCK(l->l_biglocks, l); | |
1120 | } else { | 1120 | } else { |
--- src/sys/kern/kern_exit.c 2009/07/01 22:30:30 1.214.4.2
+++ src/sys/kern/kern_exit.c 2015/11/07 20:43:23 1.214.4.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: kern_exit.c,v 1.214.4.2 2009/07/01 22:30:30 snj Exp $ */ | 1 | /* $NetBSD: kern_exit.c,v 1.214.4.3 2015/11/07 20:43:23 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | |
9 | * NASA Ames Research Center, and by Andrew Doran. | 9 | * NASA Ames Research Center, and by Andrew Doran. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -57,27 +57,27 @@ | @@ -57,27 +57,27 @@ | |||
57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
64 | * SUCH DAMAGE. | 64 | * SUCH DAMAGE. | |
65 | * | 65 | * | |
66 | * @(#)kern_exit.c 8.10 (Berkeley) 2/23/95 | 66 | * @(#)kern_exit.c 8.10 (Berkeley) 2/23/95 | |
67 | */ | 67 | */ | |
68 | 68 | |||
69 | #include <sys/cdefs.h> | 69 | #include <sys/cdefs.h> | |
70 | __KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.214.4.2 2009/07/01 22:30:30 snj Exp $"); | 70 | __KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.214.4.3 2015/11/07 20:43:23 snj Exp $"); | |
71 | 71 | |||
72 | #include "opt_ktrace.h" | 72 | #include "opt_ktrace.h" | |
73 | #include "opt_perfctrs.h" | 73 | #include "opt_perfctrs.h" | |
74 | #include "opt_sa.h" | 74 | #include "opt_sa.h" | |
75 | #include "opt_sysv.h" | 75 | #include "opt_sysv.h" | |
76 | 76 | |||
77 | #include <sys/param.h> | 77 | #include <sys/param.h> | |
78 | #include <sys/aio.h> | 78 | #include <sys/aio.h> | |
79 | #include <sys/systm.h> | 79 | #include <sys/systm.h> | |
80 | #include <sys/ioctl.h> | 80 | #include <sys/ioctl.h> | |
81 | #include <sys/tty.h> | 81 | #include <sys/tty.h> | |
82 | #include <sys/time.h> | 82 | #include <sys/time.h> | |
83 | #include <sys/resource.h> | 83 | #include <sys/resource.h> | |
@@ -224,28 +224,35 @@ exit1(struct lwp *l, int rv) | @@ -224,28 +224,35 @@ exit1(struct lwp *l, int rv) | |||
224 | * begin to tear down the rest of the process state. | 224 | * begin to tear down the rest of the process state. | |
225 | */ | 225 | */ | |
226 | if (sa || p->p_nlwps > 1) | 226 | if (sa || p->p_nlwps > 1) | |
227 | exit_lwps(l); | 227 | exit_lwps(l); | |
228 | 228 | |||
229 | ksiginfo_queue_init(&kq); | 229 | ksiginfo_queue_init(&kq); | |
230 | 230 | |||
231 | /* | 231 | /* | |
232 | * If we have been asked to stop on exit, do so now. | 232 | * If we have been asked to stop on exit, do so now. | |
233 | */ | 233 | */ | |
234 | if (__predict_false(p->p_sflag & PS_STOPEXIT)) { | 234 | if (__predict_false(p->p_sflag & PS_STOPEXIT)) { | |
235 | KERNEL_UNLOCK_ALL(l, &l->l_biglocks); | 235 | KERNEL_UNLOCK_ALL(l, &l->l_biglocks); | |
236 | sigclearall(p, &contsigmask, &kq); | 236 | sigclearall(p, &contsigmask, &kq); | |
237 | ||||
238 | if (!mutex_tryenter(proc_lock)) { | |||
239 | mutex_exit(p->p_lock); | |||
240 | mutex_enter(proc_lock); | |||
241 | mutex_enter(p->p_lock); | |||
242 | } | |||
237 | p->p_waited = 0; | 243 | p->p_waited = 0; | |
238 | membar_producer(); | 244 | p->p_pptr->p_nstopchild++; | |
245 | mutex_exit(proc_lock); | |||
239 | p->p_stat = SSTOP; | 246 | p->p_stat = SSTOP; | |
240 | lwp_lock(l); | 247 | lwp_lock(l); | |
241 | p->p_nrlwps--; | 248 | p->p_nrlwps--; | |
242 | l->l_stat = LSSTOP; | 249 | l->l_stat = LSSTOP; | |
243 | mutex_exit(p->p_lock); | 250 | mutex_exit(p->p_lock); | |
244 | mi_switch(l); | 251 | mi_switch(l); | |
245 | KERNEL_LOCK(l->l_biglocks, l); | 252 | KERNEL_LOCK(l->l_biglocks, l); | |
246 | mutex_enter(p->p_lock); | 253 | mutex_enter(p->p_lock); | |
247 | } | 254 | } | |
248 | 255 | |||
249 | /* | 256 | /* | |
250 | * Bin any remaining signals and mark the process as dying so it will | 257 | * Bin any remaining signals and mark the process as dying so it will | |
251 | * not be found for, e.g. signals. | 258 | * not be found for, e.g. signals. | |
@@ -1001,26 +1008,26 @@ proc_free(struct proc *p, struct rusage | @@ -1001,26 +1008,26 @@ proc_free(struct proc *p, struct rusage | |||
1001 | * make process 'parent' the new parent of process 'child'. | 1008 | * make process 'parent' the new parent of process 'child'. | |
1002 | * | 1009 | * | |
1003 | * Must be called with proc_lock held. | 1010 | * Must be called with proc_lock held. | |
1004 | */ | 1011 | */ | |
1005 | void | 1012 | void | |
1006 | proc_reparent(struct proc *child, struct proc *parent) | 1013 | proc_reparent(struct proc *child, struct proc *parent) | |
1007 | { | 1014 | { | |
1008 | 1015 | |||
1009 | KASSERT(mutex_owned(proc_lock)); | 1016 | KASSERT(mutex_owned(proc_lock)); | |
1010 | 1017 | |||
1011 | if (child->p_pptr == parent) | 1018 | if (child->p_pptr == parent) | |
1012 | return; | 1019 | return; | |
1013 | 1020 | |||
1014 | if (child->p_stat == SZOMB || | 1021 | if (child->p_stat == SZOMB || child->p_stat == SDEAD || | |
1015 | (child->p_stat == SSTOP && !child->p_waited)) { | 1022 | (child->p_stat == SSTOP && !child->p_waited)) { | |
1016 | child->p_pptr->p_nstopchild--; | 1023 | child->p_pptr->p_nstopchild--; | |
1017 | parent->p_nstopchild++; | 1024 | parent->p_nstopchild++; | |
1018 | } | 1025 | } | |
1019 | if (parent == initproc) | 1026 | if (parent == initproc) | |
1020 | child->p_exitsig = SIGCHLD; | 1027 | child->p_exitsig = SIGCHLD; | |
1021 | 1028 | |||
1022 | LIST_REMOVE(child, p_sibling); | 1029 | LIST_REMOVE(child, p_sibling); | |
1023 | LIST_INSERT_HEAD(&parent->p_children, child, p_sibling); | 1030 | LIST_INSERT_HEAD(&parent->p_children, child, p_sibling); | |
1024 | child->p_pptr = parent; | 1031 | child->p_pptr = parent; | |
1025 | child->p_ppid = parent->p_pid; | 1032 | child->p_ppid = parent->p_pid; | |
1026 | } | 1033 | } |
--- src/sys/kern/kern_synch.c 2009/04/23 17:47:13 1.254.2.6
+++ src/sys/kern/kern_synch.c 2015/11/07 20:43:23 1.254.2.7
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: kern_synch.c,v 1.254.2.6 2009/04/23 17:47:13 snj Exp $ */ | 1 | /* $NetBSD: kern_synch.c,v 1.254.2.7 2015/11/07 20:43:23 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009 | 4 | * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009 | |
5 | * The NetBSD Foundation, Inc. | 5 | * The NetBSD Foundation, Inc. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * This code is derived from software contributed to The NetBSD Foundation | 8 | * This code is derived from software contributed to The NetBSD Foundation | |
9 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | 9 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | |
10 | * NASA Ames Research Center, by Charles M. Hannum, Andrew Doran and | 10 | * NASA Ames Research Center, by Charles M. Hannum, Andrew Doran and | |
11 | * Daniel Sieger. | 11 | * Daniel Sieger. | |
12 | * | 12 | * | |
13 | * Redistribution and use in source and binary forms, with or without | 13 | * Redistribution and use in source and binary forms, with or without | |
14 | * modification, are permitted provided that the following conditions | 14 | * modification, are permitted provided that the following conditions | |
@@ -59,27 +59,27 @@ | @@ -59,27 +59,27 @@ | |||
59 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 59 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
60 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 60 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
61 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 61 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
62 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 62 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
63 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 63 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
64 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 64 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
65 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 65 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
66 | * SUCH DAMAGE. | 66 | * SUCH DAMAGE. | |
67 | * | 67 | * | |
68 | * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95 | 68 | * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95 | |
69 | */ | 69 | */ | |
70 | 70 | |||
71 | #include <sys/cdefs.h> | 71 | #include <sys/cdefs.h> | |
72 | __KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.254.2.6 2009/04/23 17:47:13 snj Exp $"); | 72 | __KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.254.2.7 2015/11/07 20:43:23 snj Exp $"); | |
73 | 73 | |||
74 | #include "opt_kstack.h" | 74 | #include "opt_kstack.h" | |
75 | #include "opt_perfctrs.h" | 75 | #include "opt_perfctrs.h" | |
76 | #include "opt_sa.h" | 76 | #include "opt_sa.h" | |
77 | 77 | |||
78 | #define __MUTEX_PRIVATE | 78 | #define __MUTEX_PRIVATE | |
79 | 79 | |||
80 | #include <sys/param.h> | 80 | #include <sys/param.h> | |
81 | #include <sys/systm.h> | 81 | #include <sys/systm.h> | |
82 | #include <sys/proc.h> | 82 | #include <sys/proc.h> | |
83 | #include <sys/kernel.h> | 83 | #include <sys/kernel.h> | |
84 | #if defined(PERFCTRS) | 84 | #if defined(PERFCTRS) | |
85 | #include <sys/pmc.h> | 85 | #include <sys/pmc.h> | |
@@ -1018,27 +1018,33 @@ suspendsched(void) | @@ -1018,27 +1018,33 @@ suspendsched(void) | |||
1018 | * We do this by process in order not to violate the locking rules. | 1018 | * We do this by process in order not to violate the locking rules. | |
1019 | */ | 1019 | */ | |
1020 | mutex_enter(proc_lock); | 1020 | mutex_enter(proc_lock); | |
1021 | PROCLIST_FOREACH(p, &allproc) { | 1021 | PROCLIST_FOREACH(p, &allproc) { | |
1022 | if ((p->p_flag & PK_MARKER) != 0) | 1022 | if ((p->p_flag & PK_MARKER) != 0) | |
1023 | continue; | 1023 | continue; | |
1024 | 1024 | |||
1025 | mutex_enter(p->p_lock); | 1025 | mutex_enter(p->p_lock); | |
1026 | if ((p->p_flag & PK_SYSTEM) != 0) { | 1026 | if ((p->p_flag & PK_SYSTEM) != 0) { | |
1027 | mutex_exit(p->p_lock); | 1027 | mutex_exit(p->p_lock); | |
1028 | continue; | 1028 | continue; | |
1029 | } | 1029 | } | |
1030 | 1030 | |||
1031 | p->p_stat = SSTOP; | 1031 | if (p->p_stat != SSTOP) { | |
1032 | if (p->p_stat != SZOMB && p->p_stat != SDEAD) { | |||
1033 | p->p_pptr->p_nstopchild++; | |||
1034 | p->p_waited = 0; | |||
1035 | } | |||
1036 | p->p_stat = SSTOP; | |||
1037 | } | |||
1032 | 1038 | |||
1033 | LIST_FOREACH(l, &p->p_lwps, l_sibling) { | 1039 | LIST_FOREACH(l, &p->p_lwps, l_sibling) { | |
1034 | if (l == curlwp) | 1040 | if (l == curlwp) | |
1035 | continue; | 1041 | continue; | |
1036 | 1042 | |||
1037 | lwp_lock(l); | 1043 | lwp_lock(l); | |
1038 | 1044 | |||
1039 | /* | 1045 | /* | |
1040 | * Set L_WREBOOT so that the LWP will suspend itself | 1046 | * Set L_WREBOOT so that the LWP will suspend itself | |
1041 | * when it tries to return to user mode. We want to | 1047 | * when it tries to return to user mode. We want to | |
1042 | * try and get to get as many LWPs as possible to | 1048 | * try and get to get as many LWPs as possible to | |
1043 | * the user / kernel boundary, so that they will | 1049 | * the user / kernel boundary, so that they will | |
1044 | * release any locks that they hold. | 1050 | * release any locks that they hold. |