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] Take 3 vDSO patch for ppc/ppc64


Benjamin Herrenschmidt wrote:

On Thu, 2005-11-03 at 19:17 -0600, Tom Gall wrote:


Greetings,

New this time is just some formatting cleanup to make sure it's compliant with gnu style. Hopefully a step in the right direction.....



Did I miss something ? I can't find where NEED_DL_SYSINFO_DSO is defined for powerpc ... This is necessary afaik, for the vDSO symbols to be "found" by glibc.



The attached draft patch should resolve this problem and support your test effort.

The real issues is handling partial implementations of VDSO (where the kernel version implements some but not all vdso functions). The implementation below adds _dl_vdso_weakref() to handle this case.

I also included a draft hp-timing for ppc32. There seems to be an interaction between existing hp-timing 64-bit support and the new vsdo code. We are still working out the details.


diff -urN libc24-cvstip-20051102/elf/rtld.c libc24/elf/rtld.c
--- libc24-cvstip-20051102/elf/rtld.c	2005-09-29 17:03:37.000000000 -0500
+++ libc24/elf/rtld.c	2005-11-03 20:10:45.000000000 -0600
@@ -1296,6 +1296,13 @@
 	  elf_get_dynamic_info (l, dyn_temp);
 	  _dl_setup_hash (l);
 	  l->l_relocated = 1;
+	  /* Initialize l_local_scope to contain just this map. This allows 
+	     the use of dl_lookup_symbol_x to resolve symbols within the vdso.
+	     So we create a single entry list pointing to l_real as its only
+	     element */
+	  
+	  l->l_local_scope[0]->r_nlist = 1;
+	  l->l_local_scope[0]->r_list = &l->l_real;
 
 	  /* Now that we have the info handy, use the DSO image's soname
 	     so this object can be looked up by name.  Note that we do not
diff -urN libc24-cvstip-20051102/sysdeps/powerpc/Versions libc24/sysdeps/powerpc/Versions
--- libc24-cvstip-20051102/sysdeps/powerpc/Versions	2004-02-13 21:25:10.000000000 -0600
+++ libc24/sysdeps/powerpc/Versions	2005-11-03 20:10:45.000000000 -0600
@@ -13,5 +13,6 @@
   GLIBC_PRIVATE {
     __novmx__libc_longjmp; __novmx__libc_siglongjmp;
     __vmx__libc_longjmp; __vmx__libc_siglongjmp;
+    __vdso_get_tbfreq;
   }
 }
diff -urN libc24-cvstip-20051102/sysdeps/powerpc/elf/libc-start.c libc24/sysdeps/powerpc/elf/libc-start.c
--- libc24-cvstip-20051102/sysdeps/powerpc/elf/libc-start.c	Thu Jul 07 17:57:33 2005
+++ libc24/sysdeps/powerpc/elf/libc-start.c	Wed Dec 31 18:00:00 1969
@@ -1,99 +0,0 @@
-/* Copyright (C) 1998,2000,2001,2002,2003,2004 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, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <ldsodefs.h>
-#include <bp-start.h>
-#include <bp-sym.h>
-
-extern int __cache_line_size;
-weak_extern (__cache_line_size)
-
-/* The main work is done in the generic function.  */
-#define LIBC_START_MAIN generic_start_main
-#define LIBC_START_DISABLE_INLINE
-#define LIBC_START_MAIN_AUXVEC_ARG
-#define MAIN_AUXVEC_ARG
-#include <sysdeps/generic/libc-start.c>
-
-
-struct startup_info
-{
-  void *__unbounded sda_base;
-  int (*main) (int, char **, char **, void *);
-  int (*init) (int, char **, char **, void *);
-  void (*fini) (void);
-};
-
-
-int
-/* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
-   BPs in the arglist of startup_info.main and startup_info.init. */
-BP_SYM (__libc_start_main) (int argc, char *__unbounded *__unbounded ubp_av,
-			    char *__unbounded *__unbounded ubp_ev,
-			    ElfW(auxv_t) *__unbounded auxvec,
-			    void (*rtld_fini) (void),
-			    struct startup_info *__unbounded stinfo,
-			    char *__unbounded *__unbounded stack_on_entry)
-{
-#if __BOUNDED_POINTERS__
-  char **argv;
-#else
-# define argv ubp_av
-#endif
-
-  /* the PPC SVR4 ABI says that the top thing on the stack will
-     be a NULL pointer, so if not we assume that we're being called
-     as a statically-linked program by Linux...	 */
-  if (*stack_on_entry != NULL)
-    {
-      char *__unbounded *__unbounded temp;
-      /* ...in which case, we have argc as the top thing on the
-	 stack, followed by argv (NULL-terminated), envp (likewise),
-	 and the auxilary vector.  */
-      /* 32/64-bit agnostic load from stack */
-      argc = *(long int *__unbounded) stack_on_entry;
-      ubp_av = stack_on_entry + 1;
-      ubp_ev = ubp_av + argc + 1;
-#ifdef HAVE_AUX_VECTOR
-      temp = ubp_ev;
-      while (*temp != NULL)
-        ++temp;
-      auxvec = (ElfW(auxv_t) *)++temp;
-#endif
-      rtld_fini = NULL;
-    }
-
-  /* Initialize the __cache_line_size variable from the aux vector.  */
-  for (ElfW(auxv_t) *av = auxvec; av->a_type != AT_NULL; ++av)
-    switch (av->a_type)
-      {
-      case AT_DCACHEBSIZE:
-        {
-          int *cls = & __cache_line_size;
-          if (cls != NULL)
-            *cls = av->a_un.a_val;
-        }
-        break;
-      }
-
-  return generic_start_main (stinfo->main, argc, ubp_av, auxvec,
-			     stinfo->init, stinfo->fini, rtld_fini,
-			     stack_on_entry);
-}
diff -urN libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/Makefile libc24/sysdeps/unix/sysv/linux/powerpc/Makefile
--- libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/Makefile	2004-04-19 01:18:35.000000000 -0500
+++ libc24/sysdeps/unix/sysv/linux/powerpc/Makefile	2005-11-03 20:10:45.000000000 -0600
@@ -2,3 +2,8 @@
 ifeq ($(subdir),rt)
 librt-routines += rt-sysdep
 endif
