This is the mail archive of the glibc-cvs@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]

GNU C Library master sources branch azanella/master-hp-timing-refactor created. glibc-2.28.9000-596-gcc149fc


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, azanella/master-hp-timing-refactor has been created
        at  cc149fcd77512e1e955f1808dd8f88897bd0276c (commit)

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=cc149fcd77512e1e955f1808dd8f88897bd0276c

commit cc149fcd77512e1e955f1808dd8f88897bd0276c
Author: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Date:   Tue Jan 29 17:43:45 2019 +0000

    Add generic hp-timing support
    
    Add missing generic hp_timing support.  It uses clock_gettime (CLOCK_MONOTONIC)
    which has unspecified starting time, nano-second accuracy, and should faster on
    architectures that implementes the symbol as vDSO.
    
    Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. I also
    checked the builds for all afected ABIs.
    
    	* benchtests/Makefile (USE_CLOCK_GETTIME) Remove.
    	* benchtests/README: Update description.
    	* benchtests/bench-timing.h: Default to hp-timing.
    	* sysdeps/generic/hp-timing.h (HP_TIMING_DIFF, HP_TIMING_ACCUM_NT,
    	HP_TIMING_PRINT): Remove.
    	(HP_TIMING_NOW): Add generic implementation.
    	(hp_timing_t): Change to uint64_t.

diff --git a/benchtests/Makefile b/benchtests/Makefile
index e190775..50cb7cd 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -127,17 +127,11 @@ endif
 
 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
 
-# Use clock_gettime to measure performance of functions.  The default is to use
-# HP_TIMING if it is available.
-ifdef USE_CLOCK_GETTIME
-CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
-else
 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
 # of functions.  All x86 processors since 2010 support RDTSCP instruction.
 ifdef USE_RDTSCP
 CPPFLAGS-nonlib += -DUSE_RDTSCP
 endif
-endif
 
 DETAILED_OPT :=
 
diff --git a/benchtests/README b/benchtests/README
index aaf0b65..c4f03fd 100644
--- a/benchtests/README
+++ b/benchtests/README
@@ -27,12 +27,7 @@ BENCH_DURATION.
 
 The benchmark suite does function call measurements using architecture-specific
 high precision timing instructions whenever available.  When such support is
-not available, it uses clock_gettime (CLOCK_PROCESS_CPUTIME_ID).  One can force
-the benchmark to use clock_gettime by invoking make as follows:
-
-  $ make USE_CLOCK_GETTIME=1 bench
-
-Again, one must run `make bench-clean' before changing the measurement method.
+not available, it uses clock_gettime (CLOCK_MONOTONIC).
 
 On x86 processors, RDTSCP instruction provides more precise timing data
 than RDTSC instruction.  All x86 processors since 2010 support RDTSCP
diff --git a/benchtests/bench-timing.h b/benchtests/bench-timing.h
index 93fe379..e213dec 100644
--- a/benchtests/bench-timing.h
+++ b/benchtests/bench-timing.h
@@ -18,49 +18,21 @@
 
 #undef attribute_hidden
 #define attribute_hidden
+#define __clock_gettime clock_gettime
 #include <hp-timing.h>
 #include <stdint.h>
 
-#if HP_TIMING_INLINE && !defined USE_CLOCK_GETTIME
-# define GL(x) _##x
-# define GLRO(x) _##x
+#define GL(x) _##x
+#define GLRO(x) _##x
 typedef hp_timing_t timing_t;
 
-# define TIMING_TYPE "hp_timing"
+#define TIMING_TYPE "hp_timing"
 
-# define TIMING_INIT(res) ({ (res) = 1; })
+#define TIMING_INIT(res) ({ (res) = 1; })
 
-# define TIMING_NOW(var) HP_TIMING_NOW (var)
-# define TIMING_DIFF(diff, start, end) HP_TIMING_DIFF ((diff), (start), (end))
-# define TIMING_ACCUM(sum, diff) HP_TIMING_ACCUM_NT ((sum), (diff))
-
-#else
-
-#include <time.h>
-typedef uint64_t timing_t;
-
-# define TIMING_TYPE "clock_gettime"
-
-/* Measure the resolution of the clock so we can scale the number of
-   benchmark iterations by this value.  */
-# define TIMING_INIT(res) \
-({									      \
-  struct timespec start;						      \
-  clock_getres (CLOCK_PROCESS_CPUTIME_ID, &start);			      \
-  (res) = start.tv_nsec;					      \
-})
-
-# define TIMING_NOW(var) \
-({									      \
-  struct timespec tv;							      \
-  clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tv);			      \
-  (var) = (uint64_t) (tv.tv_nsec + (uint64_t) 1000000000 * tv.tv_sec);	      \
-})
-
-# define TIMING_DIFF(diff, start, end) (diff) = (end) - (start)
-# define TIMING_ACCUM(sum, diff) (sum) += (diff)
-
-#endif
+#define TIMING_NOW(var) HP_TIMING_NOW (var)
+#define TIMING_DIFF(diff, start, end) HP_TIMING_DIFF ((diff), (start), (end))
+#define TIMING_ACCUM(sum, diff) HP_TIMING_ACCUM_NT ((sum), (diff))
 
 #define TIMING_PRINT_MEAN(d_total_s, d_iters) \
   printf ("\t%g", (d_total_s) / (d_iters))
diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h
index 278998d..2528279 100644
--- a/sysdeps/generic/hp-timing.h
+++ b/sysdeps/generic/hp-timing.h
@@ -20,16 +20,23 @@
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-/* There are no generic definitions for the times.  We could write something
-   using the `gettimeofday' system call where available but the overhead of
-   the system call might be too high.  */
+#include <time.h>
+#include <stdint.h>
+#include <hp-timing-common.h>
 
-/* Provide dummy definitions.  */
+/* It should not be used for ld.so.  */
 #define HP_TIMING_INLINE	(0)
-typedef int hp_timing_t;
-#define HP_TIMING_NOW(var)
-#define HP_TIMING_DIFF(Diff, Start, End)
-#define HP_TIMING_ACCUM_NT(Sum, Diff)
-#define HP_TIMING_PRINT(Buf, Len, Val)
+
+typedef uint64_t hp_timing_t;
+
+/* The clock_gettime (CLOCK_MONOTONIC) has unspecified starting time,
+   nano-second accuracy, and for some architectues is implemented as
+   vDSO symbol.  */
+#define HP_TIMING_NOW(var) \
+({								\
+  struct timespec tv;						\
+  __clock_gettime (CLOCK_MONOTONIC, &tv);			\
+  (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec);	\
+})
 
 #endif	/* hp-timing.h */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=3506b307b6529288638bea19dea4e24ea9b0a92c

commit 3506b307b6529288638bea19dea4e24ea9b0a92c
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Jan 24 12:46:59 2019 +0000

    Refactor hp-timing rtld usage
    
    This patch refactor how hp-timing is used on loader code for statistics
    report.  The HP_TIMING_AVAIL and HP_SMALL_TIMING_AVAIL are removed and
    HP_TIMING_INLINE is used instead to check for hp-timing avaliability.
    For alpha, which only defines HP_SMALL_TIMING_AVAIL, the HP_TIMING_INLINE
    is set iff for IS_IN(rtld).
    
    Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. I also
    checked the builds for all afected ABIs.
    
    	* benchtests/bench-timing.h: Replace HP_TIMING_AVAIL with
    	HP_TIMING_INLINE.
    	* nptl/descr.h: Likewise.
    	* elf/rtld.c (RLTD_TIMING_DECLARE, RTLD_TIMING_NOW, RTLD_TIMING_DIFF,
    	RTLD_TIMING_ACCUM_NT, RTLD_TIMING_SET): Define.
    	(dl_start_final_info, _dl_start_final, dl_main, print_statistics):
    	Abstract hp-timing usage with RTLD_* macros.
    	* sysdeps/alpha/hp-timing.h (HP_TIMING_INLINE): Define iff IS_IN(rtld).
    	(HP_TIMING_AVAIL, HP_SMALL_TIMING_AVAIL): Remove.
    	* sysdeps/generic/hp-timing.h (HP_TIMING_AVAIL, HP_SMALL_TIMING_AVAIL,
    	HP_TIMING_NONAVAIL): Likewise.
    	* sysdeps/ia64/hp-timing.h (HP_TIMING_AVAIL, HP_SMALL_TIMING_AVAIL):
    	Likewise.
    	* sysdeps/powerpc/powerpc32/power4/hp-timing.h (HP_TIMING_AVAIL,
    	HP_SMALL_TIMING_AVAIL): Likewise.
    	* sysdeps/powerpc/powerpc64/hp-timing.h (HP_TIMING_AVAIL,
    	HP_SMALL_TIMING_AVAIL): Likewise.
    	* sysdeps/sparc/sparc32/sparcv9/hp-timing.h (HP_TIMING_AVAIL,
    	HP_SMALL_TIMING_AVAIL): Likewise.
    	* sysdeps/sparc/sparc64/hp-timing.h (HP_TIMING_AVAIL,
    	HP_SMALL_TIMING_AVAIL): Likewise.
    	* sysdeps/x86/hp-timing.h (HP_TIMING_AVAIL, HP_SMALL_TIMING_AVAIL):
    	Likewise.
    	* sysdeps/generic/hp-timing-common.h: Update comment with
    	HP_TIMING_AVAIL removal.

diff --git a/benchtests/bench-timing.h b/benchtests/bench-timing.h
index 41b7324..93fe379 100644
--- a/benchtests/bench-timing.h
+++ b/benchtests/bench-timing.h
@@ -21,7 +21,7 @@
 #include <hp-timing.h>
 #include <stdint.h>
 
