unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO
@ 2019-11-10  2:56 Alistair Francis
  2019-11-10  2:56 ` [PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable Alistair Francis
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alistair Francis @ 2019-11-10  2:56 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis

Add support for the clock_gettim64 vDSO calls. These are protected by
the HAVE_CLOCK_GETTIME64_VSYSCALL define.

HAVE_CLOCK_GETTIME64_VSYSCALL should be defined for 32-bit platforms
(WORDSIZE == 32) that only run on the 5.1 kernel or later. WORDSIZE ==
64 platforms can use #define __vdso_clock_gettime64 __vdso_clock_gettime
and use the __vdso_clock_gettime syscall as they don't have a
__vdso_clock_gettime64 call.

	* sysdeps/unix/sysv/linux/init-first.c: Add clock_gettime64
	vDSO.
	* sysdeps/unix/sysv/linux/libc-vdso.h: Likewise.
---
 sysdeps/unix/sysv/linux/init-first.c | 10 ++++++++++
 sysdeps/unix/sysv/linux/libc-vdso.h  |  4 ++++
 2 files changed, 14 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/init-first.c b/sysdeps/unix/sysv/linux/init-first.c
index d90ca820be0..d005d133220 100644
--- a/sysdeps/unix/sysv/linux/init-first.c
+++ b/sysdeps/unix/sysv/linux/init-first.c
@@ -24,6 +24,11 @@
 int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
   attribute_hidden;
 #endif
+/* vDSO symbol used on clock_gettime64 implementation.  */
+#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
+int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *)
+  attribute_hidden;
+#endif
 /* vDSO symbol used on clock_getres implementation.  */
 #ifdef HAVE_CLOCK_GETRES_VSYSCALL
 int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *)
@@ -52,6 +57,11 @@ __libc_vdso_platform_setup (void)
     = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME_VSYSCALL);
 #endif
 
+#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
+  VDSO_SYMBOL(clock_gettime64)
+    = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME64_VSYSCALL);
+#endif
+
 #ifdef HAVE_CLOCK_GETRES_VSYSCALL
   VDSO_SYMBOL(clock_getres)
     = get_vdso_mangle_symbol (HAVE_CLOCK_GETRES_VSYSCALL);
diff --git a/sysdeps/unix/sysv/linux/libc-vdso.h b/sysdeps/unix/sysv/linux/libc-vdso.h
index 792ac39d85a..c6d505bab39 100644
--- a/sysdeps/unix/sysv/linux/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/libc-vdso.h
@@ -32,6 +32,10 @@
 extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
   attribute_hidden;
 #endif
+#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
+extern int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *)
+  attribute_hidden;
+#endif
 #ifdef HAVE_CLOCK_GETRES_VSYSCALL
 extern int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *)
   attribute_hidden;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable
  2019-11-10  2:56 [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO Alistair Francis
@ 2019-11-10  2:56 ` Alistair Francis
  2019-11-21 17:46   ` Adhemerval Zanella
  2019-11-18 21:40 ` [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO Alistair Francis
  2019-11-21 17:46 ` Adhemerval Zanella
  2 siblings, 1 reply; 7+ messages in thread
From: Alistair Francis @ 2019-11-10  2:56 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO
  2019-11-10  2:56 [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO Alistair Francis
  2019-11-10  2:56 ` [PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable Alistair Francis
@ 2019-11-18 21:40 ` Alistair Francis
  2019-11-21 17:46 ` Adhemerval Zanella
  2 siblings, 0 replies; 7+ messages in thread
From: Alistair Francis @ 2019-11-18 21:40 UTC (permalink / raw)
  To: Alistair Francis; +Cc: GNU C Library

On Sat, Nov 9, 2019 at 7:02 PM Alistair Francis
<alistair.francis@wdc.com> wrote:
>
> Add support for the clock_gettim64 vDSO calls. These are protected by
> the HAVE_CLOCK_GETTIME64_VSYSCALL define.
>
> HAVE_CLOCK_GETTIME64_VSYSCALL should be defined for 32-bit platforms
> (WORDSIZE == 32) that only run on the 5.1 kernel or later. WORDSIZE ==
> 64 platforms can use #define __vdso_clock_gettime64 __vdso_clock_gettime
> and use the __vdso_clock_gettime syscall as they don't have a
> __vdso_clock_gettime64 call.
>
>         * sysdeps/unix/sysv/linux/init-first.c: Add clock_gettime64
>         vDSO.
>         * sysdeps/unix/sysv/linux/libc-vdso.h: Likewise.

Ping!

Alistair

> ---
>  sysdeps/unix/sysv/linux/init-first.c | 10 ++++++++++
>  sysdeps/unix/sysv/linux/libc-vdso.h  |  4 ++++
>  2 files changed, 14 insertions(+)
>
> diff --git a/sysdeps/unix/sysv/linux/init-first.c b/sysdeps/unix/sysv/linux/init-first.c
> index d90ca820be0..d005d133220 100644
> --- a/sysdeps/unix/sysv/linux/init-first.c
> +++ b/sysdeps/unix/sysv/linux/init-first.c
> @@ -24,6 +24,11 @@
>  int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
>    attribute_hidden;
>  #endif
> +/* vDSO symbol used on clock_gettime64 implementation.  */
> +#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
> +int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *)
> +  attribute_hidden;
> +#endif
>  /* vDSO symbol used on clock_getres implementation.  */
>  #ifdef HAVE_CLOCK_GETRES_VSYSCALL
>  int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *)
> @@ -52,6 +57,11 @@ __libc_vdso_platform_setup (void)
>      = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME_VSYSCALL);
>  #endif
>
> +#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
> +  VDSO_SYMBOL(clock_gettime64)
> +    = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME64_VSYSCALL);
> +#endif
> +
>  #ifdef HAVE_CLOCK_GETRES_VSYSCALL
>    VDSO_SYMBOL(clock_getres)
>      = get_vdso_mangle_symbol (HAVE_CLOCK_GETRES_VSYSCALL);
> diff --git a/sysdeps/unix/sysv/linux/libc-vdso.h b/sysdeps/unix/sysv/linux/libc-vdso.h
> index 792ac39d85a..c6d505bab39 100644
> --- a/sysdeps/unix/sysv/linux/libc-vdso.h
> +++ b/sysdeps/unix/sysv/linux/libc-vdso.h
> @@ -32,6 +32,10 @@
>  extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
>    attribute_hidden;
>  #endif
> +#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
> +extern int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *)
> +  attribute_hidden;
> +#endif
>  #ifdef HAVE_CLOCK_GETRES_VSYSCALL
>  extern int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *)
>    attribute_hidden;
> --
> 2.23.0
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO
  2019-11-10  2:56 [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO Alistair Francis
  2019-11-10  2:56 ` [PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable Alistair Francis
  2019-11-18 21:40 ` [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO Alistair Francis
@ 2019-11-21 17:46 ` Adhemerval Zanella
  2019-11-21 18:19   ` Alistair Francis
  2 siblings, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2019-11-21 17:46 UTC (permalink / raw)
  To: libc-alpha



On 09/11/2019 23:56, Alistair Francis wrote:
> Add support for the clock_gettim64 vDSO calls. These are protected by
> the HAVE_CLOCK_GETTIME64_VSYSCALL define.
> 
> HAVE_CLOCK_GETTIME64_VSYSCALL should be defined for 32-bit platforms
> (WORDSIZE == 32) that only run on the 5.1 kernel or later. WORDSIZE ==
> 64 platforms can use #define __vdso_clock_gettime64 __vdso_clock_gettime
> and use the __vdso_clock_gettime syscall as they don't have a
> __vdso_clock_gettime64 call.
> 
> 	* sysdeps/unix/sysv/linux/init-first.c: Add clock_gettime64
> 	vDSO.
> 	* sysdeps/unix/sysv/linux/libc-vdso.h: Likewise.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/unix/sysv/linux/init-first.c | 10 ++++++++++
>  sysdeps/unix/sysv/linux/libc-vdso.h  |  4 ++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/sysdeps/unix/sysv/linux/init-first.c b/sysdeps/unix/sysv/linux/init-first.c
> index d90ca820be0..d005d133220 100644
> --- a/sysdeps/unix/sysv/linux/init-first.c
> +++ b/sysdeps/unix/sysv/linux/init-first.c
> @@ -24,6 +24,11 @@
>  int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
>    attribute_hidden;
>  #endif
> +/* vDSO symbol used on clock_gettime64 implementation.  */
> +#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
> +int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *)
> +  attribute_hidden;
> +#endif
>  /* vDSO symbol used on clock_getres implementation.  */
>  #ifdef HAVE_CLOCK_GETRES_VSYSCALL
>  int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *)
> @@ -52,6 +57,11 @@ __libc_vdso_platform_setup (void)
>      = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME_VSYSCALL);
>  #endif
>  
> +#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
> +  VDSO_SYMBOL(clock_gettime64)
> +    = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME64_VSYSCALL);
> +#endif
> +
>  #ifdef HAVE_CLOCK_GETRES_VSYSCALL
>    VDSO_SYMBOL(clock_getres)
>      = get_vdso_mangle_symbol (HAVE_CLOCK_GETRES_VSYSCALL);

