Index: include/time.h =================================================================== --- include/time.h (revision 184492) +++ include/time.h (working copy) @@ -108,6 +108,7 @@ #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 Index: include/unistd.h =================================================================== --- include/unistd.h (revision 184492) +++ include/unistd.h (working copy) @@ -111,7 +111,7 @@ #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 Index: sys/sys/time.h =================================================================== --- sys/sys/time.h (revision 184492) +++ sys/sys/time.h (working copy) @@ -246,6 +246,7 @@ #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 Index: sys/kern/kern_time.c =================================================================== --- sys/kern/kern_time.c (revision 184492) +++ sys/kern/kern_time.c (working copy) @@ -201,6 +201,7 @@ { struct timeval sys, user; struct proc *p; + uint64_t runtime, curtime, switchtime; p = td->td_proc; switch (clock_id) { @@ -242,6 +243,16 @@ 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); }