Index: kern_exit.c =================================================================== RCS file: /usr/cvs/src/sys/kern/kern_exit.c,v retrieving revision 1.285 diff -u -r1.285 kern_exit.c --- kern_exit.c 22 Feb 2006 18:57:49 -0000 1.285 +++ kern_exit.c 28 Feb 2006 17:00:58 -0000 @@ -110,7 +110,6 @@ void exit1(struct thread *td, int rv) { - uint64_t new_switchtime; struct proc *p, *nq, *q; struct tty *tp; struct vnode *ttyvp; @@ -557,19 +556,6 @@ p->p_state = PRS_ZOMBIE; PROC_UNLOCK(p->p_pptr); - /* Do the same timestamp bookkeeping that mi_switch() would do. */ - new_switchtime = cpu_ticks(); - p->p_rux.rux_runtime += (new_switchtime - PCPU_GET(switchtime)); - p->p_rux.rux_uticks += td->td_uticks; - p->p_rux.rux_sticks += td->td_sticks; - p->p_rux.rux_iticks += td->td_iticks; - PCPU_SET(switchtime, new_switchtime); - PCPU_SET(switchticks, ticks); - cnt.v_swtch++; - - /* Add our usage into the usage of all our children. */ - ruadd(p->p_ru, &p->p_rux, &p->p_stats->p_cru, &p->p_crux); - sched_exit(p->p_pptr, td); /* Index: kern_thread.c =================================================================== RCS file: /usr/cvs/src/sys/kern/kern_thread.c,v retrieving revision 1.229 diff -u -r1.229 kern_thread.c --- kern_thread.c 15 Feb 2006 23:52:01 -0000 1.229 +++ kern_thread.c 28 Feb 2006 17:01:54 -0000 @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -457,6 +458,7 @@ struct thread *td; struct proc *p; struct ksegrp *kg; + uint64_t new_switchtime; td = curthread; kg = td->td_ksegrp; @@ -561,7 +563,6 @@ ksegrp_unlink(kg); ksegrp_stash(kg); } - PROC_UNLOCK(p); td->td_ksegrp = NULL; PCPU_SET(deadthread, td); } else { @@ -584,8 +585,26 @@ * This includes an EX threaded process that is coming * here via exit1(). (exit1 dethreads the proc first). */ - PROC_UNLOCK(p); } + + /* Do the same timestamp bookkeeping that mi_switch() would do. */ + new_switchtime = cpu_ticks(); + p->p_rux.rux_runtime += (new_switchtime - PCPU_GET(switchtime)); + p->p_rux.rux_uticks += td->td_uticks; + p->p_rux.rux_sticks += td->td_sticks; + p->p_rux.rux_iticks += td->td_iticks; + PCPU_SET(switchtime, new_switchtime); + PCPU_SET(switchticks, ticks); + cnt.v_swtch++; + + /* + * If we are the last thread, the process is dying, so add our + * usage into the usage of all our children. + */ + if (p->p_numthreads == 1) + ruadd(p->p_ru, &p->p_rux, &p->p_stats->p_cru, &p->p_crux); + + PROC_UNLOCK(p); td->td_state = TDS_INACTIVE; CTR1(KTR_PROC, "thread_exit: cpu_throw() thread %p", td); cpu_throw(td, choosethread());