Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread Add pthread_getcpuclockid(3)



details:   https://anonhg.NetBSD.org/src/rev/34056fc72452
branches:  trunk
changeset: 814986:34056fc72452
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Apr 23 23:12:19 2016 +0000

description:
Add pthread_getcpuclockid(3)

diffstat:

 lib/libpthread/Makefile                |    4 +-
 lib/libpthread/pthread.h               |    4 +-
 lib/libpthread/pthread_getcpuclockid.3 |  121 +++++++++++++++++++++++++++++++++
 lib/libpthread/pthread_getcpuclockid.c |   46 ++++++++++++
 4 files changed, 173 insertions(+), 2 deletions(-)

diffs (218 lines):

diff -r 911c30a10f92 -r 34056fc72452 lib/libpthread/Makefile
--- a/lib/libpthread/Makefile   Sat Apr 23 23:11:31 2016 +0000
+++ b/lib/libpthread/Makefile   Sat Apr 23 23:12:19 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.85 2014/12/16 20:05:54 pooka Exp $
+#      $NetBSD: Makefile,v 1.86 2016/04/23 23:12:19 christos Exp $
 #
 
 WARNS?=        5
@@ -54,6 +54,7 @@
 SRCS+= pthread_cancelstub.c
 .endif
 SRCS+= pthread_cond.c
+SRCS+= pthread_getcpuclockid.c
 SRCS+= pthread_lock.c 
 SRCS+= ${PTHREAD_MAKELWP}
 SRCS+= pthread_misc.c
@@ -134,6 +135,7 @@
        pthread_create.3 pthread_detach.3 pthread_equal.3 \
        pthread_curcpu_np.3 \
        pthread_exit.3 \
+       pthread_getcpuclockid.3 \
        pthread_getname_np.3 \
        pthread_getspecific.3 pthread_join.3 \
        pthread_key_create.3 pthread_kill.3 \
diff -r 911c30a10f92 -r 34056fc72452 lib/libpthread/pthread.h
--- a/lib/libpthread/pthread.h  Sat Apr 23 23:11:31 2016 +0000
+++ b/lib/libpthread/pthread.h  Sat Apr 23 23:12:19 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread.h,v 1.35 2012/11/03 03:10:50 christos Exp $    */
+/*     $NetBSD: pthread.h,v 1.36 2016/04/23 23:12:19 christos Exp $    */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -138,6 +138,8 @@
 
 unsigned int   pthread_curcpu_np(void);
 
+int    pthread_getcpuclockid(pthread_t, clockid_t *);
+
 struct pthread_cleanup_store {
        void    *pad[4];
 };
diff -r 911c30a10f92 -r 34056fc72452 lib/libpthread/pthread_getcpuclockid.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpthread/pthread_getcpuclockid.3    Sat Apr 23 23:12:19 2016 +0000
@@ -0,0 +1,121 @@
+.\"    $NetBSD: pthread_getcpuclockid.3,v 1.1 2016/04/23 23:12:19 christos Exp $
+.\"
+.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Christos Zoulas.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 23, 2016
+.Dt clock_getcpuclockid2 2
+.Os
+.Sh NAME
+.Nm clock_getcpuclockid2
+.Nd retrieve the clock id of a process or lwp
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In time.h
+.Ft int
+.Fn clock_getcpuclockid2 "idtype_t idtype" "id_t id" "clockid_t *clock_id"
+.Ft int
+.Fn clock_getcpuclockid "pid_t pid" "clockid_t *clock_id"
+.Sh DESCRIPTION
+The
+.Fn cpu_getcpuclockid2
+function retrieves the
+.Fa clock_id
+for the specified
+.Fa id
+and
+.Fa idtype.
+Supported
+.Fa idtypes
+are:
+.Bl -tag -width P_LWPID
+.It Dv P_PID
+The specified process id or
+.Dv 0
+for the current process.
+.It Dv P_LWPID
+The specified LWP id or
+.Dv 0
+for the current LWP.
+.El
+.Pp
+The
+.Fn clock_getcpuclockid
+function is equivalent to calling
+.Fn clock_getcpuclockid2
+with
+.Fa idtype
+.Dv P_PID
+and
+.Fa id
+.Fa pid .
+.Pp
+The
+.Xr clock_gettime 2
+function can be used with the returned
+.Fa clock_id
+to retrieve process and LWP times.
+.Sh RETURN VALUES
+The
+.Fn clock_getcpuclockid
+and
+.Fn clock_getcpuclockid2
+functions succeed and return 0, placing the requested
+.Fa clock_id 
+in the argument.
+On error, the value \-1 is returned
+and the value of
+.Va errno
+is set to reflect what went wrong.
+.Sh ERRORS
+These functions fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+An unsuppored
+.Fa idtype
+was supplied.
+.El
+.Sh SEE ALSO
+.Xr clock_gettime 2
+.Sh STANDARDS
+The
+.Fn clock_getcpuclockid
+function conforms to
+.St -p1003.1-2001 .
+The
+.Fn clock_getcpuclockid2
+is a
+.Nx
+extension.
+.Sh HISTORY
+The
+.Fn clock_getcpuclockid
+and
+.Fn clock_getcpuclockid2
+functions appeared in
+.Nx 8 .
diff -r 911c30a10f92 -r 34056fc72452 lib/libpthread/pthread_getcpuclockid.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpthread/pthread_getcpuclockid.c    Sat Apr 23 23:12:19 2016 +0000
@@ -0,0 +1,46 @@
+/*     $NetBSD: pthread_getcpuclockid.c,v 1.1 2016/04/23 23:12:19 christos Exp $       */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: pthread_getcpuclockid.c,v 1.1 2016/04/23 23:12:19 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <pthread.h>
+#include <time.h>
+
+#include "pthread_int.h"
+
+int
+pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id)
+{
+       return clock_getcpuclockid2(P_LWPID, (id_t)thread->pt_lid, clock_id);
+}



Home | Main Index | Thread Index | Old Index