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