This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC v3 02/23] 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, alistair dot francis at wdc dot com, alistair23 at gmail dot com
- Date: Tue, 16 Jul 2019 17:08:46 -0700
- Subject: [RFC v3 02/23] sysdeps/gettimeofday: Use clock_gettime64 if avaliable
- Ironport-sdr: ydN58vf940vYSBeGucRj31qNqhBJuL4hXh2u5/7vASmLKubULXp1AXJ91402gGeZSTTGcRw0Ij pTkfTzg02I8tto3vqsJ/IIAO4dFy4jqzQweeonZfUh/lV+gPP2iMsvA44koV3af+l6YjuxUrW7 VjHhcAOTXbBCfUE3lZ7ysAOWaXze9EOkNfP9ZoKSh1Nb+u4p1NTl9h158psprzfYS98yM1JHGD bztMs1PXU6oCmYMNqHmj7vZqv4Oxp0sM51oG6GBPcOyAH9ZmRLt5jLqxj/mX/c/YMwX90MtSeo Jq4=
- Ironport-sdr: DSl3dJ5+6OU6cyqt3E5hrlx9z36sdEQ553L6BCZBt0WhyHNqPoNBOlWLntzgF0hP/Roqqmo7IM 7DqT/Hmt/IHqMQNq6sgSVGrvdebINrfhpAQxf+2ViGLJY9n9qHeHNDBehZhoGa7FKdlAxmzZHJ iezwQ9s4x4i97WqNhPXzsNBnW2Xh14rrHIGNPt/4ndgyRaM0GJ6bZ7Z3957DimxWz7J1bNsTMW SK6JfPm68YUgfKgB2Q7HqjQGdFH5ZX2wt4Kp0D9mr3RaIEVYbdqjlx2OkwM/pdUZwp/32ZKCCC +ZM2SW4u/d2qwbPLQUdocmEQ
- Ironport-sdr: Y2E4wkGxn9Gc9u98z798jGhO7depKPTcb1xcsz4Q3CFdRYUyuHtgb1YXHDyRJOj3FBfYcbqUEh tUKZSfVXMkt7ZJDETnITsNIlBCOOQj+RAZoDgXXtJ7WIZKAcFBbWkwTQMT8d2+ZqyLWKXRzdi6 9JAp4rSrw1OX62sVXC/RGU81aS60XFQe8BDVKm/bcgLoKRa4cX0HbkSer3alogqQ4n4I37OIro BYmWhF1n0/SWntC2GqH2OQWh0j3ZJRsOM2ctQdobBR+guM42X5xufZ8A6NRLQ4cR2lKSTq2pqD 7vM=
- References: <cover.1563321715.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 477b9b49b3..9ca390a9c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1028,6 +1028,7 @@
* nptl/thrd_sleep.c: Use clock_nanosleep_time64 instead of nanosleep.
* sysdeps/unix/sysv/linux/nanosleep.c: Likewise.
* sysdeps/unix/sysv/linux/nanosleep_nocancel.c: Likewise.
+ * 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..151b1e606c 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 __timespec64 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 __timespec64 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