-#if HP_TIMING_AVAIL && !defined USE_CLOCK_GETTIME
+#if HP_TIMING_INLINE && !defined USE_CLOCK_GETTIME
 # define GL(x) _##x
 # define GLRO(x) _##x
 typedef hp_timing_t timing_t;
diff --git a/elf/rtld.c b/elf/rtld.c
index 4864e01..a626448 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -46,6 +46,21 @@
 
 #include <assert.h>
 
+#if HP_TIMING_INLINE
+# define RLTD_TIMING_DECLARE(var, classifier,...) \
+  classifier hp_timing_t var __VA_ARGS__
+# define RTLD_TIMING_NOW(var)                    HP_TIMING_NOW(var)
+# define RTLD_TIMING_DIFF(diff, start, end)      HP_TIMING_DIFF(diff, start, end)
+# define RTLD_TIMING_ACCUM_NT(sum, diff)         HP_TIMING_ACCUM_NT(sum, diff)
+# define RTLD_TIMING_SET(var, value)             (var) = (value)
+#else
+# define RLTD_TIMING_DECLARE(var, classifier...)
+# define RTLD_TIMING_NOW(var)
+# define RTLD_TIMING_DIFF(diff, start, end)
+# define RTLD_TIMING_ACCUM_NT(sum, diff)
+# define RTLD_TIMING_SET(var, value)
+#endif
+
 /* Avoid PLT use for our local calls at startup.  */
 extern __typeof (__mempcpy) __mempcpy attribute_hidden;
 
@@ -303,11 +318,9 @@ static struct libname_list _dl_rtld_libname;
 static struct libname_list _dl_rtld_libname2;
 
 /* Variable for statistics.  */
-#ifndef HP_TIMING_NONAVAIL
-static hp_timing_t relocate_time;
-static hp_timing_t load_time attribute_relro;
-static hp_timing_t start_time attribute_relro;
-#endif
+RLTD_TIMING_DECLARE (relocate_time, static);
+RLTD_TIMING_DECLARE (load_time,     static, attribute_relro);
+RLTD_TIMING_DECLARE (start_time,    static, attribute_relro);
 
 /* Additional definitions needed by TLS initialization.  */
 #ifdef TLS_INIT_HELPER
@@ -335,9 +348,7 @@ static ElfW(Addr) _dl_start_final (void *arg);
 struct dl_start_final_info
 {
   struct link_map l;
-#if !defined HP_TIMING_NONAVAIL && HP_TIMING_INLINE
-  hp_timing_t start_time;
-#endif
+  RLTD_TIMING_DECLARE (start_time,);
 };
 static ElfW(Addr) _dl_start_final (void *arg,
 				   struct dl_start_final_info *info);
@@ -371,16 +382,10 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
 {
   ElfW(Addr) start_addr;
 
-  if (HP_SMALL_TIMING_AVAIL)
-    {
-      /* If it hasn't happen yet record the startup time.  */
-      if (! HP_TIMING_INLINE)
-	HP_TIMING_NOW (start_time);
-#if !defined DONT_USE_BOOTSTRAP_MAP && !defined HP_TIMING_NONAVAIL
-      else
-	start_time = info->start_time;
+  /* If it hasn't happen yet record the startup time.  */
+#if !defined DONT_USE_BOOTSTRAP_MAP
+  RTLD_TIMING_SET (start_time, info->start_time);
 #endif
-    }
 
   /* Transfer data about ourselves to the permanent link_map structure.  */
 #ifndef DONT_USE_BOOTSTRAP_MAP
@@ -412,23 +417,16 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
      entry point on the same stack we entered on.  */
   start_addr = _dl_sysdep_start (arg, &dl_main);
 
-#ifndef HP_TIMING_NONAVAIL
-  hp_timing_t rtld_total_time;
-  if (HP_SMALL_TIMING_AVAIL)
-    {
-      hp_timing_t end_time;
+  RLTD_TIMING_DECLARE (rtld_total_time,);
+  RLTD_TIMING_DECLARE (end_time,);
 
-      /* Get the current time.  */
-      HP_TIMING_NOW (end_time);
+  RTLD_TIMING_NOW (end_time);
 
-      /* Compute the difference.  */
-      HP_TIMING_DIFF (rtld_total_time, start_time, end_time);
-    }
-#endif
+  RTLD_TIMING_DIFF (rtld_total_time, start_time, end_time);
 
   if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_STATISTICS))
     {
-#ifndef HP_TIMING_NONAVAIL
+#if HP_TIMING_INLINE
       print_statistics (&rtld_total_time);
 #else
       print_statistics (NULL);
@@ -457,11 +455,10 @@ _dl_start (void *arg)
 #define RESOLVE_MAP(sym, version, flags) BOOTSTRAP_MAP
 #include "dynamic-link.h"
 
-  if (HP_TIMING_INLINE && HP_SMALL_TIMING_AVAIL)
 #ifdef DONT_USE_BOOTSTRAP_MAP
-    HP_TIMING_NOW (start_time);
+  RTLD_TIMING_NOW (start_time);
 #else
-    HP_TIMING_NOW (info.start_time);
+  RTLD_TIMING_NOW (info.start_time);
 #endif
 
   /* Partly clean the `bootstrap_map' structure up.  Don't use
@@ -876,11 +873,9 @@ dl_main (const ElfW(Phdr) *phdr,
   unsigned int i;
   bool prelinked = false;
   bool rtld_is_main = false;
-#ifndef HP_TIMING_NONAVAIL
-  hp_timing_t start;
-  hp_timing_t stop;
-  hp_timing_t diff;
-#endif
+  RLTD_TIMING_DECLARE (start,);
+  RLTD_TIMING_DECLARE (stop,);
+  RLTD_TIMING_DECLARE (diff,);
   void *tcbp = NULL;
 
   GL(dl_init_static_tls) = &_dl_nothread_init_static_tls;
@@ -1048,12 +1043,12 @@ of this helper program; chances are you did not intend to run this program.\n\
 	}
       else
 	{
-	  HP_TIMING_NOW (start);
+	  RTLD_TIMING_NOW (start);
 	  _dl_map_object (NULL, rtld_progname, lt_executable, 0,
 			  __RTLD_OPENEXEC, LM_ID_BASE);
-	  HP_TIMING_NOW (stop);
+	  RTLD_TIMING_NOW (stop);
 
-	  HP_TIMING_DIFF (load_time, start, stop);
+	  RTLD_TIMING_DIFF (load_time, start, stop);
 	}
 
       /* Now the map for the main executable is available.  */
@@ -1617,11 +1612,11 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 
   if (__glibc_unlikely (preloadlist != NULL))
     {
-      HP_TIMING_NOW (start);
+      RTLD_TIMING_NOW (start);
       npreloads += handle_ld_preload (preloadlist, main_map);
-      HP_TIMING_NOW (stop);
-      HP_TIMING_DIFF (diff, start, stop);
-      HP_TIMING_ACCUM_NT (load_time, diff);
+      RTLD_TIMING_NOW (stop);
+      RTLD_TIMING_DIFF (diff, start, stop);
+      RTLD_TIMING_ACCUM_NT (load_time, diff);
     }
 
   /* There usually is no ld.so.preload file, it should only be used
@@ -1681,7 +1676,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 	      file[file_size - 1] = '\0';
 	    }
 
-	  HP_TIMING_NOW (start);
+	  RTLD_TIMING_NOW (start);
 
 	  if (file != problem)
 	    {
@@ -1699,9 +1694,9 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 	      npreloads += do_preload (p, main_map, preload_file);
 	    }
 
-	  HP_TIMING_NOW (stop);
-	  HP_TIMING_DIFF (diff, start, stop);
-	  HP_TIMING_ACCUM_NT (load_time, diff);
+	  RTLD_TIMING_NOW (stop);
+	  RTLD_TIMING_DIFF (diff, start, stop);
+	  RTLD_TIMING_ACCUM_NT (load_time, diff);
 
 	  /* We don't need the file anymore.  */
 	  __munmap (file, file_size);
@@ -1725,11 +1720,11 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
   /* Load all the libraries specified by DT_NEEDED entries.  If LD_PRELOAD
      specified some libraries to load, these are inserted before the actual
      dependencies in the executable's searchlist for symbol resolution.  */
-  HP_TIMING_NOW (start);
+  RTLD_TIMING_NOW (start);
   _dl_map_object_deps (main_map, preloads, npreloads, mode == trace, 0);
-  HP_TIMING_NOW (stop);
-  HP_TIMING_DIFF (diff, start, stop);
-  HP_TIMING_ACCUM_NT (load_time, diff);
+  RTLD_TIMING_NOW (stop);
+  RTLD_TIMING_DIFF (diff, start, stop);
+  RTLD_TIMING_ACCUM_NT (load_time, diff);
 
   /* Mark all objects as being in the global scope.  */
   for (i = main_map->l_searchlist.r_nlist; i > 0; )
@@ -2122,12 +2117,10 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
       if (main_map->l_info [ADDRIDX (DT_GNU_CONFLICT)] != NULL)
 	{
 	  ElfW(Rela) *conflict, *conflictend;
-#ifndef HP_TIMING_NONAVAIL
-	  hp_timing_t start;
-	  hp_timing_t stop;
-#endif
+	  RLTD_TIMING_DECLARE (start, );
+	  RLTD_TIMING_DECLARE (stop, );
 
-	  HP_TIMING_NOW (start);
+	  RTLD_TIMING_NOW (start);
 	  assert (main_map->l_info [VALIDX (DT_GNU_CONFLICTSZ)] != NULL);
 	  conflict = (ElfW(Rela) *)
 	    main_map->l_info [ADDRIDX (DT_GNU_CONFLICT)]->d_un.d_ptr;
@@ -2135,8 +2128,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 	    ((char *) conflict
 	     + main_map->l_info [VALIDX (DT_GNU_CONFLICTSZ)]->d_un.d_val);
 	  _dl_resolve_conflicts (main_map, conflict, conflictend);
-	  HP_TIMING_NOW (stop);
-	  HP_TIMING_DIFF (relocate_time, start, stop);
+	  RTLD_TIMING_NOW (stop);
+	  RTLD_TIMING_DIFF (relocate_time, start, stop);
 	}
 
 
@@ -2164,15 +2157,13 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 	 know that because it is self-contained).  */
 
       int consider_profiling = GLRO(dl_profile) != NULL;
