This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable
- From: Alistair Francis <alistair dot francis at wdc dot com>
- To: libc-alpha at sourceware dot org
- Cc: alistair23 at gmail dot com, Alistair Francis <alistair dot francis at wdc dot com>
- Date: Sat, 9 Nov 2019 18:56:58 -0800
- Subject: [PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable
- Ironport-sdr: R0k2x5RoV0RvxPtgWlkOK0JwK1z3YVIbouucOdKBE8TrP2avgoxBiKQKQetPSVONYxHzP1WIAq KagZYuTdhcLcjyrjBGQyVKVoPT2gT1WjhEhPyM8TQXQ5SSSSW3p8GJwLdBtiM4KWmAGV1OKb7j 7CT5LiIDReBFvpuRvCRBZt3LDwP5jWCJrywxCV32a5NV8ZpBPxhxtZGv1TgXru/JQaHAeijHle uivXMpqn19jjnBIcQndLO23qQ2wCEJgSyyvAZmowiFYeR5uS0sxviYvVByCW5OcZrWTvAQn8rn WQg=
- Ironport-sdr: jFvzTSjTrGIfwzs6fDHhYZhkHebtUi5mSwZVc1iLUfJXKrImUDqTdX6m8QN9QWgCCB8NZF7YJ9 k4fpn7TyXr0Ud41E0oaUjaMTpOuYQrWuQFPunfxvHsrBhvrMaGvmh8VLQaMtsjlCXNnIU/eqyc diMU+37E8vlwTgf6x90zCU9J27m3uCL78rvUUr5j2BzybZuLWfBE7XMsP+Ard8IawBaLL9vVtf vlD3xK/nRO79R3BPtrcDd8G+tX8tYXZKPyhmGJwveSOIBwfqDcUuCKGZp9RxVhBWSmBchq2EPA KJu5kCgWFO4RP4VH4o9TZ+Lo
- Ironport-sdr: SiEYdwtEba/p3WkTtR4Fr47md/NwOBmFrn0M9GKCKR/Y7PYmb1nnV1KJU5ZM12Vz+hM/Shz31c 0sjWXPlDQ75HkkD6OWnqhvvyx+YSibzF4afb567Xceqj4Su+ZA1awj88hU7xMXB+YRgJrA/bjU QRkwxDjn62iPnVPWslSTllwW1oNzcb3gs75vVH83zzPoCpKuuKexd6pPMq0ZuGQVycngUVdoDQ OX/XbjRqufj6wx4uSqVb2bueDUo9BaULjjmFoTdVkDOUWfQKFFmV4Sk/QlFNIEO2FjBPlLFEIv C5k=
- References: <20191110025658.3149-1-alistair.francis@wdc.com>
- Wdcironportexception: Internal
With the clock_gettime64 call we prefer to use vDSO. There is no call
to clock_gettime64 on glibc with older headers and kernel 5.1+ if it
doesn't support vDSO.
---
This was patch was runtime tested with RV32 and RV64
It was build tested using the ./scripts/build-many-glibcs.py script.
I also ran:
$ make ; make install ; make check
tests on native ARM (32-bit) with the following three confiugrations:
- 4.19 Kernel and 4.19 Headers
- 5.2 Kernel and 4.19 Headers
- 5.2 Kernel and 5.2 Headers
and didn't see any regressions
v2:
- Add commit message
- Change ret_64 to int
include/time.h | 3 ++
sysdeps/unix/sysv/linux/clock_gettime.c | 50 ++++++++++++++++++++++++-
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/include/time.h b/include/time.h
index d7800eb30f8..c19c73ae09f 100644
--- a/include/time.h
+++ b/include/time.h
@@ -211,11 +211,14 @@ extern double __difftime (time_t time1, time_t time0);
#if __TIMESIZE == 64
# define __clock_nanosleep_time64 __clock_nanosleep
+# define __clock_gettime64 __clock_gettime
#else
extern int __clock_nanosleep_time64 (clockid_t clock_id,
int flags, const struct __timespec64 *req,
struct __timespec64 *rem);
libc_hidden_proto (__clock_nanosleep_time64)
+extern int __clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp);
+libc_hidden_proto (__clock_gettime64)
#endif
/* Use in the clock_* functions. Size of the field representing the
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index ca40983f6ca..e7af9902f3e 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -17,6 +17,7 @@
<https://www.gnu.org/licenses/>. */
#include <sysdep.h>
+#include <kernel-features.h>
#include <errno.h>
#include <time.h>
#include "kernel-posix-cpu-timers.h"
@@ -30,10 +31,57 @@
/* Get current value of CLOCK and store it in TP. */
int
+__clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp)
+{
+#ifdef __ASSUME_TIME64_SYSCALLS
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 __NR_clock_gettime
+# define __vdso_clock_gettime64 __vdso_clock_gettime
+# endif
+ return INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
+#else
+# if defined __NR_clock_gettime64 && defined HAVE_CLOCK_GETTIME64_VSYSCALL
+ int ret_64;
+ ret_64 = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
+
+ if (ret_64 == 0 || errno != ENOSYS)
+ return ret_64;
+# endif /* __NR_clock_gettime64 && HAVE_CLOCK_GETTIME64_VSYSCALL */
+ int ret;
+ struct timespec tp32;
+
+ ret = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32);
+
+ if (ret == 0)
+ *tp = valid_timespec_to_timespec64 (tp32);
+
+ return ret;
+#endif /* __ASSUME_TIME64_SYSCALLS */
+}
+
+#if __TIMESIZE != 64
+int
__clock_gettime (clockid_t clock_id, struct timespec *tp)
{
- return INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);
+ int ret;
+ struct __timespec64 tp64;
+
+ ret = __clock_gettime64 (clock_id, &tp64);
+
+ if (ret == 0)
+ {
+ if (! in_time_t_range (tp64.tv_sec))
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+
+ *tp = valid_timespec64_to_timespec (tp64);
+ }
+
+ return ret;
}
+#endif
libc_hidden_def (__clock_gettime)
versioned_symbol (libc, __clock_gettime, clock_gettime, GLIBC_2_17);
--
2.23.0