Hi Alan,
This patch does:
a) introduce hash_process(p) inline for symmetry with unhash_process(p)
b) removes lastpid_lock spinlock as it is not needed - get_pid() is only
ever called from do_fork() global kernel lock held
c) makes get_pid(void) - the CLONE_PID flag is so rarely used (every
reboot) that it seems silly to always pass an extra argument to
get_pid() - instead, the check can be made by the caller (and it was
made earlier already so perhaps the compiler can do some magic about
it) and get_pid() should be as fast as possible.
d) setting p->state = TASK_UNINTERRUPTBLE in do_fork() removed as it
seems to serve no purpose. (except to prevent the scheduler from
picking up a child which is not ready to do anything yet - but surely
this is prevented from happening by some other means, no?)
Regards,
Tigran
--- linux/kernel/fork.c Wed Jun 14 13:38:34 2000
+++ work/kernel/fork.c Tue Jun 20 12:46:34 2000
@@ -183,18 +183,11 @@
init_task.rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
}
-/* Protects next_safe and last_pid. */
-spinlock_t lastpid_lock = SPIN_LOCK_UNLOCKED;
-
-static int get_pid(unsigned long flags)
+static int get_pid(void)
{
static int next_safe = PID_MAX;
struct task_struct *p;
- if (flags & CLONE_PID)
- return current->pid;
-
- spin_lock(&lastpid_lock);
if((++last_pid) & 0xffff8000) {
last_pid = 300; /* Skip daemons etc. */
goto inside;
@@ -224,7 +217,6 @@
}
read_unlock(&tasklist_lock);
}
- spin_unlock(&lastpid_lock);
return last_pid;
}
@@ -609,6 +601,15 @@
p->flags = new_flags;
}
+static inline void hash_process(struct task_struct *p)
+{
+ write_lock_irq(&tasklist_lock);
+ SET_LINKS(p);
+ hash_pid(p);
+ nr_threads++;
+ write_unlock_irq(&tasklist_lock);
+}
+
/*
* Ok, this is the main fork-routine. It copies the system process
* information (task[nr]) and sets up the necessary registers. It
@@ -658,10 +659,11 @@
p->did_exec = 0;
p->swappable = 0;
- p->state = TASK_UNINTERRUPTIBLE;
-
copy_flags(clone_flags, p);
- p->pid = get_pid(clone_flags);
+ if (flags & CLONE_PID)
+ p->pid = current->pid;
+ else
+ p->pid = get_pid();
/*
* This is a "shadow run" state. The process
@@ -754,12 +756,7 @@
* Let it rip!
*/
retval = p->pid;
- write_lock_irq(&tasklist_lock);
- SET_LINKS(p);
- hash_pid(p);
- nr_threads++;
- write_unlock_irq(&tasklist_lock);
-
+ hash_process(p);
wake_up_process(p); /* do this last */
++total_forks;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Fri Jun 23 2000 - 21:00:19 EST