981dc9
commit 38cc11daa43b11b12a7774405accee1007de1adf
981dc9
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
981dc9
Date:   Wed Jan 16 16:22:29 2019 +0000
981dc9
981dc9
    nptl: Remove pthread_clock_gettime pthread_clock_settime
981dc9
    
981dc9
    This patch removes CLOCK_THREAD_CPUTIME_ID and CLOCK_PROCESS_CPUTIME_ID support
981dc9
    from clock_gettime and clock_settime generic implementation.  For Linux, kernel
981dc9
    already provides supports through the syscall and Hurd HTL lacks
981dc9
    __pthread_clock_gettime and __pthread_clock_settime internal implementation.
981dc9
    
981dc9
    As described in clock_gettime man-page [1] on 'Historical note for SMP
981dc9
    system', implementing CLOCK_{THREAD,PROCESS}_CPUTIME_ID with timer registers
981dc9
    is error-prone and susceptible to timing and accurary issues that the libc
981dc9
    can not deal without kernel support.
981dc9
    
981dc9
    This allows removes unused code which, however, still incur in some runtime
981dc9
    overhead in thread creation (the struct pthread cpuclock_offset
981dc9
    initialization).
981dc9
    
981dc9
    If hurd eventually wants to support them it should either either implement as
981dc9
    a kernel facility (or something related due its architecture) or in system
981dc9
    specific implementation.
981dc9
    
981dc9
    Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. I also
981dc9
    checked on a i686-gnu build.
981dc9
    
981dc9
            * nptl/Makefile (libpthread-routines): Remove pthread_clock_gettime and
981dc9
            pthread_clock_settime.
981dc9
            * nptl/pthreadP.h (__find_thread_by_id): Remove prototype.
981dc9
            * elf/dl-support.c [!HP_TIMING_NOAVAIL] (_dl_cpuclock_offset): Remove.
981dc9
            (_dl_non_dynamic_init): Remove _dl_cpuclock_offset setting.
981dc9
            * elf/rtld.c (_dl_start_final): Likewise.
981dc9
            * nptl/allocatestack.c (__find_thread_by_id): Remove function.
981dc9
            * sysdeps/generic/ldsodefs.h [!HP_TIMING_NOAVAIL] (_dl_cpuclock_offset):
981dc9
            Remove.
981dc9
            * sysdeps/mach/hurd/dl-sysdep.c [!HP_TIMING_NOAVAIL]
981dc9
            (_dl_cpuclock_offset): Remove.
981dc9
            * nptl/descr.h (struct pthread): Rename cpuclock_offset to
981dc9
            cpuclock_offset_ununsed.
981dc9
            * nptl/nptl-init.c (__pthread_initialize_minimal_internal): Remove
981dc9
            cpuclock_offset set.
981dc9
            * nptl/pthread_create.c (START_THREAD_DEFN): Likewise.
981dc9
            * sysdeps/nptl/fork.c (__libc_fork): Likewise.
981dc9
            * nptl/pthread_clock_gettime.c: Remove file.
981dc9
            * nptl/pthread_clock_settime.c: Likewise.
981dc9
            * sysdeps/unix/clock_gettime.c (hp_timing_gettime): Remove function.
981dc9
            [HP_TIMING_AVAIL] (realtime_gettime): Remove CLOCK_THREAD_CPUTIME_ID
981dc9
            and CLOCK_PROCESS_CPUTIME_ID support.
981dc9
            * sysdeps/unix/clock_settime.c (hp_timing_gettime): Likewise.
981dc9
            [HP_TIMING_AVAIL] (realtime_gettime): Likewise.
981dc9
            * sysdeps/posix/clock_getres.c (hp_timing_getres): Likewise.
981dc9
            [HP_TIMING_AVAIL] (__clock_getres): Likewise.
981dc9
            * sysdeps/unix/clock_nanosleep.c (CPUCLOCK_P, INVALID_CLOCK_P):
981dc9
            Likewise.
981dc9
            (__clock_nanosleep): Remove CPUCLOCK_P and INVALID_CLOCK_P usage.
981dc9
    
981dc9
    [1] http://man7.org/linux/man-pages/man2/clock_gettime.2.html
981dc9
981dc9
Conflicts:
981dc9
	nptl/pthread_clock_gettime.c
981dc9
	nptl/pthread_clock_settime.c
981dc9
	  (Removal after copyright year update upstream.)
