summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_thread.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2012-01-03 21:03:28 +0000
committerjhb <jhb@FreeBSD.org>2012-01-03 21:03:28 +0000
commitb759911211e03135d6bf5a0eaaf1f806eeeeff88 (patch)
tree89ea291cf034389fe88d6494a07b7354f8f61c8d /sys/kern/kern_thread.c
parent0c5a3f31efc71beb9a4e0e208ad135288a8142a5 (diff)
downloadFreeBSD-src-b759911211e03135d6bf5a0eaaf1f806eeeeff88.zip
FreeBSD-src-b759911211e03135d6bf5a0eaaf1f806eeeeff88.tar.gz
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. Reviewed by: bde, kib MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_thread.c')
-rw-r--r--sys/kern/kern_thread.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c
index d9df5c3..d4c5c4c 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -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;
OpenPOWER on IntegriCloud