summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2013-06-17 19:11:54 +0000
committerguenther <guenther@openbsd.org>2013-06-17 19:11:54 +0000
commit7b36c281ba1c99d528efca950572c207acd2e184 (patch)
treef5c2b481403a1c10e5fb3838834ab4fd89d0397e
parent2nd part of: (diff)
downloadwireguard-openbsd-7b36c281ba1c99d528efca950572c207acd2e184.tar.xz
wireguard-openbsd-7b36c281ba1c99d528efca950572c207acd2e184.zip
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@
-rw-r--r--include/time.h13
-rw-r--r--include/unistd.h6
-rw-r--r--lib/libc/gen/Makefile.inc8
-rw-r--r--lib/libc/gen/clock_getcpuclockid.365
-rw-r--r--lib/libc/gen/clock_getcpuclockid.c31
-rw-r--r--lib/libc/shlib_version2
-rw-r--r--lib/libc/sys/clock_gettime.245
-rw-r--r--lib/libpthread/include/pthread.h6
-rw-r--r--lib/libpthread/man/Makefile.inc3
-rw-r--r--lib/libpthread/man/pthread_getcpuclockid.361
-rw-r--r--lib/libpthread/man/pthreads.37
-rw-r--r--lib/librthread/Makefile3
-rw-r--r--lib/librthread/rthread_getcpuclockid.c28
-rw-r--r--lib/librthread/shlib_version2
-rw-r--r--sys/kern/kern_exec.c6
-rw-r--r--sys/kern/kern_time.c35
-rw-r--r--sys/sys/_time.h21
-rw-r--r--sys/sys/types.h8
-rw-r--r--usr.bin/kdump/kdump_subr.h3
-rw-r--r--usr.bin/kdump/mksubr12
20 files changed, 321 insertions, 44 deletions
diff --git a/include/time.h b/include/time.h
index 95e01b712e0..537d9eaa0fc 100644
--- a/include/time.h
+++ b/include/time.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: time.h,v 1.24 2013/04/02 05:16:14 guenther Exp $ */
+/* $OpenBSD: time.h,v 1.25 2013/06/17 19:11:54 guenther Exp $ */
/* $NetBSD: time.h,v 1.9 1994/10/26 00:56:35 cgd Exp $ */
/*
@@ -101,6 +101,13 @@ typedef __timer_t timer_t;
#endif
#endif
+#if __POSIX_VISIBLE >= 200112
+#ifndef _PID_T_DEFINED_
+#define _PID_T_DEFINED_
+typedef __pid_t pid_t;
+#endif
+#endif
+
struct tm {
int tm_sec; /* seconds after the minute [0-60] */
int tm_min; /* minutes after the hour [0-59] */
@@ -154,6 +161,10 @@ int clock_settime(clockid_t, const struct timespec *);
int nanosleep(const struct timespec *, struct timespec *);
#endif
+#if __POSIX_VISIBLE >= 200112
+int clock_getcpuclockid(pid_t, clockid_t *);
+#endif
+
#if __BSD_VISIBLE
char *timezone(int, int);
void tzsetwall(void);
diff --git a/include/unistd.h b/include/unistd.h
index 0604d44407f..1c402512d2a 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unistd.h,v 1.78 2013/06/04 23:01:07 brad Exp $ */
+/* $OpenBSD: unistd.h,v 1.79 2013/06/17 19:11:54 guenther Exp $ */
/* $NetBSD: unistd.h,v 1.26.4.1 1996/05/28 02:31:51 mrg Exp $ */
/*-
@@ -66,7 +66,7 @@
#define _POSIX_BARRIERS 200112L
#define _POSIX_CHOWN_RESTRICTED 1
#define _POSIX_CLOCK_SELECTION (-1)
-#define _POSIX_CPUTIME (-1)
+#define _POSIX_CPUTIME 200809L
#define _POSIX_FSYNC 200112L
#define _POSIX_IPV6 0
#define _POSIX_JOB_CONTROL 1
@@ -93,7 +93,7 @@
#define _POSIX_SYNCHRONIZED_IO (-1)
#define _POSIX_THREAD_ATTR_STACKADDR 200112L
#define _POSIX_THREAD_ATTR_STACKSIZE 200112L
-#define _POSIX_THREAD_CPUTIME (-1)
+#define _POSIX_THREAD_CPUTIME 200809L
#define _POSIX_THREAD_PRIO_INHERIT (-1)
#define _POSIX_THREAD_PRIO_PROTECT (-1)
#define _POSIX_THREAD_PRIORITY_SCHEDULING (-1)
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index e3c040e576a..a6b77b0154a 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,10 +1,11 @@
-# $OpenBSD: Makefile.inc,v 1.61 2013/05/31 20:59:23 ajacoutot Exp $
+# $OpenBSD: Makefile.inc,v 1.62 2013/06/17 19:11:54 guenther Exp $
# gen sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen ${LIBCSRCDIR}/gen
SRCS+= alarm.c assert.c auth_subr.c authenticate.c \
- basename.c clock.c closedir.c confstr.c ctermid.c ctype_.c \
+ basename.c clock.c clock_getcpuclockid.c \
+ closedir.c confstr.c ctermid.c ctype_.c \
daemon.c devname.c dirfd.c dirname.c disklabel.c elf_hash.c err.c \
errx.c errlist.c errno.c exec.c \
fdatasync.c fnmatch.c fpclassify.c frexp.c \
@@ -36,7 +37,8 @@ SRCS+= _sys_errlist.c _sys_nerr.c _sys_siglist.c
.include "${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen/Makefile.inc"
-MAN+= alarm.3 auth_subr.3 authenticate.3 basename.3 clock.3 confstr.3 \
+MAN+= alarm.3 auth_subr.3 authenticate.3 basename.3 clock.3 \
+ clock_getcpuclockid.3 confstr.3 \
ctermid.3 ctype.3 daemon.3 devname.3 directory.3 dirname.3 err.3 \
exec.3 fabs.3 fnmatch.3 fpclassify.3 fpgetmask.3 frexp.3 ftok.3 fts.3 \
ftw.3 getbsize.3 getcap.3 getcwd.3 getdomainname.3 getdiskbyname.3 \
diff --git a/lib/libc/gen/clock_getcpuclockid.3 b/lib/libc/gen/clock_getcpuclockid.3
new file mode 100644
index 00000000000..181a5929df3
--- /dev/null
+++ b/lib/libc/gen/clock_getcpuclockid.3
@@ -0,0 +1,65 @@
+.\" $OpenBSD: clock_getcpuclockid.3,v 1.1 2013/06/17 19:11:54 guenther Exp $
+.\"
+.\" Copyright (c) 2013 Philip Guenther <guenther@openbsd.org>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: June 17 2013 $
+.Dt CLOCK_GETCPUCLOCKID 3
+.Os
+.Sh NAME
+.Nm clock_getcpuclockid
+.Nd get a clock measuring process CPU time
+.Sh SYNOPSIS
+.Fd #include <time.h>
+.Ft int
+.Fn clock_getcpuclockid "pid_t pid" "clockid_t *clock_id"
+.Sh DESCRIPTION
+The
+.Fn clock_getcpuclockid
+function allows the calling process to get a
+.Vt clockid_t
+value that measures the time spent by CPUs running in user or kernel mode
+on behalf of the process specified by
+.Fa pid .
+If
+.Fa pid
+is zero, then a clock for the calling process will be returned.
+.Sh RETURN VALUES
+If successful,
+.Fn clock_getcpuclockid
+will return zero.
+Otherwise an error number will be returned to indicate the error.
+.Sh ERRORS
+.Fn clock_getcpuclockid
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EPERM
+.Fa pid
+is neither zero nor the PID of the calling process.
+.El
+.Sh SEE ALSO
+.Xr clock_gettime 2 ,
+.Xr pthread_getcpuclockid 3
+.Sh STANDARDS
+The
+.Fn clock_getcpuclockid
+function conforms to
+.St -p1003.1-2008 .
+.Sh HISTORY
+The
+.Fn clock_getcpuclockid
+function first appeared in
+.St -p1003.1d-99
+and has been available since
+.Ox 5.4 .
diff --git a/lib/libc/gen/clock_getcpuclockid.c b/lib/libc/gen/clock_getcpuclockid.c
new file mode 100644
index 00000000000..f0c18aac1f5
--- /dev/null
+++ b/lib/libc/gen/clock_getcpuclockid.c
@@ -0,0 +1,31 @@
+/* $OpenBSD: clock_getcpuclockid.c,v 1.1 2013/06/17 19:11:54 guenther Exp $ */
+/*
+ * Copyright (c) 2013 Philip Guenther <guenther@openbsd.org>
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+
+int
+clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
+{
+ if (pid != 0 && pid != getpid())
+ return (EPERM);
+
+ *clock_id = CLOCK_PROCESS_CPUTIME_ID;
+ return (0);
+}
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version
index 3f763170cb9..7d7d8121727 100644
--- a/lib/libc/shlib_version
+++ b/lib/libc/shlib_version
@@ -1,4 +1,4 @@
major=68
-minor=3
+minor=4
# note: If changes were made to include/thread_private.h or if system
# calls were added/changed then librthread/shlib_version also be updated.
diff --git a/lib/libc/sys/clock_gettime.2 b/lib/libc/sys/clock_gettime.2
index 7d4adedb3c2..e7b36d7121f 100644
--- a/lib/libc/sys/clock_gettime.2
+++ b/lib/libc/sys/clock_gettime.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: clock_gettime.2,v 1.20 2013/03/31 08:34:27 guenther Exp $
+.\" $OpenBSD: clock_gettime.2,v 1.21 2013/06/17 19:11:54 guenther Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: March 31 2013 $
+.Dd $Mdocdate: June 17 2013 $
.Dt CLOCK_GETTIME 2
.Os
.Sh NAME
@@ -48,22 +48,33 @@ The
.Fn clock_gettime
and
.Fn clock_settime
+functions
allow the calling process to retrieve or set the value used by a clock
which is specified by
.Fa clock_id .
.Pp
.Fa clock_id
-can be one of four values:
-.Dv CLOCK_REALTIME
-for time that increments as
-a wall clock should,
-.Dv CLOCK_VIRTUAL
-for time that increments only when
-the CPU is running in user mode on behalf of the calling process,
-.Dv CLOCK_PROF
-for time that increments when the CPU is running in user or kernel mode, or
-.Dv CLOCK_MONOTONIC
-for time that increments at a steady rate (monotonically).
+can be a value from
+.Xr clock_getcpuclockid 3
+or
+.Xr pthread_getcpuclockid 3
+or one of five predefined values:
+.Bl -tag -width CLOCK_MONOTONIC
+.It Dv CLOCK_REALTIME
+time that increments as a wall clock should
+.It Dv CLOCK_VIRTUAL
+time that increments only when
+the CPU is running in user mode on behalf of the calling process
+.It Dv CLOCK_PROCESS_CPUTIME_ID
+time that increments when the CPU is running in user or kernel mode
+on behalf of the calling process
+.It Dv CLOCK_THREAD_CPUTIME_ID
+time that increments when the CPU is running in user or kernel mode
+on behalf of the calling thread
+.It Dv CLOCK_MONOTONIC
+time that increments as a wall clock should but whose absolute value
+is meaningless and cannot jump, providing accurate interval measurement
+.El
.Pp
The structure pointed to by
.Fa tp
@@ -77,7 +88,9 @@ struct timespec {
};
.Ed
.Pp
-Only the superuser may set the time of day.
+Only the
+.Dv CLOCK_REALTIME
+clock can be set, and only the superuser may do so.
If the system securelevel is greater than 1 (see
.Xr init 8 ) ,
the time may only be advanced.
@@ -129,7 +142,9 @@ or a value outside the range of the specified clock.
.Sh SEE ALSO
.Xr date 1 ,
.Xr adjtime 2 ,
-.Xr ctime 3
+.Xr clock_getcpuclockid 3 ,
+.Xr ctime 3 ,
+.Xr pthread_getcpuclockid 3
.Sh STANDARDS
The
.Fn clock_getres ,
diff --git a/lib/libpthread/include/pthread.h b/lib/libpthread/include/pthread.h
index de6a8096483..7329429d750 100644
--- a/lib/libpthread/include/pthread.h
+++ b/lib/libpthread/include/pthread.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pthread.h,v 1.39 2012/12/05 23:20:05 deraadt Exp $ */
+/* $OpenBSD: pthread.h,v 1.40 2013/06/17 19:11:54 guenther Exp $ */
/*
* Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu
@@ -309,6 +309,10 @@ int pthread_spin_destroy(pthread_spinlock_t *);
int pthread_spin_trylock(pthread_spinlock_t *);
int pthread_spin_lock(pthread_spinlock_t *);
int pthread_spin_unlock(pthread_spinlock_t *);
+
+#if __POSIX_VISIBLE >= 200112
+int pthread_getcpuclockid(pthread_t, clockid_t *);
+#endif
__END_DECLS
#endif /* _PTHREAD_H_ */
diff --git a/lib/libpthread/man/Makefile.inc b/lib/libpthread/man/Makefile.inc
index 80f85126f51..7fd3ba1dcd6 100644
--- a/lib/libpthread/man/Makefile.inc
+++ b/lib/libpthread/man/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.33 2012/05/03 09:07:17 pirofti Exp $
+# $OpenBSD: Makefile.inc,v 1.34 2013/06/17 19:11:54 guenther Exp $
# $FreeBSD: Makefile.inc,v 1.6 1999/08/28 00:03:02 peter Exp $
# POSIX thread man files
@@ -32,6 +32,7 @@ MAN+= \
pthread_equal.3 \
pthread_exit.3 \
pthread_getconcurrency.3 \
+ pthread_getcpuclockid.3 \
pthread_getspecific.3 \
pthread_join.3 \
pthread_key_create.3 \
diff --git a/lib/libpthread/man/pthread_getcpuclockid.3 b/lib/libpthread/man/pthread_getcpuclockid.3
new file mode 100644
index 00000000000..b01ff49afda
--- /dev/null
+++ b/lib/libpthread/man/pthread_getcpuclockid.3
@@ -0,0 +1,61 @@
+.\" $OpenBSD: pthread_getcpuclockid.3,v 1.1 2013/06/17 19:11:54 guenther Exp $
+.\"
+.\" Copyright (c) 2013 Philip Guenther <guenther@openbsd.org>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: June 17 2013 $
+.Dt PTHREAD_GETCPUCLOCKID 3
+.Os
+.Sh NAME
+.Nm pthread_getcpuclockid
+.Nd get a clock measuring thread CPU time
+.Sh SYNOPSIS
+.Fd #include <pthread.h>
+.Ft int
+.Fn pthread_getcpuclockid "pthread_t thread" "clockid_t *clock_id"
+.Sh DESCRIPTION
+The
+.Fn pthread_getcpuclockid
+function allows the calling thread to get a
+.Vt clockid_t
+value that measures the time spent by CPUs running in user or kernel mode
+on behalf of the thread specified by
+.Fa thread .
+.Sh RETURN VALUES
+If successful,
+.Fn pthread_getcpuclockid
+will return zero.
+Otherwise an error number will be returned to indicate the error.
+.Sh ERRORS
+.Fn pthread_getcpuclockid
+will fail if:
+.Bl -tag -width Er
+.It Bq Er ESRCH
+thread is an invalid thread ID.
+.El
+.Sh SEE ALSO
+.Xr clock_gettime 2 ,
+.Xr clock_getcpuclockid 3
+.Sh STANDARDS
+The
+.Fn pthread_getcpuclockid
+function conforms to
+.St -p1003.1-2008 .
+.Sh HISTORY
+The
+.Fn pthread_getcpuclockid
+function first appeared in
+.St -p1003.1d-99
+and has been available since
+.Ox 5.4 .
diff --git a/lib/libpthread/man/pthreads.3 b/lib/libpthread/man/pthreads.3
index 9f76594d4ad..3843b8a1f3a 100644
--- a/lib/libpthread/man/pthreads.3
+++ b/lib/libpthread/man/pthreads.3
@@ -1,6 +1,6 @@
-.\" $OpenBSD: pthreads.3,v 1.38 2012/09/02 13:29:29 jmc Exp $
+.\" $OpenBSD: pthreads.3,v 1.39 2013/06/17 19:11:54 guenther Exp $
.\" David Leonard <d@openbsd.org>, 1998. Public domain.
-.Dd $Mdocdate: September 2 2012 $
+.Dd $Mdocdate: June 17 2013 $
.Dt PTHREADS 3
.Os
.Sh NAME
@@ -269,6 +269,8 @@ Set cancelability state.
Set cancelability state.
.It Fn pthread_sigmask
Examine/change a thread's signal mask.
+.It Fn pthread_getcpuclockid
+Get a CPU time clock for a thread.
.El
.Ss Thread stacks
Each thread has a different stack, whether it be provided by a
@@ -419,6 +421,7 @@ with larger numbers generating more verbose output.
.Xr pthread_detach 3 ,
.Xr pthread_equal 3 ,
.Xr pthread_exit 3 ,
+.Xr pthread_getcpuclockid 3,
.Xr pthread_getspecific 3 ,
.Xr pthread_join 3 ,
.Xr pthread_key_create 3 ,
diff --git a/lib/librthread/Makefile b/lib/librthread/Makefile
index 9f9d6264e5c..1c82668a5ea 100644
--- a/lib/librthread/Makefile
+++ b/lib/librthread/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.34 2012/11/22 19:10:27 miod Exp $
+# $OpenBSD: Makefile,v 1.35 2013/06/17 19:11:54 guenther Exp $
# For ``COMPILER_VERSION'' and ``ELF_TOOLCHAIN''
.include <bsd.own.mk>
@@ -27,6 +27,7 @@ SRCS= rthread.c \
rthread_debug.c \
rthread_file.c \
rthread_fork.c \
+ rthread_getcpuclockid.c \
rthread_libc.c \
rthread_mutex_prio.c \
rthread_mutexattr.c \
diff --git a/lib/librthread/rthread_getcpuclockid.c b/lib/librthread/rthread_getcpuclockid.c
new file mode 100644
index 00000000000..52d50c6ad68
--- /dev/null
+++ b/lib/librthread/rthread_getcpuclockid.c
@@ -0,0 +1,28 @@
+/* $OpenBSD: rthread_getcpuclockid.c,v 1.1 2013/06/17 19:11:54 guenther Exp $ */
+/*
+ * Copyright (c) 2013 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <time.h>
+#include <pthread.h>
+
+#include "rthread.h"
+
+int
+pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id)
+{
+ *clock_id = __CLOCK_ENCODE(CLOCK_THREAD_CPUTIME_ID, thread->tid);
+ return (0);
+}
diff --git a/lib/librthread/shlib_version b/lib/librthread/shlib_version
index 49b346400a8..8f4855b2ca5 100644
--- a/lib/librthread/shlib_version
+++ b/lib/librthread/shlib_version
@@ -1,2 +1,2 @@
major=17
-minor=2
+minor=3
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)) {
diff --git a/sys/sys/_time.h b/sys/sys/_time.h
index 05bab99d9a5..add19a636e4 100644
--- a/sys/sys/_time.h
+++ b/sys/sys/_time.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: _time.h,v 1.2 2012/05/10 19:13:12 kettenis Exp $ */
+/* $OpenBSD: _time.h,v 1.3 2013/06/17 19:11:54 guenther Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@@ -32,10 +32,21 @@
#ifndef _SYS__TIME_H_
#define _SYS__TIME_H_
-#define CLOCK_REALTIME 0
-#define CLOCK_VIRTUAL 1
-#define CLOCK_PROF 2
-#define CLOCK_MONOTONIC 3
+#define CLOCK_REALTIME 0
+#define CLOCK_VIRTUAL 1
+#define CLOCK_PROCESS_CPUTIME_ID 2
+#define CLOCK_MONOTONIC 3
+#define CLOCK_THREAD_CPUTIME_ID 4
+
+#if __BSD_VISIBLE
+/*
+ * Per-process and per-thread clocks encode the PID or TID into the
+ * high bits, with the type in the bottom bits
+ */
+#define __CLOCK_ENCODE(type,id) ((type) | ((id) << 12))
+#define __CLOCK_TYPE(c) ((c) & 0xfff)
+#define __CLOCK_PTID(c) (((c) >> 12) & 0xfffff)
+#endif
/*
* Structure defined by POSIX 1003.1b to be like a itimerval,
diff --git a/sys/sys/types.h b/sys/sys/types.h
index 05301f2aa0f..786127b5c14 100644
--- a/sys/sys/types.h
+++ b/sys/sys/types.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: types.h,v 1.36 2013/06/11 16:42:18 deraadt Exp $ */
+/* $OpenBSD: types.h,v 1.37 2013/06/17 19:11:54 guenther Exp $ */
/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */
/*-
@@ -137,7 +137,6 @@ typedef __ino_t ino_t; /* inode number */
typedef __key_t key_t; /* IPC key (for Sys V IPC) */
typedef __mode_t mode_t; /* permissions */
typedef __nlink_t nlink_t; /* link count */
-typedef __pid_t pid_t; /* process id */
typedef __rlim_t rlim_t; /* resource limit */
typedef __segsz_t segsz_t; /* segment size */
typedef __swblk_t swblk_t; /* swap offset */
@@ -171,6 +170,11 @@ typedef __clock_t clock_t;
typedef __clockid_t clockid_t;
#endif
+#ifndef _PID_T_DEFINED_
+#define _PID_T_DEFINED_
+typedef __pid_t pid_t;
+#endif
+
#ifndef _SIZE_T_DEFINED_
#define _SIZE_T_DEFINED_
typedef __size_t size_t;
diff --git a/usr.bin/kdump/kdump_subr.h b/usr.bin/kdump/kdump_subr.h
index f27c3fa10fd..20c53de4263 100644
--- a/usr.bin/kdump/kdump_subr.h
+++ b/usr.bin/kdump/kdump_subr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: kdump_subr.h,v 1.8 2012/12/25 09:35:51 guenther Exp $ */
+/* $OpenBSD: kdump_subr.h,v 1.9 2013/06/17 19:11:54 guenther Exp $ */
/*
* Copyright(c) 2006 2006 David Kirchner <dpk@dpk.net>
*
@@ -55,6 +55,7 @@ void prioname(int);
void madvisebehavname(int);
void msyncflagsname(int);
void clockname(int);
+void clocktypename(int);
void schedpolicyname(int);
void kldunloadfflagsname(int);
void ksethrcmdname(int);
diff --git a/usr.bin/kdump/mksubr b/usr.bin/kdump/mksubr
index 1682fd9e99a..d0b048bedc3 100644
--- a/usr.bin/kdump/mksubr
+++ b/usr.bin/kdump/mksubr
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: mksubr,v 1.14 2012/12/25 09:35:51 guenther Exp $
+# $OpenBSD: mksubr,v 1.15 2013/06/17 19:11:54 guenther Exp $
#
# Copyright (c) 2006 David Kirchner <dpk@dpk.net>
#
@@ -429,6 +429,14 @@ flagsandmodename (int flags, int mode) {
}
}
+void
+clockname (int clockid)
+{
+ clocktypename(__CLOCK_TYPE(clockid));
+ if (__CLOCK_PTID(clockid) != 0)
+ printf("(%d)", __CLOCK_PTID(clockid));
+}
+
/*
* MANUAL
*
@@ -476,7 +484,7 @@ auto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h
#auto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h"
auto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
auto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
-auto_switch_type "clockname" "CLOCK_[A-Z]+[[:space:]]+[0-9]+" "sys/_time.h"
+auto_switch_type "clocktypename" "CLOCK_[_A-Z]+[[:space:]]+[0-9]+" "sys/_time.h"
#auto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h"
#auto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
#auto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h"