981dc9
981dc9
diff --git a/elf/dl-support.c b/elf/dl-support.c
981dc9
index c8439fcc53d126f3..ef5455b91c17ca30 100644
981dc9
--- a/elf/dl-support.c
981dc9
+++ b/elf/dl-support.c
981dc9
@@ -127,11 +127,6 @@ void *_dl_random;
981dc9
 #include <dl-procruntime.c>
981dc9
 #include <dl-procinfo.c>
981dc9
 
981dc9
-/* Initial value of the CPU clock.  */
981dc9
-#ifndef HP_TIMING_NONAVAIL
981dc9
-hp_timing_t _dl_cpuclock_offset;
981dc9
-#endif
981dc9
-
981dc9
 void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls;
981dc9
 
981dc9
 size_t _dl_pagesize = EXEC_PAGESIZE;
981dc9
@@ -312,9 +307,6 @@ _dl_non_dynamic_init (void)
981dc9
   _dl_main_map.l_phdr = GL(dl_phdr);
981dc9
   _dl_main_map.l_phnum = GL(dl_phnum);
981dc9
 
981dc9
-  if (HP_SMALL_TIMING_AVAIL)
981dc9
-    HP_TIMING_NOW (_dl_cpuclock_offset);
981dc9
-
981dc9
   _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
981dc9
 
981dc9
   /* Set up the data structures for the system-supplied DSO early,
981dc9
diff --git a/elf/rtld.c b/elf/rtld.c
981dc9
index 0aa1a2a19f649e16..e107bd14f9478a90 100644
981dc9
--- a/elf/rtld.c
981dc9
+++ b/elf/rtld.c
981dc9
@@ -401,8 +401,6 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
981dc9
 # endif
981dc9
 #endif
981dc9
 
981dc9
-  HP_TIMING_NOW (GL(dl_cpuclock_offset));
981dc9
-
981dc9
   /* Initialize the stack end variable.  */
981dc9
   __libc_stack_end = __builtin_frame_address (0);
981dc9
 
981dc9
diff --git a/nptl/Makefile b/nptl/Makefile
981dc9
index 447dce0590295c9c..d6b37b6efd3b7d78 100644
981dc9
--- a/nptl/Makefile
981dc9
+++ b/nptl/Makefile
981dc9
@@ -109,7 +109,6 @@ libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \
981dc9
 		      pthread_once \
981dc9
 		      old_pthread_atfork \
981dc9
 		      pthread_getcpuclockid \
981dc9
-		      pthread_clock_gettime pthread_clock_settime \
981dc9
 		      shm-directory \
981dc9
 		      sem_init sem_destroy \
981dc9
 		      sem_open sem_close sem_unlink \
981dc9
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
981dc9
index d0971a97fdbe098e..5fa45b19987717e1 100644
981dc9
--- a/nptl/allocatestack.c
981dc9
+++ b/nptl/allocatestack.c
981dc9
@@ -964,54 +964,6 @@ __reclaim_stacks (void)
981dc9
 }
981dc9
 
981dc9
 
981dc9
-#if HP_TIMING_AVAIL
981dc9
-# undef __find_thread_by_id
981dc9
-/* Find a thread given the thread ID.  */
981dc9
-attribute_hidden
981dc9
-struct pthread *
981dc9
-__find_thread_by_id (pid_t tid)
981dc9
-{
981dc9
-  struct pthread *result = NULL;
981dc9
-
981dc9
-  lll_lock (stack_cache_lock, LLL_PRIVATE);
981dc9
-
981dc9
-  /* Iterate over the list with system-allocated threads first.  */
981dc9
-  list_t *runp;
981dc9
-  list_for_each (runp, &stack_used)
981dc9
-    {
981dc9
-      struct pthread *curp;
981dc9
-
981dc9
-      curp = list_entry (runp, struct pthread, list);
981dc9
-
981dc9
-      if (curp->tid == tid)
981dc9
-	{
981dc9
-	  result = curp;
981dc9
-	  goto out;
981dc9
-	}
981dc9
-    }
981dc9
-
981dc9
-  /* Now the list with threads using user-allocated stacks.  */
981dc9
-  list_for_each (runp, &__stack_user)
981dc9
-    {
981dc9
-      struct pthread *curp;
981dc9
-
981dc9
-      curp = list_entry (runp, struct pthread, list);
981dc9
-
981dc9
-      if (curp->tid == tid)
981dc9
-	{
981dc9
-	  result = curp;
981dc9
-	  goto out;
981dc9
-	}
981dc9
-    }
981dc9
-
981dc9
- out:
981dc9
-  lll_unlock (stack_cache_lock, LLL_PRIVATE);
981dc9
-
981dc9
-  return result;
981dc9
-}
981dc9
-#endif
981dc9
-
981dc9
-
981dc9
 #ifdef SIGSETXID
