e354a5
commit 1e372ded4f83362509c8672ff501cba871bb1edc
e354a5
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
e354a5
Date:   Thu Jan 24 12:46:59 2019 +0000
e354a5
e354a5
    Refactor hp-timing rtld usage
e354a5
    
e354a5
    This patch refactor how hp-timing is used on loader code for statistics
e354a5
    report.  The HP_TIMING_AVAIL and HP_SMALL_TIMING_AVAIL are removed and
e354a5
    HP_TIMING_INLINE is used instead to check for hp-timing avaliability.
e354a5
    For alpha, which only defines HP_SMALL_TIMING_AVAIL, the HP_TIMING_INLINE
e354a5
    is set iff for IS_IN(rtld).
e354a5
    
e354a5
    Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. I also
e354a5
    checked the builds for all afected ABIs.
e354a5
    
e354a5
            * benchtests/bench-timing.h: Replace HP_TIMING_AVAIL with
e354a5
            HP_TIMING_INLINE.
e354a5
            * nptl/descr.h: Likewise.
e354a5
            * elf/rtld.c (RLTD_TIMING_DECLARE, RTLD_TIMING_NOW, RTLD_TIMING_DIFF,
e354a5
            RTLD_TIMING_ACCUM_NT, RTLD_TIMING_SET): Define.
e354a5
            (dl_start_final_info, _dl_start_final, dl_main, print_statistics):
e354a5
            Abstract hp-timing usage with RTLD_* macros.
e354a5
            * sysdeps/alpha/hp-timing.h (HP_TIMING_INLINE): Define iff IS_IN(rtld).
e354a5
            (HP_TIMING_AVAIL, HP_SMALL_TIMING_AVAIL): Remove.
e354a5
            * sysdeps/generic/hp-timing.h (HP_TIMING_AVAIL, HP_SMALL_TIMING_AVAIL,
e354a5
            HP_TIMING_NONAVAIL): Likewise.
e354a5
            * sysdeps/ia64/hp-timing.h (HP_TIMING_AVAIL, HP_SMALL_TIMING_AVAIL):
e354a5
            Likewise.
e354a5
            * sysdeps/powerpc/powerpc32/power4/hp-timing.h (HP_TIMING_AVAIL,
e354a5
            HP_SMALL_TIMING_AVAIL): Likewise.
e354a5
            * sysdeps/powerpc/powerpc64/hp-timing.h (HP_TIMING_AVAIL,
e354a5
            HP_SMALL_TIMING_AVAIL): Likewise.
e354a5
            * sysdeps/sparc/sparc32/sparcv9/hp-timing.h (HP_TIMING_AVAIL,
e354a5
            HP_SMALL_TIMING_AVAIL): Likewise.
e354a5
            * sysdeps/sparc/sparc64/hp-timing.h (HP_TIMING_AVAIL,
e354a5
            HP_SMALL_TIMING_AVAIL): Likewise.
e354a5
            * sysdeps/x86/hp-timing.h (HP_TIMING_AVAIL, HP_SMALL_TIMING_AVAIL):
e354a5
            Likewise.
e354a5
            * sysdeps/generic/hp-timing-common.h: Update comment with
e354a5
            HP_TIMING_AVAIL removal.
e354a5
e354a5
diff --git a/benchtests/bench-timing.h b/benchtests/bench-timing.h
e354a5
index 96cde1e8be2e0c2f..8ba6be51d5b6d4e1 100644
e354a5
--- a/benchtests/bench-timing.h
e354a5
+++ b/benchtests/bench-timing.h
e354a5
@@ -21,7 +21,7 @@
e354a5
 #include <hp-timing.h>
e354a5
 #include <stdint.h>
e354a5
 
e354a5
-#if HP_TIMING_AVAIL && !defined USE_CLOCK_GETTIME
e354a5
+#if HP_TIMING_INLINE && !defined USE_CLOCK_GETTIME
e354a5
 # define GL(x) _##x
e354a5
 # define GLRO(x) _##x
e354a5
 typedef hp_timing_t timing_t;
e354a5
diff --git a/elf/rtld.c b/elf/rtld.c
e354a5
index 375e0de8fa2e049e..ffbd8f4553bb3425 100644
e354a5
--- a/elf/rtld.c
e354a5
+++ b/elf/rtld.c
e354a5
@@ -46,6 +46,49 @@
e354a5
 
e354a5
 #include <assert.h>
e354a5
 
