This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC v5 06/21] sysdeps/timespec_get: Use clock_gettime64 if avaliable
- From: Alistair Francis <alistair dot francis at wdc dot com>
- To: libc-alpha at sourceware dot org
- Cc: arnd at arndb dot de, adhemerval dot zanella at linaro dot org, fweimer at redhat dot com, palmer at sifive dot com, macro at wdc dot com, zongbox at gmail dot com, alistair dot francis at wdc dot com, alistair23 at gmail dot com
- Date: Thu, 29 Aug 2019 09:50:16 -0700
- Subject: [RFC v5 06/21] sysdeps/timespec_get: Use clock_gettime64 if avaliable
- Ironport-sdr: x1c472ffU9fmqB1jCmujWAa+PZ+2Bv99H2Q7cezz5ZtYABJZwILP9JTjhHZS7EeU2wH0sPZv8z jrWt2ubmEnNU5bdMHiSkjU7p0i8sErH/JHkdPvCJAp0YsYd0QvOGF6k3TGtQuRR2M7CKTy29eY PUCwAf3Js86wKg/fKtpKzxzbeKY1RYN/lycirpz4nSVvGZ7aYBLAepCQ0cYEK2Ef3Ai41JJGQT 9IaXvoVmvEeuPJU0g2OiNxJr4gAQVj66xPmxFh8Er5MCpwAuNvGTDszIr1zNFep+Kz7AoVbHnc 0Wg=
- Ironport-sdr: n0qZb69qm4uzwU6VU2VVBY9j7MqZhVYrAPcJcmcMirpHWckKw8zYlDy5WT29aM142j62/1nwGH fGHvlILzZc6ETCVtWPCenFHonl9/ldL3SuU3s/ebQnklGO8Op8Xod0WY4iIHjysq8Ej+uxqKce V7Up1wfORDUJYLcLz3rJ3ASzszE3KuLO2PK4BLX5ilMQ7Cd2DqtQ7RGIsshLES88gT7z1aPOvM hYSLs10W3UCST30xPMVUy8F01ZF1Ea6MwxVcngAKal8yg/vmLigYLN0WnveJ7o9iZ3N8685QXz C/KmxVnIqLnJVwODvU0z8EaK
- Ironport-sdr: WyA8Esck6jUxVdwzGn/D89lTmOpjWUKk6t1KfYt3WI+TnnU7ADghKNa0wh9+XYK86PIzW3VXiR KNSO3iMTZIAfFOvt2LoYBJ/PvH9Yfi7oHFDN5UDq9O0ZrbcG+tEVgvNw36bjZpkduSkBe9VpAX +uy5/OKEES2s/Gync5uGC4CWvLRMbKSnRO7ng4m/pD9c0D/D4QK5ckN36Z660vtcLD4yithKuC P/5PfPqzL7eMflUIcMbq8b//oLyDJuaYU4e/4mAWE0UwtD3XOOr3OuS1M64siCEN7k/tA9sB3X oK8=
- References: <cover.1567097252.git.alistair.francis@wdc.com>
- Wdcironportexception: Internal
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
* sysdeps/unix/sysv/linux/timespec_get.c: Use clock_gettime64
if avaliable.
---
include/time.h | 1 +
sysdeps/unix/sysv/linux/timespec_get.c | 48 ++++++++++++++++++++++++--
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/include/time.h b/include/time.h
index 1e33f34e1f6..ae88eac62d6 100644
--- a/include/time.h
+++ b/include/time.h
@@ -178,6 +178,7 @@ extern double __difftime (time_t time1, time_t time0);
#define __nanosleep_time64 __nanosleep
#define __nanosleep_nocancel_time64 __nanosleep_nocancel
#define __clock_gettime64 __clock_gettime
+#define __timespec_get64 timespec_get
#endif
/* Use in the clock_* functions. Size of the field representing the
diff --git a/sysdeps/unix/sysv/linux/timespec_get.c b/sysdeps/unix/sysv/linux/timespec_get.c
index 52080ddf08a..f53e75d5719 100644
--- a/sysdeps/unix/sysv/linux/timespec_get.c
+++ b/sysdeps/unix/sysv/linux/timespec_get.c
@@ -26,16 +26,34 @@
/* Set TS to calendar time based in time base BASE. */
int
-timespec_get (struct timespec *ts, int base)
+__timespec_get64 (struct timespec *ts, int base)
{
switch (base)
{
int res;
INTERNAL_SYSCALL_DECL (err);
case TIME_UTC:
- res = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, ts);
+#ifdef __ASSUME_TIME64_SYSCALLS
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 __NR_clock_gettime
+# endif
+ res = INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, ts);
+#else
+# ifdef __NR_clock_gettime64
+ res = INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, ts);
+# endif /* __NR_clock_gettime64 */
+ struct timespec ts32;
+
+ res = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, &ts32);
+
+ if (res == 0 || !INTERNAL_SYSCALL_ERROR_P (res, err))
+ {
+ ts->tv_sec = ts32.tv_sec;
+ ts->tv_nsec = ts32.tv_nsec;
+ }
+#endif
if (INTERNAL_SYSCALL_ERROR_P (res, err))
- return 0;
+ return 0;
break;
default:
@@ -44,3 +62,27 @@ timespec_get (struct timespec *ts, int base)
return base;
}
+
+#if __TIMESIZE != 64
+int
+timespec_get (struct timespec *ts, int base)
+{
+ int ret;
+ struct __timespec64 ts64;
+
+ ret = __timespec_get64 (&ts64, base);
+
+ if (ret == 0 || !INTERNAL_SYSCALL_ERROR_P (ret, err))
+ {
+ ts->tv_sec = ts64.tv_sec;
+ ts->tv_nsec = ts64.tv_nsec;
+ if (! in_time_t_range (ts64.tv_sec))
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+ }
+
+ return ret;
+}
+#endif
--
2.22.0