Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Move pid allocation to the bottom of the process al...
details: https://anonhg.NetBSD.org/src/rev/4d5d7e4ab22d
branches: trunk
changeset: 538496:4d5d7e4ab22d
user: christos <christos%NetBSD.org@localhost>
date: Mon Oct 21 17:37:53 2002 +0000
description:
Move pid allocation to the bottom of the process allocation, so that we
don't have to deal with partially initialized proc structs in the scheduler.
Pointed out by: Artur Grabowski and Chuck Silvers.
diffstat:
sys/kern/kern_fork.c | 162 +++++++++++++++++++++++++-------------------------
1 files changed, 81 insertions(+), 81 deletions(-)
diffs (190 lines):
diff -r c469d2c243f7 -r 4d5d7e4ab22d sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c Mon Oct 21 17:07:36 2002 +0000
+++ b/sys/kern/kern_fork.c Mon Oct 21 17:37:53 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_fork.c,v 1.94 2002/09/25 22:21:42 thorpej Exp $ */
+/* $NetBSD: kern_fork.c,v 1.95 2002/10/21 17:37:53 christos Exp $ */
/*-
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.94 2002/09/25 22:21:42 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.95 2002/10/21 17:37:53 christos Exp $");
#include "opt_ktrace.h"
#include "opt_systrace.h"
@@ -250,85 +250,6 @@
p2 = pool_get(&proc_pool, PR_WAITOK);
/*
- * BEGIN PID ALLOCATION.
- */
- s = proclist_lock_write();
-
- /*
- * Find an unused process ID. We remember a range of unused IDs
- * ready to use (from nextpid+1 through pidchecked-1).
- */
- nextpid++;
- retry:
- /*
- * If the process ID prototype has wrapped around,
- * restart somewhat above 0, as the low-numbered procs
- * tend to include daemons that don't exit.
- */
- if (nextpid >= PID_MAX) {
- nextpid = 500;
- pidchecked = 0;
- }
- if (nextpid >= pidchecked) {
- const struct proclist_desc *pd;
-
- pidchecked = PID_MAX;
- /*
- * Scan the process lists to check whether this pid
- * is in use. Remember the lowest pid that's greater
- * than nextpid, so we can avoid checking for a while.
- */
- pd = proclists;
- again:
- LIST_FOREACH(tp, pd->pd_list, p_list) {
- while (tp->p_pid == nextpid ||
- tp->p_pgrp->pg_id == nextpid ||
- tp->p_session->s_sid == nextpid) {
- nextpid++;
- if (nextpid >= pidchecked)
- goto retry;
- }
- if (tp->p_pid > nextpid && pidchecked > tp->p_pid)
- pidchecked = tp->p_pid;
-
- if (tp->p_pgrp->pg_id > nextpid &&
- pidchecked > tp->p_pgrp->pg_id)
- pidchecked = tp->p_pgrp->pg_id;
-
- if (tp->p_session->s_sid > nextpid &&
- pidchecked > tp->p_session->s_sid)
- pidchecked = tp->p_session->s_sid;
- }
-
- /*
- * If there's another list, scan it. If we have checked
- * them all, we've found one!
- */
- pd++;
- if (pd->pd_list != NULL)
- goto again;
- }
-
- /*
- * Put the proc on allproc before unlocking PID allocation
- * so that waiters won't grab it as soon as we unlock.
- */
-
- p2->p_stat = SIDL; /* protect against others */
- p2->p_pid = nextpid;
- p2->p_exitsig = exitsig; /* signal for parent on exit */
- p2->p_forw = p2->p_back = NULL; /* shouldn't be necessary */
-
- LIST_INSERT_HEAD(&allproc, p2, p_list);
-
- LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
-
- /*
- * END PID ALLOCATION.
- */
- proclist_unlock_write(s);
-
- /*
* Make a proc table entry for the new process.
* Start by zeroing the section of proc that is zero-initialized,
* then copy the section that is copied directly from the parent.
@@ -471,6 +392,85 @@
(arg != NULL) ? arg : p2);
/*
+ * BEGIN PID ALLOCATION.
+ */
+ s = proclist_lock_write();
+
+ /*
+ * Find an unused process ID. We remember a range of unused IDs
+ * ready to use (from nextpid+1 through pidchecked-1).
+ */
+ nextpid++;
+ retry:
+ /*
+ * If the process ID prototype has wrapped around,
+ * restart somewhat above 0, as the low-numbered procs
+ * tend to include daemons that don't exit.
+ */
+ if (nextpid >= PID_MAX) {
+ nextpid = 500;
+ pidchecked = 0;
+ }
+ if (nextpid >= pidchecked) {
+ const struct proclist_desc *pd;
+
+ pidchecked = PID_MAX;
+ /*
+ * Scan the process lists to check whether this pid
+ * is in use. Remember the lowest pid that's greater
+ * than nextpid, so we can avoid checking for a while.
+ */
+ pd = proclists;
+ again:
+ LIST_FOREACH(tp, pd->pd_list, p_list) {
+ while (tp->p_pid == nextpid ||
+ tp->p_pgrp->pg_id == nextpid ||
+ tp->p_session->s_sid == nextpid) {
+ nextpid++;
+ if (nextpid >= pidchecked)
+ goto retry;
+ }
+ if (tp->p_pid > nextpid && pidchecked > tp->p_pid)
+ pidchecked = tp->p_pid;
+
+ if (tp->p_pgrp->pg_id > nextpid &&
+ pidchecked > tp->p_pgrp->pg_id)
+ pidchecked = tp->p_pgrp->pg_id;
+
+ if (tp->p_session->s_sid > nextpid &&
+ pidchecked > tp->p_session->s_sid)
+ pidchecked = tp->p_session->s_sid;
+ }
+
+ /*
+ * If there's another list, scan it. If we have checked
+ * them all, we've found one!
+ */
+ pd++;
+ if (pd->pd_list != NULL)
+ goto again;
+ }
+
+ /*
+ * Put the proc on allproc before unlocking PID allocation
+ * so that waiters won't grab it as soon as we unlock.
+ */
+
+ p2->p_stat = SIDL; /* protect against others */
+ p2->p_pid = nextpid;
+ p2->p_exitsig = exitsig; /* signal for parent on exit */
+ p2->p_forw = p2->p_back = NULL; /* shouldn't be necessary */
+
+ LIST_INSERT_HEAD(&allproc, p2, p_list);
+
+ LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
+
+ /*
+ * END PID ALLOCATION.
+ */
+ proclist_unlock_write(s);
+
+ /*
* Make child runnable, set start time, and add to run queue.
*/
SCHED_LOCK(s);
Home |
Main Index |
Thread Index |
Old Index