diff options
author | phk <phk@FreeBSD.org> | 2006-02-07 21:22:02 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2006-02-07 21:22:02 +0000 |
commit | bb2f62f5367d29657fc52a4cfcd3573c39679b70 (patch) | |
tree | 95918de865b5c6e707ecd4ce458d058d287406e9 /sys/kern/kern_resource.c | |
parent | c7f3a565d2e7b4fed16d19bfe4b300ca8ef7ad27 (diff) | |
download | FreeBSD-src-bb2f62f5367d29657fc52a4cfcd3573c39679b70.zip FreeBSD-src-bb2f62f5367d29657fc52a4cfcd3573c39679b70.tar.gz |
Modify the way we account for CPU time spent (step 1)
Keep track of time spent by the cpu in various contexts in units of
"cputicks" and scale to real-world microsec^H^H^H^H^H^H^H^Hclock_t
only when somebody wants to inspect the numbers.
For now "cputicks" are still derived from the current timecounter
and therefore things should by definition remain sensible also on
SMP machines. (The main reason for this first milestone commit is
to verify that hypothesis.)
On slower machines, the avoided multiplications to normalize timestams
at every context switch, comes out as a 5-7% better score on the
unixbench/context1 microbenchmark. On more modern hardware no change
in performance is seen.
Diffstat (limited to 'sys/kern/kern_resource.c')
-rw-r--r-- | sys/kern/kern_resource.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 397a7c5..8ecac2e 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -704,7 +704,7 @@ calcru(p, up, sp) struct timeval *up; struct timeval *sp; { - struct bintime bt; + uint64_t bt; struct rusage_ext rux; struct thread *td; int bt_valid; @@ -712,6 +712,7 @@ calcru(p, up, sp) PROC_LOCK_ASSERT(p, MA_OWNED); mtx_assert(&sched_lock, MA_NOTOWNED); bt_valid = 0; + bt = 0; mtx_lock_spin(&sched_lock); rux = p->p_rux; FOREACH_THREAD_IN_PROC(p, td) { @@ -725,12 +726,16 @@ calcru(p, up, sp) KASSERT(td->td_oncpu != NOCPU, ("%s: running thread has no CPU", __func__)); if (!bt_valid) { - binuptime(&bt); + bt = cpu_ticks(); bt_valid = 1; } - bintime_add(&rux.rux_runtime, &bt); - bintime_sub(&rux.rux_runtime, - &pcpu_find(td->td_oncpu)->pc_switchtime); + /* + * XXX: Doesn't this mean that this quantum will + * XXX: get counted twice if calcru() is called + * XXX: from SIGINFO ? + */ + rux.rux_runtime += + (bt - pcpu_find(td->td_oncpu)->pc_switchtime); } } mtx_unlock_spin(&sched_lock); @@ -758,7 +763,6 @@ calcru1(p, ruxp, up, sp) struct timeval *up; struct timeval *sp; { - struct timeval tv; /* {user, system, interrupt, total} {ticks, usec}; previous tu: */ u_int64_t ut, uu, st, su, it, iu, tt, tu, ptu; @@ -770,8 +774,7 @@ calcru1(p, ruxp, up, sp) st = 1; tt = 1; } - bintime2timeval(&ruxp->rux_runtime, &tv); - tu = (u_int64_t)tv.tv_sec * 1000000 + tv.tv_usec; + tu = (ruxp->rux_runtime * 1000000LL) / cpu_tickrate(); ptu = ruxp->rux_uu + ruxp->rux_su + ruxp->rux_iu; if (tu < ptu) { printf( @@ -884,7 +887,7 @@ ruadd(ru, rux, ru2, rux2) register long *ip, *ip2; register int i; - bintime_add(&rux->rux_runtime, &rux2->rux_runtime); + rux->rux_runtime += rux2->rux_runtime; rux->rux_uticks += rux2->rux_uticks; rux->rux_sticks += rux2->rux_sticks; rux->rux_iticks += rux2->rux_iticks; |