PERFORCE change 92548 for review
John Baldwin
jhb at FreeBSD.org
Tue Feb 28 13:55:52 PST 2006
http://perforce.freebsd.org/chv.cgi?CH=92548
Change 92548 by jhb at jhb_slimer on 2006/02/28 21:55:02
Account for the last time slice of all exiting threads. We
were missing the last time slice for all threads but the last
in multithreaded processes. We have to defer the ruadd() until
after the last update as well, so it is also in thread_exit() now.
Submitted by: davidxu (mostly)
Affected files ...
.. //depot/projects/smpng/sys/kern/kern_exit.c#114 edit
.. //depot/projects/smpng/sys/kern/kern_thread.c#86 edit
Differences ...
==== //depot/projects/smpng/sys/kern/kern_exit.c#114 (text+ko) ====
@@ -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);
/*
==== //depot/projects/smpng/sys/kern/kern_thread.c#86 (text+ko) ====
@@ -35,6 +35,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/resourcevar.h>
#include <sys/smp.h>
#include <sys/sysctl.h>
#include <sys/sched.h>
@@ -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());
More information about the p4-projects
mailing list