+
+ifeq ($(subdir),misc)
+routines += dl-vdso
+endif
+
diff -urN libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h libc24/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
--- libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h	Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h	Thu Nov 03 20:10:45 2005
@@ -0,0 +1,36 @@
+/* Resolved function pointers to VDSO functions.
+   Copyright (C) 2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+
+#ifndef _LIBC_VDSO_H
+#define _LIBC_VDSO_H
+
+#ifdef SHARED
+
+typedef int (* __vdso_gettimeofday_t)(void *, void *);
+
+typedef int (* __vdso_clock_gettime_t)(clockid_t, struct timespec *);
+
+typedef int (* __vdso_clock_getres_t)(struct timeval*, void*);
+
+typedef hp_timing_t (* __vdso_get_tbfreq_t)(void);
+
+#endif
+
+#endif /* _LIBC_VDSO_H */
diff -urN libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/clock_getres.c libc24/sysdeps/unix/sysv/linux/powerpc/clock_getres.c
--- libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/clock_getres.c	Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/clock_getres.c	Thu Nov 03 20:10:45 2005
@@ -0,0 +1,197 @@
+/* clock_getres -- Get the resolution of a POSIX clockid_t.  Linux version.
+   Copyright (C) 2003, 2004 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <time.h>
+#include <sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h>
+#include <sysdeps/unix/sysv/linux/kernel-features.h>
+
+#undef __clock_getres
+#include <bits/libc-vdso.h>
+
+
+#define SYSCALL_GETRES_MONOTONIC \
+#ifdef SHARED                    \
+  if (__vdso_clock_getres== NULL)\
+    retval = INLINE_SYSCALL (clock_getres, 2, clock_id, res); \
+  else \
+    return (__vdso_clock_getres) (clock_id, tp); \
+  break
+
+#define SYSCALL_GETRES_REALTIME \
+  retval = INLINE_SYSCALL (clock_getres, 2, clock_id, res); \
+  break
+
+#ifdef __ASSUME_POSIX_TIMERS
+
+/* This means the REALTIME and MONOTONIC clock are definitely
+   supported in the kernel.  */
+# define SYSDEP_GETRES							      \
+  SYSDEP_GETRES_CPUTIME						      \
+  case CLOCK_REALTIME:							      \
+    SYSCALL_GETRES_REALTIME                                                  \
+  case CLOCK_MONOTONIC:						      \
+    SYSCALL_GETRES_MONOTONIC
+
+# define __libc_missing_posix_timers 0
+#elif defined __NR_clock_getres
+/* Is the syscall known to exist?  */
+extern int __libc_missing_posix_timers attribute_hidden;
+
+static inline int
+maybe_syscall_getres (clockid_t clock_id, struct timespec *res)
+{
+  int e = EINVAL;
+
+  if (!__libc_missing_posix_timers)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      int r = INTERNAL_SYSCALL (clock_getres, err, 2, clock_id, res);
+      if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+	return 0;
+
+      e = INTERNAL_SYSCALL_ERRNO (r, err);
+      if (e == ENOSYS)
+	{
+	  __libc_missing_posix_timers = 1;
+	  e = EINVAL;
+	}
+    }
+
+  return e;
+}
+
+/* The REALTIME and MONOTONIC clock might be available.  Try the
+   syscall first.  */
+# define SYSDEP_GETRES							      \
+  SYSDEP_GETRES_CPUTIME						      \
+  case CLOCK_REALTIME:							      \
+  case CLOCK_MONOTONIC:						      \
+    retval = maybe_syscall_getres (clock_id, res);			      \
+    if (retval == 0)							      \
+      break;								      \
+    /* Fallback code.  */						      \
+    if (retval == EINVAL && clock_id == CLOCK_REALTIME)		      \
+      retval = realtime_getres (res);					      \
+    else								      \
+      {								      \
+	__set_errno (retval);						      \
+	retval = -1;							      \
+      }								      \
+    break;
+#endif
+
+#ifdef __NR_clock_getres
+/* We handled the REALTIME clock here.  */
+# define HANDLED_REALTIME	1
+# define HANDLED_CPUTIME	1
+
+# if __ASSUME_POSIX_CPU_TIMERS > 0
+
+#  define SYSDEP_GETRES_CPU SYSCALL_GETRES
+#  define SYSDEP_GETRES_CPUTIME	/* Default catches them too.  */
+
+# else
+
+extern int __libc_missing_posix_cpu_timers attribute_hidden;
+
+static int
+maybe_syscall_getres_cpu (clockid_t clock_id, struct timespec *res)
+{
+  int e = EINVAL;
+
+  if (!__libc_missing_posix_cpu_timers)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      int r = INTERNAL_SYSCALL (clock_getres, err, 2, clock_id, res);
+      if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+	return 0;
+
+      e = INTERNAL_SYSCALL_ERRNO (r, err);
+# ifndef __ASSUME_POSIX_TIMERS
+      if (e == ENOSYS)
+	{
+	  __libc_missing_posix_timers = 1;
+	  __libc_missing_posix_cpu_timers = 1;
+	  e = EINVAL;
+	}
+      else
+# endif
+	{
+	  if (e == EINVAL)
+	    {
+	      /* Check whether the kernel supports CPU clocks at all.
+		 If not, record it for the future.  */
+	      r = INTERNAL_SYSCALL (clock_getres, err, 2,
+				    MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+				    NULL);
+	      if (INTERNAL_SYSCALL_ERROR_P (r, err))
+		__libc_missing_posix_cpu_timers = 1;
+	    }
+	}
+    }
+
+  return e;
+}
+
+#  define SYSDEP_GETRES_CPU						      \
+  retval = maybe_syscall_getres_cpu (clock_id, res);			      \
+  if (retval == 0)							      \
+    break;								      \
+  if (retval != EINVAL || !__libc_missing_posix_cpu_timers)		      \
+    {									      \
+      __set_errno (retval);						      \
+      retval = -1;							      \
+      break;								      \
+    }									      \
+  retval = -1 /* Otherwise continue on to the HP_TIMING version.  */;
+
+static inline int
+maybe_syscall_getres_cputime (clockid_t clock_id, struct timespec *res)
+{
+  return maybe_syscall_getres_cpu
+    (clock_id == CLOCK_THREAD_CPUTIME_ID
+     ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED)
+     : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+     res);
+}
+
+#  define SYSDEP_GETRES_CPUTIME					      \
+    case CLOCK_PROCESS_CPUTIME_ID:					      \
+    case CLOCK_THREAD_CPUTIME_ID:					      \
+      retval = maybe_syscall_getres_cputime (clock_id, res);		      \
+      if (retval == 0)							      \
+	break;								      \
+      if (retval != EINVAL || !__libc_missing_posix_cpu_timers)	      \
+	{								      \
+	  __set_errno (retval);						      \
+	  retval = -1;							      \
+	  break;							      \
+	}								      \
+      retval = hp_timing_getres (res);					      \
+      break;
+#  if !HP_TIMING_AVAIL
+#   define hp_timing_getres(res) (__set_errno (EINVAL), -1)
+#  endif
+
+# endif
+#endif
+
+#include <sysdeps/posix/clock_getres.c>
diff -urN libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c libc24/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c
--- libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c	Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c	Thu Nov 03 20:10:45 2005
@@ -0,0 +1,196 @@
+/* clock_gettime -- Get current time from a POSIX clockid_t.  Linux version.
+   Copyright (C) 2003, 2004 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <time.h>
+#include <sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h>
+#include <sysdeps/unix/sysv/linux/kernel-features.h>
+
+#undef __clock_gettime
+#include <bits/libc-vdso.h>
+
+#define SYSCALL_GETTIME_CLOCK_MONOTONIC \
+#ifdef SHARED                           \
+  if (__vdso_clock_gettime== NULL)      \
+    retval = INLINE_SYSCALL (clock_gettime, 2, clock_id, tp); \
+  else \
+    return (__vdso_clock_gettime) (clock_id, tp); \
+  break
+
+#define SYSCALL_GETTIME_CLOCK_REALTIME \
+  retval = INLINE_SYSCALL (clock_gettime, 2, clock_id, tp); \
+  break
+
+#ifdef __ASSUME_POSIX_TIMERS
+
+/* This means the REALTIME and MONOTONIC clock are definitely
+   supported in the kernel.  */
+# define SYSDEP_GETTIME						      \
+  SYSDEP_GETTIME_CPUTIME						      \
+  case CLOCK_REALTIME:							      \
+    SYSCALL_GETTIME_CLOCK_REALTIME                                           \
+  case CLOCK_MONOTONIC:						      \
+    SYSCALL_GETTIME_CLOCK_MONOTONIC
+
+# define __libc_missing_posix_timers 0
+#elif defined __NR_clock_gettime
+/* Is the syscall known to exist?  */
+int __libc_missing_posix_timers attribute_hidden;
+
+static inline int
+maybe_syscall_gettime (clockid_t clock_id, struct timespec *tp)
+{
+  int e = EINVAL;
+
+  if (!__libc_missing_posix_timers)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      int r = INTERNAL_SYSCALL (clock_gettime, err, 2, clock_id, tp);
+      if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+	return 0;
+
+      e = INTERNAL_SYSCALL_ERRNO (r, err);
+      if (e == ENOSYS)
+	{
+	  __libc_missing_posix_timers = 1;
+	  e = EINVAL;
+	}
+    }
+
+  return e;
+}
+
+/* The REALTIME and MONOTONIC clock might be available.  Try the
+   syscall first.  */
+# define SYSDEP_GETTIME						      \
+  SYSDEP_GETTIME_CPUTIME						      \
+  case CLOCK_REALTIME:							      \
+  case CLOCK_MONOTONIC:						      \
+    retval = maybe_syscall_gettime (clock_id, tp);			      \
+    if (retval == 0)							      \
+      break;								      \
+    /* Fallback code.  */						      \
+    if (retval == EINVAL && clock_id == CLOCK_REALTIME)		      \
+      retval = realtime_gettime (tp);					      \
+    else 								      \
+      {								      \
+	__set_errno (retval);						      \
+	retval = -1;							      \
+      }								      \
+    break;
+#endif
+
+#ifdef __NR_clock_gettime
+/* We handled the REALTIME clock here.  */
+# define HANDLED_REALTIME	1
+# define HANDLED_CPUTIME	1
+
+# if __ASSUME_POSIX_CPU_TIMERS > 0
+
+#  define SYSDEP_GETTIME_CPU SYSCALL_GETTIME
+#  define SYSDEP_GETTIME_CPUTIME	/* Default catches them too.  */
+
+# else
+
+int __libc_missing_posix_cpu_timers attribute_hidden;
+
+static int
+maybe_syscall_gettime_cpu (clockid_t clock_id, struct timespec *tp)
+{
+  int e = EINVAL;
+
+  if (!__libc_missing_posix_cpu_timers)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      int r = INTERNAL_SYSCALL (clock_gettime, err, 2, clock_id, tp);
+      if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+	return 0;
+
+      e = INTERNAL_SYSCALL_ERRNO (r, err);
+# ifndef __ASSUME_POSIX_TIMERS
+      if (e == ENOSYS)
+	{
+	  __libc_missing_posix_timers = 1;
+	  __libc_missing_posix_cpu_timers = 1;
+	  e = EINVAL;
+	}
+      else
+# endif
+	{
+	  if (e == EINVAL)
+	    {
+	      /* Check whether the kernel supports CPU clocks at all.
+		 If not, record it for the future.  */
+	      r = INTERNAL_SYSCALL (clock_getres, err, 2,
+				    MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+				    NULL);
+	      if (INTERNAL_SYSCALL_ERROR_P (r, err))
+		__libc_missing_posix_cpu_timers = 1;
+	    }
+	}
+    }
+
+  return e;
+}
+
+#  define SYSDEP_GETTIME_CPU						      \
+  retval = maybe_syscall_gettime_cpu (clock_id, tp);			      \
+  if (retval == 0)							      \
+    break;								      \
+  if (retval != EINVAL || !__libc_missing_posix_cpu_timers)		      \
+    {									      \
+      __set_errno (retval);						      \
+      retval = -1;							      \
+      break;								      \
+    }									      \
+  retval = -1 /* Otherwise continue on to the HP_TIMING version.  */;
+
+static inline int
+maybe_syscall_gettime_cputime (clockid_t clock_id, struct timespec *tp)
+{
+  return maybe_syscall_gettime_cpu
+    (clock_id == CLOCK_THREAD_CPUTIME_ID
+     ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED)
+     : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+     tp);
+}
+
+#  define SYSDEP_GETTIME_CPUTIME					      \
+    case CLOCK_PROCESS_CPUTIME_ID:					      \
+    case CLOCK_THREAD_CPUTIME_ID:					      \
+      retval = maybe_syscall_gettime_cputime (clock_id, tp);		      \
+      if (retval == 0)							      \
+	break;								      \
+      if (retval != EINVAL || !__libc_missing_posix_cpu_timers)	      \
+	{								      \
+	  __set_errno (retval);						      \
+	  retval = -1;							      \
+	  break;							      \
+	}								      \
+      retval = hp_timing_gettime (clock_id, tp);			      \
+      break;
+#  if !HP_TIMING_AVAIL
+#   define hp_timing_gettime(clock_id, tp) (__set_errno (EINVAL), -1)
+#  endif
+
+# endif
+#endif
+
+#include <sysdeps/unix/clock_gettime.c>
diff -urN libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c libc24/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c
--- libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c	Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c	Thu Nov 10 18:19:21 2005
@@ -0,0 +1,128 @@
+/* VDSO symbol handling in the ELF dynamic linker.
+   Copyright (C) 2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include "config.h"
+#include <dl-hash.h>
+#include <ldsodefs.h>
+
+/* This function attempts to resolve a symbol in the VDSO map but
+   simply returns NULL if it is not there.  This is intended for the
+   syscall replacement case where the runtime can fail-safe back to
+   the syscall.  For example if we are running on an older kernel
+   that does not implement the specific function yet.  */
+
+void *internal_function
+_dl_vdso_weakref (const char *name)
+{
+  const ElfW (Sym) * ref = NULL;
+  struct link_map *map = GLRO (dl_sysinfo_map);
+  void *value = NULL;
+  lookup_t result;
+
+  /* This is a tricky because by default _dl_lookup_symbol_x will fail
+     and exit if the symbol is not found.  Specifying a "skip_map" is
+     one case where _dl_loopup_symbol_x will do what we want,  but the
+     l_local_scope in the dl_sysinfo_map will not to give the desired
+     result.  So we create a dummy scope and link-map struct to be
+     the "skip_map".  As the dummy.l_real points back to the real VDSO
+     map, do_lookup_x can find the symbol if it is there.  */
+  struct r_scope_elem *symbol_scope[2];
+  struct link_map *scope_list[2];
+  struct r_scope_elem dummy_scope;
+  struct link_map dummy;
+
+  symbol_scope[0] = &dummy_scope;
+  symbol_scope[1] = NULL;
+  symbol_scope[0]->r_nlist = 2;
+  symbol_scope[0]->r_list = &scope_list[0];
+  scope_list[0] = map->l_local_scope[0]->r_list[0];
+  scope_list[1] = &dummy;
+  dummy.l_real = map->l_real;
+
+  if (map != NULL)
+    {
+      /* Search the scope of the given vdso map.  */
+      result = GLRO (dl_lookup_symbol_x) (name, map, &ref,
+					  symbol_scope, NULL, 0, 0, &dummy);
+
+      if (ref != NULL)
+	{
+	  value = DL_SYMBOL_ADDRESS (result, ref);
+	}
+    }
+
+  return value;
+}
+
+
+void *internal_function
+_dl_vdso_sym (const char *name)
+{
+  const ElfW (Sym) * ref = NULL;
+  struct link_map *map = GLRO (dl_sysinfo_map);
+  void *value = NULL;
+  lookup_t result;
+
+  if (map != NULL)
+    {
+      /* Search the scope of the given vdso map.  */
+      result = GLRO (dl_lookup_symbol_x) (name, map, &ref,
+					  map->l_local_scope,
+					  NULL, 0, 0, NULL);
+
+      if (ref != NULL)
+	{
+	  value = DL_SYMBOL_ADDRESS (result, ref);
+	}
+    }
+
+  return value;
+}
+
+void *internal_function
+_dl_vdso_vsym (const char *name, const char *version)
+{
+  const ElfW (Sym) * ref = NULL;
+  struct link_map *map = GLRO (dl_sysinfo_map);
+  void *value = NULL;
+  struct r_found_version vers;
+  lookup_t result;
+
+  if (map != NULL)
+    {
+      /* Compute hash value to the version string.  */
+      vers.name = version;
+      vers.hidden = 1;
+      vers.hash = _dl_elf_hash (version);
+      /* We don't have a specific file where the symbol can be found.  */
+      vers.filename = NULL;
+
+      /* Search the scope of the vdso map.  */
+      result = GLRO (dl_lookup_symbol_x) (name, map, &ref,
+					  map->l_local_scope,
+					  &vers, 0, 0, NULL);
+
+      if (ref != NULL)
+	{
+	  value = DL_SYMBOL_ADDRESS (result, ref);
+
+	}
+    }
+  return value;
+}
diff -urN libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h libc24/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h
--- libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h	Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h	Thu Nov 10 18:19:27 2005
@@ -0,0 +1,34 @@
+/* Run-time dynamic linker data structures for loaded ELF shared objects.
+   Copyright (C) 2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef	_DL_VDSO_H
+#define _DL_VDSO_H
+
+/* Functions for resolving symbols in the VDSO link map.  */
+extern void *
+_dl_vdso_weakref (const char *name)
+     internal_function attribute_hidden;
+
+     extern void *_dl_vdso_sym (const char *name)
+     internal_function attribute_hidden;
+
+     extern void *_dl_vdso_vsym (const char *name, const char *version)
+     internal_function attribute_hidden;
+
+#endif /* ldsodefs.h */
diff -urN libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c libc24/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
--- libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c	2005-10-31 20:11:53.000000000 -0600
+++ libc24/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c	2005-11-03 20:10:45.000000000 -0600
@@ -22,7 +22,11 @@
 #include <string.h>
 #include <unistd.h>
 #include <libc-internal.h>