-#ifndef HP_TIMING_NONAVAIL
-      hp_timing_t start;
-      hp_timing_t stop;
-#endif
+      RLTD_TIMING_DECLARE (start, );
+      RLTD_TIMING_DECLARE (stop, );
 
       /* If we are profiling we also must do lazy reloaction.  */
       GLRO(dl_lazy) |= consider_profiling;
 
-      HP_TIMING_NOW (start);
+      RTLD_TIMING_NOW (start);
       unsigned i = main_map->l_searchlist.r_nlist;
       while (i-- > 0)
 	{
@@ -2199,9 +2190,9 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 	  if (l->l_tls_blocksize != 0 && tls_init_tp_called)
 	    _dl_add_to_slotinfo (l);
 	}
-      HP_TIMING_NOW (stop);
+      RTLD_TIMING_NOW (stop);
 
-      HP_TIMING_DIFF (relocate_time, start, stop);
+      RTLD_TIMING_DIFF (relocate_time, start, stop);
 
       /* Now enable profiling if needed.  Like the previous call,
 	 this has to go here because the calls it makes should use the
@@ -2244,19 +2235,17 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 	 re-relocation, we might call a user-supplied function
 	 (e.g. calloc from _dl_relocate_object) that uses TLS data.  */
 
-#ifndef HP_TIMING_NONAVAIL
-      hp_timing_t start;
-      hp_timing_t stop;
-      hp_timing_t add;
-#endif
+      RLTD_TIMING_DECLARE (start,);
+      RLTD_TIMING_DECLARE (stop,);
+      RLTD_TIMING_DECLARE (add,);
 
-      HP_TIMING_NOW (start);
+      RTLD_TIMING_NOW (start);
       /* Mark the link map as not yet relocated again.  */
       GL(dl_rtld_map).l_relocated = 0;
       _dl_relocate_object (&GL(dl_rtld_map), main_map->l_scope, 0, 0);
-      HP_TIMING_NOW (stop);
-      HP_TIMING_DIFF (add, start, stop);
-      HP_TIMING_ACCUM_NT (relocate_time, add);
+      RTLD_TIMING_NOW (stop);
+      RTLD_TIMING_DIFF (add, start, stop);
+      RTLD_TIMING_ACCUM_NT (relocate_time, add);
     }
 
   /* Do any necessary cleanups for the startup OS interface code.
@@ -2694,38 +2683,35 @@ static void
 __attribute ((noinline))
 print_statistics (hp_timing_t *rtld_total_timep)
 {
-#ifndef HP_TIMING_NONAVAIL
+#if HP_TIMING_INLINE
   char buf[200];
+  char pbuf[30];
   char *cp;
   char *wp;
 
   /* Total time rtld used.  */
-  if (HP_SMALL_TIMING_AVAIL)
+  HP_TIMING_PRINT (buf, sizeof (buf), *rtld_total_timep);
+  _dl_debug_printf ("\nruntime linker statistics:\n"
+		    "  total startup time in dynamic loader: %s\n", buf);
+
+  /* Print relocation statistics.  */
+  HP_TIMING_PRINT (buf, sizeof (buf), relocate_time);
+  cp = _itoa ((1000ULL * relocate_time) / *rtld_total_timep,
+	      pbuf + sizeof (pbuf), 10, 0);
+  wp = pbuf;
+  switch (pbuf + sizeof (pbuf) - cp)
     {
-      HP_TIMING_PRINT (buf, sizeof (buf), *rtld_total_timep);
-      _dl_debug_printf ("\nruntime linker statistics:\n"
-			"  total startup time in dynamic loader: %s\n", buf);
-
-      /* Print relocation statistics.  */
-      char pbuf[30];
-      HP_TIMING_PRINT (buf, sizeof (buf), relocate_time);
-      cp = _itoa ((1000ULL * relocate_time) / *rtld_total_timep,
-		  pbuf + sizeof (pbuf), 10, 0);
-      wp = pbuf;
-      switch (pbuf + sizeof (pbuf) - cp)
-	{
-	case 3:
-	  *wp++ = *cp++;
-	case 2:
-	  *wp++ = *cp++;
-	case 1:
-	  *wp++ = '.';
-	  *wp++ = *cp++;
-	}
-      *wp = '\0';
-      _dl_debug_printf ("\
-	    time needed for relocation: %s (%s%%)\n", buf, pbuf);
+    case 3:
+      *wp++ = *cp++;
+    case 2:
+      *wp++ = *cp++;
+    case 1:
+      *wp++ = '.';
+      *wp++ = *cp++;
     }
+  *wp = '\0';
+  _dl_debug_printf ("\
+	    time needed for relocation: %s (%s%%)\n", buf, pbuf);
 #endif
 
   unsigned long int num_relative_relocations = 0;
@@ -2766,29 +2752,24 @@ print_statistics (hp_timing_t *rtld_total_timep)
 		    GL(dl_num_cache_relocations),
 		    num_relative_relocations);
 
-#ifndef HP_TIMING_NONAVAIL
+#if HP_TIMING_INLINE
   /* Time spend while loading the object and the dependencies.  */
-  if (HP_SMALL_TIMING_AVAIL)
+  HP_TIMING_PRINT (buf, sizeof (buf), load_time);
+  cp = _itoa ((1000ULL * load_time) / *rtld_total_timep,
+	      pbuf + sizeof (pbuf), 10, 0);
+  wp = pbuf;
+  switch (pbuf + sizeof (pbuf) - cp)
     {
-      char pbuf[30];
-      HP_TIMING_PRINT (buf, sizeof (buf), load_time);
-      cp = _itoa ((1000ULL * load_time) / *rtld_total_timep,
-		  pbuf + sizeof (pbuf), 10, 0);
-      wp = pbuf;
-      switch (pbuf + sizeof (pbuf) - cp)
-	{
-	case 3:
-	  *wp++ = *cp++;
-	case 2:
-	  *wp++ = *cp++;
-	case 1:
-	  *wp++ = '.';
-	  *wp++ = *cp++;
-	}
-      *wp = '\0';
-      _dl_debug_printf ("\
-	   time needed to load objects: %s (%s%%)\n",
-				buf, pbuf);
+    case 3:
+      *wp++ = *cp++;
+    case 2:
+      *wp++ = *cp++;
+    case 1:
+      *wp++ = '.';
+      *wp++ = *cp++;
     }
+  *wp = '\0';
+  _dl_debug_printf ("\
+	   time needed to load objects: %s (%s%%)\n", buf, pbuf);
 #endif
 }
diff --git a/nptl/descr.h b/nptl/descr.h
index 6fd2cb1..b62c467 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -342,7 +342,7 @@ struct pthread
   /* Lock for synchronizing setxid calls.  */
   unsigned int setxid_futex;
 
-#if HP_TIMING_AVAIL
+#if HP_TIMING_INLINE
   hp_timing_t cpuclock_offset_ununsed;
 #endif
 
diff --git a/sysdeps/alpha/hp-timing.h b/sysdeps/alpha/hp-timing.h
index 4811326..08d8d66 100644
--- a/sysdeps/alpha/hp-timing.h
+++ b/sysdeps/alpha/hp-timing.h
@@ -17,16 +17,13 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _HP_TIMING_H
-#define _HP_TIMING_H	1
+#ifndef _HP_TIMING_ALPHA_H
+#define _HP_TIMING_ALPHA_H	1
 
+#if IS_IN(rtld)
 /* We always have the timestamp register, but it's got only a 4 second
    range.  Use it for ld.so profiling only.  */
-#define HP_TIMING_AVAIL		(0)
-#define HP_SMALL_TIMING_AVAIL	(1)
-
-/* We indeed have inlined functions.  */
-#define HP_TIMING_INLINE	(1)
+# define HP_TIMING_INLINE	(1)
 
 /* We use 32 bit values for the times.  */
 typedef unsigned int hp_timing_t;
@@ -34,13 +31,16 @@ typedef unsigned int hp_timing_t;
 /* The "rpcc" instruction returns a 32-bit counting half and a 32-bit
    "virtual cycle counter displacement".  Subtracting the two gives us
    a virtual cycle count.  */
-#define HP_TIMING_NOW(VAR) \
+# define HP_TIMING_NOW(VAR) \
   do {									      \
     unsigned long int x_;						      \
     asm volatile ("rpcc %0" : "=r"(x_));				      \
     (VAR) = (int) (x_) - (int) (x_ >> 32);				      \
   } while (0)
+# include <hp-timing-common.h>
 
-#include <hp-timing-common.h>
+#else
+# include <sysdeps/generic/hp-timing.h>
+#endif /* IS_IN(rtld)  */
 
 #endif	/* hp-timing.h */
diff --git a/sysdeps/generic/hp-timing-common.h b/sysdeps/generic/hp-timing-common.h
index 0ffb853..f7a0147 100644
--- a/sysdeps/generic/hp-timing-common.h
+++ b/sysdeps/generic/hp-timing-common.h
@@ -20,8 +20,6 @@
 /* In case a platform supports timers in the hardware the following macros
    and types must be defined:
 
-   - 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
diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h
index fb2a603..278998d 100644
--- a/sysdeps/generic/hp-timing.h
+++ b/sysdeps/generic/hp-timing.h
@@ -25,8 +25,6 @@
    the system call might be too high.  */
 
 /* Provide dummy definitions.  */
