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
This commit is contained in:
parent
00abcb6acd
commit
7e8db78116
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=335553
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user