+#include <bits/libc-vdso.h>
 
+#ifdef SHARED
+extern __vdso_get_tbfreq_t __vdso_get_tbfreq;
+#endif
 
 hp_timing_t
 __get_clockfreq (void)
@@ -38,68 +42,78 @@
   if (timebase_freq != 0)
     return timebase_freq;
 
-  int fd = open ("/proc/cpuinfo", O_RDONLY);
-  if (__builtin_expect (fd != -1, 1))
+  /* if we can use the vDSO to obtain the timebase even better */
+#ifdef SHARED
+  if (__vdso_get_tbfreq != NULL)
     {
-      /* The timebase will be in the 1st 1024 bytes for systems with up
-         to 8 processors.  If the first read returns less then 1024
-	 bytes read,  we have the whole cpuinfo and can start the scan.
-	 Otherwise we will have to read more to insure we have the
-	 timebase value in the scan.  */
-      char buf[1024];
-      ssize_t n;
-
-      n = read (fd, buf, sizeof (buf));
-      if (n == sizeof (buf))
-	{
-	  /* We are here because the 1st read returned exactly sizeof
-	     (buf) bytes.  This implies that we are not at EOF and may
-	     not have read the timebase value yet.  So we need to read
-	     more bytes until we know we have EOF.  We copy the lower
-	     half of buf to the upper half and read sizeof (buf)/2
-	     bytes into the lower half of buf and repeat until we
-	     reach EOF.  We can assume that the timebase will be in
-	     the last 512 bytes of cpuinfo, so two 512 byte half_bufs
-	     will be sufficient to contain the timebase and will
-	     handle the case where the timebase spans the half_buf
-	     boundry.  */
-	  const ssize_t half_buf = sizeof (buf) / 2;
-	  while (n >= half_buf)
-	    {
-	      memcpy (buf, buf + half_buf, half_buf);
-	      n = read (fd, buf + half_buf, half_buf);
-	    }
-	  if (n >= 0)
-	    n += half_buf;
-	}
-
-      if (__builtin_expect (n, 1) > 0)
-	{
-	  char *mhz = memmem (buf, n, "timebase", 7);
-
-	  if (__builtin_expect (mhz != NULL, 1))
-	    {
-	      char *endp = buf + n;
-
-	      /* Search for the beginning of the string.  */
-	      while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
-		++mhz;
-
-	      while (mhz < endp && *mhz != '\n')
-		{
-		  if (*mhz >= '0' && *mhz <= '9')
-		    {
-		      result *= 10;
-		      result += *mhz - '0';
-		    }
+    timebase_freq=(__vdso_get_tbfreq)();
+    }  
+  else
+#endif
+    {
+    int fd = open ("/proc/cpuinfo", O_RDONLY);
 
+    if (__builtin_expect (fd != -1, 1))
+      {
+        /* The timebase will be in the 1st 1024 bytes for systems with up
+           to 8 processors.  If the first read returns less then 1024
+	   bytes read,  we have the whole cpuinfo and can start the scan.
+	   Otherwise we will have to read more to insure we have the
+	   timebase value in the scan.  */
+        char buf[1024];
+        ssize_t n;
+
+        n = read (fd, buf, sizeof (buf));
+        if (n == sizeof (buf))
+	  {
+	    /* We are here because the 1st read returned exactly sizeof
+	       (buf) bytes.  This implies that we are not at EOF and may
+	       not have read the timebase value yet.  So we need to read
+	       more bytes until we know we have EOF.  We copy the lower
+	       half of buf to the upper half and read sizeof (buf)/2
+	       bytes into the lower half of buf and repeat until we
+	       reach EOF.  We can assume that the timebase will be in
+	       the last 512 bytes of cpuinfo, so two 512 byte half_bufs
+	       will be sufficient to contain the timebase and will
+	       handle the case where the timebase spans the half_buf
+	       boundry.  */
+	    const ssize_t half_buf = sizeof (buf) / 2;
+	    while (n >= half_buf)
+	      {
+	        memcpy (buf, buf + half_buf, half_buf);
+	        n = read (fd, buf + half_buf, half_buf);
+	      }
+	    if (n >= 0)
+	      n += half_buf;
+	  }
+
+        if (__builtin_expect (n, 1) > 0)
+	  {
+	    char *mhz = memmem (buf, n, "timebase", 7);
+
+	    if (__builtin_expect (mhz != NULL, 1))
+	      {
+  	        char *endp = buf + n;
+ 
+	        /* Search for the beginning of the string.  */
+	        while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
 		  ++mhz;
-		}
-	    }
-	  timebase_freq = result;
-	}
-      close (fd);
-    }
 
+	        while (mhz < endp && *mhz != '\n')
+		  {
+		    if (*mhz >= '0' && *mhz <= '9')
+		      {
+		        result *= 10;
+		        result += *mhz - '0';
+		      }
+
+		    ++mhz;
+		  }
+	      }
+	    timebase_freq = result;
+	  }
+        close (fd);
+      }
+  }
   return timebase_freq;
 }