Ok.

> diff --git a/sysdeps/unix/sysv/linux/libc-vdso.h b/sysdeps/unix/sysv/linux/libc-vdso.h
> index 792ac39d85a..c6d505bab39 100644
> --- a/sysdeps/unix/sysv/linux/libc-vdso.h
> +++ b/sysdeps/unix/sysv/linux/libc-vdso.h
> @@ -32,6 +32,10 @@
>  extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
>    attribute_hidden;
>  #endif
> +#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
> +extern int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *)
> +  attribute_hidden;
> +#endif
>  #ifdef HAVE_CLOCK_GETRES_VSYSCALL
>  extern int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *)
>    attribute_hidden;
> 

Ok.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable
  2019-11-10  2:56 ` [PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable Alistair Francis
@ 2019-11-21 17:46   ` Adhemerval Zanella
  2019-11-21 18:37     ` Alistair Francis
  0 siblings, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2019-11-21 17:46 UTC (permalink / raw)
  To: libc-alpha



On 09/11/2019 23:56, Alistair Francis wrote:
> 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"

It requires to define HAVE_SYSCALL if HAVE_CLOCK_GETTIME64_VSYSCALL is also
defined, otherwise architectures that define __ASSUME_TIME64_SYSCALLS and
HAVE_CLOCK_GETTIME64_VSYSCALL will not use the vdso.

> @@ -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);

Right, so it would call either __vdso_clock_gettime/__NR_clock_gettime or
__vdso_clock_gettime64/__NR_clock_gettime64.

> +#else
> +# if defined __NR_clock_gettime64 && defined HAVE_CLOCK_GETTIME64_VSYSCALL

I think we can assume that if the ABI provides the time64 vDSO symbol
it also provides the syscall (__NR_clock_gettime64).  So we can just 
check if HAVE_CLOCK_GETTIME64_VSYSCALL is defined. Something like:

#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 HAVE_CLOCK_GETTIME64_VSYSCALL
  int ret64 = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
  if (ret64 == 0 || errno != ENOSYS)
    return ret64;
# endif
  struct timespec tp32;
  int ret = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32);
  if (ret == 0)
    *tp = valid_timespec_to_timespec64 (tp32);
  return ret;
#endif


> +  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  */

Ok.

> +}
> +
> +#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);

Ok.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO
  2019-11-21 17:46 ` Adhemerval Zanella