e354a5
+/* Only enables rtld profiling for architectures which provides non generic
e354a5
+   hp-timing support.  The generic support requires either syscall
e354a5
+   (clock_gettime), which will incur in extra overhead on loading time.
e354a5
+   Using vDSO is also an option, but it will require extra support on loader
e354a5
+   to setup the vDSO pointer before its usage.  */
e354a5
+#if HP_TIMING_INLINE
e354a5
+# define RLTD_TIMING_DECLARE(var, classifier,...) \
e354a5
+  classifier hp_timing_t var __VA_ARGS__
e354a5
+# define RTLD_TIMING_VAR(var)        RLTD_TIMING_DECLARE (var, )
e354a5
+# define RTLD_TIMING_SET(var, value) (var) = (value)
e354a5
+# define RTLD_TIMING_REF(var)        &(var)
e354a5
+
e354a5
+static inline void
e354a5
+rtld_timer_start (hp_timing_t *var)
e354a5
+{
e354a5
+  HP_TIMING_NOW (*var);
e354a5
+}
e354a5
+
e354a5
+static inline void
e354a5
+rtld_timer_stop (hp_timing_t *var, hp_timing_t start)
e354a5
+{
e354a5
+  hp_timing_t stop;
e354a5
+  HP_TIMING_NOW (stop);
e354a5
+  HP_TIMING_DIFF (*var, start, stop);
e354a5
+}
e354a5
+
e354a5
+static inline void
e354a5
+rtld_timer_accum (hp_timing_t *sum, hp_timing_t start)
e354a5
+{
e354a5
+  hp_timing_t stop;
e354a5
+  rtld_timer_stop (&stop, start);
e354a5
+  HP_TIMING_ACCUM_NT(*sum, stop);
e354a5
+}
e354a5
+#else
e354a5
+# define RLTD_TIMING_DECLARE(var, classifier...)
e354a5
+# define RTLD_TIMING_SET(var, value)
e354a5
+# define RTLD_TIMING_VAR(var)
e354a5
+# define RTLD_TIMING_REF(var)			 0
e354a5
+# define rtld_timer_start(var)
e354a5
+# define rtld_timer_stop(var, start)
e354a5
+# define rtld_timer_accum(sum, start)
e354a5
+#endif
e354a5
+
e354a5
 /* Avoid PLT use for our local calls at startup.  */
e354a5
 extern __typeof (__mempcpy) __mempcpy attribute_hidden;
e354a5
 
e354a5
@@ -62,7 +105,7 @@ static void print_missing_version (int errcode, const char *objname,
e354a5
 				   const char *errsting);
e354a5
 
e354a5
 /* Print the various times we collected.  */
e354a5
-static void print_statistics (hp_timing_t *total_timep);
e354a5
+static void print_statistics (const hp_timing_t *total_timep);
e354a5
 
e354a5
 /* Add audit objects.  */
e354a5
 static void process_dl_audit (char *str);
e354a5
@@ -303,11 +346,9 @@ static struct libname_list _dl_rtld_libname;
e354a5
 static struct libname_list _dl_rtld_libname2;
e354a5
 
e354a5
 /* Variable for statistics.  */
e354a5
-#ifndef HP_TIMING_NONAVAIL
e354a5
-static hp_timing_t relocate_time;
e354a5
-static hp_timing_t load_time attribute_relro;
e354a5
-static hp_timing_t start_time attribute_relro;
e354a5
-#endif
e354a5
+RLTD_TIMING_DECLARE (relocate_time, static);
e354a5
+RLTD_TIMING_DECLARE (load_time,     static, attribute_relro);
e354a5
+RLTD_TIMING_DECLARE (start_time,    static, attribute_relro);
e354a5
 
e354a5
 /* Additional definitions needed by TLS initialization.  */
e354a5
 #ifdef TLS_INIT_HELPER
e354a5
@@ -335,9 +376,7 @@ static ElfW(Addr) _dl_start_final (void *arg);
e354a5
 struct dl_start_final_info
e354a5
 {
e354a5
   struct link_map l;
e354a5
-#if !defined HP_TIMING_NONAVAIL && HP_TIMING_INLINE
e354a5
-  hp_timing_t start_time;
e354a5
-#endif
e354a5
+  RTLD_TIMING_VAR (start_time);
e354a5
 };
e354a5
 static ElfW(Addr) _dl_start_final (void *arg,
e354a5
 				   struct dl_start_final_info *info);
e354a5
@@ -371,16 +410,11 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
e354a5
 {
e354a5
   ElfW(Addr) start_addr;
e354a5
 
e354a5
-  if (HP_SMALL_TIMING_AVAIL)
e354a5
-    {
e354a5
-      /* If it hasn't happen yet record the startup time.  */
e354a5
-      if (! HP_TIMING_INLINE)
e354a5
-	HP_TIMING_NOW (start_time);
e354a5
-#if !defined DONT_USE_BOOTSTRAP_MAP && !defined HP_TIMING_NONAVAIL
e354a5
-      else
e354a5
-	start_time = info->start_time;
e354a5
+  /* If it hasn't happen yet record the startup time.  */
e354a5
+  rtld_timer_start (&start_time);
e354a5
+#if !defined DONT_USE_BOOTSTRAP_MAP
e354a5
+  RTLD_TIMING_SET (start_time, info->start_time);
e354a5
 #endif
e354a5
-    }
e354a5
 
e354a5
   /* Transfer data about ourselves to the permanent link_map structure.  */
e354a5
 #ifndef DONT_USE_BOOTSTRAP_MAP
e354a5
@@ -412,27 +446,11 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
e354a5
      entry point on the same stack we entered on.  */
e354a5
   start_addr = _dl_sysdep_start (arg, &dl_main);
e354a5
 
e354a5
-#ifndef HP_TIMING_NONAVAIL
e354a5
-  hp_timing_t rtld_total_time;
e354a5
-  if (HP_SMALL_TIMING_AVAIL)
e354a5
-    {
e354a5
-      hp_timing_t end_time;
e354a5
-
e354a5
-      /* Get the current time.  */
e354a5
-      HP_TIMING_NOW (end_time);
e354a5
-
e354a5
-      /* Compute the difference.  */
e354a5
-      HP_TIMING_DIFF (rtld_total_time, start_time, end_time);
e354a5
-    }
e354a5
-#endif
e354a5
-
e354a5
   if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_STATISTICS))
