summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_proc.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2004-10-05 18:51:11 +0000
committerjhb <jhb@FreeBSD.org>2004-10-05 18:51:11 +0000
commitce2d3f89aff9ff16be2117862f32ec4e0da9a1b8 (patch)
tree61af271e7225bd0154aaa08a967c5ce027c7bc2a /sys/kern/kern_proc.c
parentc8e4aa1cd58a20597b74285a3cc35ea24ba5c47c (diff)
downloadFreeBSD-src-ce2d3f89aff9ff16be2117862f32ec4e0da9a1b8.zip
FreeBSD-src-ce2d3f89aff9ff16be2117862f32ec4e0da9a1b8.tar.gz
Rework how we store process times in the kernel such that we always store
the raw values including for child process statistics and only compute the system and user timevals on demand. - Fix the various kern_wait() syscall wrappers to only pass in a rusage pointer if they are going to use the result. - Add a kern_getrusage() function for the ABI syscalls to use so that they don't have to play stackgap games to call getrusage(). - Fix the svr4_sys_times() syscall to just call calcru() to calculate the times it needs rather than calling getrusage() twice with associated stackgap, etc. - Add a new rusage_ext structure to store raw time stats such as tick counts for user, system, and interrupt time as well as a bintime of the total runtime. A new p_rux field in struct proc replaces the same inline fields from struct proc (i.e. p_[isu]ticks, p_[isu]u, and p_runtime). A new p_crux field in struct proc contains the "raw" child time usage statistics. ruadd() has been changed to handle adding the associated rusage_ext structures as well as the values in rusage. Effectively, the values in rusage_ext replace the ru_utime and ru_stime values in struct rusage. These two fields in struct rusage are no longer used in the kernel. - calcru() has been split into a static worker function calcru1() that calculates appropriate timevals for user and system time as well as updating the rux_[isu]u fields of a passed in rusage_ext structure. calcru() uses a copy of the process' p_rux structure to compute the timevals after updating the runtime appropriately if any of the threads in that process are currently executing. It also now only locks sched_lock internally while doing the rux_runtime fixup. calcru() now only requires the caller to hold the proc lock and calcru1() only requires the proc lock internally. calcru() also no longer allows callers to ask for an interrupt timeval since none of them actually did. - calcru() now correctly handles threads executing on other CPUs. - A new calccru() function computes the child system and user timevals by calling calcru1() on p_crux. Note that this means that any code that wants child times must now call this function rather than reading from p_cru directly. This function also requires the proc lock. - This finishes the locking for rusage and friends so some of the Giant locks in exit1() and kern_wait() are now gone. - The locking in ttyinfo() has been tweaked so that a shared lock of the proctree lock is used to protect the process group rather than the process group lock. By holding this lock until the end of the function we now ensure that the process/thread that we pick to dump info about will no longer vanish while we are trying to output its info to the console. Submitted by: bde (mostly) MFC after: 1 month
Diffstat (limited to 'sys/kern/kern_proc.c')
-rw-r--r--sys/kern/kern_proc.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 2f8b4df..f4f5648 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -674,23 +674,11 @@ fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp)
kp->ki_dsize = vm->vm_dsize;
kp->ki_ssize = vm->vm_ssize;
}
- if ((p->p_sflag & PS_INMEM) && p->p_stats) {
- kp->ki_start = p->p_stats->p_start;
- timevaladd(&kp->ki_start, &boottime);
- kp->ki_rusage = p->p_stats->p_ru;
- calcru(p, &kp->ki_rusage.ru_utime, &kp->ki_rusage.ru_stime,
- NULL);
- kp->ki_childstime = p->p_stats->p_cru.ru_stime;
- kp->ki_childutime = p->p_stats->p_cru.ru_utime;
- /* Some callers want child-times in a single value */
- kp->ki_childtime = kp->ki_childstime;
- timevaladd(&kp->ki_childtime, &kp->ki_childutime);
- }
kp->ki_sflag = p->p_sflag;
kp->ki_swtime = p->p_swtime;
kp->ki_pid = p->p_pid;
kp->ki_nice = p->p_nice;
- bintime2timeval(&p->p_runtime, &tv);
+ bintime2timeval(&p->p_rux.rux_runtime, &tv);
kp->ki_runtime = tv.tv_sec * (u_int64_t)1000000 + tv.tv_usec;
if (p->p_state != PRS_ZOMBIE) {
#if 0
@@ -758,6 +746,17 @@ fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp)
kp->ki_stat = SZOMB;
}
mtx_unlock_spin(&sched_lock);
+ if ((p->p_sflag & PS_INMEM) && p->p_stats != NULL) {
+ kp->ki_start = p->p_stats->p_start;
+ timevaladd(&kp->ki_start, &boottime);
+ kp->ki_rusage = p->p_stats->p_ru;
+ calcru(p, &kp->ki_rusage.ru_utime, &kp->ki_rusage.ru_stime);
+ calccru(p, &kp->ki_childutime, &kp->ki_childstime);
+
+ /* Some callers want child-times in a single value */
+ kp->ki_childtime = kp->ki_childstime;
+ timevaladd(&kp->ki_childtime, &kp->ki_childutime);
+ }
sp = NULL;
tp = NULL;
if (p->p_pgrp) {
OpenPOWER on IntegriCloud