diff options
author | 2013-06-17 19:11:54 +0000 | |
---|---|---|
committer | 2013-06-17 19:11:54 +0000 | |
commit | 7b36c281ba1c99d528efca950572c207acd2e184 (patch) | |
tree | f5c2b481403a1c10e5fb3838834ab4fd89d0397e /lib | |
parent | 2nd part of: (diff) | |
download | wireguard-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@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 8 | ||||
-rw-r--r-- | lib/libc/gen/clock_getcpuclockid.3 | 65 | ||||
-rw-r--r-- | lib/libc/gen/clock_getcpuclockid.c | 31 | ||||
-rw-r--r-- | lib/libc/shlib_version | 2 | ||||
-rw-r--r-- | lib/libc/sys/clock_gettime.2 | 45 | ||||
-rw-r--r-- | lib/libpthread/include/pthread.h | 6 | ||||
-rw-r--r-- | lib/libpthread/man/Makefile.inc | 3 | ||||
-rw-r--r-- | lib/libpthread/man/pthread_getcpuclockid.3 | 61 | ||||
-rw-r--r-- | lib/libpthread/man/pthreads.3 | 7 | ||||
-rw-r--r-- | lib/librthread/Makefile | 3 | ||||
-rw-r--r-- | lib/librthread/rthread_getcpuclockid.c | 28 | ||||
-rw-r--r-- | lib/librthread/shlib_version | 2 |
12 files changed, 236 insertions, 25 deletions
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 |