e354a5
     {
e354a5
-#ifndef HP_TIMING_NONAVAIL
e354a5
-      print_statistics (&rtld_total_time);
e354a5
-#else
e354a5
-      print_statistics (NULL);
e354a5
-#endif
e354a5
+      RTLD_TIMING_VAR (rtld_total_time);
e354a5
+      rtld_timer_stop (&rtld_total_time, start_time);
e354a5
+      print_statistics (RTLD_TIMING_REF(rtld_total_time));
e354a5
     }
e354a5
 
e354a5
   return start_addr;
e354a5
@@ -457,11 +475,10 @@ _dl_start (void *arg)
e354a5
 #define RESOLVE_MAP(sym, version, flags) BOOTSTRAP_MAP
e354a5
 #include "dynamic-link.h"
e354a5
 
e354a5
-  if (HP_TIMING_INLINE && HP_SMALL_TIMING_AVAIL)
e354a5
 #ifdef DONT_USE_BOOTSTRAP_MAP
e354a5
-    HP_TIMING_NOW (start_time);
e354a5
+  rtld_timer_start (&start_time);
e354a5
 #else
e354a5
-    HP_TIMING_NOW (info.start_time);
e354a5
+  rtld_timer_start (&info.start_time);
e354a5
 #endif
e354a5
 
e354a5
   /* Partly clean the `bootstrap_map' structure up.  Don't use
e354a5
@@ -1078,11 +1095,6 @@ dl_main (const ElfW(Phdr) *phdr,
e354a5
   unsigned int i;
e354a5
   bool prelinked = false;
e354a5
   bool rtld_is_main = false;
e354a5
-#ifndef HP_TIMING_NONAVAIL
e354a5
-  hp_timing_t start;
e354a5
-  hp_timing_t stop;
e354a5
-  hp_timing_t diff;
e354a5
-#endif
e354a5
   void *tcbp = NULL;
e354a5
 
e354a5
   GL(dl_init_static_tls) = &_dl_nothread_init_static_tls;
e354a5
@@ -1256,12 +1268,11 @@ of this helper program; chances are you did not intend to run this program.\n\
e354a5
 	}
e354a5
       else
e354a5
 	{
e354a5
-	  HP_TIMING_NOW (start);
e354a5
+	  RTLD_TIMING_VAR (start);
e354a5
+	  rtld_timer_start (&start;;
e354a5
 	  _dl_map_object (NULL, rtld_progname, lt_executable, 0,
e354a5
 			  __RTLD_OPENEXEC, LM_ID_BASE);
e354a5
-	  HP_TIMING_NOW (stop);
e354a5
-
e354a5
-	  HP_TIMING_DIFF (load_time, start, stop);
e354a5
+	  rtld_timer_stop (&load_time, start);
e354a5
 	}
e354a5
 
e354a5
       /* Now the map for the main executable is available.  */
e354a5
@@ -1664,20 +1675,18 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
e354a5
 
e354a5
   if (__glibc_unlikely (preloadlist != NULL))
