29e444
From 3f38cbfa2a44bf510122d3fcb0f0504a208dbf5e Mon Sep 17 00:00:00 2001
29e444
From: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
29e444
Date: Fri, 15 Mar 2013 10:58:56 -0300
29e444
Subject: [PATCH 19/42] PowerPC: gettimeofday optimization by using IFUNC
29e444
 (backported from commit
29e444
 ef26eece6331a1f6d959818e37c438cc7ce68e53)
29e444
29e444
---
29e444
 sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h | 10 +++++
29e444
 sysdeps/unix/sysv/linux/powerpc/gettimeofday.c   | 48 +++++++++++++++++-------
29e444
 3 files changed, 52 insertions(+), 13 deletions(-)
29e444
12745e
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
29e444
index cda8491..e4ae630 100644
12745e
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
12745e
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
29e444
@@ -32,6 +32,16 @@ extern void *__vdso_get_tbfreq;
29e444
 
29e444
 extern void *__vdso_getcpu;
29e444
 
29e444
+/* This macro is needed for PPC64 to return a skeleton OPD entry of a vDSO
29e444
+   symbol.  This works because _dl_vdso_vsym always return the function
29e444
+   address, and no vDSO symbols use the TOC or chain pointers from the OPD
29e444
+   so we can allow them to be garbage.  */
29e444
+#if defined(__PPC64__) || defined(__powerpc64__)
29e444
+#define VDSO_IFUNC_RET(value)  &value
29e444
+#else
29e444
+#define VDSO_IFUNC_RET(value)  value
29e444
+#endif
29e444
+
29e444
 #endif
29e444
 
29e444
 #endif /* _LIBC_VDSO_H */
12745e
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
29e444
index 7376135..4f4abbd 100644
12745e
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
12745e
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
29e444
@@ -15,26 +15,48 @@
29e444
    License along with the GNU C Library; if not, see
29e444
    <http://www.gnu.org/licenses/>.  */
29e444
 
29e444
-#include <sysdep.h>
29e444
-#include <bp-checks.h>
29e444
-#include <stddef.h>
29e444
 #include <sys/time.h>
29e444
-#include <time.h>
29e444
-#include <hp-timing.h>
29e444
 
29e444
-#include <bits/libc-vdso.h>
29e444
+#ifdef SHARED
29e444
 
29e444
-/* Get the current time of day and timezone information,
29e444
-   putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
29e444
-   Returns 0 on success, -1 on errors.  */
29e444
+# include <dl-vdso.h>
29e444
+# include <bits/libc-vdso.h>
29e444
+
29e444
+void *gettimeofday_ifunc (void) __asm__ ("__gettimeofday");
29e444
+
29e444
+static int
29e444
+__gettimeofday_syscall (struct timeval *tv, struct timezone *tz)
29e444
+{
29e444
+  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
29e444
+}
29e444
+
29e444
+void *
29e444
+gettimeofday_ifunc (void)
29e444
+{
29e444
+  /* If the vDSO is not available we fall back syscall.  */
29e444
+  return (__vdso_gettimeofday ? VDSO_IFUNC_RET (__vdso_gettimeofday)
29e444
+	  : __gettimeofday_syscall);
29e444
+}
29e444
+asm (".type __gettimeofday, %gnu_indirect_function");
29e444
+
29e444
+/* This is doing "libc_hidden_def (__gettimeofday)" but the compiler won't
29e444
+   let us do it in C because it doesn't know we're defining __gettimeofday
29e444
+   here in this file.  */
29e444
+asm (".globl __GI___gettimeofday\n"
29e444
+     "__GI___gettimeofday = __gettimeofday");
29e444
+
29e444
+#else
29e444
+
29e444
+# include <sysdep.h>
29e444
+# include <errno.h>
29e444
 
29e444
 int
29e444
-__gettimeofday (tv, tz)
29e444
-     struct timeval *tv;
29e444
-     struct timezone *tz;
29e444
+__gettimeofday (struct timeval *tv, struct timezone *tz)
29e444
 {
29e444
-  return INLINE_VSYSCALL (gettimeofday, 2, CHECK_1 (tv), CHECK_1 (tz));
29e444
+  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
29e444
 }
29e444
 libc_hidden_def (__gettimeofday)
29e444
+
29e444
+#endif
29e444
 weak_alias (__gettimeofday, gettimeofday)
29e444
 libc_hidden_weak (gettimeofday)
29e444
-- 
29e444
1.7.11.7
29e444