981dc9
 static void
981dc9
 setxid_mark_thread (struct xid_command *cmdp, struct pthread *t)
981dc9
diff --git a/nptl/descr.h b/nptl/descr.h
981dc9
index 9c01e1b9863b178c..c3b81d8b27839502 100644
981dc9
--- a/nptl/descr.h
981dc9
+++ b/nptl/descr.h
981dc9
@@ -343,8 +343,7 @@ struct pthread
981dc9
   unsigned int setxid_futex;
981dc9
 
981dc9
 #if HP_TIMING_AVAIL
981dc9
-  /* Offset of the CPU clock at start thread start time.  */
981dc9
-  hp_timing_t cpuclock_offset;
981dc9
+  hp_timing_t cpuclock_offset_ununsed;
981dc9
 #endif
981dc9
 
981dc9
   /* If the thread waits to join another one the ID of the latter is
981dc9
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
981dc9
index 907411d5bca2af79..098bc059f4771ef2 100644
981dc9
--- a/nptl/nptl-init.c
981dc9
+++ b/nptl/nptl-init.c
981dc9
@@ -275,9 +275,6 @@ __pthread_initialize_minimal_internal (void)
981dc9
   THREAD_SETMEM (pd, user_stack, true);
981dc9
   if (LLL_LOCK_INITIALIZER != 0)
981dc9
     THREAD_SETMEM (pd, lock, LLL_LOCK_INITIALIZER);
981dc9
-#if HP_TIMING_AVAIL
981dc9
-  THREAD_SETMEM (pd, cpuclock_offset, GL(dl_cpuclock_offset));
981dc9
-#endif
981dc9
 
981dc9
   /* Initialize the robust mutex data.  */
