diff options
author | jeff <jeff@FreeBSD.org> | 2003-02-17 02:19:58 +0000 |
---|---|---|
committer | jeff <jeff@FreeBSD.org> | 2003-02-17 02:19:58 +0000 |
commit | aa384c931fc62f42246713400c2b6e5b5d446165 (patch) | |
tree | 2a35dbab1876c5ce91132e41356bc345d69fcd07 /sys/kern | |
parent | d6241fff35979f7d7518ca96ece7f192829bbf35 (diff) | |
download | FreeBSD-src-aa384c931fc62f42246713400c2b6e5b5d446165.zip FreeBSD-src-aa384c931fc62f42246713400c2b6e5b5d446165.tar.gz |
- Move ke_sticks, ke_iticks, ke_uticks, ke_uu, ke_su, and ke_iu back into
the proc. These counters are only examined through calcru.
Submitted by: davidxu
Tested on: x86, alpha, UP/SMP
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_clock.c | 8 | ||||
-rw-r--r-- | sys/kern/kern_resource.c | 134 | ||||
-rw-r--r-- | sys/kern/subr_trap.c | 4 |
3 files changed, 67 insertions, 79 deletions
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 8cb6fcd..df7ca5a 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -49,6 +49,7 @@ #include <sys/ktr.h> #include <sys/mutex.h> #include <sys/proc.h> +#include <sys/resource.h> #include <sys/resourcevar.h> #include <sys/sched.h> #include <sys/signalvar.h> @@ -375,7 +376,7 @@ statclock(frame) */ if (p->p_flag & P_KSES) thread_add_ticks_intr(1, 1); - ke->ke_uticks++; + p->p_uticks++; if (ke->ke_ksegrp->kg_nice > NZERO) cp_time[CP_NICE]++; else @@ -394,12 +395,13 @@ statclock(frame) * in ``non-process'' (i.e., interrupt) work. */ if ((td->td_ithd != NULL) || td->td_intr_nesting_level >= 2) { - ke->ke_iticks++; + p->p_iticks++; cp_time[CP_INTR]++; } else { if (p->p_flag & P_KSES) thread_add_ticks_intr(0, 1); - ke->ke_sticks++; + td->td_sticks++; + p->p_sticks++; if (p != PCPU_GET(idlethread)->td_proc) cp_time[CP_SYS]++; else diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 9ad3732..d0892e1 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -671,32 +671,23 @@ calcru(p, up, sp, ip) { /* {user, system, interrupt, total} {ticks, usec}; previous tu: */ u_int64_t ut, uu, st, su, it, iu, tt, tu, ptu; - u_int64_t uut = 0, sut = 0, iut = 0; - int s; struct timeval tv; struct bintime bt; - struct kse *ke; - struct ksegrp *kg; mtx_assert(&sched_lock, MA_OWNED); /* XXX: why spl-protect ? worst case is an off-by-one report */ - FOREACH_KSEGRP_IN_PROC(p, kg) { - /* we could accumulate per ksegrp and per process here*/ - FOREACH_KSE_IN_GROUP(kg, ke) { - s = splstatclock(); - ut = ke->ke_uticks; - st = ke->ke_sticks; - it = ke->ke_iticks; - splx(s); - - tt = ut + st + it; - if (tt == 0) { - st = 1; - tt = 1; - } + ut = p->p_uticks; + st = p->p_sticks; + it = p->p_iticks; + + tt = ut + st + it; + if (tt == 0) { + st = 1; + tt = 1; + } - if (ke == curthread->td_kse) { + if (curthread->td_proc == p) { /* * Adjust for the current time slice. This is actually fairly * important since the error here is on the order of a time @@ -705,64 +696,59 @@ calcru(p, up, sp, ip) * processors also being 'current'. */ - binuptime(&bt); - bintime_sub(&bt, PCPU_PTR(switchtime)); - bintime_add(&bt, &p->p_runtime); - } else { - bt = p->p_runtime; - } - bintime2timeval(&bt, &tv); - tu = (u_int64_t)tv.tv_sec * 1000000 + tv.tv_usec; - ptu = ke->ke_uu + ke->ke_su + ke->ke_iu; - if (tu < ptu || (int64_t)tu < 0) { - /* XXX no %qd in kernel. Truncate. */ - printf("calcru: negative time of %ld usec for pid %d (%s)\n", - (long)tu, p->p_pid, p->p_comm); - tu = ptu; - } + binuptime(&bt); + bintime_sub(&bt, PCPU_PTR(switchtime)); + bintime_add(&bt, &p->p_runtime); + } else { + bt = p->p_runtime; + } + bintime2timeval(&bt, &tv); + tu = (u_int64_t)tv.tv_sec * 1000000 + tv.tv_usec; + ptu = p->p_uu + p->p_su + p->p_iu; + if (tu < ptu || (int64_t)tu < 0) { + /* XXX no %qd in kernel. Truncate. */ + printf("calcru: negative time of %ld usec for pid %d (%s)\n", + (long)tu, p->p_pid, p->p_comm); + tu = ptu; + } - /* Subdivide tu. */ - uu = (tu * ut) / tt; - su = (tu * st) / tt; - iu = tu - uu - su; + /* Subdivide tu. */ + uu = (tu * ut) / tt; + su = (tu * st) / tt; + iu = tu - uu - su; - /* Enforce monotonicity. */ - if (uu < ke->ke_uu || su < ke->ke_su || iu < ke->ke_iu) { - if (uu < ke->ke_uu) - uu = ke->ke_uu; - else if (uu + ke->ke_su + ke->ke_iu > tu) - uu = tu - ke->ke_su - ke->ke_iu; - if (st == 0) - su = ke->ke_su; - else { - su = ((tu - uu) * st) / (st + it); - if (su < ke->ke_su) - su = ke->ke_su; - else if (uu + su + ke->ke_iu > tu) - su = tu - uu - ke->ke_iu; - } - KASSERT(uu + su + ke->ke_iu <= tu, - ("calcru: monotonisation botch 1")); - iu = tu - uu - su; - KASSERT(iu >= ke->ke_iu, - ("calcru: monotonisation botch 2")); - } - ke->ke_uu = uu; - ke->ke_su = su; - ke->ke_iu = iu; - uut += uu; - sut += su; - iut += iu; - - } /* end kse loop */ - } /* end kseg loop */ - up->tv_sec = uut / 1000000; - up->tv_usec = uut % 1000000; - sp->tv_sec = sut / 1000000; - sp->tv_usec = sut % 1000000; + /* Enforce monotonicity. */ + if (uu < p->p_uu || su < p->p_su || iu < p->p_iu) { + if (uu < p->p_uu) + uu = p->p_uu; + else if (uu + p->p_su + p->p_iu > tu) + uu = tu - p->p_su - p->p_iu; + if (st == 0) + su = p->p_su; + else { + su = ((tu - uu) * st) / (st + it); + if (su < p->p_su) + su = p->p_su; + else if (uu + su + p->p_iu > tu) + su = tu - uu - p->p_iu; + } + KASSERT(uu + su + p->p_iu <= tu, + ("calcru: monotonisation botch 1")); + iu = tu - uu - su; + KASSERT(iu >= p->p_iu, + ("calcru: monotonisation botch 2")); + } + p->p_uu = uu; + p->p_su = su; + p->p_iu = iu; + + up->tv_sec = uu / 1000000; + up->tv_usec = uu % 1000000; + sp->tv_sec = su / 1000000; + sp->tv_usec = su % 1000000; if (ip != NULL) { - ip->tv_sec = iut / 1000000; - ip->tv_usec = iut % 1000000; + ip->tv_sec = iu / 1000000; + ip->tv_usec = iu % 1000000; } } diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c index eec2ae6..47e8472 100644 --- a/sys/kern/subr_trap.c +++ b/sys/kern/subr_trap.c @@ -124,7 +124,7 @@ userret(td, frame, oticks) quad_t ticks; mtx_lock_spin(&sched_lock); - ticks = ke->ke_sticks - oticks; + ticks = td->td_sticks - oticks; mtx_unlock_spin(&sched_lock); addupc_task(ke, TRAPF_PC(frame), (u_int)ticks * psratio); } @@ -175,7 +175,7 @@ ast(struct trapframe *framep) */ mtx_lock_spin(&sched_lock); ke = td->td_kse; - sticks = ke->ke_sticks; + sticks = td->td_sticks; flags = ke->ke_flags; sflag = p->p_sflag; p->p_sflag &= ~(PS_ALRMPEND | PS_NEEDSIGCHK | PS_PROFPEND | PS_XCPU); |