[Glibc-bsd-commits] r4738 - in trunk/glibc-ports/kfreebsd: . bits fbtl

Petr Salinger ps-guest at alioth.debian.org
Fri Jul 12 14:17:05 UTC 2013


Author: ps-guest
Date: 2013-07-12 14:17:05 +0000 (Fri, 12 Jul 2013)
New Revision: 4738

Added:
   trunk/glibc-ports/kfreebsd/fbtl/clock_getcpuclockid.c
   trunk/glibc-ports/kfreebsd/fbtl/clock_getres.c
   trunk/glibc-ports/kfreebsd/fbtl/clock_gettime.c
   trunk/glibc-ports/kfreebsd/fbtl/clock_nanosleep.c
   trunk/glibc-ports/kfreebsd/fbtl/clock_settime.c
   trunk/glibc-ports/kfreebsd/fbtl/pthread_getcpuclockid.c
   trunk/glibc-ports/kfreebsd/fbtl/sysconf.c
Modified:
   trunk/glibc-ports/kfreebsd/bits/time.h
   trunk/glibc-ports/kfreebsd/fbtl/Makefile
   trunk/glibc-ports/kfreebsd/fbtl/Versions
   trunk/glibc-ports/kfreebsd/syscalls.list
Log:
use upcoming kernel timers for CLOCK_*_CPUTIME_ID and related  clock_id's


Modified: trunk/glibc-ports/kfreebsd/bits/time.h
===================================================================
--- trunk/glibc-ports/kfreebsd/bits/time.h	2013-07-12 14:09:44 UTC (rev 4737)
+++ trunk/glibc-ports/kfreebsd/bits/time.h	2013-07-12 14:17:05 UTC (rev 4738)
@@ -61,6 +61,10 @@
 #   define CLOCK_THREAD_CPUTIME_ID	14
 /* High-resolution timer from the CPU.  */
 #   define CLOCK_PROCESS_CPUTIME_ID	15
+#   ifdef __USE_BSD
+#     define CPUCLOCK_WHICH_PID 0
+#     define CPUCLOCK_WHICH_TID 1
+#   endif
 
 /* Flag to indicate time is absolute.  */
 #   define TIMER_RELTIME	0   /* relative timer */

Modified: trunk/glibc-ports/kfreebsd/fbtl/Makefile
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/Makefile	2013-07-12 14:09:44 UTC (rev 4737)
+++ trunk/glibc-ports/kfreebsd/fbtl/Makefile	2013-07-12 14:17:05 UTC (rev 4738)
@@ -46,8 +46,13 @@
 libpthread-routines += ptw-exit-thread
 libpthread-routines += ptw-sigprocmask
 libpthread-routines += ptw-ioctl
+libpthread-routines += ptw-sys_clock_getcpuclockid2
 endif
 
+ifeq ($(subdir),rt)
+sysdep_routines += sys_clock_getcpuclockid2
+endif
+
 ifeq ($(subdir),posix)
 CFLAGS-fork.c = $(libio-mtsafe)
 CFLAGS-getpid.o = -fomit-frame-pointer

Modified: trunk/glibc-ports/kfreebsd/fbtl/Versions
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/Versions	2013-07-12 14:09:44 UTC (rev 4737)
+++ trunk/glibc-ports/kfreebsd/fbtl/Versions	2013-07-12 14:17:05 UTC (rev 4738)
@@ -12,5 +12,7 @@
     __syscall_sigsuspend;
     __syscall_sigaction;
     __syscall__umtx_op;
+# needed by librt as INLINE_SYSCALL:
+    __syscall_clock_getcpuclockid2;
   }
 }