981dc9
   {
981dc9
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
981dc9
index 19efe1e35feed5be..00be8f92793e8710 100644
981dc9
--- a/nptl/pthreadP.h
981dc9
+++ b/nptl/pthreadP.h
981dc9
@@ -406,16 +406,6 @@ extern int __pthread_multiple_threads attribute_hidden;
981dc9
 extern int *__libc_multiple_threads_ptr attribute_hidden;
981dc9
 #endif
981dc9
 
981dc9
-/* Find a thread given its TID.  */
981dc9
-extern struct pthread *__find_thread_by_id (pid_t tid) attribute_hidden
981dc9
-#ifdef SHARED
981dc9
-;
981dc9
-#else
981dc9
-weak_function;
981dc9
-#define __find_thread_by_id(tid) \
981dc9
-  (__find_thread_by_id ? (__find_thread_by_id) (tid) : (struct pthread *) NULL)
981dc9
-#endif
981dc9
-
981dc9
 extern void __pthread_init_static_tls (struct link_map *) attribute_hidden;
981dc9
 
981dc9
 extern size_t __pthread_get_minstack (const pthread_attr_t *attr);
981dc9
diff --git a/nptl/pthread_clock_gettime.c b/nptl/pthread_clock_gettime.c
981dc9
deleted file mode 100644
981dc9
index 6bc75cfe3f1ff856..0000000000000000
981dc9
--- a/nptl/pthread_clock_gettime.c
981dc9
+++ /dev/null
981dc9
@@ -1,67 +0,0 @@
981dc9
-/* Copyright (C) 2001-2018 Free Software Foundation, Inc.
981dc9
-   This file is part of the GNU C Library.
981dc9
-
981dc9
-   The GNU C Library is free software; you can redistribute it and/or
981dc9
-   modify it under the terms of the GNU Lesser General Public License as
981dc9
-   published by the Free Software Foundation; either version 2.1 of the
981dc9
-   License, or (at your option) any later version.
981dc9
-
981dc9
-   The GNU C Library is distributed in the hope that it will be useful,
981dc9
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
981dc9
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
981dc9
-   Lesser General Public License for more details.
981dc9
-
981dc9
-   You should have received a copy of the GNU Lesser General Public
981dc9
-   License along with the GNU C Library; see the file COPYING.LIB.  If
981dc9
-   not, see <http://www.gnu.org/licenses/>.  */
981dc9
-
981dc9
-#include <errno.h>
981dc9
-#include <stdlib.h>
981dc9
-#include <time.h>
981dc9
-#include "pthreadP.h"
981dc9
-
981dc9
-
981dc9
-#if HP_TIMING_AVAIL
981dc9
-int
981dc9
-__pthread_clock_gettime (clockid_t clock_id, hp_timing_t freq,
981dc9
-			 struct timespec *tp)
981dc9
-{
981dc9
-  hp_timing_t tsc;
981dc9
-
981dc9
-  /* Get the current counter.  */
981dc9
-  HP_TIMING_NOW (tsc);
981dc9
-
981dc9
-  /* This is the ID of the thread we are looking for.  */
981dc9
-  pid_t tid = ((unsigned int) clock_id) >> CLOCK_IDFIELD_SIZE;
981dc9
-
981dc9
-  /* Compute the offset since the start time of the process.  */
981dc9
-  if (tid == 0 || tid == THREAD_GETMEM (THREAD_SELF, tid))
981dc9
-    /* Our own clock.  */
981dc9
-    tsc -= THREAD_GETMEM (THREAD_SELF, cpuclock_offset);
981dc9
-  else
981dc9
-    {
981dc9
-      /* This is more complicated.  We have to locate the thread based
981dc9
-	 on the ID.  This means walking the list of existing
981dc9
-	 threads.  */
981dc9
-      struct pthread *thread = __find_thread_by_id (tid);
981dc9
-      if (thread == NULL)
981dc9
-	{
981dc9
-	  __set_errno (EINVAL);
981dc9
-	  return -1;
981dc9
-	}
981dc9
-
981dc9
-      /* There is a race here.  The thread might terminate and the stack
981dc9
-	 become unusable.  But this is the user's problem.  */
981dc9
-      tsc -= thread->cpuclock_offset;
981dc9
-    }
981dc9
-
981dc9
-  /* Compute the seconds.  */
981dc9
-  tp->tv_sec = tsc / freq;
981dc9
-
981dc9
-  /* And the nanoseconds.  This computation should be stable until
981dc9
-     we get machines with about 16GHz frequency.  */
981dc9
-  tp->tv_nsec = ((tsc % freq) * 1000000000ull) / freq;
981dc9
-
981dc9
-  return 0;
981dc9
-}
981dc9
-#endif
981dc9
diff --git a/nptl/pthread_clock_settime.c b/nptl/pthread_clock_settime.c
981dc9
deleted file mode 100644
981dc9
index 29d35c64cfa817a3..0000000000000000
981dc9
--- a/nptl/pthread_clock_settime.c
981dc9
+++ /dev/null
981dc9
@@ -1,54 +0,0 @@
981dc9
-/* Copyright (C) 2001-2018 Free Software Foundation, Inc.
981dc9
-   This file is part of the GNU C Library.
981dc9
-
981dc9
-   The GNU C Library is free software; you can redistribute it and/or
981dc9
-   modify it under the terms of the GNU Lesser General Public License as
981dc9
-   published by the Free Software Foundation; either version 2.1 of the
981dc9
-   License, or (at your option) any later version.
981dc9
-
981dc9
-   The GNU C Library is distributed in the hope that it will be useful,
981dc9
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
981dc9
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
981dc9
-   Lesser General Public License for more details.
981dc9
-
981dc9
-   You should have received a copy of the GNU Lesser General Public
981dc9
-   License along with the GNU C Library; see the file COPYING.LIB.  If
981dc9
-   not, see <http://www.gnu.org/licenses/>.  */
981dc9
-
981dc9
-#include <errno.h>
981dc9
-#include <stdlib.h>
981dc9
-#include <time.h>
981dc9
-#include "pthreadP.h"
981dc9
-
981dc9
-
981dc9
-#if HP_TIMING_AVAIL
981dc9
-int
981dc9
-__pthread_clock_settime (clockid_t clock_id, hp_timing_t offset)
981dc9
-{
981dc9
-  /* This is the ID of the thread we are looking for.  */
981dc9
-  pid_t tid = ((unsigned int) clock_id) >> CLOCK_IDFIELD_SIZE;
981dc9
-
981dc9
-  /* Compute the offset since the start time of the process.  */
981dc9
-  if (tid == 0 || tid == THREAD_GETMEM (THREAD_SELF, tid))
981dc9
-    /* Our own clock.  */
981dc9
-    THREAD_SETMEM (THREAD_SELF, cpuclock_offset, offset);
981dc9
-  else
981dc9
-    {
981dc9
-      /* This is more complicated.  We have to locate the thread based
981dc9
-	 on the ID.  This means walking the list of existing
981dc9
-	 threads.  */
981dc9
-      struct pthread *thread = __find_thread_by_id (tid);
981dc9
-      if (thread == NULL)
981dc9
-	{
981dc9
-	  __set_errno (EINVAL);
981dc9
-	  return -1;
981dc9
-	}
981dc9
-
981dc9
-      /* There is a race here.  The thread might terminate and the stack
981dc9
-	 become unusable.  But this is the user's problem.  */
981dc9
-      thread->cpuclock_offset = offset;
981dc9
-    }
981dc9
-
981dc9
-  return 0;
981dc9
-}
981dc9
-#endif
981dc9
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
981dc9
index fe75d04113b8aa3f..f58a15cd1c7bbb6f 100644
981dc9
--- a/nptl/pthread_create.c
981dc9
+++ b/nptl/pthread_create.c
981dc9
@@ -379,13 +379,6 @@ START_THREAD_DEFN
981dc9
 {
981dc9
   struct pthread *pd = START_THREAD_SELF;
981dc9
 
981dc9
-#if HP_TIMING_AVAIL
981dc9
-  /* Remember the time when the thread was started.  */
981dc9
-  hp_timing_t now;
981dc9
-  HP_TIMING_NOW (now);
981dc9
-  THREAD_SETMEM (pd, cpuclock_offset, now);
981dc9
-#endif
981dc9
-
981dc9
   /* Initialize resolver state pointer.  */
981dc9
   __resp = &pd->res;
981dc9
 
981dc9
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
981dc9
index c6b7e61badbfd513..f0185ce0d16c0f69 100644
981dc9
--- a/sysdeps/generic/ldsodefs.h
981dc9
+++ b/sysdeps/generic/ldsodefs.h
981dc9
@@ -359,11 +359,6 @@ struct rtld_global
981dc9
   /* The object to be initialized first.  */
981dc9
   EXTERN struct link_map *_dl_initfirst;
981dc9
 
981dc9
-#if HP_SMALL_TIMING_AVAIL
981dc9
-  /* Start time on CPU clock.  */
981dc9
-  EXTERN hp_timing_t _dl_cpuclock_offset;
981dc9
-#endif
981dc9
-
981dc9
   /* Map of shared object to be profiled.  */
981dc9
   EXTERN struct link_map *_dl_profile_map;
981dc9
 
981dc9
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
981dc9
index b72913d3baaed1d9..7bd1d70c96c229e0 100644
981dc9
--- a/sysdeps/mach/hurd/dl-sysdep.c
981dc9
+++ b/sysdeps/mach/hurd/dl-sysdep.c
981dc9
@@ -62,10 +62,6 @@ int __libc_multiple_libcs = 0;	/* Defining this here avoids the inclusion
981dc9
 void *__libc_stack_end = NULL;
981dc9
 rtld_hidden_data_def(__libc_stack_end)
981dc9
 
981dc9
-#if HP_TIMING_AVAIL
981dc9
-hp_timing_t _dl_cpuclock_offset;
981dc9
-#endif
981dc9
-
981dc9
 /* TODO: Initialize.  */
981dc9
 void *_dl_random attribute_relro = NULL;
981dc9
 
981dc9
@@ -246,10 +242,6 @@ unfmh();			/* XXX */
981dc9
   /* Initialize frequently used global variable.  */
981dc9
   GLRO(dl_pagesize) = __getpagesize ();
981dc9
 
981dc9
-#if HP_TIMING_AVAIL
981dc9
-  HP_TIMING_NOW (_dl_cpuclock_offset);
981dc9
-#endif
981dc9
-
981dc9
 fmh();				/* XXX */
981dc9
 
981dc9
   /* See hurd/hurdstartup.c; this deals with getting information
981dc9
diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c
981dc9
index 1a9429b579cd346e..37db30f3d1e846b6 100644
981dc9
--- a/sysdeps/nptl/fork.c
981dc9
+++ b/sysdeps/nptl/fork.c
981dc9
@@ -83,14 +83,6 @@ __libc_fork (void)
981dc9
       if (__fork_generation_pointer != NULL)
981dc9
 	*__fork_generation_pointer += __PTHREAD_ONCE_FORK_GEN_INCR;
981dc9
 
981dc9
-#if HP_TIMING_AVAIL
981dc9
-      /* The CPU clock of the thread and process have to be set to zero.  */
981dc9
-      hp_timing_t now;
981dc9
-      HP_TIMING_NOW (now);
981dc9
-      THREAD_SETMEM (self, cpuclock_offset, now);
981dc9
-      GL(dl_cpuclock_offset) = now;
981dc9
-#endif
981dc9
-
981dc9
 #ifdef __NR_set_robust_list
981dc9
       /* Initialize the robust mutex list setting in the kernel which has
981dc9
 	 been reset during the fork.  We do not check for errors because if
981dc9
diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c
981dc9
index 43228c381e6a73f1..5b0d8eb8a1a0593e 100644
981dc9
--- a/sysdeps/posix/clock_getres.c
981dc9
+++ b/sysdeps/posix/clock_getres.c
981dc9
@@ -24,37 +24,6 @@
981dc9
 #include <libc-internal.h>
981dc9
 
981dc9
 
981dc9
-#if HP_TIMING_AVAIL
981dc9
-static long int nsec;		/* Clock frequency of the processor.  */
981dc9
-
981dc9
-static int
981dc9
-hp_timing_getres (struct timespec *res)
981dc9
-{
981dc9
-  if (__glibc_unlikely (nsec == 0))
981dc9
-    {
981dc9
-      hp_timing_t freq;
981dc9
-
981dc9
-      /* This can only happen if we haven't initialized the `nsec'
981dc9
-	 variable yet.  Do this now.  We don't have to protect this
981dc9
-	 code against multiple execution since all of them should
981dc9
-	 lead to the same result.  */
981dc9
-      freq = __get_clockfreq ();
981dc9
-      if (__glibc_unlikely (freq == 0))
981dc9
-	/* Something went wrong.  */
981dc9
-	return -1;
981dc9
-
981dc9
-      nsec = MAX (UINT64_C (1000000000) / freq, 1);
981dc9
-    }
981dc9
-
981dc9
-  /* Fill in the values.
981dc9
-     The seconds are always zero (unless we have a 1Hz machine).  */
981dc9
-  res->tv_sec = 0;
981dc9
-  res->tv_nsec = nsec;
981dc9
-
981dc9
-  return 0;
981dc9
-}
981dc9
-#endif
981dc9
-
981dc9
 static inline int
981dc9
 realtime_getres (struct timespec *res)
981dc9
 {
981dc9
@@ -87,21 +56,8 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
981dc9
       break;
981dc9
 
981dc9
     default:
981dc9
-#if HP_TIMING_AVAIL
981dc9
-      if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
981dc9
-	  == CLOCK_THREAD_CPUTIME_ID)
981dc9
-	retval = hp_timing_getres (res);
981dc9
-      else
981dc9
-#endif
981dc9
-	__set_errno (EINVAL);
981dc9
-      break;
981dc9
-
981dc9
-#if HP_TIMING_AVAIL
981dc9
-    case CLOCK_PROCESS_CPUTIME_ID:
981dc9
-    case CLOCK_THREAD_CPUTIME_ID:
981dc9
-      retval = hp_timing_getres (res);
981dc9
+      __set_errno (EINVAL);
981dc9
       break;
981dc9
-#endif
981dc9
     }
981dc9
 
981dc9
   return retval;
981dc9
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
981dc9
index f19fdf7e5f310973..f3ebbe15ccc2e95e 100644
981dc9
--- a/sysdeps/unix/clock_gettime.c
981dc9
+++ b/sysdeps/unix/clock_gettime.c
981dc9
@@ -24,57 +24,6 @@
981dc9
 #include <ldsodefs.h>
981dc9
 
981dc9
 
981dc9
-#if HP_TIMING_AVAIL
981dc9
-/* Clock frequency of the processor.  We make it a 64-bit variable
981dc9
-   because some jokers are already playing with processors with more
981dc9
-   than 4GHz.  */
981dc9
-static hp_timing_t freq;
981dc9
-
981dc9
-
981dc9
-/* This function is defined in the thread library.  */
981dc9
-extern int __pthread_clock_gettime (clockid_t clock_id, hp_timing_t freq,
981dc9
-				    struct timespec *tp)
981dc9
-     __attribute__ ((__weak__));
981dc9
-
981dc9
-static int
981dc9
-hp_timing_gettime (clockid_t clock_id, struct timespec *tp)
981dc9
-{
981dc9
-  hp_timing_t tsc;
981dc9
-
981dc9
-  if (__glibc_unlikely (freq == 0))
981dc9
-    {
981dc9
-      /* This can only happen if we haven't initialized the `freq'
981dc9
-	 variable yet.  Do this now. We don't have to protect this
981dc9
-	 code against multiple execution since all of them should
981dc9
-	 lead to the same result.  */
981dc9
-      freq = __get_clockfreq ();
981dc9
-      if (__glibc_unlikely (freq == 0))
981dc9
-	/* Something went wrong.  */
981dc9
-	return -1;
981dc9
-    }
981dc9
-
981dc9
-  if (clock_id != CLOCK_PROCESS_CPUTIME_ID
981dc9
-      && __pthread_clock_gettime != NULL)
981dc9
-    return __pthread_clock_gettime (clock_id, freq, tp);
981dc9
-
981dc9
-  /* Get the current counter.  */
981dc9
-  HP_TIMING_NOW (tsc);
981dc9
-
981dc9
-  /* Compute the offset since the start time of the process.  */
981dc9
-  tsc -= GL(dl_cpuclock_offset);
981dc9
-
981dc9
-  /* Compute the seconds.  */
981dc9
-  tp->tv_sec = tsc / freq;
981dc9
-
981dc9
-  /* And the nanoseconds.  This computation should be stable until
981dc9
-     we get machines with about 16GHz frequency.  */
981dc9
-  tp->tv_nsec = ((tsc % freq) * UINT64_C (1000000000)) / freq;
981dc9
-
981dc9
-  return 0;
981dc9
-}
981dc9
-#endif
981dc9
-
981dc9
-
981dc9
 static inline int
981dc9
 realtime_gettime (struct timespec *tp)
981dc9
 {
981dc9
@@ -105,20 +54,8 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
981dc9
       break;
981dc9
 
981dc9
     default:
981dc9
-#if HP_TIMING_AVAIL
981dc9
-      if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
981dc9
-	  == CLOCK_THREAD_CPUTIME_ID)
981dc9
-	retval = hp_timing_gettime (clock_id, tp);
981dc9
-      else
981dc9
-#endif
981dc9
-	__set_errno (EINVAL);
981dc9
-      break;
981dc9
-
981dc9
-#if HP_TIMING_AVAIL
981dc9
-    case CLOCK_PROCESS_CPUTIME_ID:
981dc9
-      retval = hp_timing_gettime (clock_id, tp);
981dc9
+      __set_errno (EINVAL);
981dc9
       break;
981dc9
-#endif
981dc9
     }
