From owner-p4-projects@FreeBSD.ORG Tue Feb 28 21:55:52 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id F3BE416A423; Tue, 28 Feb 2006 21:55:51 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9910F16A42C for ; Tue, 28 Feb 2006 21:55:51 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B87943D4C for ; Tue, 28 Feb 2006 21:55:51 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k1SLtoTh068199 for ; Tue, 28 Feb 2006 21:55:50 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k1SLtohm068196 for perforce@freebsd.org; Tue, 28 Feb 2006 21:55:50 GMT (envelope-from jhb@freebsd.org) Date: Tue, 28 Feb 2006 21:55:50 GMT Message-Id: <200602282155.k1SLtohm068196@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 92548 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Feb 2006 21:55:52 -0000 http://perforce.freebsd.org/chv.cgi?CH=92548 Change 92548 by jhb@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 #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());