-#define HP_TIMING_AVAIL		(0)
-#define HP_SMALL_TIMING_AVAIL	(0)
 #define HP_TIMING_INLINE	(0)
 typedef int hp_timing_t;
 #define HP_TIMING_NOW(var)
@@ -34,7 +32,4 @@ typedef int hp_timing_t;
 #define HP_TIMING_ACCUM_NT(Sum, Diff)
 #define HP_TIMING_PRINT(Buf, Len, Val)
 
-/* Since this implementation is not available we tell the user about it.  */
-#define HP_TIMING_NONAVAIL	1
-
 #endif	/* hp-timing.h */
diff --git a/sysdeps/ia64/hp-timing.h b/sysdeps/ia64/hp-timing.h
index 17ef023..2ca248a 100644
--- a/sysdeps/ia64/hp-timing.h
+++ b/sysdeps/ia64/hp-timing.h
@@ -20,10 +20,6 @@
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-/* We always assume having the timestamp register.  */
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
-
 /* We indeed have inlined functions.  */
 #define HP_TIMING_INLINE	(1)
 
diff --git a/sysdeps/powerpc/powerpc32/power4/hp-timing.h b/sysdeps/powerpc/powerpc32/power4/hp-timing.h
index 0d77aa0..ed2ca9b 100644
--- a/sysdeps/powerpc/powerpc32/power4/hp-timing.h
+++ b/sysdeps/powerpc/powerpc32/power4/hp-timing.h
@@ -20,10 +20,6 @@
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-/* We always assume having the timestamp register.  */
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
-
 /* We indeed have inlined functions.  */
 #define HP_TIMING_INLINE	(1)
 
diff --git a/sysdeps/powerpc/powerpc64/hp-timing.h b/sysdeps/powerpc/powerpc64/hp-timing.h
index fb9ac1c..01678cd 100644
--- a/sysdeps/powerpc/powerpc64/hp-timing.h
+++ b/sysdeps/powerpc/powerpc64/hp-timing.h
@@ -20,10 +20,6 @@
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-/* We always assume having the timestamp register.  */
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
-
 /* We indeed have inlined functions.  */
 #define HP_TIMING_INLINE	(1)
 
diff --git a/sysdeps/sparc/sparc32/sparcv9/hp-timing.h b/sysdeps/sparc/sparc32/sparcv9/hp-timing.h
index 6a4ab08..3270c5b 100644
--- a/sysdeps/sparc/sparc32/sparcv9/hp-timing.h
+++ b/sysdeps/sparc/sparc32/sparcv9/hp-timing.h
@@ -20,8 +20,6 @@
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
 #define HP_TIMING_INLINE	(1)
 
 typedef unsigned long long int hp_timing_t;
diff --git a/sysdeps/sparc/sparc64/hp-timing.h b/sysdeps/sparc/sparc64/hp-timing.h
index db95c02..0f02b2a 100644
--- a/sysdeps/sparc/sparc64/hp-timing.h
+++ b/sysdeps/sparc/sparc64/hp-timing.h
@@ -20,8 +20,6 @@
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
 #define HP_TIMING_INLINE	(1)
 
 typedef unsigned long int hp_timing_t;
diff --git a/sysdeps/x86/hp-timing.h b/sysdeps/x86/hp-timing.h
index 9b6a998..ccb9f92 100644
--- a/sysdeps/x86/hp-timing.h
+++ b/sysdeps/x86/hp-timing.h
@@ -22,10 +22,6 @@
 #include <isa.h>
 
 #if MINIMUM_ISA == 686 || MINIMUM_ISA == 8664
-/* We always assume having the timestamp register.  */
-# define HP_TIMING_AVAIL	(1)
-# define HP_SMALL_TIMING_AVAIL	(1)
-
 /* We indeed have inlined functions.  */
 # define HP_TIMING_INLINE	(1)
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=c56f48dcbb3bec6c354a8b632614a69b60711d40

