ce426f
From 01c3d9bb14a1e90159d6999cf3469e62c0c5d4b2 Mon Sep 17 00:00:00 2001
ce426f
From: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
ce426f
Date: Fri, 3 May 2013 15:00:31 -0500
ce426f
Subject: [PATCH 27/42] PowerPC: Add time vDSO support
ce426f
ce426f
PowerPC kernel now provides a vDSO implementation for time syscall
ce426f
(commit fcb41a2030abe0eb716ef0798035ef9562097f42). This patch changes
ce426f
time syscall wrapper to use the vDSO when available. It also changes
ce426f
the default non vDSO time on PowerPC to use sysdeps/posix/time.c
ce426f
(since gettimeofday is a vDSO call).
ce426f
(cherry picked from commit 83e7640f6bf68708ecf0b09d83c670203167271e)
ce426f
---
ce426f
 sysdeps/unix/sysv/linux/powerpc/Versions         |  1 +
ce426f
 sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h |  6 ++-
ce426f
 sysdeps/unix/sysv/linux/powerpc/init-first.c     |  4 +-
ce426f
 sysdeps/unix/sysv/linux/powerpc/time.c           | 62 ++++++++++++++++++++++++
ce426f
 5 files changed, 81 insertions(+), 3 deletions(-)
ce426f
 create mode 100644 sysdeps/unix/sysv/linux/powerpc/time.c
ce426f
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Versions glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Versions
ce426f
index 396a423..289c4fe 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Versions
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Versions
ce426f
@@ -4,5 +4,6 @@ libc {
ce426f
     __vdso_clock_gettime;
ce426f
     __vdso_clock_getres;
ce426f
     __vdso_getcpu;
ce426f
+    __vdso_time;
ce426f
   }
ce426f
 }
ce426f
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
ce426f
index e4ae630..f7f635e 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
ce426f
@@ -32,14 +32,16 @@ extern void *__vdso_get_tbfreq;
ce426f
 
ce426f
 extern void *__vdso_getcpu;
ce426f
 
ce426f
+extern void *__vdso_time;
ce426f
+
ce426f
 /* This macro is needed for PPC64 to return a skeleton OPD entry of a vDSO
ce426f
    symbol.  This works because _dl_vdso_vsym always return the function
ce426f
    address, and no vDSO symbols use the TOC or chain pointers from the OPD
ce426f
    so we can allow them to be garbage.  */
ce426f
 #if defined(__PPC64__) || defined(__powerpc64__)
ce426f
-#define VDSO_IFUNC_RET(value)  &value
ce426f
+#define VDSO_IFUNC_RET(value)  ((void *) &(value))
ce426f
 #else
ce426f
-#define VDSO_IFUNC_RET(value)  value
ce426f
+#define VDSO_IFUNC_RET(value)  ((void *) (value))
ce426f
 #endif
ce426f
 
ce426f
 #endif
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/init-first.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/init-first.c
ce426f
index 5587e2a..3cefd9b 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/init-first.c
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/init-first.c
ce426f
@@ -28,7 +28,7 @@ void *__vdso_clock_gettime;
ce426f
 void *__vdso_clock_getres;
ce426f
 void *__vdso_get_tbfreq;
ce426f
 void *__vdso_getcpu;
ce426f
-
ce426f
+void *__vdso_time;
ce426f
 
ce426f
 static inline void
ce426f
 _libc_vdso_platform_setup (void)
ce426f
@@ -44,6 +44,8 @@ _libc_vdso_platform_setup (void)
ce426f
   __vdso_get_tbfreq = _dl_vdso_vsym ("__kernel_get_tbfreq", &linux2615);
ce426f
 
ce426f
   __vdso_getcpu = _dl_vdso_vsym ("__kernel_getcpu", &linux2615);
ce426f
+
ce426f
+  __vdso_time = _dl_vdso_vsym ("__kernel_time", &linux2615);
ce426f
 }
ce426f
 
ce426f
 # define VDSO_SETUP _libc_vdso_platform_setup
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/time.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/time.c
ce426f
new file mode 100644
ce426f
index 0000000..66b4eb3
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/time.c
ce426f
@@ -0,0 +1,62 @@
ce426f
+/* time system call for Linux/PowerPC.
ce426f
+   Copyright (C) 2013 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#ifdef SHARED
ce426f
+
ce426f
+# include <time.h>
ce426f
+# include <sysdep.h>
ce426f
+# include <bits/libc-vdso.h>
ce426f
+
ce426f
+void *time_ifunc (void) asm ("time");
ce426f
+
ce426f
+static time_t
ce426f
+time_syscall (time_t *t)
ce426f
+{
ce426f
+  struct timeval tv;
ce426f
+  time_t result;
ce426f
+
ce426f
+  if (INLINE_VSYSCALL (gettimeofday, 2, &tv, NULL) < 0)
ce426f
+    result = (time_t) -1;
ce426f
+  else
ce426f
+    result = (time_t) tv.tv_sec;
ce426f
+
ce426f
+  if (t != NULL)
ce426f
+    *t = result;
ce426f
+  return result;
ce426f
+}
ce426f
+
ce426f
+void *
ce426f
+time_ifunc (void)
ce426f
+{
ce426f
+  /* If the vDSO is not available we fall back to the syscall.  */
ce426f
+  return (__vdso_time ? VDSO_IFUNC_RET (__vdso_time)
ce426f
+	  : time_syscall);
ce426f
+}
ce426f
+asm (".type time, %gnu_indirect_function");
ce426f
+
ce426f
+/* This is doing "libc_hidden_def (time)" but the compiler won't
ce426f
+ * let us do it in C because it doesn't know we're defining time
ce426f
+ * here in this file.  */
ce426f
+asm (".globl __GI_time\n"
ce426f
+     "__GI_time = time");
ce426f
+
ce426f
+#else
ce426f
+
ce426f
+#include <sysdeps/posix/time.c>
ce426f
+
ce426f
+#endif
ce426f
-- 
ce426f
1.7.11.7
ce426f