@ 2019-11-21 18:19   ` Alistair Francis
  0 siblings, 0 replies; 7+ messages in thread
From: Alistair Francis @ 2019-11-21 18:19 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Thu, Nov 21, 2019 at 9:46 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 09/11/2019 23:56, Alistair Francis wrote:
> > Add support for the clock_gettim64 vDSO calls. These are protected by
> > the HAVE_CLOCK_GETTIME64_VSYSCALL define.
> >
> > HAVE_CLOCK_GETTIME64_VSYSCALL should be defined for 32-bit platforms
> > (WORDSIZE == 32) that only run on the 5.1 kernel or later. WORDSIZE ==
> > 64 platforms can use #define __vdso_clock_gettime64 __vdso_clock_gettime
> > and use the __vdso_clock_gettime syscall as they don't have a
> > __vdso_clock_gettime64 call.
> >
> >       * sysdeps/unix/sysv/linux/init-first.c: Add clock_gettime64
> >       vDSO.
> >       * sysdeps/unix/sysv/linux/libc-vdso.h: Likewise.
>
> LGTM, thanks.
>
> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

Thanks! I added your reviewed line to the commit message.

Alistair

>
> > ---
> >  sysdeps/unix/sysv/linux/init-first.c | 10 ++++++++++
> >  sysdeps/unix/sysv/linux/libc-vdso.h  |  4 ++++
> >  2 files changed, 14 insertions(+)
> >
> > diff --git a/sysdeps/unix/sysv/linux/init-first.c b/sysdeps/unix/sysv/linux/init-first.c
> > index d90ca820be0..d005d133220 100644
> > --- a/sysdeps/unix/sysv/linux/init-first.c
> > +++ b/sysdeps/unix/sysv/linux/init-first.c
> > @@ -24,6 +24,11 @@
> >  int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
> >    attribute_hidden;
> >  #endif
> > +/* vDSO symbol used on clock_gettime64 implementation.  */
> > +#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
> > +int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *)
> > +  attribute_hidden;
> > +#endif
> >  /* vDSO symbol used on clock_getres implementation.  */
> >  #ifdef HAVE_CLOCK_GETRES_VSYSCALL
> >  int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *)
> > @@ -52,6 +57,11 @@ __libc_vdso_platform_setup (void)
> >      = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME_VSYSCALL);
> >  #endif
> >
> > +#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
> > +  VDSO_SYMBOL(clock_gettime64)
> > +    = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME64_VSYSCALL);
> > +#endif
> > +
> >  #ifdef HAVE_CLOCK_GETRES_VSYSCALL
> >    VDSO_SYMBOL(clock_getres)
> >      = get_vdso_mangle_symbol (HAVE_CLOCK_GETRES_VSYSCALL);
>
> Ok.
>
> > diff --git a/sysdeps/unix/sysv/linux/libc-vdso.h b/sysdeps/unix/sysv/linux/libc-vdso.h
> > index 792ac39d85a..c6d505bab39 100644
> > --- a/sysdeps/unix/sysv/linux/libc-vdso.h
> > +++ b/sysdeps/unix/sysv/linux/libc-vdso.h
> > @@ -32,6 +32,10 @@
> >  extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
> >    attribute_hidden;
> >  #endif
> > +#ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
> > +extern int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *)
> > +  attribute_hidden;
> > +#endif
> >  #ifdef HAVE_CLOCK_GETRES_VSYSCALL
> >  extern int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *)
> >    attribute_hidden;
> >
>
> Ok.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable
  2019-11-21 17:46   ` Adhemerval Zanella
