svn commit: r184806 - in stable/7: include sys/kern sys/sys
David Xu
davidxu at FreeBSD.org
Sun Nov 9 17:42:47 PST 2008
Author: davidxu
Date: Mon Nov 10 01:42:46 2008
New Revision: 184806
URL: http://svn.freebsd.org/changeset/base/184806
Log:
MFC:
Add POSIX clock id CLOCK_THREAD_CPUTIME_ID support.
Approved by: re (kib)
Modified:
stable/7/include/time.h
stable/7/include/unistd.h
stable/7/sys/kern/kern_time.c
stable/7/sys/sys/time.h
Modified: stable/7/include/time.h
==============================================================================
--- stable/7/include/time.h Mon Nov 10 01:24:19 2008 (r184805)
+++ stable/7/include/time.h Mon Nov 10 01:42:46 2008 (r184806)
@@ -108,6 +108,7 @@ typedef __timer_t timer_t;
#define CLOCK_MONOTONIC_PRECISE 11 /* FreeBSD-specific. */
#define CLOCK_MONOTONIC_FAST 12 /* FreeBSD-specific. */
#define CLOCK_SECOND 13 /* FreeBSD-specific. */
+#define CLOCK_THREAD_CPUTIME_ID 14
#endif /* !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112 */
#if !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 200112
Modified: stable/7/include/unistd.h
==============================================================================
--- stable/7/include/unistd.h Mon Nov 10 01:24:19 2008 (r184805)
+++ stable/7/include/unistd.h Mon Nov 10 01:42:46 2008 (r184806)
@@ -111,7 +111,7 @@ typedef __useconds_t useconds_t;
#define _POSIX_SPIN_LOCKS 200112L
#define _POSIX_THREAD_ATTR_STACKADDR 200112L
#define _POSIX_THREAD_ATTR_STACKSIZE 200112L
-#define _POSIX_THREAD_CPUTIME -1
+#define _POSIX_THREAD_CPUTIME 200112L
#define _POSIX_THREAD_PRIO_INHERIT 200112L
#define _POSIX_THREAD_PRIO_PROTECT 200112L
#define _POSIX_THREAD_PRIORITY_SCHEDULING 200112L
Modified: stable/7/sys/kern/kern_time.c
==============================================================================
--- stable/7/sys/kern/kern_time.c Mon Nov 10 01:24:19 2008 (r184805)
+++ stable/7/sys/kern/kern_time.c Mon Nov 10 01:42:46 2008 (r184806)
@@ -201,6 +201,7 @@ kern_clock_gettime(struct thread *td, cl
{
struct timeval sys, user;
struct proc *p;
+ uint64_t runtime, curtime, switchtime;
p = td->td_proc;
switch (clock_id) {
@@ -242,6 +243,16 @@ kern_clock_gettime(struct thread *td, cl
ats->tv_sec = time_second;
ats->tv_nsec = 0;
break;
+ case CLOCK_THREAD_CPUTIME_ID:
+ critical_enter();
+ switchtime = PCPU_GET(switchtime);
+ curtime = cpu_ticks();
+ runtime = td->td_runtime;
+ critical_exit();
+ runtime = cputick2usec(runtime + curtime - switchtime);
+ ats->tv_sec = runtime / 1000000;
+ ats->tv_nsec = runtime % 1000000 * 1000;
+ break;
default:
return (EINVAL);
}
Modified: stable/7/sys/sys/time.h
==============================================================================
--- stable/7/sys/sys/time.h Mon Nov 10 01:24:19 2008 (r184805)
+++ stable/7/sys/sys/time.h Mon Nov 10 01:42:46 2008 (r184806)
@@ -246,6 +246,7 @@ struct clockinfo {
#define CLOCK_MONOTONIC_PRECISE 11 /* FreeBSD-specific. */
#define CLOCK_MONOTONIC_FAST 12 /* FreeBSD-specific. */
#define CLOCK_SECOND 13 /* FreeBSD-specific. */
+#define CLOCK_THREAD_CPUTIME_ID 14
#endif
#ifndef TIMER_ABSTIME
More information about the svn-src-stable-7
mailing list