981dc9
commit b06f4c0094d3c68be39ada0ed26ae99d51f48013
981dc9
Author: Wilco Dijkstra <wdijkstr@arm.com>
981dc9
Date:   Fri Feb 1 12:19:42 2019 +0000
981dc9
981dc9
    Cleanup clock_*time includes
981dc9
    
981dc9
    Clock_gettime, settime and getres implementations are unncessarily
981dc9
    complex due to using defines and C file inclusion.  Simplify the
981dc9
    code by replacing the redundant defines and removing the inclusion,
981dc9
    making it much easier to understand.  No functional changes.
981dc9
    
981dc9
            * sysdeps/posix/clock_getres.c (__clock_getres): Cleanup.
981dc9
            * sysdeps/unix/clock_gettime.c (__clock_gettime): Cleanup.
981dc9
            * sysdeps/unix/clock_settime.c (__clock_settime): Cleanup.
981dc9
            * sysdeps/unix/sysv/linux/clock_getres.c (__clock_getres): Cleanup.
981dc9
            * sysdeps/unix/sysv/linux/clock_gettime.c (__clock_gettime): Cleanup.
981dc9
            * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime): Cleanup.
981dc9
981dc9
diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c
981dc9
index e7924e0891b0a476..43228c381e6a73f1 100644
981dc9
--- a/sysdeps/posix/clock_getres.c
981dc9
+++ b/sysdeps/posix/clock_getres.c
981dc9
@@ -82,20 +82,11 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
981dc9
 
981dc9
   switch (clock_id)
981dc9
     {
981dc9
-#ifdef SYSDEP_GETRES
981dc9
-      SYSDEP_GETRES;
981dc9
-#endif
981dc9
-
981dc9
-#ifndef HANDLED_REALTIME
981dc9
     case CLOCK_REALTIME:
981dc9
       retval = realtime_getres (res);
981dc9
       break;
981dc9
-#endif	/* handled REALTIME */
981dc9
 
981dc9
     default:
981dc9
-#ifdef SYSDEP_GETRES_CPU
981dc9
-      SYSDEP_GETRES_CPU;
981dc9
-#endif
981dc9
 #if HP_TIMING_AVAIL
981dc9
       if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
981dc9
 	  == CLOCK_THREAD_CPUTIME_ID)
981dc9
@@ -105,7 +96,7 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
981dc9
 	__set_errno (EINVAL);
981dc9
       break;
981dc9
 
981dc9
-#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
981dc9
+#if HP_TIMING_AVAIL
981dc9
     case CLOCK_PROCESS_CPUTIME_ID:
981dc9
     case CLOCK_THREAD_CPUTIME_ID:
981dc9
       retval = hp_timing_getres (res);
981dc9
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
981dc9
index 96df78ab1ed09c04..f19fdf7e5f310973 100644
981dc9
--- a/sysdeps/unix/clock_gettime.c
981dc9
+++ b/sysdeps/unix/clock_gettime.c
981dc9
@@ -95,11 +95,6 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
981dc9
 
981dc9
   switch (clock_id)
981dc9
     {
981dc9
-#ifdef SYSDEP_GETTIME
981dc9
-      SYSDEP_GETTIME;
981dc9
-#endif
981dc9
-
981dc9
-#ifndef HANDLED_REALTIME
981dc9
     case CLOCK_REALTIME:
981dc9
       {
981dc9
 	struct timeval tv;
981dc9
@@ -108,12 +103,8 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
981dc9
 	  TIMEVAL_TO_TIMESPEC (&tv, tp);
981dc9
       }
981dc9
       break;
981dc9
-#endif
981dc9
 
981dc9
     default:
981dc9
-#ifdef SYSDEP_GETTIME_CPU
981dc9
-      SYSDEP_GETTIME_CPU (clock_id, tp);
981dc9
-#endif
981dc9
 #if HP_TIMING_AVAIL
981dc9
       if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
981dc9
 	  == CLOCK_THREAD_CPUTIME_ID)