@ 2019-11-21 18:37     ` Alistair Francis
  0 siblings, 0 replies; 7+ messages in thread
From: Alistair Francis @ 2019-11-21 18:37 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Thu, Nov 21, 2019 at 9:47 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 09/11/2019 23:56, Alistair Francis wrote:
> > 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"
>
> It requires to define HAVE_SYSCALL if HAVE_CLOCK_GETTIME64_VSYSCALL is also
> defined, otherwise architectures that define __ASSUME_TIME64_SYSCALLS and
> HAVE_CLOCK_GETTIME64_VSYSCALL will not use the vdso.
>
> > @@ -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);
>
> Right, so it would call either __vdso_clock_gettime/__NR_clock_gettime or
> __vdso_clock_gettime64/__NR_clock_gettime64.
>
> > +#else
> > +# if defined __NR_clock_gettime64 && defined HAVE_CLOCK_GETTIME64_VSYSCALL
>
> I think we can assume that if the ABI provides the time64 vDSO symbol
> it also provides the syscall (__NR_clock_gettime64).  So we can just
> check if HAVE_CLOCK_GETTIME64_VSYSCALL is defined. Something like:
>
> #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 HAVE_CLOCK_GETTIME64_VSYSCALL
>   int ret64 = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
>   if (ret64 == 0 || errno != ENOSYS)
>     return ret64;
> # endif
>   struct timespec tp32;
>   int ret = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32);
>   if (ret == 0)
>     *tp = valid_timespec_to_timespec64 (tp32);
>   return ret;
> #endif

Thanks for the review. I have updated it to do what you wrote above.

Alistair

>
>
> > +  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  */
>
> Ok.
>
> > +}
> > +
> > +#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);
>
> Ok.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-21 18:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-10  2:56 [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO Alistair Francis
2019-11-10  2:56 ` [PATCH v2 2/2] sysdeps/clock_gettime: Use clock_gettime64 if avaliable Alistair Francis
2019-11-21 17:46   ` Adhemerval Zanella
2019-11-21 18:37     ` Alistair Francis
2019-11-18 21:40 ` [PATCH v2 1/2] sysdeps: Add clock_gettime64 vDSO Alistair Francis
2019-11-21 17:46 ` Adhemerval Zanella
2019-11-21 18:19   ` Alistair Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).