This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC v4 06/24] 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: Fri, 9 Aug 2019 18:00:03 -0700
- Subject: [RFC v4 06/24] sysdeps/timespec_get: Use clock_gettime64 if avaliable
- Ironport-sdr: qJvPQpeGYjQT25xl4Lt183LdtneKzE+s6aT+cRXkcaEbnQYFf7l9S++a7EVqmFf3QkeivtP7QF oqM1PRufrkK7/ZoqxtTeWj09JHe6t833CtW25RKuMhqJ0NpTZ51qBmDvcGPvY/tPSGDGC8sWbf dkEnmRApfJdHOlYSBAz9F5XHojqyTUrkLz74vTZca0eK2zYoCJtuC/EPdIu747khCFkoPc3cOJ cnHsdvIsw1i/gfegL/FcFDBYkeYmwD5gbH+BwCA2rltA4SwxVUBQD3mZzyLWmcaIl7ZZaUTozX eaA=
- Ironport-sdr: a3mBvwPKMmLAeeR7Pc3yibUcb5zA5V1C7jMhOnfADenynXJCbRRHZ49fEyyLB2cyqz+OVKvQlf PyQJBlgOUurGAzM5db/WU1MxJ7YqbYEv5ymVMZuQthy3R+pmKiaFGjWJL1lnLUGx20Erf599dr 9GZblkL3jx9XR6L4bNKnvQVouUM/UQbNQFTZiPeydyUxs2B86mJ/Wcmm4+tN6v8NRwCqNdgYH5 +CAk65qfUuOVz4RrgohyKMWF7UDOhx4zW52GDdMPafDOwYF3ciNfbD4PZMM3tpTdAsMqXMhP7T kv6S34mrSSkJF+6fLSiOnflv
- Ironport-sdr: PYL6CxbAMyyYne3mCk/R4HwJYYhIKrPKesk8I0EbgUcdgnUApsv0zjISstCdaBxBBsSS9Q339q LE+KnZIzKAGzTh3aWq8Th8FhjKqVEvOT/VAl7Z7XBNJhPJsJmza/p0jZBuByXURZOiArzGcBaD cTMx6XhDX+MRRVz3hB3Ho4mDrNIktDc5/IacTg1Cq6s0aJiTxJT8d2wgXfv2xsj34/qOqferGQ IpfgwcdjxHThIzdZJT9I81pOskxXbWfLp8MkhOxHM3STk4okNNlny1ZtvoHh4NvPfF71asucf5 BgQ=
- References: <cover.1565398513.git.alistair.francis@wdc.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
sysdeps/unix/sysv/linux/timespec_get.c | 56 +++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 2 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/timespec_get.c b/sysdeps/unix/sysv/linux/timespec_get.c
index 52080ddf08a..97ef9c5f799 100644
--- a/sysdeps/unix/sysv/linux/timespec_get.c
+++ b/sysdeps/unix/sysv/linux/timespec_get.c
@@ -24,6 +24,58 @@
#endif
#include <sysdep-vdso.h>
+int
+__timespec_get (struct timespec *ts, int base)
+{
+#ifdef __ASSUME_TIME64_SYSCALLS
+ return INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, ts);
+#else
+ long int ret;
+# ifdef __NR_clock_gettime64
+# if __TIMESIZE == 64
+ ret = INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, ts);
+
+ if (ret == 0 || errno != ENOSYS)
+ {
+ return ret;
+ }
+# else
+ struct __timespec64 ts64;
+
+ ret = INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, &ts64);
+
+ if (ret == 0 || errno != ENOSYS)
+ {
+ ts->tv_sec = ts64.tv_sec;
+ ts->tv_nsec = ts64.tv_nsec;
+ return ret;
+ }
+# endif /* __TIMESIZE == 64 */
+# endif /* __NR_clock_gettime64 */
+# if __TIMESIZE == 64
+ struct timespec ts32;
+
+ if (! in_time_t_range (ts->tv_sec))
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+
+ valid_timespec64_to_timespec (ts, &ts32);
+ ret = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, &ts32);
+
+ if (ret == 0 || errno != ENOSYS)
+ {
+ ts->tv_sec = ts32.tv_sec;
+ ts->tv_nsec = ts32.tv_nsec;
+ }
+ return ret;
+# else
+ return INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, ts);
+# endif /* __TIMESIZE == 64 */
+#endif
+}
+
/* Set TS to calendar time based in time base BASE. */
int
timespec_get (struct timespec *ts, int base)
@@ -33,9 +85,9 @@ timespec_get (struct timespec *ts, int base)
int res;
INTERNAL_SYSCALL_DECL (err);
case TIME_UTC:
- res = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, ts);
+ res = __timespec_get (ts, base);
if (INTERNAL_SYSCALL_ERROR_P (res, err))
- return 0;
+ return 0;
break;
default:
--
2.22.0