This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC v2 07/20] sysdeps/gettimeofday: 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, zong at andestech dot com, alistair dot francis at wdc dot com, alistair23 at gmail dot com
- Date: Mon, 24 Jun 2019 17:09:04 -0700
- Subject: [RFC v2 07/20] sysdeps/gettimeofday: Use clock_gettime64 if avaliable
- Ironport-sdr: a/3A60mHI0xL1gQ1kXWXC+MY4NGgJyJt8CqodeY06zFABRTLPWICbV6dkGM35YI6eBsQEzxABG wy9DA1FsO9w9RErJ7iqKXW5zM/S8C9TNY/jEFfcY8A7Kvg/pI1UI1ndN1RAn/JxjPUCt7Y7Lr9 UZHOUbDAvLtDHSPPIlN1Ti3YeGIamlhY9C70slsK+rjjrYZ0LOoZgcBoj58FmLEMcCm7e2HTSD zWnY1Y2wChOwIFIAXgKBss8xuvCqHvndpB9cRN9IaWJicEGGD0aqFMrwY66xAdr16apIm3PuQ+ 9dr+AKqeQxYhfZBVMK1OxQbt
- Ironport-sdr: /mxpbohggUL0XPGc0RBOUKL3GWeQEPHmqmK8QnZ5xNExlO54wRxFRlgJCtziYPnJJHDfUZGT22 WGoe9qZfmKcKxS8ldYj60JIkZMRoc72iAREx0MgMNH+XttKG927pempIGWId52zII72d13LAHV +jUMHPJRcBBFVUIekf1mQ3O1A9TUmog8pFQvVPF9WiHShhYMbeVoFkKJ+iDSQhxz2+42yDnCkO C31gy1w05IvtOdYh5zsT3ExB6i3aM10FNGG2L0U5juD4kJr+jfpfA3JCNZBwE/XBELBA/mJLkP 9Ss=
- References: <cover.1561421042.git.alistair.francis@wdc.com>
Not all architectures support the obsolete gettimeofday so use the
newer clock_gettime64 syscall if it is avaliable. This fixes RV32
build issues.
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
ChangeLog | 1 +
sysdeps/unix/sysv/linux/gettimeofday.c | 28 ++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index a700783ef3..f1c7acb6ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
* sysdeps/unix/sysv/linux/nanosleep.c: Likewise.
* sysdeps/unix/sysv/linux/nanosleep_nocancel.c: Likewise.
* sysdeps/unix/sysv/linux/lowlevellock-futex.h: Use __NR_futex_time64 if we don't have __NR_futex.
+ * sysdeps/unix/sysv/linux/gettimeofday.c: Use clock_gettime64 syscall for gettimeofday.
2019-06-20 Dmitry V. Levin <ldv@altlinux.org>
Florian Weimer <fweimer@redhat.com>
diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c
index a74f03825a..3d2b943123 100644
--- a/sysdeps/unix/sysv/linux/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/gettimeofday.c
@@ -32,7 +32,35 @@
int
__gettimeofday (struct timeval *tv, struct timezone *tz)
{
+#ifdef __ASSUME_TIME64_SYSCALLS
+ int ret;
+ struct timespec now;
+
+ ret = INLINE_VSYSCALL (clock_gettime64, 2, CLOCK_REALTIME,
+ &now);
+
+ /* Convert from timespec to timeval */
+ tv->tv_sec = now.tv_sec;
+ tv->tv_usec = now.tv_nsec / 1000;
+
+ return ret;
+#else
+# ifdef __NR_clock_gettime64
+ long int ret;
+ struct timespec now;
+
+ ret = INLINE_VSYSCALL (clock_gettime64, 2, CLOCK_REALTIME,
+ &now);
+
+ /* Convert from timespec to timeval */
+ tv->tv_sec = now.tv_sec;
+ tv->tv_usec = now.tv_nsec / 1000;
+
+ if (ret == 0 || errno != ENOSYS)
+ return ret;
+# endif
return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
+#endif
}
libc_hidden_def (__gettimeofday)
weak_alias (__gettimeofday, gettimeofday)
--
2.22.0