commit c56f48dcbb3bec6c354a8b632614a69b60711d40
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Jan 16 18:10:56 2019 +0000

    Do not use HP_TIMING_NOW for random bits
    
    This patch removes the HP_TIMING_BITS usage for fast random bits and replace
    with clock_gettime (CLOCK_MONOTONIC).  It has unspecified starting time and
    nano-second accuracy, so its randomness is significantly better than
    gettimeofday.
    
    Althoug it should incur in more overhead (specially for architecture that
    support hp-timing), the symbol is also common implemented as a vDSO.
    
    Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. I also
    checked on a i686-gnu build.
    
    	* resolv/res_mkquery.c [HP_TIMING_AVAIL] (RANDOM_BITS,
    	(__res_context_mkquery): Remove usage hp-timing usage and replace with
    	clock_gettime.
    	* resolv/res_send.c [HP_TIMING_AVAIL] (nameserver_offset): Likewise.
    	* sysdeps/posix/tempname.c [HP_TIMING_AVAIL] (__gen_tempname):
    	Likewise.

diff --git a/resolv/res_mkquery.c b/resolv/res_mkquery.c
index 19b8b40..e73f650 100644
--- a/resolv/res_mkquery.c
+++ b/resolv/res_mkquery.c
@@ -82,6 +82,7 @@
  * SOFTWARE.
  */
 
+#include <stdint.h>
 #include <sys/types.h>
 #include <sys/param.h>
 #include <netinet/in.h>
@@ -93,11 +94,13 @@
 #include <sys/time.h>
 #include <shlib-compat.h>
 
-#include <hp-timing.h>
-#include <stdint.h>
-#if HP_TIMING_AVAIL
-# define RANDOM_BITS(Var) { uint64_t v64; HP_TIMING_NOW (v64); Var = v64; }
-#endif
+static inline int
+random_bits (void)
+{
+  struct timespec tv;
+  __clock_gettime (CLOCK_MONOTONIC, &tv);
+  return tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec;
+}
 
 int
 __res_context_mkquery (struct resolv_context *ctx, int op, const char *dname,
@@ -121,13 +124,11 @@ __res_context_mkquery (struct resolv_context *ctx, int op, const char *dname,
      by one after the initial randomization which still predictable if
      the application does multiple requests.  */
   int randombits;
-#ifdef RANDOM_BITS
-  RANDOM_BITS (randombits);
-#else
-  struct timeval tv;
-  __gettimeofday (&tv, NULL);
-  randombits = (tv.tv_sec << 8) ^ tv.tv_usec;
-#endif
+  {
+    struct timespec tv;
+    __clock_gettime (CLOCK_MONOTONIC, &tv);
+    randombits = tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec;
+  }
 
   hp->id = randombits;
   hp->opcode = op;
diff --git a/resolv/res_send.c b/resolv/res_send.c
index fa040c1..acf1110 100644
--- a/resolv/res_send.c
+++ b/resolv/res_send.c
@@ -109,7 +109,6 @@
 #include <unistd.h>
 #include <kernel-features.h>
 #include <libc-diag.h>
-#include <hp-timing.h>
 
 #if PACKETSZ > 65536
 #define MAXPACKET       PACKETSZ
@@ -309,15 +308,9 @@ nameserver_offset (struct __res_state *statp)
   if ((offset & 1) == 0)
     {
       /* Initialization is required.  */
-#if HP_TIMING_AVAIL
-      uint64_t ticks;
-      HP_TIMING_NOW (ticks);
-      offset = ticks;
-#else
-      struct timeval tv;
-      __gettimeofday (&tv, NULL);
-      offset = ((tv.tv_sec << 8) ^ tv.tv_usec);
-#endif
+      struct timespec tv;
+      __clock_gettime (CLOCK_MONOTONIC, &tv);
+      offset = tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec;
       /* The lowest bit is the most random.  Preserve it.  */
       offset <<= 1;
 
diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c
index 2ed39d1..eccf625 100644
--- a/sysdeps/posix/tempname.c
+++ b/sysdeps/posix/tempname.c
@@ -70,25 +70,6 @@
 # define __secure_getenv secure_getenv
 #endif
 
-#ifdef _LIBC
-# include <hp-timing.h>
-# if HP_TIMING_AVAIL
-#  define RANDOM_BITS(Var) \
-  if (__glibc_unlikely (value == UINT64_C (0)))				      \
-    {									      \
-      /* If this is the first time this function is used initialize	      \
-	 the variable we accumulate the value in to some somewhat	      \
-	 random value.  If we'd not do this programs at startup time	      \
-	 might have a reduced set of possible names, at least on slow	      \
-	 machines.  */							      \
-      struct timeval tv;						      \
-      __gettimeofday (&tv, NULL);					      \
-      value = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;		      \
-    }									      \
-  HP_TIMING_NOW (Var)
-# endif
-#endif
-
 /* Use the widest available unsigned type if uint64_t is not
    available.  The algorithm below extracts a number less than 62**6
    (approximately 2**35.725) from uint64_t, so ancient hosts where
@@ -227,15 +208,11 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
   XXXXXX = &tmpl[len - 6 - suffixlen];
 
   /* Get some more or less random data.  */
-#ifdef RANDOM_BITS
-  RANDOM_BITS (random_time_bits);
-#else
   {
-    struct timeval tv;
-    __gettimeofday (&tv, NULL);
-    random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;
+    struct timespec tv;
+    __clock_gettime (CLOCK_MONOTONIC, &tv);
+    random_time_bits = tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec;
   }
-#endif
   value += random_time_bits ^ __getpid ();
 
   for (count = 0; count < attempts; value += 7777, ++count)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=f344827c038f865744389ee12b7022f9a9c90251

commit f344827c038f865744389ee12b7022f9a9c90251
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Jan 16 17:30:07 2019 +0000

    linux: Assume CLOCK_{PROCESS,THREAD}_CPUTIME_ID
    
    This patch assumes that clock_getres syscall always support
    CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID, so there is no need
    to fallback to hp-timing support for _SC_MONOTONIC_CLOCK.  This allows
    simplify the sysconf support to always use the syscall.
    
    The ia64 implementation is also simplified and consolidate in one file.
    
    Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/ia64/has_cpuclock.c: Remove file.
    	* sysdeps/unix/sysv/linux/ia64/sysconf.c (ia64_check_cpuclock): New
    	function.
    	* sysdeps/unix/sysv/linux/sysconf.c (has_cpuclock): Remove function.
    	(check_clock_getres): New function.
    	(__sysconf): Use check_clock_getres instead of has_cpuclock.

diff --git a/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c b/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c
deleted file mode 100644
index b3afb37..0000000
--- a/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Copyright (C) 2000-2019 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, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <not-cancel.h>
-
-static int itc_usable;
-
-static int
-has_cpuclock (void)
-{
-  if (__builtin_expect (itc_usable == 0, 0))
-    {
-      int newval = 1;
-      int fd = __open_nocancel ("/proc/sal/itc_drift", O_RDONLY);
-      if (__builtin_expect (fd != -1, 1))
-	{
-	  char buf[16];
-	  /* We expect the file to contain a single digit followed by
-	     a newline.  If the format changes we better not rely on
-	     the file content.  */
-	  if (__read_nocancel (fd, buf, sizeof buf) != 2
-	      || buf[0] != '0' || buf[1] != '\n')
-	    newval = -1;
-
-	  __close_nocancel_nostatus (fd);
-	}
-
-      itc_usable = newval;
-    }
-
-  return itc_usable;
-}
diff --git a/sysdeps/unix/sysv/linux/ia64/sysconf.c b/sysdeps/unix/sysv/linux/ia64/sysconf.c
index ef75322..48bb008 100644
--- a/sysdeps/unix/sysv/linux/ia64/sysconf.c
+++ b/sysdeps/unix/sysv/linux/ia64/sysconf.c
@@ -16,15 +16,39 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <assert.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include <unistd.h>
-
-
-#include "has_cpuclock.c"
-#define HAS_CPUCLOCK(name) (has_cpuclock () ? _POSIX_VERSION : -1)
-
+#include <not-cancel.h>
+
+static bool itc_usable;
+
+static bool
+ia64_check_cpuclock (void)
+{
+  if (__glibc_unlikely (itc_usable == 0))
+    {
+      int newval = true;
+      int fd = __open_nocancel ("/proc/sal/itc_drift", O_RDONLY);
+      if (__glibc_likely (fd != -1))
+	{
+	  char buf[16];
+	  /* We expect the file to contain a single digit followed by
+	     a newline.  If the format changes we better not rely on
+	     the file content.  */
+	  if (__read_nocancel (fd, buf, sizeof buf) != 2
+	      || buf[0] != '0' || buf[1] != '\n')
+	    newval = false;
+
+	  __close_nocancel_nostatus (fd);
+	}
+
+      itc_usable = newval;
+    }
+
+  return itc_usable;
+}
+#define HAS_CPUCLOCK(name) (ia64_check_cpuclock () ? _POSIX_VERSION : -1)
 
 /* Now the generic Linux version.  */
 #include <sysdeps/unix/sysv/linux/sysconf.c>
diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c
index 4b297ba..b870a21 100644
--- a/sysdeps/unix/sysv/linux/sysconf.c
+++ b/sysdeps/unix/sysv/linux/sysconf.c
@@ -35,31 +35,19 @@
 static long int posix_sysconf (int name);
 
 
-#ifndef HAS_CPUCLOCK
 static long int
-has_cpuclock (int name)
+check_clock_getres (clockid_t clk_id)
 {
-# if defined __NR_clock_getres || HP_TIMING_AVAIL
-  /* If we have HP_TIMING, we will fall back on that if the system
-     call does not work, so we support it either way.  */
-#  if !HP_TIMING_AVAIL
-  /* Check using the clock_getres system call.  */
   struct timespec ts;
   INTERNAL_SYSCALL_DECL (err);
-  int r = INTERNAL_SYSCALL (clock_getres, err, 2,
-			    (name == _SC_CPUTIME
-			     ? CLOCK_PROCESS_CPUTIME_ID
-			     : CLOCK_THREAD_CPUTIME_ID),
-			    &ts);
+  int r = INTERNAL_SYSCALL_CALL (clock_getres, err, clk_id, &ts);
   if (INTERNAL_SYSCALL_ERROR_P (r, err))
     return -1;
-#  endif
   return _POSIX_VERSION;
-# else
-  return -1;
-# endif
 }
-# define HAS_CPUCLOCK(name) has_cpuclock (name)
+
+#ifndef HAS_CPUCLOCK
+# define HAS_CPUCLOCK(name) check_clock_getres (name)
 #endif
 
 
@@ -71,29 +59,22 @@ __sysconf (int name)
 
   switch (name)
     {
-      struct rlimit rlimit;
-#ifdef __NR_clock_getres
     case _SC_MONOTONIC_CLOCK:
-      /* Check using the clock_getres system call.  */
-      {
-	struct timespec ts;
-	INTERNAL_SYSCALL_DECL (err);
-	int r;
-	r = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
-	return INTERNAL_SYSCALL_ERROR_P (r, err) ? -1 : _POSIX_VERSION;
-      }
-#endif
+      return check_clock_getres (CLOCK_MONOTONIC);
 
     case _SC_CPUTIME:
+      return HAS_CPUCLOCK (CLOCK_PROCESS_CPUTIME_ID);
     case _SC_THREAD_CPUTIME:
-      return HAS_CPUCLOCK (name);
+      return HAS_CPUCLOCK (CLOCK_THREAD_CPUTIME_ID);
 
-    case _SC_ARG_MAX:
+    case _SC_ARG_MAX: {
+      struct rlimit rlimit;
       /* Use getrlimit to get the stack limit.  */
       if (__getrlimit (RLIMIT_STACK, &rlimit) == 0)
 	return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
 
       return legacy_ARG_MAX;
+    } break;
 
     case _SC_NGROUPS_MAX:
       /* Try to read the information from the /proc/sys/kernel/ngroups_max
@@ -101,13 +82,14 @@ __sysconf (int name)
       procfname = "/proc/sys/kernel/ngroups_max";
       break;
 
-    case _SC_SIGQUEUE_MAX:
+    case _SC_SIGQUEUE_MAX: {
+      struct rlimit rlimit;
       if (__getrlimit (RLIMIT_SIGPENDING, &rlimit) == 0)
 	return rlimit.rlim_cur;
 
       /* The /proc/sys/kernel/rtsig-max file contains the answer.  */
       procfname = "/proc/sys/kernel/rtsig-max";
-      break;
+    } break;
 
     default:
       break;

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=408e23c740b074d606a1233e97619c04c50a7ad8

commit 408e23c740b074d606a1233e97619c04c50a7ad8
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Jan 16 16:22:29 2019 +0000

    nptl: Remove pthread_clock_gettime pthread_clock_settime
    
    This patch removes CLOCK_THREAD_CPUTIME_ID and CLOCK_PROCESS_CPUTIME_ID support
    from clock_gettime and clock_settime generic implementation.  For Linux, kernel
    already provides supports through the syscall and Hurd HTL lacks
    __pthread_clock_gettime and __pthread_clock_settime internal implementation.
    
    This allows removes unused code which, however, still incur in some runtime
    overhead in thread creation (the struct pthread cpuclock_offset
    initialization)
    
    Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. I also
    checked on a i686-gnu build.
    
    	* nptl/Makefile (libpthread-routines): Remove pthread_clock_gettime and
    	pthread_clock_settime.
    	* nptl/pthreadP.h (__find_thread_by_id): Remove prototype.
    	* elf/dl-support.c [!HP_TIMING_NOAVAIL] (_dl_cpuclock_offset): Remove.
    	(_dl_non_dynamic_init): Remove _dl_cpuclock_offset setting.
    	* elf/rtld.c (_dl_start_final): Likewise.
    	* nptl/allocatestack.c (__find_thread_by_id): Remove function.
    	* sysdeps/generic/ldsodefs.h [!HP_TIMING_NOAVAIL] (_dl_cpuclock_offset):
    	Remove.
    	* sysdeps/mach/hurd/dl-sysdep.c [!HP_TIMING_NOAVAIL]
    	(_dl_cpuclock_offset): Remove.
    	* nptl/descr.h (struct pthread): Rename cpuclock_offset to
    	cpuclock_offset_ununsed.
    	* nptl/nptl-init.c (__pthread_initialize_minimal_internal): Remove
    	cpuclock_offset set.
    	* nptl/pthread_create.c (START_THREAD_DEFN): Likewise.
    	* sysdeps/nptl/fork.c (__libc_fork): Likewise.
    	* nptl/pthread_clock_gettime.c: Remove file.
    	* nptl/pthread_clock_settime.c: Likewise.
    	* sysdeps/unix/clock_gettime.c (hp_timing_gettime): Remove function.
    	[HP_TIMING_AVAIL] (realtime_gettime): Remove CLOCK_THREAD_CPUTIME_ID
    	and CLOCK_PROCESS_CPUTIME_ID support.
    	* sysdeps/unix/clock_settime.c (hp_timing_gettime): Likewise.
    	[HP_TIMING_AVAIL] (realtime_gettime): Likewise.
    	* sysdeps/posix/clock_getres.c (hp_timing_getres): Likewise.
    	[HP_TIMING_AVAIL] (__clock_getres): Likewise.
    	* sysdeps/unix/clock_nanosleep.c (CPUCLOCK_P, INVALID_CLOCK_P):
    	Likewise.
    	(__clock_nanosleep): Remove CPUCLOCK_P and INVALID_CLOCK_P usage.

diff --git a/elf/dl-support.c b/elf/dl-support.c
index 42c350c..0a8b636 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -129,11 +129,6 @@ void *_dl_random;
 #include <dl-procruntime.c>
 #include <dl-procinfo.c>
 
-/* Initial value of the CPU clock.  */
-#ifndef HP_TIMING_NONAVAIL
-hp_timing_t _dl_cpuclock_offset;
-#endif
-
 void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls;
 
 size_t _dl_pagesize = EXEC_PAGESIZE;
@@ -314,9 +309,6 @@ _dl_non_dynamic_init (void)
   _dl_main_map.l_phdr = GL(dl_phdr);
   _dl_main_map.l_phnum = GL(dl_phnum);
 
-  if (HP_SMALL_TIMING_AVAIL)
-    HP_TIMING_NOW (_dl_cpuclock_offset);
-
   _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
 
   /* Set up the data structures for the system-supplied DSO early,
diff --git a/elf/rtld.c b/elf/rtld.c
index 5d97f41..4864e01 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -403,8 +403,6 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
 # endif
 #endif
 
-  HP_TIMING_NOW (GL(dl_cpuclock_offset));
-
   /* Initialize the stack end variable.  */
   __libc_stack_end = __builtin_frame_address (0);
 
diff --git a/nptl/Makefile b/nptl/Makefile
index 340282c..d283f7d 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -109,7 +109,6 @@ libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \
 		      pthread_once \
 		      old_pthread_atfork \
 		      pthread_getcpuclockid \
-		      pthread_clock_gettime pthread_clock_settime \
 		      shm-directory \
 		      sem_init sem_destroy \
 		      sem_open sem_close sem_unlink \
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 670cb8f..578f4e3 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -962,54 +962,6 @@ __reclaim_stacks (void)
 }
 
 
-#if HP_TIMING_AVAIL
-# undef __find_thread_by_id
-/* Find a thread given the thread ID.  */
-attribute_hidden
-struct pthread *
-__find_thread_by_id (pid_t tid)
-{
-  struct pthread *result = NULL;
-
-  lll_lock (stack_cache_lock, LLL_PRIVATE);
-
-  /* Iterate over the list with system-allocated threads first.  */
-  list_t *runp;
-  list_for_each (runp, &stack_used)
-    {
-      struct pthread *curp;
-
-      curp = list_entry (runp, struct pthread, list);
-
-      if (curp->tid == tid)
-	{
-	  result = curp;
-	  goto out;
-	}
-    }
-
-  /* Now the list with threads using user-allocated stacks.  */
-  list_for_each (runp, &__stack_user)
-    {
-      struct pthread *curp;
-
-      curp = list_entry (runp, struct pthread, list);
-
-      if (curp->tid == tid)
-	{
-	  result = curp;
-	  goto out;
-	}
-    }
-
- out:
-  lll_unlock (stack_cache_lock, LLL_PRIVATE);
-
-  return result;
-}
-#endif
-
-
 #ifdef SIGSETXID
 static void
 setxid_mark_thread (struct xid_command *cmdp, struct pthread *t)
diff --git a/nptl/descr.h b/nptl/descr.h
index 9c54cbc..6fd2cb1 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -343,8 +343,7 @@ struct pthread
   unsigned int setxid_futex;
 
 #if HP_TIMING_AVAIL
-  /* Offset of the CPU clock at start thread start time.  */
-  hp_timing_t cpuclock_offset;
+  hp_timing_t cpuclock_offset_ununsed;
 #endif
 
   /* If the thread waits to join another one the ID of the latter is
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index b5895fa..6691211 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -276,9 +276,6 @@ __pthread_initialize_minimal_internal (void)
   THREAD_SETMEM (pd, user_stack, true);
   if (LLL_LOCK_INITIALIZER != 0)
     THREAD_SETMEM (pd, lock, LLL_LOCK_INITIALIZER);
-#if HP_TIMING_AVAIL
-  THREAD_SETMEM (pd, cpuclock_offset, GL(dl_cpuclock_offset));
-#endif
 
   /* Initialize the robust mutex data.  */
   {
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 626bd4b..f0facfd 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -401,16 +401,6 @@ extern int __pthread_multiple_threads attribute_hidden;
 extern int *__libc_multiple_threads_ptr attribute_hidden;
 #endif
 
-/* Find a thread given its TID.  */
-extern struct pthread *__find_thread_by_id (pid_t tid) attribute_hidden
-#ifdef SHARED
-;
-#else
-weak_function;
-#define __find_thread_by_id(tid) \
-  (__find_thread_by_id ? (__find_thread_by_id) (tid) : (struct pthread *) NULL)
-#endif
-
 extern void __pthread_init_static_tls (struct link_map *) attribute_hidden;
 
 extern size_t __pthread_get_minstack (const pthread_attr_t *attr);
diff --git a/nptl/pthread_clock_gettime.c b/nptl/pthread_clock_gettime.c
deleted file mode 100644
index f1d9104..0000000
--- a/nptl/pthread_clock_gettime.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Copyright (C) 2001-2019 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; see the file COPYING.LIB.  If
-   not, see <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <stdlib.h>
-#include <time.h>
-#include "pthreadP.h"
-
-
-#if HP_TIMING_AVAIL
-int
-__pthread_clock_gettime (clockid_t clock_id, hp_timing_t freq,
-			 struct timespec *tp)
-{
-  hp_timing_t tsc;
-
-  /* Get the current counter.  */
-  HP_TIMING_NOW (tsc);
-
-  /* This is the ID of the thread we are looking for.  */
-  pid_t tid = ((unsigned int) clock_id) >> CLOCK_IDFIELD_SIZE;
-
-  /* Compute the offset since the start time of the process.  */
-  if (tid == 0 || tid == THREAD_GETMEM (THREAD_SELF, tid))
-    /* Our own clock.  */
-    tsc -= THREAD_GETMEM (THREAD_SELF, cpuclock_offset);
-  else
-    {
-      /* This is more complicated.  We have to locate the thread based
-	 on the ID.  This means walking the list of existing
-	 threads.  */
-      struct pthread *thread = __find_thread_by_id (tid);
-      if (thread == NULL)
-	{
-	  __set_errno (EINVAL);
-	  return -1;
-	}
-
-      /* There is a race here.  The thread might terminate and the stack
-	 become unusable.  But this is the user's problem.  */
-      tsc -= thread->cpuclock_offset;
-    }
-
-  /* Compute the seconds.  */
-  tp->tv_sec = tsc / freq;
-
-  /* And the nanoseconds.  This computation should be stable until
-     we get machines with about 16GHz frequency.  */
-  tp->tv_nsec = ((tsc % freq) * 1000000000ull) / freq;
-
-  return 0;
-}
-#endif
diff --git a/nptl/pthread_clock_settime.c b/nptl/pthread_clock_settime.c
deleted file mode 100644
index 0fe6482..0000000
--- a/nptl/pthread_clock_settime.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/* Copyright (C) 2001-2019 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; see the file COPYING.LIB.  If
-   not, see <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <stdlib.h>
-#include <time.h>
-#include "pthreadP.h"
-
-
-#if HP_TIMING_AVAIL
-int
-__pthread_clock_settime (clockid_t clock_id, hp_timing_t offset)
-{
-  /* This is the ID of the thread we are looking for.  */
-  pid_t tid = ((unsigned int) clock_id) >> CLOCK_IDFIELD_SIZE;
-
-  /* Compute the offset since the start time of the process.  */
-  if (tid == 0 || tid == THREAD_GETMEM (THREAD_SELF, tid))
-    /* Our own clock.  */
-    THREAD_SETMEM (THREAD_SELF, cpuclock_offset, offset);
-  else
-    {
-      /* This is more complicated.  We have to locate the thread based
-	 on the ID.  This means walking the list of existing
-	 threads.  */
-      struct pthread *thread = __find_thread_by_id (tid);
-      if (thread == NULL)
-	{
-	  __set_errno (EINVAL);
-	  return -1;
-	}
-
-      /* There is a race here.  The thread might terminate and the stack
-	 become unusable.  But this is the user's problem.  */
-      thread->cpuclock_offset = offset;
-    }
-
-  return 0;
-}
-#endif
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 2bd2b10..18b7bbe 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -379,13 +379,6 @@ START_THREAD_DEFN
 {
   struct pthread *pd = START_THREAD_SELF;
 
-#if HP_TIMING_AVAIL
-  /* Remember the time when the thread was started.  */
-  hp_timing_t now;
-  HP_TIMING_NOW (now);
-  THREAD_SETMEM (pd, cpuclock_offset, now);
-#endif
-
   /* Initialize resolver state pointer.  */
   __resp = &pd->res;
 
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 37cab6f..346bbb8 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -352,11 +352,6 @@ struct rtld_global
   /* The object to be initialized first.  */
   EXTERN struct link_map *_dl_initfirst;
 
-#if HP_SMALL_TIMING_AVAIL
-  /* Start time on CPU clock.  */
-  EXTERN hp_timing_t _dl_cpuclock_offset;
-#endif
-
   /* Map of shared object to be profiled.  */
   EXTERN struct link_map *_dl_profile_map;
 
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index a58338c..72c80a8 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -62,10 +62,6 @@ int __libc_multiple_libcs = 0;	/* Defining this here avoids the inclusion
 void *__libc_stack_end = NULL;
 rtld_hidden_data_def(__libc_stack_end)
 
-#if HP_TIMING_AVAIL
-hp_timing_t _dl_cpuclock_offset;
-#endif
-
 /* TODO: Initialize.  */
 void *_dl_random attribute_relro = NULL;
 
@@ -246,10 +242,6 @@ unfmh();			/* XXX */
   /* Initialize frequently used global variable.  */
   GLRO(dl_pagesize) = __getpagesize ();
 
-#if HP_TIMING_AVAIL
-  HP_TIMING_NOW (_dl_cpuclock_offset);
-#endif
-
 fmh();				/* XXX */
 
   /* See hurd/hurdstartup.c; this deals with getting information
diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c
index bd68f18..3ae32f5 100644
--- a/sysdeps/nptl/fork.c
+++ b/sysdeps/nptl/fork.c
@@ -83,14 +83,6 @@ __libc_fork (void)
       if (__fork_generation_pointer != NULL)
 	*__fork_generation_pointer += __PTHREAD_ONCE_FORK_GEN_INCR;
 
-#if HP_TIMING_AVAIL
-      /* The CPU clock of the thread and process have to be set to zero.  */
-      hp_timing_t now;
-      HP_TIMING_NOW (now);
-      THREAD_SETMEM (self, cpuclock_offset, now);
-      GL(dl_cpuclock_offset) = now;
-#endif
-
 #ifdef __NR_set_robust_list
       /* Initialize the robust mutex list setting in the kernel which has
 	 been reset during the fork.  We do not check for errors because if
diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c
index dac4761..01024a3 100644
--- a/sysdeps/posix/clock_getres.c
+++ b/sysdeps/posix/clock_getres.c
@@ -24,37 +24,6 @@
 #include <libc-internal.h>
 
 
-#if HP_TIMING_AVAIL
-static long int nsec;		/* Clock frequency of the processor.  */
-
-static int
-hp_timing_getres (struct timespec *res)
-{
-  if (__glibc_unlikely (nsec == 0))
-    {
-      hp_timing_t freq;
-
-      /* This can only happen if we haven't initialized the `nsec'
-	 variable yet.  Do this now.  We don't have to protect this
-	 code against multiple execution since all of them should
-	 lead to the same result.  */
-      freq = __get_clockfreq ();
-      if (__glibc_unlikely (freq == 0))
-	/* Something went wrong.  */
-	return -1;
-
-      nsec = MAX (UINT64_C (1000000000) / freq, 1);
-    }
-
-  /* Fill in the values.
-     The seconds are always zero (unless we have a 1Hz machine).  */
-  res->tv_sec = 0;
-  res->tv_nsec = nsec;
-
-  return 0;
-}
-#endif
-
 static inline int
 realtime_getres (struct timespec *res)
 {
@@ -87,21 +56,8 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
       break;
 
     default:
-#if HP_TIMING_AVAIL
-      if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
-	  == CLOCK_THREAD_CPUTIME_ID)
-	retval = hp_timing_getres (res);
-      else
-#endif
-	__set_errno (EINVAL);
-      break;
-
-#if HP_TIMING_AVAIL
-    case CLOCK_PROCESS_CPUTIME_ID:
-    case CLOCK_THREAD_CPUTIME_ID:
-      retval = hp_timing_getres (res);
+      __set_errno (EINVAL);
       break;
-#endif
     }
 
   return retval;
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index 33a1f33..10a6c96 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -24,57 +24,6 @@
 #include <ldsodefs.h>
 
 
-#if HP_TIMING_AVAIL
-/* Clock frequency of the processor.  We make it a 64-bit variable
-   because some jokers are already playing with processors with more
-   than 4GHz.  */
-static hp_timing_t freq;
-
-
-/* This function is defined in the thread library.  */
-extern int __pthread_clock_gettime (clockid_t clock_id, hp_timing_t freq,
-				    struct timespec *tp)
-     __attribute__ ((__weak__));
-
-static int
-hp_timing_gettime (clockid_t clock_id, struct timespec *tp)
-{
-  hp_timing_t tsc;
-
-  if (__glibc_unlikely (freq == 0))
-    {
-      /* This can only happen if we haven't initialized the `freq'
-	 variable yet.  Do this now. We don't have to protect this
-	 code against multiple execution since all of them should
-	 lead to the same result.  */
-      freq = __get_clockfreq ();
-      if (__glibc_unlikely (freq == 0))
-	/* Something went wrong.  */
-	return -1;
-    }
-
-  if (clock_id != CLOCK_PROCESS_CPUTIME_ID
-      && __pthread_clock_gettime != NULL)
-    return __pthread_clock_gettime (clock_id, freq, tp);
-
-  /* Get the current counter.  */
-  HP_TIMING_NOW (tsc);
-
-  /* Compute the offset since the start time of the process.  */
-  tsc -= GL(dl_cpuclock_offset);
-
-  /* Compute the seconds.  */
-  tp->tv_sec = tsc / freq;
-
-  /* And the nanoseconds.  This computation should be stable until
-     we get machines with about 16GHz frequency.  */
-  tp->tv_nsec = ((tsc % freq) * UINT64_C (1000000000)) / freq;
-
-  return 0;
-}
-#endif
-
-
 static inline int
 realtime_gettime (struct timespec *tp)
 {
@@ -105,20 +54,8 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
       break;
 
     default:
-#if HP_TIMING_AVAIL
-      if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
-	  == CLOCK_THREAD_CPUTIME_ID)
-	retval = hp_timing_gettime (clock_id, tp);
-      else
-#endif
-	__set_errno (EINVAL);
-      break;
-
-#if HP_TIMING_AVAIL
-    case CLOCK_PROCESS_CPUTIME_ID:
-      retval = hp_timing_gettime (clock_id, tp);
+      __set_errno (EINVAL);
       break;
-#endif
     }
 
   return retval;
diff --git a/sysdeps/unix/clock_nanosleep.c b/sysdeps/unix/clock_nanosleep.c
index 7722d11..b276085 100644
--- a/sysdeps/unix/clock_nanosleep.c
+++ b/sysdeps/unix/clock_nanosleep.c
@@ -19,23 +19,8 @@
 #include <assert.h>
 #include <errno.h>
 #include <time.h>
-#include <hp-timing.h>
 #include <sysdep-cancel.h>
 
-#if HP_TIMING_AVAIL
-# define CPUCLOCK_P(clock) \
-  ((clock) == CLOCK_PROCESS_CPUTIME_ID					      \
-   || ((clock) & ((1 << CLOCK_IDFIELD_SIZE) - 1)) == CLOCK_THREAD_CPUTIME_ID)
-#else
-# define CPUCLOCK_P(clock) 0
-#endif
-
-#ifndef INVALID_CLOCK_P
-# define INVALID_CLOCK_P(cl) \
-  ((cl) < CLOCK_REALTIME || (cl) > CLOCK_THREAD_CPUTIME_ID)
-#endif
-
-
 /* This implementation assumes that these is only a `nanosleep' system
    call.  So we have to remap all other activities.  */
 int
@@ -51,14 +36,7 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
   if (clock_id == CLOCK_THREAD_CPUTIME_ID)
     return EINVAL;		/* POSIX specifies EINVAL for this case.  */
 
-#ifdef SYSDEP_NANOSLEEP
-  SYSDEP_NANOSLEEP;
-#endif
-
-  if (CPUCLOCK_P (clock_id))
-    return ENOTSUP;
-
-  if (INVALID_CLOCK_P (clock_id))
+  if (clock_id < CLOCK_REALTIME || clock_id > CLOCK_THREAD_CPUTIME_ID)
     return EINVAL;
 
   /* If we got an absolute time, remap it.  */
@@ -71,7 +49,7 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
       assert (sizeof (sec) >= sizeof (now.tv_sec));
 
       /* Get the current time for this clock.  */
-      if (__builtin_expect (__clock_gettime (clock_id, &now), 0) != 0)
+      if (__clock_gettime (clock_id, &now) != 0)
 	return errno;
 
       /* Compute the difference.  */
@@ -90,12 +68,12 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
       /* Make sure we are not modifying the struct pointed to by REM.  */
       rem = NULL;
     }
-  else if (__builtin_expect (flags, 0) != 0)
+  else if (flags != 0)
     return EINVAL;
   else if (clock_id != CLOCK_REALTIME)
     /* Not supported.  */
     return ENOTSUP;
 
-  return __builtin_expect (__nanosleep (req, rem), 0) ? errno : 0;
+  return __nanosleep (req, rem), 0 ? errno : 0;
 }
 weak_alias (__clock_nanosleep, clock_nanosleep)
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
index 80bea2d..72575c1 100644
--- a/sysdeps/unix/clock_settime.c
+++ b/sysdeps/unix/clock_settime.c
@@ -21,59 +21,11 @@
 #include <ldsodefs.h>
 
 
