diff options
author | jhb <jhb@FreeBSD.org> | 2004-10-05 18:51:11 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2004-10-05 18:51:11 +0000 |
commit | ce2d3f89aff9ff16be2117862f32ec4e0da9a1b8 (patch) | |
tree | 61af271e7225bd0154aaa08a967c5ce027c7bc2a /sys/compat/linux/linux_misc.c | |
parent | c8e4aa1cd58a20597b74285a3cc35ea24ba5c47c (diff) | |
download | FreeBSD-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/compat/linux/linux_misc.c')
-rw-r--r-- | sys/compat/linux/linux_misc.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 3f08028..f17e0ad 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -689,9 +689,9 @@ struct l_times_argv { int linux_times(struct thread *td, struct linux_times_args *args) { - struct timeval tv; + struct timeval tv, utime, stime, cutime, cstime; struct l_times_argv tms; - struct rusage ru; + struct proc *p; int error; #ifdef DEBUG @@ -699,15 +699,17 @@ linux_times(struct thread *td, struct linux_times_args *args) printf(ARGS(times, "*")); #endif - mtx_lock_spin(&sched_lock); - calcru(td->td_proc, &ru.ru_utime, &ru.ru_stime, NULL); - mtx_unlock_spin(&sched_lock); + p = td->td_proc; + PROC_LOCK(p); + calcru(p, &utime, &stime); + calccru(p, &cutime, &cstime); + PROC_UNLOCK(p); - tms.tms_utime = CONVTCK(ru.ru_utime); - tms.tms_stime = CONVTCK(ru.ru_stime); + tms.tms_utime = CONVTCK(utime); + tms.tms_stime = CONVTCK(stime); - tms.tms_cutime = CONVTCK(td->td_proc->p_stats->p_cru.ru_utime); - tms.tms_cstime = CONVTCK(td->td_proc->p_stats->p_cru.ru_stime); + tms.tms_cutime = CONVTCK(cutime); + tms.tms_cstime = CONVTCK(cstime); if ((error = copyout(&tms, args->buf, sizeof(tms)))) return error; @@ -851,7 +853,7 @@ int linux_wait4(struct thread *td, struct linux_wait4_args *args) { int error, options, tmpstat; - struct rusage ru; + struct rusage ru, *rup; struct proc *p; #ifdef DEBUG @@ -866,7 +868,11 @@ linux_wait4(struct thread *td, struct linux_wait4_args *args) if (args->options & __WCLONE) options |= WLINUXCLONE; - error = kern_wait(td, args->pid, &tmpstat, options, &ru); + if (args->rusage != NULL) + rup = &ru; + else + rup = NULL; + error = kern_wait(td, args->pid, &tmpstat, options, rup); if (error) return error; |