Added: trunk/glibc-ports/kfreebsd/fbtl/clock_getcpuclockid.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/clock_getcpuclockid.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/clock_getcpuclockid.c	2013-07-12 14:17:05 UTC (rev 4738)
@@ -0,0 +1,32 @@
+/* Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+#include <kernel-features.h>
+
+int __syscall_clock_getcpuclockid2(long id, int which, clockid_t *clock_id);
+libc_hidden_proto (__syscall_clock_getcpuclockid2)
+
+
+int
+__clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
+{
+   return INLINE_SYSCALL(clock_getcpuclockid2, 3, pid, CPUCLOCK_WHICH_PID, clock_id);
+}
+strong_alias (__clock_getcpuclockid, clock_getcpuclockid)

Added: trunk/glibc-ports/kfreebsd/fbtl/clock_getres.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/clock_getres.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/clock_getres.c	2013-07-12 14:17:05 UTC (rev 4738)
@@ -0,0 +1,42 @@
+/* Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stdint.h>
+#include <time.h>
+#include <sys/time.h>
+#include <libc-internal.h>
+#include <ldsodefs.h>
+#include <sysdep.h>
+
+int __syscall_clock_getres(clockid_t clock_id, struct timespec *tp);
+libc_hidden_proto (__syscall_clock_getres)
+
+/* Get resolution of clock.  */
+int
+__clock_getres (clockid_t clock_id, struct timespec *tp)
+{
+  /* we could try to provide fallback
+     via ??? for CLOCK_REALTIME
+     via HP_TIMING for CLOCK_PROCESS_CPUTIME_ID, 
+       CLOCK_THREAD_CPUTIME_ID and related timers
+
+     for now just pass it to kernel       
+   */    
+  return INLINE_SYSCALL (clock_getres, 2, clock_id, tp);
+}
+strong_alias (__clock_getres, clock_getres)

Added: trunk/glibc-ports/kfreebsd/fbtl/clock_gettime.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/clock_gettime.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/clock_gettime.c	2013-07-12 14:17:05 UTC (rev 4738)
@@ -0,0 +1,42 @@
+/* Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stdint.h>
+#include <time.h>
+#include <sys/time.h>
+#include <libc-internal.h>
+#include <ldsodefs.h>
+#include <sysdep.h>
+
+int __syscall_clock_gettime(clockid_t clock_id, struct timespec *tp);
+libc_hidden_proto (__syscall_clock_gettime)
+
+/* Get current value of CLOCK and store it in TP.  */
+int
+__clock_gettime (clockid_t clock_id, struct timespec *tp)
+{
+  /* we could try to provide fallback
+     via gettimeofday for  CLOCK_REALTIME
+     via HP_TIMING for CLOCK_PROCESS_CPUTIME_ID, 
+       CLOCK_THREAD_CPUTIME_ID and related timers
+
+     for now just pass it to kernel       
+   */    
+  return INLINE_SYSCALL (clock_gettime, 2, clock_id, tp);
+}
+strong_alias (__clock_gettime, clock_gettime)