-#if HP_TIMING_AVAIL
-/* Clock frequency of the processor.  We make it a 64-bit variable
-   because some jokers are already playing with processors with more
-   than 4GHz.  */
-static hp_timing_t freq;
-
-
-/* This function is defined in the thread library.  */
-extern void __pthread_clock_settime (clockid_t clock_id, hp_timing_t offset)
-     __attribute__ ((__weak__));
-
-
-static int
-hp_timing_settime (clockid_t clock_id, const struct timespec *tp)
-{
-  hp_timing_t tsc;
-  hp_timing_t usertime;
-
-  /* First thing is to get the current time.  */
-  HP_TIMING_NOW (tsc);
-
-  if (__glibc_unlikely (freq == 0))
-    {
-      /* This can only happen if we haven't initialized the `freq'
-	 variable yet.  Do this now. We don't have to protect this
-	 code against multiple execution since all of them should lead
-	 to the same result.  */
-      freq = __get_clockfreq ();
-      if (__glibc_unlikely (freq == 0))
-	/* Something went wrong.  */
-	return -1;
-    }
-
-  /* Convert the user-provided time into CPU ticks.  */
-  usertime = tp->tv_sec * freq + (tp->tv_nsec * freq) / 1000000000ull;
-
-  /* Determine the offset and use it as the new base value.  */
-  if (clock_id == CLOCK_PROCESS_CPUTIME_ID
-      || __pthread_clock_settime == NULL)
-    GL(dl_cpuclock_offset) = tsc - usertime;
-  else
-    __pthread_clock_settime (clock_id, tsc - usertime);
-
-  return 0;
-}
-#endif
-
-
 /* Set CLOCK to value TP.  */
 int
 __clock_settime (clockid_t clock_id, const struct timespec *tp)
 {
-  int retval;
+  int retval = -1;
 
   /* Make sure the time cvalue is OK.  */
   if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
@@ -91,16 +43,7 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
     } break;
 
     default:
