From owner-svn-src-stable-9@FreeBSD.ORG Fri Jan 13 20:15:28 2012 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0F8281065677; Fri, 13 Jan 2012 20:15:28 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EDA948FC08; Fri, 13 Jan 2012 20:15:27 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q0DKFRjR078452; Fri, 13 Jan 2012 20:15:27 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q0DKFRcR078448; Fri, 13 Jan 2012 20:15:27 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201201132015.q0DKFRcR078448@svn.freebsd.org> From: John Baldwin Date: Fri, 13 Jan 2012 20:15:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r230079 - stable/9/sys/kern X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jan 2012 20:15:28 -0000 Author: jhb Date: Fri Jan 13 20:15:27 2012 New Revision: 230079 URL: http://svn.freebsd.org/changeset/base/230079 Log: MFC 229429: Some small fixes to CPU accounting for threads: - Only initialize the per-cpu switchticks and switchtime in sched_throw() for the very first context switch on APs during boot. This avoids a small gap between the middle of thread_exit() and sched_throw() where time is not accounted to any thread. - In thread_exit(), update the timestamp bookkeeping to track the changes to mi_switch() introduced by td_rux so that the code once again matches the comment claiming it is mimicing mi_switch(). Specifically, only update the per-thread stats directly and depend on ruxagg() to update p_rux rather than adjusting p_rux directly. While here, move the timestamp bookkeeping as late in the function as possible. Modified: stable/9/sys/kern/kern_thread.c stable/9/sys/kern/sched_4bsd.c stable/9/sys/kern/sched_ule.c Directory Properties: stable/9/sys/ (props changed) stable/9/sys/amd64/include/xen/ (props changed) stable/9/sys/boot/ (props changed) stable/9/sys/boot/i386/efi/ (props changed) stable/9/sys/boot/ia64/efi/ (props changed) stable/9/sys/boot/ia64/ski/ (props changed) stable/9/sys/boot/powerpc/boot1.chrp/ (props changed) stable/9/sys/boot/powerpc/ofw/ (props changed) stable/9/sys/cddl/contrib/opensolaris/ (props changed) stable/9/sys/conf/ (props changed) stable/9/sys/contrib/dev/acpica/ (props changed) stable/9/sys/contrib/octeon-sdk/ (props changed) stable/9/sys/contrib/pf/ (props changed) stable/9/sys/contrib/x86emu/ (props changed) Modified: stable/9/sys/kern/kern_thread.c ============================================================================== --- stable/9/sys/kern/kern_thread.c Fri Jan 13 19:54:00 2012 (r230078) +++ stable/9/sys/kern/kern_thread.c Fri Jan 13 20:15:27 2012 (r230079) @@ -381,7 +381,7 @@ thread_free(struct thread *td) void thread_exit(void) { - uint64_t new_switchtime; + uint64_t runtime, new_switchtime; struct thread *td; struct thread *td2; struct proc *p; @@ -410,15 +410,6 @@ thread_exit(void) */ cpu_thread_exit(td); /* XXXSMP */ - /* Do the same timestamp bookkeeping that mi_switch() would do. */ - new_switchtime = cpu_ticks(); - p->p_rux.rux_runtime += (new_switchtime - PCPU_GET(switchtime)); - PCPU_SET(switchtime, new_switchtime); - PCPU_SET(switchticks, ticks); - PCPU_INC(cnt.v_swtch); - /* Save our resource usage in our process. */ - td->td_ru.ru_nvcsw++; - rucollect(&p->p_ru, &td->td_ru); /* * The last thread is left attached to the process * So that the whole bundle gets recycled. Skip @@ -467,7 +458,21 @@ thread_exit(void) PMC_SWITCH_CONTEXT(td, PMC_FN_CSW_OUT); #endif PROC_UNLOCK(p); + + /* Do the same timestamp bookkeeping that mi_switch() would do. */ + new_switchtime = cpu_ticks(); + runtime = new_switchtime - PCPU_GET(switchtime); + td->td_runtime += runtime; + td->td_incruntime += runtime; + PCPU_SET(switchtime, new_switchtime); + PCPU_SET(switchticks, ticks); + PCPU_INC(cnt.v_swtch); + + /* Save our resource usage in our process. */ + td->td_ru.ru_nvcsw++; ruxagg(p, td); + rucollect(&p->p_ru, &td->td_ru); + thread_lock(td); PROC_SUNLOCK(p); td->td_state = TDS_INACTIVE; Modified: stable/9/sys/kern/sched_4bsd.c ============================================================================== --- stable/9/sys/kern/sched_4bsd.c Fri Jan 13 19:54:00 2012 (r230078) +++ stable/9/sys/kern/sched_4bsd.c Fri Jan 13 20:15:27 2012 (r230079) @@ -1571,14 +1571,14 @@ sched_throw(struct thread *td) if (td == NULL) { mtx_lock_spin(&sched_lock); spinlock_exit(); + PCPU_SET(switchtime, cpu_ticks()); + PCPU_SET(switchticks, ticks); } else { lock_profile_release_lock(&sched_lock.lock_object); MPASS(td->td_lock == &sched_lock); } mtx_assert(&sched_lock, MA_OWNED); KASSERT(curthread->td_md.md_spinlock_count == 1, ("invalid count")); - PCPU_SET(switchtime, cpu_ticks()); - PCPU_SET(switchticks, ticks); cpu_throw(td, choosethread()); /* doesn't return */ } Modified: stable/9/sys/kern/sched_ule.c ============================================================================== --- stable/9/sys/kern/sched_ule.c Fri Jan 13 19:54:00 2012 (r230078) +++ stable/9/sys/kern/sched_ule.c Fri Jan 13 20:15:27 2012 (r230079) @@ -2581,6 +2581,8 @@ sched_throw(struct thread *td) /* Correct spinlock nesting and acquire the correct lock. */ TDQ_LOCK(tdq); spinlock_exit(); + PCPU_SET(switchtime, cpu_ticks()); + PCPU_SET(switchticks, ticks); } else { MPASS(td->td_lock == TDQ_LOCKPTR(tdq)); tdq_load_rem(tdq, td); @@ -2589,8 +2591,6 @@ sched_throw(struct thread *td) KASSERT(curthread->td_md.md_spinlock_count == 1, ("invalid count")); newtd = choosethread(); TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)newtd; - PCPU_SET(switchtime, cpu_ticks()); - PCPU_SET(switchticks, ticks); cpu_throw(td, newtd); /* doesn't return */ }