diff -urN libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c libc24/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
--- libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c	Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c	Thu Nov 03 20:10:45 2005
@@ -0,0 +1,54 @@
+/* Copyright (C) 2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <bp-checks.h>
+#include <stddef.h>
+#include <sys/time.h>
+#include <time.h>
+#include <hp-timing.h>
+
+#undef __gettimeofday
+#include <bits/libc-vdso.h>
+
+/* 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
+extern __vdso_gettimeofday_t __vdso_gettimeofday;
+#endif
+
+int
+__gettimeofday (tv, tz)
+     struct timeval *tv;
+     struct timezone *tz;
+{
+#ifdef SHARED
+  if (__vdso_gettimeofday == NULL)
+#endif
+    return INLINE_SYSCALL (gettimeofday, 2, CHECK_1 (tv), CHECK_1 (tz));
+#ifdef SHARED
+  else
+    { 
+      return (*__vdso_gettimeofday) (tv, tz);
+    }
+#endif
+}
+
+INTDEF (__gettimeofday) weak_alias (__gettimeofday, gettimeofday)
diff -urN libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/libc-start.c libc24/sysdeps/unix/sysv/linux/powerpc/libc-start.c
--- libc24-cvstip-20051102/sysdeps/unix/sysv/linux/powerpc/libc-start.c	Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/libc-start.c	Thu Nov 10 18:18:51 2005
@@ -0,0 +1,201 @@
+/* Copyright (C) 1998,2000,2001,2002,2003,2004,2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <ldsodefs.h>
+#include <bp-start.h>
+#include <bp-sym.h>
+
+extern int __cache_line_size;
+weak_extern (__cache_line_size)
+/* The main work is done in the generic function.  */
+#define LIBC_START_MAIN generic_start_main
+#define LIBC_START_DISABLE_INLINE
+#define LIBC_START_MAIN_AUXVEC_ARG
+#define MAIN_AUXVEC_ARG
+#define INIT_MAIN_ARGS
+#include <sysdeps/generic/libc-start.c>
+     struct startup_info
+     {
+       void *__unbounded sda_base;
+       int (*main) (int, char **, char **, void *);
+       int (*init) (int, char **, char **, void *);
+       void (*fini) (void);
+     };
+
+
+#ifdef SHARED
+#include <sys/time.h>
+#include <dl-vdso.h>
+#undef __gettimeofday
+#undef __clock_gettime
+#undef __clock_getres
+#include <bits/libc-vdso.h>
+
+     __vdso_gettimeofday_t __vdso_gettimeofday;
+     __vdso_clock_gettime_t __vdso_clock_gettime;
+     __vdso_clock_getres_t __vdso_clock_getres;
+     __vdso_get_tbfreq_t __vdso_get_tbfreq;
+
+#if __WORDSIZE == 64
+     typedef struct
+     {
+       void *func;
+       void *toc_ptr;
+       void *extra;
+     } _ppc_func_desciptor;
+
+     static struct
+     {
+       _ppc_func_desciptor fd_gettimeofday;
+       _ppc_func_desciptor fd_clock_gettime;
+       _ppc_func_desciptor fd_clock_getres;
+       _ppc_func_desciptor fd_get_tbfreq;
+     } __vdso_descriptor;
+#endif
+
+     static inline void _libc_vdso_platform_setup (void)
+{
+  void *vdso_ref = NULL;
+
+  __vdso_gettimeofday = NULL;
+  __vdso_clock_gettime = NULL;
+  __vdso_clock_getres = NULL;
+  __vdso_get_tbfreq = NULL;
+
+  vdso_ref = _dl_vdso_weakref ("__kernel_gettimeofday");
+
+#if __WORDSIZE == 64
+  if (vdso_ref != NULL)
+    {
+      __vdso_descriptor.fd_gettimeofday.func = vdso_ref;
+      __vdso_descriptor.fd_gettimeofday.toc_ptr = NULL;
+      __vdso_descriptor.fd_gettimeofday.extra = NULL;
+      __vdso_gettimeofday = (__vdso_gettimeofday_t)
+	& __vdso_descriptor.fd_gettimeofday;
+    }
+#else
+  __vdso_gettimeofday = (__vdso_gettimeofday_t) vdso_ref;
+#endif
+
+  vdso_ref = _dl_vdso_weakref ("__kernel_clock_gettime");
+
+#if __WORDSIZE == 64
+  if (vdso_ref != NULL)
+    {
+      __vdso_descriptor.fd_clock_gettime.func = vdso_ref;
+      __vdso_descriptor.fd_clock_gettime.toc_ptr = NULL;
+      __vdso_descriptor.fd_clock_gettime.extra = NULL;
+      __vdso_clock_gettime = (__vdso_clock_gettime_t)
+	& __vdso_descriptor.fd_clock_gettime;
+    }
+#else
+  __vdso_clock_gettime = (__vdso_clock_gettime_t) vdso_ref;
+#endif
+
+  vdso_ref = _dl_vdso_weakref ("__kernel_clock_getres");
+
+#if __WORDSIZE == 64
+  if (vdso_ref != NULL)
+    {
+      __vdso_descriptor.fd_clock_getres.func = vdso_ref;
+      __vdso_descriptor.fd_clock_getres.toc_ptr = NULL;
+      __vdso_descriptor.fd_clock_getres.extra = NULL;
+      __vdso_clock_getres = (__vdso_clock_getres_t)
+	& __vdso_descriptor.fd_clock_getres;
+    }
+#else
+  __vdso_clock_getres = (__vdso_clock_getres_t) vdso_ref;
+#endif
+
+  vdso_ref = _dl_vdso_weakref ("__kernel_vdso_get_tbfreq");
+
+#if __WORDSIZE == 64
+  if (vdso_ref != NULL)
+    {
+      __vdso_descriptor.fd_clock_getres.func = vdso_ref;
+      __vdso_descriptor.fd_clock_getres.toc_ptr = NULL;
+      __vdso_descriptor.fd_clock_getres.extra = NULL;
+      __vdso_get_tbfreq = (__vdso_get_tbfreq_t)
+	& __vdso_descriptor.fd_get_tbfreq;
+    }
+#else
+  __vdso_get_tbfreq = (__vdso_get_tbfreq_t) vdso_ref;
+#endif
+}
+#endif
+
+int
+/* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
+   BPs in the arglist of startup_info.main and startup_info.init. */
+  BP_SYM (__libc_start_main) (int argc, char *__unbounded * __unbounded ubp_av,
+			      char *__unbounded * __unbounded ubp_ev,
+			      ElfW (auxv_t) * __unbounded auxvec,
+			      void (*rtld_fini) (void),
+			      struct startup_info * __unbounded stinfo,
+			      char *__unbounded * __unbounded stack_on_entry)
+{
+#if __BOUNDED_POINTERS__
+  char **argv;
+#else
+# define argv ubp_av
+#endif
+
+  /* the PPC SVR4 ABI says that the top thing on the stack will
+     be a NULL pointer, so if not we assume that we're being called
+     as a statically-linked program by Linux...  */
+  if (*stack_on_entry != NULL)
+    {
+      char *__unbounded * __unbounded temp;
+      /* ...in which case, we have argc as the top thing on the
+         stack, followed by argv (NULL-terminated), envp (likewise),
+         and the auxilary vector.  */
+      /* 32/64-bit agnostic load from stack */
+      argc = *(long int *__unbounded) stack_on_entry;
+      ubp_av = stack_on_entry + 1;
+      ubp_ev = ubp_av + argc + 1;
+#ifdef HAVE_AUX_VECTOR
+      temp = ubp_ev;
+      while (*temp != NULL)
+	++temp;
+      auxvec = (ElfW (auxv_t) *)++ temp;
+#endif
+      rtld_fini = NULL;
+    }
+
+  /* Initialize the __cache_line_size variable from the aux vector.  */
+  for (ElfW (auxv_t) * av = auxvec; av->a_type != AT_NULL; ++av)
+    switch (av->a_type)
+      {
+      case AT_DCACHEBSIZE:
+	{
+	  int *cls = &__cache_line_size;
+	  if (cls != NULL)
+	    *cls = av->a_un.a_val;
+	}
+	break;
+      }
+#ifdef SHARED
+  /* Resolve and initialize function pointers for VDSO functions.  */
+  _libc_vdso_platform_setup ();
+#endif
+  return generic_start_main (stinfo->main, argc, ubp_av, auxvec,
+			     stinfo->init, stinfo->fini, rtld_fini,
+			     stack_on_entry);
+}
diff -urN libc24-cvstip-20051102/sysdeps/powerpc/powerpc32/Makefile libc24/sysdeps/powerpc/powerpc32/Makefile
--- libc24-cvstip-20051102/sysdeps/powerpc/powerpc32/Makefile	2005-08-04 16:35:43.000000000 -0500
+++ libc24/sysdeps/powerpc/powerpc32/Makefile	2005-11-06 15:57:54.000000000 -0600
@@ -18,6 +18,8 @@
 endif
 
 ifeq ($(subdir),csu)