981dc9
@@ -123,7 +114,7 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
981dc9
 	__set_errno (EINVAL);
981dc9
       break;
981dc9
 
981dc9
-#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
981dc9
+#if HP_TIMING_AVAIL
981dc9
     case CLOCK_PROCESS_CPUTIME_ID:
981dc9
       retval = hp_timing_gettime (clock_id, tp);
981dc9
       break;
981dc9
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
981dc9
index 38813eddf7b66ca1..9d5857e61b966b44 100644
981dc9
--- a/sysdeps/unix/clock_settime.c
981dc9
+++ b/sysdeps/unix/clock_settime.c
981dc9
@@ -21,7 +21,7 @@
981dc9
 #include <ldsodefs.h>
981dc9
 
981dc9
 
981dc9
-#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
981dc9
+#if HP_TIMING_AVAIL
981dc9
 /* Clock frequency of the processor.  We make it a 64-bit variable
981dc9
    because some jokers are already playing with processors with more
981dc9
    than 4GHz.  */
981dc9
@@ -84,29 +84,15 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
981dc9
 
981dc9
   switch (clock_id)
981dc9
     {
981dc9
-#define HANDLE_REALTIME \
981dc9
-      do {								      \
981dc9
-	struct timeval tv;						      \
981dc9
-	TIMESPEC_TO_TIMEVAL (&tv, tp);					      \
981dc9
-									      \
981dc9
-	retval = __settimeofday (&tv, NULL);				      \
981dc9
-      } while (0)
981dc9
-
981dc9
-#ifdef SYSDEP_SETTIME
981dc9
-      SYSDEP_SETTIME;
981dc9
-#endif
981dc9
-
981dc9
-#ifndef HANDLED_REALTIME
981dc9
     case CLOCK_REALTIME:
981dc9
-      HANDLE_REALTIME;
981dc9
+      {
981dc9
+	struct timeval tv;
981dc9
+	TIMESPEC_TO_TIMEVAL (&tv, tp);
981dc9
+	retval = __settimeofday (&tv, NULL);
981dc9
+      }
981dc9
       break;
981dc9
-#endif
981dc9
 
981dc9
     default:
981dc9
-#ifdef SYSDEP_SETTIME_CPU
981dc9
-      SYSDEP_SETTIME_CPU;
981dc9
-#endif
981dc9
-#ifndef HANDLED_CPUTIME
981dc9
 # if HP_TIMING_AVAIL
981dc9
       if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
981dc9
 	  || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
981dc9
@@ -117,7 +103,6 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
981dc9
 	  __set_errno (EINVAL);
981dc9
 	  retval = -1;
981dc9
 	}
981dc9
-#endif
981dc9
       break;
981dc9
     }
981dc9
 
981dc9
diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c
981dc9
index 5d94f59afee80fa9..2517e66910a79d93 100644
981dc9
--- a/sysdeps/unix/sysv/linux/clock_getres.c
981dc9
+++ b/sysdeps/unix/sysv/linux/clock_getres.c
981dc9
@@ -26,26 +26,10 @@
981dc9
 #endif
981dc9
 #include <sysdep-vdso.h>
981dc9
 
