summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_exit.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_exit.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_exit.c')
-rw-r--r--sys/kern/kern_exit.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index cd7e2a4..ae44fc3 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -410,20 +410,16 @@ retry:
}
/*
- * Save exit status and final rusage info, adding in child rusage
- * info and self times.
+ * Save exit status and finalize rusage info except for times,
+ * adding in child rusage info.
*/
- mtx_lock(&Giant);
PROC_LOCK(p);
p->p_xstat = rv;
p->p_xthread = td;
+ p->p_stats->p_ru.ru_nvcsw++;
*p->p_ru = p->p_stats->p_ru;
- mtx_lock_spin(&sched_lock);
- calcru(p, &p->p_ru->ru_utime, &p->p_ru->ru_stime, NULL);
- mtx_unlock_spin(&sched_lock);
- ruadd(p->p_ru, &p->p_stats->p_cru);
+ ruadd(p->p_ru, &p->p_rux, &p->p_stats->p_cru, &p->p_crux);
- mtx_unlock(&Giant);
/*
* Notify interested parties of our demise.
*/
@@ -487,9 +483,6 @@ retry:
PROC_LOCK(p->p_pptr);
sx_xunlock(&proctree_lock);
- while (mtx_owned(&Giant))
- mtx_unlock(&Giant);
-
/*
* We have to wait until after acquiring all locks before
* changing p_state. We need to avoid all possible context
@@ -508,8 +501,8 @@ retry:
/* Do the same timestamp bookkeeping that mi_switch() would do. */
binuptime(&new_switchtime);
- bintime_add(&p->p_runtime, &new_switchtime);
- bintime_sub(&p->p_runtime, PCPU_PTR(switchtime));
+ bintime_add(&p->p_rux.rux_runtime, &new_switchtime);
+ bintime_sub(&p->p_rux.rux_runtime, PCPU_PTR(switchtime));
PCPU_SET(switchtime, new_switchtime);
PCPU_SET(switchticks, ticks);
cnt.v_swtch++;
@@ -556,10 +549,14 @@ owait(struct thread *td, struct owait_args *uap __unused)
int
wait4(struct thread *td, struct wait_args *uap)
{
- struct rusage ru;
+ struct rusage ru, *rup;
int error, status;
- error = kern_wait(td, uap->pid, &status, uap->options, &ru);
+ if (uap->rusage != NULL)
+ rup = &ru;
+ else
+ rup = NULL;
+ error = kern_wait(td, uap->pid, &status, uap->options, rup);
if (uap->status != NULL && error == 0)
error = copyout(&status, uap->status, sizeof(status));
if (uap->rusage != NULL && error == 0)
@@ -612,8 +609,10 @@ loop:
td->td_retval[0] = p->p_pid;
if (status)
*status = p->p_xstat; /* convert to int */
- if (rusage)
+ if (rusage) {
bcopy(p->p_ru, rusage, sizeof(struct rusage));
+ calcru(p, &rusage->ru_utime, &rusage->ru_stime);
+ }
/*
* If we got the child via a ptrace 'attach',
@@ -648,16 +647,15 @@ loop:
* all other writes to this proc are visible now, so
* no more locking is needed for p.
*/
- mtx_lock(&Giant);
PROC_LOCK(p);
p->p_xstat = 0; /* XXX: why? */
PROC_UNLOCK(p);
PROC_LOCK(q);
- ruadd(&q->p_stats->p_cru, p->p_ru);
+ ruadd(&q->p_stats->p_cru, &q->p_crux, p->p_ru,
+ &p->p_rux);
PROC_UNLOCK(q);
FREE(p->p_ru, M_ZOMBIE);
p->p_ru = NULL;
- mtx_unlock(&Giant);
/*
* Decrement the count of procs running with this uid.
OpenPOWER on IntegriCloud