981dc9
 
981dc9
   return retval;
981dc9
diff --git a/sysdeps/unix/clock_nanosleep.c b/sysdeps/unix/clock_nanosleep.c
981dc9
index 97b3d6b6ab9e4581..13dd0f4b905ec631 100644
981dc9
--- a/sysdeps/unix/clock_nanosleep.c
981dc9
+++ b/sysdeps/unix/clock_nanosleep.c
981dc9
@@ -19,23 +19,8 @@
981dc9
 #include <assert.h>
981dc9
 #include <errno.h>
981dc9
 #include <time.h>
981dc9
-#include <hp-timing.h>
981dc9
 #include <sysdep-cancel.h>
981dc9
 
981dc9
-#if HP_TIMING_AVAIL
981dc9
-# define CPUCLOCK_P(clock) \
981dc9
-  ((clock) == CLOCK_PROCESS_CPUTIME_ID					      \
981dc9
-   || ((clock) & ((1 << CLOCK_IDFIELD_SIZE) - 1)) == CLOCK_THREAD_CPUTIME_ID)
981dc9
-#else
981dc9
-# define CPUCLOCK_P(clock) 0
981dc9
-#endif
981dc9
-
981dc9
-#ifndef INVALID_CLOCK_P
981dc9
-# define INVALID_CLOCK_P(cl) \
981dc9
-  ((cl) < CLOCK_REALTIME || (cl) > CLOCK_THREAD_CPUTIME_ID)
981dc9
-#endif
981dc9
-
981dc9
-
981dc9
 /* This implementation assumes that these is only a `nanosleep' system
981dc9
    call.  So we have to remap all other activities.  */
