diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2013-06-17 19:11:55 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2013-06-17 19:11:55 +0000 |
commit | 407e1f7584c8aaaf7209611a864ba04253685690 (patch) | |
tree | 0b2da6aa5f947080312c01f7e306c4f4bffe39b8 /sys/kern | |
parent | 22db4b2e9c63b9f500b2d0f99d94107b5a600444 (diff) |
Add support for the _POSIX_CPUTIME and _POSIX_THREAD_CPUTIME options,
including CLOCK_{PROCESS,THREAD}_CPUTIME_ID constants and
{clock,pthread}_getcpuclockid() functions.
Worked out at t2k13 with help from tedu@ and matthew@ and testing by aja@
ok matthew@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_exec.c | 6 | ||||
-rw-r--r-- | sys/kern/kern_time.c | 35 |
2 files changed, 36 insertions, 5 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 5046191d86b..262352e6944 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.134 2013/03/30 06:32:25 tedu Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.135 2013/06/17 19:11:54 guenther Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -609,6 +609,10 @@ sys_execve(struct proc *p, void *v, register_t *retval) splx(s); } + /* reset CPU time usage for the thread, but not the process */ + timespecclear(&p->p_tu.tu_runtime); + p->p_tu.tu_uticks = p->p_tu.tu_sticks = p->p_tu.tu_iticks = 0; + uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS); pool_put(&namei_pool, nid.ni_cnd.cn_pnbuf); diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index dcb878639fd..99ea70af6d1 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.79 2013/06/03 16:55:22 guenther Exp $ */ +/* $OpenBSD: kern_time.c,v 1.80 2013/06/17 19:11:54 guenther Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -112,6 +112,8 @@ settime(struct timespec *ts) int clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp) { + struct proc *q; + switch (clock_id) { case CLOCK_REALTIME: nanotime(tp); @@ -119,13 +121,27 @@ clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp) case CLOCK_MONOTONIC: nanouptime(tp); break; - case CLOCK_PROF: + case CLOCK_PROCESS_CPUTIME_ID: nanouptime(tp); timespecsub(tp, &curcpu()->ci_schedstate.spc_runtime, tp); + timespecadd(tp, &p->p_p->ps_tu.tu_runtime, tp); + timespecadd(tp, &p->p_rtime, tp); + break; + case CLOCK_THREAD_CPUTIME_ID: + nanouptime(tp); + timespecsub(tp, &curcpu()->ci_schedstate.spc_runtime, tp); + timespecadd(tp, &p->p_tu.tu_runtime, tp); timespecadd(tp, &p->p_rtime, tp); break; default: - return (EINVAL); + /* check for clock from pthread_getcpuclockid() */ + if (__CLOCK_TYPE(clock_id) == CLOCK_THREAD_CPUTIME_ID) { + q = pfind(__CLOCK_PTID(clock_id) - THREAD_PID_OFFSET); + if (q == NULL || q->p_p != p->p_p) + return (ESRCH); + *tp = q->p_tu.tu_runtime; + } else + return (EINVAL); } return (0); } @@ -195,17 +211,28 @@ sys_clock_getres(struct proc *p, void *v, register_t *retval) } */ *uap = v; clockid_t clock_id; struct timespec ts; + struct proc *q; int error = 0; clock_id = SCARG(uap, clock_id); switch (clock_id) { case CLOCK_REALTIME: case CLOCK_MONOTONIC: + case CLOCK_PROCESS_CPUTIME_ID: + case CLOCK_THREAD_CPUTIME_ID: ts.tv_sec = 0; ts.tv_nsec = 1000000000 / hz; break; default: - return (EINVAL); + /* check for clock from pthread_getcpuclockid() */ + if (__CLOCK_TYPE(clock_id) == CLOCK_THREAD_CPUTIME_ID) { + q = pfind(__CLOCK_PTID(clock_id) - THREAD_PID_OFFSET); + if (q == NULL || q->p_p != p->p_p) + return (ESRCH); + ts.tv_sec = 0; + ts.tv_nsec = 1000000000 / hz; + } else + return (EINVAL); } if (SCARG(uap, tp)) { |