981dc9
-#define SYSCALL_GETRES \
981dc9
-  retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, res); \
981dc9
-  break
981dc9
-
981dc9
-/* The REALTIME and MONOTONIC clock are definitely supported in the
981dc9
-   kernel.  */
981dc9
-#define SYSDEP_GETRES							      \
981dc9
-  SYSDEP_GETRES_CPUTIME							      \
981dc9
-  case CLOCK_REALTIME:							      \
981dc9
-  case CLOCK_MONOTONIC:							      \
981dc9
-  case CLOCK_MONOTONIC_RAW:						      \
981dc9
-  case CLOCK_REALTIME_COARSE:						      \
981dc9
-  case CLOCK_MONOTONIC_COARSE:						      \
981dc9
-    SYSCALL_GETRES
981dc9
-
981dc9
-/* We handled the REALTIME clock here.  */
981dc9
-#define HANDLED_REALTIME	1
981dc9
-#define HANDLED_CPUTIME		1
981dc9
-
981dc9
-#define SYSDEP_GETRES_CPU SYSCALL_GETRES
981dc9
-#define SYSDEP_GETRES_CPUTIME	/* Default catches them too.  */
981dc9
-
981dc9
-#include <sysdeps/posix/clock_getres.c>
981dc9
+/* Get resolution of clock.  */
981dc9
+int
981dc9
+__clock_getres (clockid_t clock_id, struct timespec *res)
981dc9
+{
981dc9
+  return INLINE_VSYSCALL (clock_getres, 2, clock_id, res);
981dc9
+}
981dc9
+weak_alias (__clock_getres, clock_getres)
981dc9
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
981dc9
index d837fa36b1b901e5..dadfc518b74baea0 100644
981dc9
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
981dc9
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
981dc9
@@ -26,22 +26,11 @@
981dc9
 #endif
981dc9
 #include <sysdep-vdso.h>
981dc9
 
981dc9
-/* The REALTIME and MONOTONIC clock are definitely supported in the
981dc9
-   kernel.  */
981dc9
-#define SYSDEP_GETTIME \
981dc9
-  SYSDEP_GETTIME_CPUTIME;						      \
981dc9
-  case CLOCK_REALTIME:							      \
981dc9
-  case CLOCK_MONOTONIC:							      \
981dc9
-    retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);		      \
981dc9
-    break
981dc9
-
981dc9
-/* We handled the REALTIME clock here.  */
981dc9
-#define HANDLED_REALTIME	1
981dc9
-#define HANDLED_CPUTIME	1
981dc9
-
981dc9
-#define SYSDEP_GETTIME_CPU(clock_id, tp) \
981dc9
-  retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
981dc9
-  break
981dc9
-#define SYSDEP_GETTIME_CPUTIME	/* Default catches them too.  */
981dc9
-
981dc9
-#include <sysdeps/unix/clock_gettime.c>
981dc9
+/* Get current value of CLOCK and store it in TP.  */
981dc9
+int
981dc9
+__clock_gettime (clockid_t clock_id, struct timespec *tp)
981dc9
+{
981dc9
+  return INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);
981dc9
+}
981dc9
+weak_alias (__clock_gettime, clock_gettime)
981dc9
+libc_hidden_def (__clock_gettime)
981dc9
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
981dc9
index 5f3f22f74b3e745c..c71461a4f6deac5a 100644
981dc9
--- a/sysdeps/unix/sysv/linux/clock_settime.c
981dc9
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
981dc9
@@ -21,18 +21,17 @@
981dc9
 
981dc9
 #include "kernel-posix-cpu-timers.h"
981dc9
 
981dc9
-
981dc9
-/* The REALTIME clock is definitely supported in the kernel.  */
981dc9
-#define SYSDEP_SETTIME \
981dc9
-  case CLOCK_REALTIME:							      \
981dc9
-    retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp);		      \
981dc9
-    break
981dc9
-
981dc9
-/* We handled the REALTIME clock here.  */
981dc9
-#define HANDLED_REALTIME	1
981dc9
-
981dc9
-#define HANDLED_CPUTIME 1
981dc9
-#define SYSDEP_SETTIME_CPU \
981dc9
-  retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
981dc9
-
981dc9
-#include <sysdeps/unix/clock_settime.c>
981dc9
+/* Set CLOCK to value TP.  */
981dc9
+int
981dc9
+__clock_settime (clockid_t clock_id, const struct timespec *tp)
981dc9
+{
981dc9
+  /* Make sure the time cvalue is OK.  */
981dc9
+  if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
981dc9
+    {
981dc9
+      __set_errno (EINVAL);
981dc9
+      return -1;
981dc9
+    }
981dc9
+
981dc9
+  return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
981dc9
+}
981dc9
+weak_alias (__clock_settime, clock_settime)