Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jun 2018 10:23:32 +0000 (UTC)
From:      Colin Percival <cperciva@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r335553 - head/sys/kern
Message-ID:  <201806221023.w5MANWSk064627@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cperciva
Date: Fri Jun 22 10:23:32 2018
New Revision: 335553
URL: https://svnweb.freebsd.org/changeset/base/335553

Log:
  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

Modified:
  head/sys/kern/kern_time.c

Modified: head/sys/kern/kern_time.c
==============================================================================
--- head/sys/kern/kern_time.c	Fri Jun 22 10:20:21 2018	(r335552)
+++ head/sys/kern/kern_time.c	Fri Jun 22 10:23:32 2018	(r335553)
@@ -280,6 +280,8 @@ get_process_cputime(struct proc *targetp, struct times
 	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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806221023.w5MANWSk064627>