+sysdep_routines += hp-timing
+elide-routines.os += hp-timing
 ifneq ($(elf),no)
 # The initfini generation code doesn't work in the presence of -fPIC, so
 # we use -fpic instead which is much better.
diff -urN libc24-cvstip-20051102/sysdeps/powerpc/powerpc32/hp-timing.c libc24/sysdeps/powerpc/powerpc32/hp-timing.c
--- libc24-cvstip-20051102/sysdeps/powerpc/powerpc32/hp-timing.c	Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/powerpc/powerpc32/hp-timing.c	Sun Nov 06 15:57:54 2005
@@ -0,0 +1,27 @@
+/* Support for high precision, low overhead timing functions. 
+   powerpc32 version.
+   Copyright (C) 2005 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <hp-timing.h>
+
+/* We have to define a variable for the overhead and thread locking. 
+   To avoid false sharing and potential "live lock" we need to insure that
+   the hp_timing lock is in a cache line by itself.  */
+hp_timing_t _dl_hp_timing_overhead __attribute__((aligned(128)));
diff -urN libc24-cvstip-20051102/sysdeps/powerpc/powerpc32/hp-timing.h libc24/sysdeps/powerpc/powerpc32/hp-timing.h
--- libc24-cvstip-20051102/sysdeps/powerpc/powerpc32/hp-timing.h	Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/powerpc/powerpc32/hp-timing.h	Sun Nov 06 15:57:54 2005
@@ -0,0 +1,183 @@
+/* High precision, low overhead timing functions.  powerpc32 version.
+   Copyright (C) 2005 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _HP_TIMING_H
+#define _HP_TIMING_H	1
+
+#include <string.h>
+#include <sys/param.h>
+#include <stdio-common/_itoa.h>
+#include <atomic.h>
+
+/* The macros defined here use the powerpc 64-bit time base register.
+   The time base is nominally clocked at 1/8th the CPU clock, but this
+   can vary.
+
+   The list of macros we need includes the following:
+
+   - HP_TIMING_AVAIL: test for availability.
+
+   - HP_TIMING_INLINE: this macro is non-zero if the functionality is not
+     implemented using function calls but instead uses some inlined code
+     which might simply consist of a few assembler instructions.  We have to
+     know this since we might want to use the macros here in places where we
+     cannot make function calls.
+
+   - hp_timing_t: This is the type for variables used to store the time
+     values.
+
+   - HP_TIMING_ZERO: clear `hp_timing_t' object.
+
+   - HP_TIMING_NOW: place timestamp for current time in variable given as
+     parameter.
+
+   - HP_TIMING_DIFF_INIT: do whatever is necessary to be able to use the
+     HP_TIMING_DIFF macro.
+
+   - HP_TIMING_DIFF: compute difference between two times and store it
+     in a third.  Source and destination might overlap.
+
+   - HP_TIMING_ACCUM: add time difference to another variable.  This might
+     be a bit more complicated to implement for some platforms as the
+     operation should be thread-safe and 64bit arithmetic on 32bit platforms
+     is not.
+
+   - HP_TIMING_ACCUM_NT: this is the variant for situations where we know
+     there are no threads involved.
+
+   - HP_TIMING_PRINT: write decimal representation of the timing value into
+     the given string.  This operation need not be inline even though
+     HP_TIMING_INLINE is specified.
+
+*/
+
+/* We always assume having the timestamp register.  */
+#define HP_TIMING_AVAIL		(1)
+
+/* We indeed have inlined functions.  */
+#define HP_TIMING_INLINE	(1)
+
+/* We use 64bit values for the times.  */
+typedef unsigned long long int hp_timing_t;
+
+typedef union  hp_timing_ut
+  {
+     hp_timing_t 	ll_tb;
+     unsigned long	l_tb[2];
+  } hp_timing_ut;
+	
+
+/* Set timestamp value to zero.  */
+#define HP_TIMING_ZERO(Var)	(Var) = (0)
+
+/* Use the `mftbu'/`mftb' instructions to obtain the 64-bit timebase 
+   32-bits at a time.  We need to insure that the upper timebase is 
+   consistent with the lower timebase.  So we read the upper timebase
+   before and after we read the lower timebase then compare them.
+   If the two upper timebase values are equal we are done. Otherwise the 
+   lower timebase may have wrapper, so we repeat the sequence.
+
+   Note that the value might not be 100% accurate since there might be
+   some more instructions running in this moment.  */
+#define HP_TIMING_NOW(Var)						      \
+  do {									      \
+    unsigned long __temp;						      \
+    hp_timing_ut tmp_val;						      \
+    __asm __volatile (							      \
+		    "1:	mftbu	%0\n"					      \
+		    "	mftb	%1\n"					      \
+		    "	mftbu	%2\n"					      \
+		    "	cmpw	%0,%2\n"				      \
+		    "	bne-	1b\n"					      \
+		    : "=r" (tmp_val.l_tb[0]), "=r" (tmp_val.l_tb[1]),         \
+		      "=r" (__temp)					      \
+		    :							      \
+		    : "cr0", "memory");					      \
+     Var =  tmp_val.ll_tb;	      \
+  } while (0)
+
+/* Use two 'mftb/mftbu' sequences in a row to find out how long it takes.
+   On current POWER4, POWER5, and 970 processors mftb/mftbu ibstructions
+   take ~10 cycles each.  */
+#define HP_TIMING_DIFF_INIT() \
+  do {									      \
+    if (GLRO(dl_hp_timing_overhead) == 0)				      \
+      {									      \
+	int __cnt = 5;							      \
+	GLRO(dl_hp_timing_overhead) = ~0ull;				      \
+	do								      \
+	  {								      \
+	    hp_timing_t __t1, __t2;					      \
+	    HP_TIMING_NOW (__t1);					      \
+	    HP_TIMING_NOW (__t2);					      \
+	    if (__t2 - __t1 < GLRO(dl_hp_timing_overhead))		      \
+	      GLRO(dl_hp_timing_overhead) = __t2 - __t1;		      \
+	  }								      \
+	while (--__cnt > 0);						      \
+      }									      \
+  } while (0)
+
+/* It's simple arithmetic in 64-bit.  */
+#define HP_TIMING_DIFF(Diff, Start, End)	(Diff) = ((End) - (Start))
+
+/* We need to insure that this add is atomic in threaded environments.  
+   But we want this needs to be a "light-weight" as posible.  So we create a
+   simple lwarx lock on the 1st word of dl_hp_timing_overhead. The lwarx gets
+   the reservation and (attempts to hold it while we compute long long sum.  
+   We follow this with a conditional stwcx to verify that no other thread
+   took the reservation while we computed the sum.  We don't care
+   about the value of the lock word, and don't change the value.  */
+#define HP_TIMING_ACCUM(Sum, Diff) \
+  do {									      \
+    hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead);		      \
+    void *lock	= & GLRO(dl_hp_timing_overhead);			      \
+    unsigned int __tmp;							      \
+    __asm __volatile (							      \
+		    "1:	lwarx	%0,0,%1\n"				      \
+		    "  " __ARCH_ACQ_INSTR "\n"				      \
+		    : "=&r" (__tmp)					      \
+		    : "b" (lock)					      \
+		    );							      \
+    (Sum) += (__diff);							      \
+    __asm __volatile (							      \
+		    "  " __ARCH_REL_INSTR "\n"				      \
+		    "	stwcx.	%0,0,%1\n"				      \
+		    "	bne-	1b\n"					      \
+		    : 							      \
+		    : "r" (__tmp), "b" (lock)				      \
+		    : "cr0", "memory");					      \
+  } while (0)
+
+/* No threads, no extra work.  */
+#define HP_TIMING_ACCUM_NT(Sum, Diff)	(Sum) += (Diff)
+
+/* Print the time value.  */
+#define HP_TIMING_PRINT(Buf, Len, Val) \
+  do {									      \
+    char __buf[20];							      \
+    char *__cp = _itoa (Val, __buf + sizeof (__buf), 10, 0);		      \
+    size_t __len = (Len);						      \
+    char *__dest = (Buf);						      \
+    while (__len-- > 0 && __cp < __buf + sizeof (__buf))		      \
+      *__dest++ = *__cp++;						      \
+    memcpy (__dest, " ticks", MIN (__len, sizeof (" ticks")));  \
+  } while (0)
+
+#endif	/* hp-timing.h */

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