This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Use VDSO interface for gettimeofday on aarch64


Here is an updated version of the gettimeofday vdso patch.  I tried to
address as many of the questions as I could.  I added two tests,
tst-gettimeofday and tst-gettimeofday2.  tst-gettimeofday2 just 
includes tst-gettimeofday but is tested with 'LD_BIND_NOW=1'.

I think defining __gettimeofday to be __redirect___gettimeofday and
including sys/time.h is the best way to handle things.  Even
if we did a explicit definition of __redirect__gettimeofday we
would need to include sys/time.h to get the timeval and timezone
structures and if we didn't redefine __gettimeofday when doing
that the definition of __gettimeofday in the header file would
conflict with the one defined by libc_ifunc_hidden.  This is how
x86 and powerpc handle it in their gettimeofday functions and also
how aarch64 handles the definition/redefinition of memcpy in
sysdeps/aarch64/multiarch/memcpy.c.

I am not sure how to handle the static linked binary issue you raised,
I have been copying what x86/powerpc did and if they or some other
platform has solved this then I would be interested in how to
do it.  Since PR 19767 is still open I assume it hasn't been fixed
anywhere yet and I would rather not try to deal with it in this
patch.

I changed __gettimeofday_syscall to __gettimeofday_vsyscall and
I got rid of the redefinition of libc_hidden_def by just calling
__hidden_ver1 directly (in the shared case).

There do seem to be places where libc calls gettimeofday (nis/nis_call.c,
login/logwtmp.c, resolv/gai_suspend.c, others).  Most of them call
__gettimeofday but some just call gettimeofday.  I am not sure what
if anything needs to be done with these calls, they don't seem to
have changed when x86 or powerpc made their gettimeofday/vdso changes..

Steve Ellcey
sellcey@cavium.com


This is what I would use for a commit message:


aarch64: Use an ifunc/VDSO to implement gettimeofday in shared glibc.

This patch uses an ifunc to implement gettimeofday in the shared libc.
If the kernel supports the VDSO interface we use it, otherwise we use
the old method of a vsyscall.  The static version of gettimeofday 
continues to use a syscall.


2018-05-15  Steve Ellcey  <sellcey@caviumnetworks.com>

	* sysdeps/unix/sysv/linux/aarch64/gettimeofday.c: New file.
	* posix/tst-gettimeofday.c: New file.
	* posix/tst-gettimeofday2.c: New file.
	* posix/Makefile (tests): Add new tests to list.
diff --git a/posix/Makefile b/posix/Makefile
index e9730ee..2cd3a44 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -95,7 +95,8 @@ tests		:= test-errno tstgetopt testfnm runtests runptests \
 		   tst-posix_spawn-fd tst-posix_spawn-setsid \
 		   tst-posix_fadvise tst-posix_fadvise64 \
 		   tst-sysconf-empty-chroot tst-glob_symlinks tst-fexecve \
-		   tst-glob-tilde test-ssize-max
+		   tst-glob-tilde test-ssize-max \
+		   tst-gettimeofday tst-gettimeofday2
 tests-internal	:= bug-regex5 bug-regex20 bug-regex33 \
 		   tst-rfc3484 tst-rfc3484-2 tst-rfc3484-3 \
 		   tst-glob_lstat_compat
@@ -257,6 +258,8 @@ tst-boost-ARGS = BOOST.tests
 bug-glob1-ARGS = "$(objpfx)"
 tst-execvp3-ARGS = --test-dir=$(objpfx)
 
+tst-gettimeofday2-ENV = LD_BIND_NOW=1
+
 testcases.h: TESTS TESTS2C.sed
 	LC_ALL=C sed -f TESTS2C.sed < $< > $@T
 	mv -f $@T $@
diff --git a/posix/tst-gettimeofday.c b/posix/tst-gettimeofday.c
index e69de29..703c1ce 100644
--- a/posix/tst-gettimeofday.c
+++ b/posix/tst-gettimeofday.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <time.h>
+
+
+/* Test that nanosleep() does sleep.  */
+static int
+do_test (void)
+{
+  /* Current time.  */
+  struct timeval tv1;
+  TEMP_FAILURE_RETRY (gettimeofday (&tv1, NULL));
+
+  /* Sleep for one second to make sure time changes.  */
+  TEMP_FAILURE_RETRY (sleep (1));
+
+  /* At least one second must have passed.  */
+  struct timeval tv2;
+  TEMP_FAILURE_RETRY (gettimeofday (&tv2, NULL));
+
+  tv2.tv_sec -= tv1.tv_sec;
+  tv2.tv_usec -= tv1.tv_usec;
+  if (tv2.tv_usec < 0)
+    --tv2.tv_sec;
+
+  if (tv2.tv_sec < 1)
+    {
+      puts ("sleep didn't sleep long enough or gettimeofday is broken");
+      return 1;
+    }
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/posix/tst-gettimeofday2.c b/posix/tst-gettimeofday2.c
index e69de29..6c08761 100644
--- a/posix/tst-gettimeofday2.c
+++ b/posix/tst-gettimeofday2.c
@@ -0,0 +1 @@
+#include "tst-gettimeofday.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
index e69de29..5b6ba70 100644
--- a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
@@ -0,0 +1,68 @@
+/* Copyright (C) 2018 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Get the current time of day and timezone information,
+   putting it into *tv and *tz.  If tz is null, *tz is not filled.
+   Returns 0 on success, -1 on errors.  */
+
+#ifdef SHARED
+
+# define __gettimeofday __redirect___gettimeofday
+# include <sys/time.h>
+# undef __gettimeofday
+# define HAVE_VSYSCALL
+# include <dl-vdso.h>
+# include <sysdep-vdso.h>
+
+static int
+__gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz)
+{
+  return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
+}
+
+/* PREPARE_VERSION will need an __LP64__ ifdef when ILP32 support
+   goes in.  See _libc_vdso_platform_setup in
+   sysdeps/unix/sysv/linux/aarch64/init-first.c.  */
+
+# undef INIT_ARCH
+# define INIT_ARCH() \
+	   PREPARE_VERSION (linux_version, "LINUX_2.6.39", 123718537); \
+	   void *vdso_gettimeofday = \
+	     _dl_vdso_vsym ("__kernel_gettimeofday", &linux_version);
+
+libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday,
+                    vdso_gettimeofday ?: (void *) __gettimeofday_vsyscall)
+
+__hidden_ver1 (__gettimeofday_vsyscall, __GI___gettimeofday,
+	       __gettimeofday_vsyscall);
+
+#else
+
+# include <sys/time.h>
+# include <sysdep.h>
+int
+__gettimeofday (struct timeval *tv, struct timezone *tz)
+{
+  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
+}
+libc_hidden_def (__gettimeofday)
+
+#endif
+
+weak_alias (__gettimeofday, gettimeofday)
+libc_hidden_weak (gettimeofday)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]