Added: trunk/glibc-ports/kfreebsd/fbtl/clock_nanosleep.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/clock_nanosleep.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/clock_nanosleep.c	2013-07-12 14:17:05 UTC (rev 4738)
@@ -0,0 +1,99 @@
+/* High-resolution sleep with the specified clock.
+   Copyright (C) 2000-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <assert.h>
+#include <errno.h>
+#include <time.h>
+#include <hp-timing.h>
+#include <sysdep-cancel.h>
+
+
+int __syscall_clock_gettime(clockid_t clock_id, struct timespec *tp);
+libc_hidden_proto (__syscall_clock_gettime)
+
+
+/* This implementation assumes that these is only a `nanosleep' system
+   call.  So we have to remap all other activities.  */
+int
+__clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
+		 struct timespec *rem)
+{
+  struct timespec now;
+
+  if (__builtin_expect (req->tv_nsec, 0) < 0
+      || __builtin_expect (req->tv_nsec, 0) >= 1000000000)
+    return EINVAL;
+
+  if (clock_id == CLOCK_THREAD_CPUTIME_ID)
+    return EINVAL;		/* POSIX specifies EINVAL for this case.  */
+
+  switch(clock_id)
+  {
+	case CLOCK_REALTIME:
+	case CLOCK_MONOTONIC:
+	case CLOCK_UPTIME:
+	case CLOCK_UPTIME_PRECISE:
+	case CLOCK_UPTIME_FAST:
+	case CLOCK_REALTIME_PRECISE:
+	case CLOCK_REALTIME_FAST:
+	case CLOCK_MONOTONIC_PRECISE:
+	case CLOCK_MONOTONIC_FAST:
+	case CLOCK_SECOND:
+	    /* almost realtime clocks */
+        break;
+        
+        default:
+            /* Not supported.  */
+            return ENOTSUP;
+  }         
+
+  /* If we got an absolute time, remap it.  */
+  if (flags == TIMER_ABSTIME)
+    {
+      long int nsec;
+      long int sec;
+
+      /* Make sure we use safe data types.  */
+      assert (sizeof (sec) >= sizeof (now.tv_sec));
+
+      /* Get the current time for this clock.  */
+      if (__builtin_expect (INLINE_SYSCALL (clock_gettime, 2, clock_id, &now), 0) != 0)
+	return errno;
+
+      /* Compute the difference.  */
+      nsec = req->tv_nsec - now.tv_nsec;
+      sec = req->tv_sec - now.tv_sec - (nsec < 0);
+      if (sec < 0)
+	/* The time has already elapsed.  */
+	return 0;
+
+      now.tv_sec = sec;
+      now.tv_nsec = nsec + (nsec < 0 ? 1000000000 : 0);
+
+      /* From now on this is our time.  */
+      req = &now;
+
+      /* Make sure we are not modifying the struct pointed to by REM.  */
+      rem = NULL;
+    }
+  else if (__builtin_expect (flags, 0) != 0)
+    return EINVAL;
+
+  return __builtin_expect (__nanosleep (req, rem), 0) ? errno : 0;
+}
+strong_alias (__clock_nanosleep, clock_nanosleep)

Added: trunk/glibc-ports/kfreebsd/fbtl/clock_settime.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/clock_settime.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/clock_settime.c	2013-07-12 14:17:05 UTC (rev 4738)
@@ -0,0 +1,54 @@
+/* Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stdint.h>
+#include <time.h>
+#include <sys/time.h>
+#include <libc-internal.h>
+#include <ldsodefs.h>
+#include <sysdep.h>
+
+int __syscall_clock_settime(clockid_t clock_id, const struct timespec *tp);
+libc_hidden_proto (__syscall_clock_settime)
+
+/* Set CLOCK to value TP.  */
+int
+__clock_settime (clockid_t clock_id, const struct timespec *tp)
+{
+  switch(clock_id)
+  {
+	case CLOCK_MONOTONIC:
+	case CLOCK_MONOTONIC_PRECISE:
+	case CLOCK_MONOTONIC_FAST:
+	    /* almost monotonic clocks */
+            __set_errno (EINVAL); /* per POSIX */
+	    return -1;
+        break;
+        default:;
+  };
+  /* we could try to provide fallback
+     via settimeofday for CLOCK_REALTIME
+     via HP_TIMING for CLOCK_PROCESS_CPUTIME_ID, 
+       CLOCK_THREAD_CPUTIME_ID and related timers
+
+     for now just pass it to kernel       
+   */    
+  
+  return INLINE_SYSCALL (clock_settime, 2, clock_id, tp);
+}
+strong_alias (__clock_settime, clock_settime)