981dc9
 int
981dc9
@@ -51,14 +36,7 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
981dc9
   if (clock_id == CLOCK_THREAD_CPUTIME_ID)
981dc9
     return EINVAL;		/* POSIX specifies EINVAL for this case.  */
981dc9
 
981dc9
-#ifdef SYSDEP_NANOSLEEP
981dc9
-  SYSDEP_NANOSLEEP;
981dc9
-#endif
981dc9
-
981dc9
-  if (CPUCLOCK_P (clock_id))
981dc9
-    return ENOTSUP;
981dc9
-
981dc9
-  if (INVALID_CLOCK_P (clock_id))
981dc9
+  if (clock_id < CLOCK_REALTIME || clock_id > CLOCK_THREAD_CPUTIME_ID)
981dc9
     return EINVAL;
981dc9
 
981dc9
   /* If we got an absolute time, remap it.  */
981dc9
@@ -71,7 +49,7 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
981dc9
       assert (sizeof (sec) >= sizeof (now.tv_sec));
981dc9
 
981dc9
       /* Get the current time for this clock.  */
981dc9
-      if (__builtin_expect (__clock_gettime (clock_id, &now), 0) != 0)
981dc9
+      if (__clock_gettime (clock_id, &now) != 0)
981dc9
 	return errno;
