diff options
author | Colin Percival <cperciva@FreeBSD.org> | 2018-06-22 10:23:32 +0000 |
---|---|---|
committer | Colin Percival <cperciva@FreeBSD.org> | 2018-06-22 10:23:32 +0000 |
commit | 7e8db78116c568e5282a1543318ec283c08fe5ba (patch) | |
tree | 765e7b9a16ee8b16b8b033d75ae240d1a9caebc6 | |
parent | 00abcb6acdab1185cd061827e99d47b952e7036c (diff) | |
download | src-7e8db78116c568e5282a1543318ec283c08fe5ba.tar.gz src-7e8db78116c568e5282a1543318ec283c08fe5ba.zip |
Improve the accuracy of the POSIX "process CPU-time" clocks by adding the
used portion of the current thread's time slice if the current thread
belongs to the process being queried (i.e., if clock_gettime is invoked
with a clock ID of CLOCK_PROCESS_CPUTIME_ID or the value provided by
passing getpid(2) to clock_getcpuclockid(3)).
The CLOCK_VIRTUAL and CLOCK_PROF timers already make this adjustment via
long-standing code in calcru(), but since those timers are not specified
by POSIX it seems useful to add it here so that the higher accuracy is
available to code which aims to be portable.
PR: 228669
Reported by: Graham Percival
Reviewed by: kib
MFC after: 1 week
Notes
Notes:
svn path=/head/; revision=335553
-rw-r--r-- | sys/kern/kern_time.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 9820509f950b..be9e5c830ab0 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -280,6 +280,8 @@ get_process_cputime(struct proc *targetp, struct timespec *ats) PROC_STATLOCK(targetp); rufetch(targetp, &ru); runtime = targetp->p_rux.rux_runtime; + if (curthread->td_proc == targetp) + runtime += cpu_ticks() - PCPU_GET(switchtime); PROC_STATUNLOCK(targetp); cputick2timespec(runtime, ats); } |