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: PowerPC: gettimeofday optimization by using IFUNC


On 03/04/2013 01:11 PM, Ryan S. Arnold wrote:
> On Wed, Feb 27, 2013 at 1:27 PM, Adhemerval Zanella
> <azanella@linux.vnet.ibm.com> wrote:
>> Ping.
>>
>> On 02/22/2013 04:31 PM, Adhemerval Zanella wrote:
>>> Hi,
>>>
>>> This patch make gettimeofday uses IFUNC and optimizing its call by avoid
>>> the unnecessary way through glibc's internal __gettimeofday. Any tips,
>>> advices, comments?
>>>
>>>
>>> 2013-02-22  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>
>>>
>>>       * sysdeps/unix/sysv/linux/powerpc/gettimeofday.c: Optimizing gettimeofday
>>>       by using IFUNC.
>>>       (gettimeofday_ifunc): Add IFUNC.
>>>       (__gettimeofday_syscall): Sycall fallback when vDSO is not present.
>>>       (__gettimeofday): Using SYSCALL directly in static mode.
> Adhemerval,
>
> This looks great.  Please commit if it tested clean in 32-bit and
> 64-bit configurations.
>
> Ryan S. Arnold
>
This an update to work correctly on PPC32: I didn't take in consideration
that PPC32 ABI does not have an ODP and thus the returned value of an 
IFUNC does not need to be the function indirection.

Tested on PPC64 and PPC32.

--

2013-03-04  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>

	* sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h: Add macro to
	return vdso values correctly in IFUNC implementations.
	* sysdeps/unix/sysv/linux/powerpc/gettimeofday.c (__gettimeofday):
	Optimization by using IFUNC.


diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h b/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
index 545fda4..2e0510c 100644
--- a/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
@@ -32,6 +32,14 @@ extern void *__vdso_get_tbfreq;
 
 extern void *__vdso_getcpu;
 
+/* Macro to return vdso_xxx value on IFUNC implementations.
+   On PPC64 the returned value is actually an OPD entry.  */
+#if defined(__PPC64__) || defined(__powerpc64__)
+#define PTR_IFUNC_RET(value)  &value
+#else
+#define PTR_IFUNC_RET(value)  value
+#endif
+
 #endif
 
 #endif /* _LIBC_VDSO_H */
diff --git a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
index f607485..8424249 100644
--- a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
@@ -15,25 +15,49 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <sysdep.h>
-#include <stddef.h>
+
 #include <sys/time.h>
-#include <time.h>
-#include <hp-timing.h>
 
-#include <bits/libc-vdso.h>
+#ifdef SHARED
+
+# include <dl-vdso.h>
+# include <bits/libc-vdso.h>
+
+void *gettimeofday_ifunc (void) __asm__ ("__gettimeofday");
+
+static int
+__gettimeofday_syscall (struct timeval *tv, struct timezone *tz)
+{
+  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
+}
+
+void *
+gettimeofday_ifunc (void)
+{
+  /* If the vDSO is not available we fall back syscall.  */
+  return (__vdso_gettimeofday ? PTR_IFUNC_RET (__vdso_gettimeofday)
+	  : __gettimeofday_syscall);
+}
+asm (".type __gettimeofday, %gnu_indirect_function");
+
+/* This is doing "libc_hidden_def (__gettimeofday)" but the compiler won't
+   let us do it in C because it doesn't know we're defining __gettimeofday
+   here in this file.  */
+asm (".globl __GI___gettimeofday\n"
+     "__GI___gettimeofday = __gettimeofday");
+
+#else
 
-/* 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.  */
+# include <sysdep.h>
+# include <errno.h>
 
 int
-__gettimeofday (tv, tz)
-     struct timeval *tv;
-     struct timezone *tz;
+__gettimeofday (struct timeval *tv, struct timezone *tz)
 {
-  return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
+  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
 }
 libc_hidden_def (__gettimeofday)
+
+#endif
 weak_alias (__gettimeofday, gettimeofday)
 libc_hidden_weak (gettimeofday)
-- 
1.7.1


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