981dc9
 
981dc9
       /* Compute the difference.  */
981dc9
@@ -90,12 +68,12 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
981dc9
       /* Make sure we are not modifying the struct pointed to by REM.  */
981dc9
       rem = NULL;
981dc9
     }
981dc9
-  else if (__builtin_expect (flags, 0) != 0)
981dc9
+  else if (flags != 0)
981dc9
     return EINVAL;
981dc9
   else if (clock_id != CLOCK_REALTIME)
981dc9
     /* Not supported.  */
981dc9
     return ENOTSUP;
981dc9
 
981dc9
-  return __builtin_expect (__nanosleep (req, rem), 0) ? errno : 0;
981dc9
+  return __nanosleep (req, rem), 0 ? errno : 0;
981dc9
 }
981dc9
 weak_alias (__clock_nanosleep, clock_nanosleep)
981dc9
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
981dc9
index 9d5857e61b966b44..4f5640f67047cef6 100644
981dc9
--- a/sysdeps/unix/clock_settime.c
981dc9
+++ b/sysdeps/unix/clock_settime.c
981dc9
@@ -21,59 +21,11 @@
981dc9
 #include <ldsodefs.h>
981dc9
 
981dc9
 
981dc9
-#if HP_TIMING_AVAIL
981dc9
-/* Clock frequency of the processor.  We make it a 64-bit variable
981dc9
-   because some jokers are already playing with processors with more
981dc9
-   than 4GHz.  */
981dc9
-static hp_timing_t freq;
981dc9
-
981dc9
-
981dc9
-/* This function is defined in the thread library.  */
981dc9
-extern void __pthread_clock_settime (clockid_t clock_id, hp_timing_t offset)
981dc9
-     __attribute__ ((__weak__));
981dc9
-
981dc9
-
981dc9
-static int
981dc9
-hp_timing_settime (clockid_t clock_id, const struct timespec *tp)
981dc9
-{
981dc9
-  hp_timing_t tsc;
981dc9
-  hp_timing_t usertime;
981dc9
-
981dc9
-  /* First thing is to get the current time.  */
981dc9
-  HP_TIMING_NOW (tsc);
981dc9
-
981dc9
-  if (__glibc_unlikely (freq == 0))
981dc9
-    {
981dc9
-      /* This can only happen if we haven't initialized the `freq'
981dc9
-	 variable yet.  Do this now. We don't have to protect this
981dc9
-	 code against multiple execution since all of them should lead
981dc9
-	 to the same result.  */
981dc9
-      freq = __get_clockfreq ();
981dc9
-      if (__glibc_unlikely (freq == 0))
981dc9
-	/* Something went wrong.  */
981dc9
-	return -1;
981dc9
-    }
981dc9
-
981dc9
-  /* Convert the user-provided time into CPU ticks.  */
981dc9
-  usertime = tp->tv_sec * freq + (tp->tv_nsec * freq) / 1000000000ull;
981dc9
-
981dc9
-  /* Determine the offset and use it as the new base value.  */
981dc9
-  if (clock_id == CLOCK_PROCESS_CPUTIME_ID
981dc9
-      || __pthread_clock_settime == NULL)
981dc9
-    GL(dl_cpuclock_offset) = tsc - usertime;
981dc9
-  else
981dc9
-    __pthread_clock_settime (clock_id, tsc - usertime);
981dc9
-
981dc9
-  return 0;
981dc9
-}
981dc9
-#endif
981dc9
-
981dc9
-
981dc9
 /* Set CLOCK to value TP.  */
981dc9
 int
981dc9
 __clock_settime (clockid_t clock_id, const struct timespec *tp)
981dc9
 {
981dc9
-  int retval;
981dc9
+  int retval = -1;
981dc9
 
981dc9
   /* Make sure the time cvalue is OK.  */
981dc9
   if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
981dc9
@@ -93,16 +45,7 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
981dc9
       break;
981dc9
 
981dc9
     default:
981dc9
-# if HP_TIMING_AVAIL
981dc9
-      if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
981dc9
-	  || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
981dc9
-	retval = hp_timing_settime (clock_id, tp);
981dc9
-      else
981dc9
-# endif
981dc9
-	{
981dc9
-	  __set_errno (EINVAL);
981dc9
-	  retval = -1;
981dc9
-	}
981dc9
+      __set_errno (EINVAL);
981dc9
       break;
981dc9
     }
981dc9