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