Added: trunk/glibc-ports/kfreebsd/fbtl/pthread_getcpuclockid.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/pthread_getcpuclockid.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/pthread_getcpuclockid.c	2013-07-12 14:17:05 UTC (rev 4738)
@@ -0,0 +1,41 @@
+/* Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+#include <kernel-features.h>
+#include <pthreadP.h>
+#include <tls.h>
+
+int __syscall_clock_getcpuclockid2(long id, int which, clockid_t *clock_id);
+libc_hidden_proto (__syscall_clock_getcpuclockid2)
+
+int
+pthread_getcpuclockid (threadid, clockid)
+     pthread_t threadid;
+     clockid_t *clockid;
+{
+  struct pthread *pd = (struct pthread *) threadid;
+
+  /* Make sure the descriptor is valid.  */
+  if (INVALID_TD_P (pd))
+    /* Not a valid thread handle.  */
+    return ESRCH;
+
+  return INLINE_SYSCALL(clock_getcpuclockid2, 3, pd->tid, CPUCLOCK_WHICH_TID, clockid);
+}

Copied: trunk/glibc-ports/kfreebsd/fbtl/sysconf.c (from rev 4736, trunk/glibc-ports/kfreebsd/sysconf.c)
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/sysconf.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/sysconf.c	2013-07-12 14:17:05 UTC (rev 4738)
@@ -0,0 +1,73 @@
+/* Get file-specific information about a file.
+   Copyright (C) 2006 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sysdep.h>
+#include <time.h>
+#include <unistd.h>
+#include <hp-timing.h>
+#include <sys/sysctl.h>
+
+static long int posix_sysconf (int name);
+
+int __syscall_clock_getcpuclockid2(long id, int which, clockid_t *clock_id);
+libc_hidden_proto (__syscall_clock_getcpuclockid2)
+
+/* Get the value of the system variable NAME.  */
+long int
+__sysconf (int name)
+{
+  int request[2];
+  int value;
+  size_t len = sizeof(value);
+
+  switch(name)
+    {
+      case _SC_CPUTIME:
+      case _SC_THREAD_CPUTIME:
+      {
+        clockid_t clock_id;
+        /* try whether we have a syscall available */ 
+        if ( ENOSYS != INLINE_SYSCALL(clock_getcpuclockid2, 3, 0, CPUCLOCK_WHICH_TID, &clock_id))
+	  return 200809L;
+	else
+	  return -1;
+      }  
+      case _SC_NGROUPS_MAX:
+	request[0] = CTL_KERN;
+	request[1] = KERN_NGROUPS;
+	if (__sysctl(request, 2, &value, &len, NULL, 0) == -1)
+	    return NGROUPS_MAX;
+	return (long)value;
+      case _SC_ARG_MAX:
+	request[0] = CTL_KERN;
+	request[1] = KERN_ARGMAX;
+	if (__sysctl(request, 2, &value, &len, NULL, 0) == -1)
+	    return ARG_MAX;
+	return (long)value;
+    }
+  return posix_sysconf (name);
+}
+
+/* Now the POSIX version.  */
+#undef __sysconf
+#define __sysconf static posix_sysconf
+#include <sysdeps/posix/sysconf.c>

Modified: trunk/glibc-ports/kfreebsd/syscalls.list
===================================================================
--- trunk/glibc-ports/kfreebsd/syscalls.list	2013-07-12 14:09:44 UTC (rev 4737)
+++ trunk/glibc-ports/kfreebsd/syscalls.list	2013-07-12 14:17:05 UTC (rev 4738)
@@ -16,6 +16,7 @@
 sys_aio_waitcomplete	-	aio_waitcomplete	i:pp		__syscall_aio_waitcomplete
 sys_aio_write		-	aio_write		i:p		__syscall_aio_write
 sys_bind		-	bind			i:ipi		__syscall_bind
+sys_clock_getcpuclockid2  -     clock_getcpuclockid2    Vi:iip		__syscall_clock_getcpuclockid2
 sys_clock_getres	-	clock_getres		i:ip		__syscall_clock_getres
 sys_clock_gettime	-	clock_gettime		i:ip		__syscall_clock_gettime
 sys_clock_settime	-	clock_settime		i:ip		__syscall_clock_settime




More information about the Glibc-bsd-commits mailing list