e354a5
     {
e354a5
-      HP_TIMING_NOW (start);
e354a5
+      RTLD_TIMING_VAR (start);
e354a5
+      rtld_timer_start (&start;;
e354a5
       npreloads += handle_preload_list (preloadlist, main_map, "LD_PRELOAD");
e354a5
-      HP_TIMING_NOW (stop);
e354a5
-      HP_TIMING_DIFF (diff, start, stop);
e354a5
-      HP_TIMING_ACCUM_NT (load_time, diff);
e354a5
+      rtld_timer_accum (&load_time, start);
e354a5
     }
e354a5
 
e354a5
   if (__glibc_unlikely (preloadarg != NULL))
e354a5
     {
e354a5
-      HP_TIMING_NOW (start);
e354a5
+      RTLD_TIMING_VAR (start);
e354a5
+      rtld_timer_start (&start;;
e354a5
       npreloads += handle_preload_list (preloadarg, main_map, "--preload");
e354a5
-      HP_TIMING_NOW (stop);
e354a5
-      HP_TIMING_DIFF (diff, start, stop);
e354a5
-      HP_TIMING_ACCUM_NT (load_time, diff);
e354a5
+      rtld_timer_accum (&load_time, start);
e354a5
     }
e354a5
 
e354a5
   /* There usually is no ld.so.preload file, it should only be used
e354a5
@@ -1737,7 +1746,8 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
e354a5
 	      file[file_size - 1] = '\0';
e354a5
 	    }
e354a5
 
e354a5
-	  HP_TIMING_NOW (start);
e354a5
+	  RTLD_TIMING_VAR (start);
e354a5
+	  rtld_timer_start (&start;;
e354a5
 
e354a5
 	  if (file != problem)
e354a5
 	    {
e354a5
@@ -1755,9 +1765,7 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
e354a5
 	      npreloads += do_preload (p, main_map, preload_file);
e354a5
 	    }
e354a5
 
e354a5
-	  HP_TIMING_NOW (stop);
e354a5
-	  HP_TIMING_DIFF (diff, start, stop);
e354a5
-	  HP_TIMING_ACCUM_NT (load_time, diff);
e354a5
+	  rtld_timer_accum (&load_time, start);
e354a5
 
e354a5
 	  /* We don't need the file anymore.  */
e354a5
 	  __munmap (file, file_size);
e354a5
@@ -1781,11 +1789,12 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
e354a5
   /* Load all the libraries specified by DT_NEEDED entries.  If LD_PRELOAD
e354a5
      specified some libraries to load, these are inserted before the actual
e354a5
      dependencies in the executable's searchlist for symbol resolution.  */
e354a5
-  HP_TIMING_NOW (start);
e354a5
-  _dl_map_object_deps (main_map, preloads, npreloads, mode == trace, 0);
e354a5
-  HP_TIMING_NOW (stop);
e354a5
-  HP_TIMING_DIFF (diff, start, stop);
e354a5
-  HP_TIMING_ACCUM_NT (load_time, diff);
e354a5
+  {
e354a5
+    RTLD_TIMING_VAR (start);
e354a5
+    rtld_timer_start (&start;;
e354a5
+    _dl_map_object_deps (main_map, preloads, npreloads, mode == trace, 0);
e354a5
+    rtld_timer_accum (&load_time, start);
e354a5
+  }
e354a5
 
e354a5
   /* Mark all objects as being in the global scope.  */
e354a5
   for (i = main_map->l_searchlist.r_nlist; i > 0; )
e354a5
@@ -2178,12 +2187,10 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
e354a5
       if (main_map->l_info [ADDRIDX (DT_GNU_CONFLICT)] != NULL)
e354a5
 	{
e354a5
 	  ElfW(Rela) *conflict, *conflictend;
e354a5
-#ifndef HP_TIMING_NONAVAIL
e354a5
-	  hp_timing_t start;
e354a5
-	  hp_timing_t stop;
e354a5
-#endif
e354a5
 
e354a5
-	  HP_TIMING_NOW (start);
e354a5
+	  RTLD_TIMING_VAR (start);
e354a5
+	  rtld_timer_start (&start;;
e354a5
+
e354a5
 	  assert (main_map->l_info [VALIDX (DT_GNU_CONFLICTSZ)] != NULL);
e354a5
 	  conflict = (ElfW(Rela) *)
e354a5
 	    main_map->l_info [ADDRIDX (DT_GNU_CONFLICT)]->d_un.d_ptr;
e354a5
@@ -2191,8 +2198,8 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
e354a5
 	    ((char *) conflict
e354a5
 	     + main_map->l_info [VALIDX (DT_GNU_CONFLICTSZ)]->d_un.d_val);
e354a5
 	  _dl_resolve_conflicts (main_map, conflict, conflictend);
e354a5
-	  HP_TIMING_NOW (stop);
e354a5
-	  HP_TIMING_DIFF (relocate_time, start, stop);
e354a5
+
e354a5
+	  rtld_timer_stop (&relocate_time, start);
e354a5
 	}
e354a5
 
e354a5
 
e354a5
@@ -2220,15 +2227,12 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
e354a5
 	 know that because it is self-contained).  */
e354a5
 
e354a5
       int consider_profiling = GLRO(dl_profile) != NULL;
e354a5
-#ifndef HP_TIMING_NONAVAIL
e354a5
-      hp_timing_t start;
e354a5
-      hp_timing_t stop;
e354a5
-#endif
e354a5
 
e354a5
       /* If we are profiling we also must do lazy reloaction.  */
e354a5
       GLRO(dl_lazy) |= consider_profiling;
e354a5
 
e354a5
-      HP_TIMING_NOW (start);
e354a5
+      RTLD_TIMING_VAR (start);
e354a5
+      rtld_timer_start (&start;;
e354a5
       unsigned i = main_map->l_searchlist.r_nlist;
e354a5
       while (i-- > 0)
e354a5
 	{
e354a5
@@ -2255,9 +2259,7 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
e354a5
 	  if (l->l_tls_blocksize != 0 && tls_init_tp_called)
e354a5
 	    _dl_add_to_slotinfo (l, true);
e354a5
 	}
e354a5
-      HP_TIMING_NOW (stop);
e354a5
-
e354a5
-      HP_TIMING_DIFF (relocate_time, start, stop);
e354a5
+      rtld_timer_stop (&relocate_time, start);
e354a5
 
e354a5
       /* Now enable profiling if needed.  Like the previous call,
e354a5
 	 this has to go here because the calls it makes should use the
e354a5
@@ -2300,19 +2302,14 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
e354a5
 	 re-relocation, we might call a user-supplied function
e354a5
 	 (e.g. calloc from _dl_relocate_object) that uses TLS data.  */
e354a5
 
e354a5
-#ifndef HP_TIMING_NONAVAIL
e354a5
-      hp_timing_t start;
e354a5
-      hp_timing_t stop;
e354a5
-      hp_timing_t add;
e354a5
-#endif
e354a5
+      RTLD_TIMING_VAR (start);
e354a5
+      rtld_timer_start (&start;;
e354a5
 
e354a5
-      HP_TIMING_NOW (start);
e354a5
       /* Mark the link map as not yet relocated again.  */
e354a5
       GL(dl_rtld_map).l_relocated = 0;
e354a5
       _dl_relocate_object (&GL(dl_rtld_map), main_map->l_scope, 0, 0);
e354a5
-      HP_TIMING_NOW (stop);
e354a5
-      HP_TIMING_DIFF (add, start, stop);
e354a5
-      HP_TIMING_ACCUM_NT (relocate_time, add);
e354a5
+
e354a5
+      rtld_timer_accum (&relocate_time, start);
e354a5
     }
e354a5
 
e354a5
   /* Do any necessary cleanups for the startup OS interface code.
e354a5
@@ -2744,46 +2741,51 @@ process_envvars (enum mode *modep)
e354a5
     }
e354a5
 }
e354a5
 
e354a5
+#if HP_TIMING_INLINE
e354a5
+static void
e354a5
+print_statistics_item (const char *title, hp_timing_t time,
e354a5
+		       hp_timing_t total)
e354a5
+{
e354a5
+  char cycles[HP_TIMING_PRINT_SIZE];
e354a5
+  HP_TIMING_PRINT (cycles, sizeof (cycles), time);
e354a5
+
e354a5
+  char relative[3 * sizeof (hp_timing_t) + 2];
e354a5
+  char *cp = _itoa ((1000ULL * time) / total, relative + sizeof (relative),
e354a5
+		    10, 0);
e354a5
+  /* Sets the decimal point.  */
e354a5
+  char *wp = relative;
e354a5
+  switch (relative + sizeof (relative) - cp)
e354a5
+    {
e354a5
+    case 3:
e354a5
+      *wp++ = *cp++;
e354a5
+      /* Fall through.  */
e354a5
+    case 2:
e354a5
+      *wp++ = *cp++;
e354a5
+      /* Fall through.  */
e354a5
+    case 1:
e354a5
+      *wp++ = '.';
e354a5
+      *wp++ = *cp++;
e354a5
+    }
e354a5
+  *wp = '\0';
e354a5
+  _dl_debug_printf ("%s: %s cycles (%s%%)\n", title, cycles, relative);
e354a5
+}
e354a5
+#endif
e354a5
 
e354a5
 /* Print the various times we collected.  */
e354a5
 static void
e354a5
 __attribute ((noinline))
e354a5
-print_statistics (hp_timing_t *rtld_total_timep)
e354a5
+print_statistics (const hp_timing_t *rtld_total_timep)
e354a5
 {
e354a5
-#ifndef HP_TIMING_NONAVAIL
e354a5
-  char buf[200];
e354a5
-  char *cp;
e354a5
-  char *wp;
e354a5
-
e354a5
-  /* Total time rtld used.  */
e354a5
-  if (HP_SMALL_TIMING_AVAIL)
e354a5
-    {
e354a5
-      HP_TIMING_PRINT (buf, sizeof (buf), *rtld_total_timep);
e354a5
-      _dl_debug_printf ("\nruntime linker statistics:\n"
e354a5
-			"  total startup time in dynamic loader: %s\n", buf);
e354a5
-
e354a5
-      /* Print relocation statistics.  */
e354a5
-      char pbuf[30];
e354a5
-      HP_TIMING_PRINT (buf, sizeof (buf), relocate_time);
e354a5
-      cp = _itoa ((1000ULL * relocate_time) / *rtld_total_timep,
e354a5
-		  pbuf + sizeof (pbuf), 10, 0);
e354a5
-      wp = pbuf;
e354a5
-      switch (pbuf + sizeof (pbuf) - cp)
e354a5
-	{
e354a5
-	case 3:
e354a5
-	  *wp++ = *cp++;
e354a5
-	  /* Fall through.  */
e354a5
-	case 2:
e354a5
-	  *wp++ = *cp++;
e354a5
-	  /* Fall through.  */
e354a5
-	case 1:
e354a5
-	  *wp++ = '.';
e354a5
-	  *wp++ = *cp++;
e354a5
-	}
e354a5
-      *wp = '\0';
e354a5
-      _dl_debug_printf ("\
e354a5
-	    time needed for relocation: %s (%s%%)\n", buf, pbuf);
e354a5
-    }
e354a5
+#if HP_TIMING_INLINE
e354a5
+  {
e354a5
+    char cycles[HP_TIMING_PRINT_SIZE];
e354a5
+    HP_TIMING_PRINT (cycles, sizeof (cycles), *rtld_total_timep);
e354a5
+    _dl_debug_printf ("\nruntime linker statistics:\n"
e354a5
+		      "  total startup time in dynamic loader: %s cycles\n",
e354a5
+		      cycles);
e354a5
+    print_statistics_item ("            time needed for relocation",
e354a5
+			   relocate_time, *rtld_total_timep);
e354a5
+  }
e354a5
 #endif
e354a5
 
e354a5
   unsigned long int num_relative_relocations = 0;
e354a5
@@ -2824,31 +2826,8 @@ print_statistics (hp_timing_t *rtld_total_timep)
e354a5
 		    GL(dl_num_cache_relocations),
e354a5
 		    num_relative_relocations);
e354a5
 
e354a5
-#ifndef HP_TIMING_NONAVAIL
e354a5
-  /* Time spend while loading the object and the dependencies.  */
e354a5
-  if (HP_SMALL_TIMING_AVAIL)
e354a5
-    {
e354a5
-      char pbuf[30];
e354a5
-      HP_TIMING_PRINT (buf, sizeof (buf), load_time);
e354a5
-      cp = _itoa ((1000ULL * load_time) / *rtld_total_timep,
e354a5
-		  pbuf + sizeof (pbuf), 10, 0);
e354a5
-      wp = pbuf;
e354a5
-      switch (pbuf + sizeof (pbuf) - cp)
e354a5
-	{
e354a5
-	case 3:
e354a5
-	  *wp++ = *cp++;
e354a5
-	  /* Fall through.  */
e354a5
-	case 2:
e354a5
-	  *wp++ = *cp++;
e354a5
-	  /* Fall through.  */
e354a5
-	case 1:
e354a5
-	  *wp++ = '.';
e354a5
-	  *wp++ = *cp++;
e354a5
-	}
e354a5
-      *wp = '\0';
e354a5
-      _dl_debug_printf ("\
e354a5
-	   time needed to load objects: %s (%s%%)\n",
e354a5
-				buf, pbuf);
e354a5
-    }
e354a5
+#if HP_TIMING_INLINE
e354a5
+  print_statistics_item ("           time needed to load objects",
e354a5
+			 load_time, *rtld_total_timep);
e354a5
 #endif
e354a5
 }
e354a5
diff --git a/nptl/descr.h b/nptl/descr.h
e354a5
index c3b81d8b27839502..98ba730bfeb7e4dd 100644
e354a5
--- a/nptl/descr.h
e354a5
+++ b/nptl/descr.h
e354a5
@@ -342,7 +342,7 @@ struct pthread
e354a5
   /* Lock for synchronizing setxid calls.  */
e354a5
   unsigned int setxid_futex;
e354a5
 
e354a5
-#if HP_TIMING_AVAIL
e354a5
+#if HP_TIMING_INLINE
e354a5
   hp_timing_t cpuclock_offset_ununsed;
e354a5
 #endif
e354a5
 
e354a5
diff --git a/sysdeps/alpha/hp-timing.h b/sysdeps/alpha/hp-timing.h
e354a5
index 62284e003acbca64..d6b603e2c51d1688 100644
e354a5
--- a/sysdeps/alpha/hp-timing.h
e354a5
+++ b/sysdeps/alpha/hp-timing.h
e354a5
@@ -17,16 +17,13 @@
e354a5
    License along with the GNU C Library.  If not, see
e354a5
    <http://www.gnu.org/licenses/>.  */
e354a5
 
e354a5
-#ifndef _HP_TIMING_H
e354a5
-#define _HP_TIMING_H	1
e354a5
+#ifndef _HP_TIMING_ALPHA_H
e354a5
+#define _HP_TIMING_ALPHA_H	1
e354a5
 
e354a5
+#if IS_IN(rtld)
e354a5
 /* We always have the timestamp register, but it's got only a 4 second
e354a5
    range.  Use it for ld.so profiling only.  */
e354a5
-#define HP_TIMING_AVAIL		(0)
e354a5
-#define HP_SMALL_TIMING_AVAIL	(1)
e354a5
-
e354a5
-/* We indeed have inlined functions.  */
e354a5
-#define HP_TIMING_INLINE	(1)
e354a5
+# define HP_TIMING_INLINE	(1)
e354a5
 
e354a5
 /* We use 32 bit values for the times.  */
e354a5
 typedef unsigned int hp_timing_t;
e354a5
@@ -34,13 +31,16 @@ typedef unsigned int hp_timing_t;
e354a5
 /* The "rpcc" instruction returns a 32-bit counting half and a 32-bit
e354a5
    "virtual cycle counter displacement".  Subtracting the two gives us
e354a5
    a virtual cycle count.  */
e354a5
-#define HP_TIMING_NOW(VAR) \
e354a5
+# define HP_TIMING_NOW(VAR) \
e354a5
   do {									      \
e354a5
     unsigned long int x_;						      \
e354a5
     asm volatile ("rpcc %0" : "=r"(x_));				      \
e354a5
     (VAR) = (int) (x_) - (int) (x_ >> 32);				      \
e354a5
   } while (0)
e354a5
+# include <hp-timing-common.h>
e354a5
 
e354a5
-#include <hp-timing-common.h>
e354a5
+#else
e354a5
+# include <sysdeps/generic/hp-timing.h>
e354a5
+#endif /* IS_IN(rtld)  */
e354a5
 
e354a5
 #endif	/* hp-timing.h */
e354a5
diff --git a/sysdeps/generic/hp-timing-common.h b/sysdeps/generic/hp-timing-common.h
e354a5
index 505c6bf5d2ee9395..ce338c990bd9fccd 100644
e354a5
--- a/sysdeps/generic/hp-timing-common.h
e354a5
+++ b/sysdeps/generic/hp-timing-common.h
e354a5
@@ -20,8 +20,6 @@
e354a5
 /* In case a platform supports timers in the hardware the following macros
e354a5
    and types must be defined:
e354a5
 
e354a5
-   - HP_TIMING_AVAIL: test for availability.
e354a5
-
e354a5
    - HP_TIMING_INLINE: this macro is non-zero if the functionality is not
e354a5
      implemented using function calls but instead uses some inlined code
e354a5
      which might simply consist of a few assembler instructions.  We have to
e354a5
@@ -47,16 +45,16 @@
e354a5
 /* Accumulate ADD into SUM.  No attempt is made to be thread-safe.  */
e354a5
 #define HP_TIMING_ACCUM_NT(Sum, Diff)		((Sum) += (Diff))
e354a5
 
e354a5
+#define HP_TIMING_PRINT_SIZE (3 * sizeof (hp_timing_t) + 1)
e354a5
+
e354a5
 /* Write a decimal representation of the timing value into the given string.  */
e354a5
 #define HP_TIMING_PRINT(Dest, Len, Val) 				\
e354a5
   do {									\
e354a5
-    char __buf[20];							\
e354a5
+    char __buf[HP_TIMING_PRINT_SIZE];					\
e354a5
     char *__dest = (Dest);						\
e354a5
     size_t __len = (Len);						\
e354a5
     char *__cp = _itoa ((Val), __buf + sizeof (__buf), 10, 0);		\
e354a5
     size_t __cp_len = MIN (__buf + sizeof (__buf) - __cp, __len);	\
e354a5
     memcpy (__dest, __cp, __cp_len);					\
e354a5
-    memcpy (__dest + __cp_len, " cycles",				\
e354a5
-	    MIN (__len - __cp_len, sizeof (" cycles")));		\
e354a5
     __dest[__len - 1] = '\0';						\
e354a5
   } while (0)
e354a5
diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h
e354a5
index e2c02c2bc0fd1564..97598099db29d69d 100644
e354a5
--- a/sysdeps/generic/hp-timing.h
e354a5
+++ b/sysdeps/generic/hp-timing.h
e354a5
@@ -25,8 +25,6 @@
e354a5
    the system call might be too high.  */
e354a5
 
e354a5
 /* Provide dummy definitions.  */
e354a5
-#define HP_TIMING_AVAIL		(0)
e354a5
-#define HP_SMALL_TIMING_AVAIL	(0)
e354a5
 #define HP_TIMING_INLINE	(0)
e354a5
 typedef int hp_timing_t;
e354a5
 #define HP_TIMING_NOW(var)
e354a5
@@ -34,7 +32,4 @@ typedef int hp_timing_t;
e354a5
 #define HP_TIMING_ACCUM_NT(Sum, Diff)
e354a5
 #define HP_TIMING_PRINT(Buf, Len, Val)
e354a5
 
e354a5
-/* Since this implementation is not available we tell the user about it.  */
e354a5
-#define HP_TIMING_NONAVAIL	1
e354a5
-
e354a5
 #endif	/* hp-timing.h */
e354a5
diff --git a/sysdeps/ia64/hp-timing.h b/sysdeps/ia64/hp-timing.h
e354a5
index d8d1d7bf2c21f6e6..5ebbbc45746d5cf2 100644
e354a5
--- a/sysdeps/ia64/hp-timing.h
e354a5
+++ b/sysdeps/ia64/hp-timing.h
e354a5
@@ -20,10 +20,6 @@
e354a5
 #ifndef _HP_TIMING_H
e354a5
 #define _HP_TIMING_H	1
e354a5
 
e354a5
-/* We always assume having the timestamp register.  */
e354a5
-#define HP_TIMING_AVAIL		(1)
e354a5
-#define HP_SMALL_TIMING_AVAIL	(1)
e354a5
-
e354a5
 /* We indeed have inlined functions.  */
e354a5
 #define HP_TIMING_INLINE	(1)
e354a5
 
e354a5
diff --git a/sysdeps/powerpc/powerpc32/power4/hp-timing.h b/sysdeps/powerpc/powerpc32/power4/hp-timing.h
e354a5
index 10efcac481349ee3..0e81f4fe6a46ab86 100644
e354a5
--- a/sysdeps/powerpc/powerpc32/power4/hp-timing.h
e354a5
+++ b/sysdeps/powerpc/powerpc32/power4/hp-timing.h
e354a5
@@ -20,10 +20,6 @@
e354a5
 #ifndef _HP_TIMING_H
e354a5
 #define _HP_TIMING_H	1
e354a5
 
e354a5
-/* We always assume having the timestamp register.  */
e354a5
-#define HP_TIMING_AVAIL		(1)
e354a5
-#define HP_SMALL_TIMING_AVAIL	(1)
e354a5
-
e354a5
 /* We indeed have inlined functions.  */
e354a5
 #define HP_TIMING_INLINE	(1)
e354a5
 
e354a5
diff --git a/sysdeps/powerpc/powerpc64/hp-timing.h b/sysdeps/powerpc/powerpc64/hp-timing.h
e354a5
index c0aa3642f6ff1a42..77fe5e85bb32c163 100644
e354a5
--- a/sysdeps/powerpc/powerpc64/hp-timing.h
e354a5
+++ b/sysdeps/powerpc/powerpc64/hp-timing.h
e354a5
@@ -20,10 +20,6 @@
e354a5
 #ifndef _HP_TIMING_H
e354a5
 #define _HP_TIMING_H	1
e354a5
 
e354a5
-/* We always assume having the timestamp register.  */
e354a5
-#define HP_TIMING_AVAIL		(1)
e354a5
-#define HP_SMALL_TIMING_AVAIL	(1)
e354a5
-
e354a5
 /* We indeed have inlined functions.  */
e354a5
 #define HP_TIMING_INLINE	(1)
e354a5
 
e354a5
diff --git a/sysdeps/sparc/sparc32/sparcv9/hp-timing.h b/sysdeps/sparc/sparc32/sparcv9/hp-timing.h
e354a5
index 42451966f6192bcb..aedf9c031a0daad9 100644
e354a5
--- a/sysdeps/sparc/sparc32/sparcv9/hp-timing.h
e354a5
+++ b/sysdeps/sparc/sparc32/sparcv9/hp-timing.h
e354a5
@@ -20,8 +20,6 @@
e354a5
 #ifndef _HP_TIMING_H
e354a5
 #define _HP_TIMING_H	1
e354a5
 
e354a5
-#define HP_TIMING_AVAIL		(1)
e354a5
-#define HP_SMALL_TIMING_AVAIL	(1)
e354a5
 #define HP_TIMING_INLINE	(1)
e354a5
 
e354a5
 typedef unsigned long long int hp_timing_t;
e354a5
diff --git a/sysdeps/sparc/sparc64/hp-timing.h b/sysdeps/sparc/sparc64/hp-timing.h
e354a5
index 66325641067e1198..ee22729063745944 100644
e354a5
--- a/sysdeps/sparc/sparc64/hp-timing.h
e354a5
+++ b/sysdeps/sparc/sparc64/hp-timing.h
e354a5
@@ -20,8 +20,6 @@
e354a5
 #ifndef _HP_TIMING_H
e354a5
 #define _HP_TIMING_H	1
e354a5
 
e354a5
-#define HP_TIMING_AVAIL		(1)
e354a5
-#define HP_SMALL_TIMING_AVAIL	(1)
e354a5
 #define HP_TIMING_INLINE	(1)
e354a5
 
e354a5
 typedef unsigned long int hp_timing_t;
e354a5
diff --git a/sysdeps/x86/hp-timing.h b/sysdeps/x86/hp-timing.h
e354a5
index 0aa6f5e3f83e0d34..4dbd2aa8af69f95e 100644
e354a5
--- a/sysdeps/x86/hp-timing.h
e354a5
+++ b/sysdeps/x86/hp-timing.h
e354a5
@@ -22,10 +22,6 @@
e354a5
 #include <isa.h>
e354a5
 
e354a5
 #if MINIMUM_ISA == 686 || MINIMUM_ISA == 8664
e354a5
-/* We always assume having the timestamp register.  */
e354a5
-# define HP_TIMING_AVAIL	(1)
e354a5
-# define HP_SMALL_TIMING_AVAIL	(1)
e354a5
-
e354a5
 /* We indeed have inlined functions.  */
e354a5
 # define HP_TIMING_INLINE	(1)
e354a5