-# if HP_TIMING_AVAIL
-      if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
-	  || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
-	retval = hp_timing_settime (clock_id, tp);
-      else
-# endif
-	{
-	  __set_errno (EINVAL);
-	  retval = -1;
-	}
+      __set_errno (EINVAL);
       break;
     }
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=2fae5ede9d89267b724e2c77a4b863531019c113

commit 2fae5ede9d89267b724e2c77a4b863531019c113
Author: Wilco Dijkstra <wdijkstr@arm.com>
Date:   Wed Jan 16 15:58:51 2019 +0000

    Cleanup clock_*time includes
    
    Clock_gettime, settime and getres implementations are unnecessarily
    complex due to using many defines and C file inclusion.  Simplify the
    code by replacing the redundant defines and removing the inclusion,
    making it much easier to understand. No functional changes.
    
    OK for commit (for 2.30)?
    
    ChangeLog:
    2019-01-14  Wilco Dijkstra  <wdijkstr@arm.com>
    
    	* sysdeps/posix/clock_getres.c (__clock_getres): Cleanup.
    	* sysdeps/unix/clock_gettime.c (__clock_gettime): Cleanup.
    	* sysdeps/unix/clock_settime.c (__clock_settime): Cleanup.
    	* sysdeps/unix/sysv/linux/clock_getres.c (__clock_getres): Cleanup.
    	* sysdeps/unix/sysv/linux/clock_gettime.c (__clock_gettime): Cleanup.
    	* sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime): Cleanup.

diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c
index f47715e..dac4761 100644
--- a/sysdeps/posix/clock_getres.c
+++ b/sysdeps/posix/clock_getres.c
@@ -82,20 +82,11 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
 
   switch (clock_id)
     {
-#ifdef SYSDEP_GETRES
-      SYSDEP_GETRES;
-#endif
-
-#ifndef HANDLED_REALTIME
     case CLOCK_REALTIME:
       retval = realtime_getres (res);
       break;
-#endif	/* handled REALTIME */
 
     default:
-#ifdef SYSDEP_GETRES_CPU
-      SYSDEP_GETRES_CPU;
-#endif
 #if HP_TIMING_AVAIL
       if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
 	  == CLOCK_THREAD_CPUTIME_ID)
@@ -105,7 +96,7 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
 	__set_errno (EINVAL);
       break;
 
-#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+#if HP_TIMING_AVAIL
     case CLOCK_PROCESS_CPUTIME_ID:
     case CLOCK_THREAD_CPUTIME_ID:
       retval = hp_timing_getres (res);
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index 138991d..33a1f33 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -95,11 +95,6 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
 
   switch (clock_id)
     {
-#ifdef SYSDEP_GETTIME
-      SYSDEP_GETTIME;
-#endif
-
-#ifndef HANDLED_REALTIME
     case CLOCK_REALTIME:
       {
 	struct timeval tv;
@@ -108,12 +103,8 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
 	  TIMEVAL_TO_TIMESPEC (&tv, tp);
       }
       break;
-#endif
 
     default:
-#ifdef SYSDEP_GETTIME_CPU
-      SYSDEP_GETTIME_CPU (clock_id, tp);
-#endif
 #if HP_TIMING_AVAIL
       if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
 	  == CLOCK_THREAD_CPUTIME_ID)
@@ -123,7 +114,7 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
 	__set_errno (EINVAL);
       break;
 
-#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+#if HP_TIMING_AVAIL
     case CLOCK_PROCESS_CPUTIME_ID:
       retval = hp_timing_gettime (clock_id, tp);
       break;
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
index b589e87..80bea2d 100644
--- a/sysdeps/unix/clock_settime.c
+++ b/sysdeps/unix/clock_settime.c
@@ -21,7 +21,7 @@
 #include <ldsodefs.h>
 
 
-#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+#if HP_TIMING_AVAIL
 /* Clock frequency of the processor.  We make it a 64-bit variable
    because some jokers are already playing with processors with more
    than 4GHz.  */
@@ -84,29 +84,13 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
 
   switch (clock_id)
     {
-#define HANDLE_REALTIME \
-      do {								      \
-	struct timeval tv;						      \
-	TIMESPEC_TO_TIMEVAL (&tv, tp);					      \
-									      \
-	retval = __settimeofday (&tv, NULL);				      \
-      } while (0)
-
-#ifdef SYSDEP_SETTIME
-      SYSDEP_SETTIME;
-#endif
-
-#ifndef HANDLED_REALTIME
-    case CLOCK_REALTIME:
-      HANDLE_REALTIME;
-      break;
-#endif
+    case CLOCK_REALTIME: {
+      struct timeval tv;
+      TIMESPEC_TO_TIMEVAL (&tv, tp);
+      retval = __settimeofday (&tv, NULL);
+    } break;
 
     default:
-#ifdef SYSDEP_SETTIME_CPU
-      SYSDEP_SETTIME_CPU;
-#endif
-#ifndef HANDLED_CPUTIME
 # if HP_TIMING_AVAIL
       if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
 	  || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
@@ -117,7 +101,6 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
 	  __set_errno (EINVAL);
 	  retval = -1;
 	}
-#endif
       break;
     }
 
diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c
index a245328..bb2ee10 100644
--- a/sysdeps/unix/sysv/linux/clock_getres.c
+++ b/sysdeps/unix/sysv/linux/clock_getres.c
@@ -26,26 +26,11 @@
 #endif
 #include <sysdep-vdso.h>
 
-#define SYSCALL_GETRES \
-  retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, res); \
-  break
+/* Get resolution of clock.  */
+int
+__clock_getres (clockid_t clock_id, struct timespec *res)
+{
+  return INLINE_VSYSCALL (clock_getres, 2, clock_id, res);
+}
+weak_alias (__clock_getres, clock_getres)
 
-/* The REALTIME and MONOTONIC clock are definitely supported in the
-   kernel.  */
-#define SYSDEP_GETRES							      \
-  SYSDEP_GETRES_CPUTIME							      \
-  case CLOCK_REALTIME:							      \
-  case CLOCK_MONOTONIC:							      \
-  case CLOCK_MONOTONIC_RAW:						      \
-  case CLOCK_REALTIME_COARSE:						      \
-  case CLOCK_MONOTONIC_COARSE:						      \
-    SYSCALL_GETRES
-
-/* We handled the REALTIME clock here.  */
-#define HANDLED_REALTIME	1
-#define HANDLED_CPUTIME		1
-
-#define SYSDEP_GETRES_CPU SYSCALL_GETRES
-#define SYSDEP_GETRES_CPUTIME	/* Default catches them too.  */
-
-#include <sysdeps/posix/clock_getres.c>
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index 9af806f..2ad7846 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -26,22 +26,12 @@
 #endif
 #include <sysdep-vdso.h>
 
-/* The REALTIME and MONOTONIC clock are definitely supported in the
-   kernel.  */
-#define SYSDEP_GETTIME \
-  SYSDEP_GETTIME_CPUTIME;						      \
-  case CLOCK_REALTIME:							      \
-  case CLOCK_MONOTONIC:							      \
-    retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);		      \
-    break
+/* Get current value of CLOCK and store it in TP.  */
+int
+__clock_gettime (clockid_t clock_id, struct timespec *tp)
+{
+  return INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);
+}
+weak_alias (__clock_gettime, clock_gettime)
+libc_hidden_def (__clock_gettime)
 
-/* We handled the REALTIME clock here.  */
-#define HANDLED_REALTIME	1
-#define HANDLED_CPUTIME	1
-
-#define SYSDEP_GETTIME_CPU(clock_id, tp) \
-  retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
-  break
-#define SYSDEP_GETTIME_CPUTIME	/* Default catches them too.  */
-
-#include <sysdeps/unix/clock_gettime.c>
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index 7e2432b..729a4b2 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -21,18 +21,18 @@
 
 #include "kernel-posix-cpu-timers.h"
 
+/* Set CLOCK to value TP.  */
+int
+__clock_settime (clockid_t clock_id, const struct timespec *tp)
+{
+  /* Make sure the time cvalue is OK.  */
+  if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
+}
+weak_alias (__clock_settime, clock_settime)
 
-/* The REALTIME clock is definitely supported in the kernel.  */
-#define SYSDEP_SETTIME \
-  case CLOCK_REALTIME:							      \
-    retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp);		      \
-    break
-
-/* We handled the REALTIME clock here.  */
-#define HANDLED_REALTIME	1
-
-#define HANDLED_CPUTIME 1
-#define SYSDEP_SETTIME_CPU \
-  retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
-
-#include <sysdeps/unix/clock_settime.c>

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU C Library master sources


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