about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-01-16 16:22:29 +0000
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-03-22 15:37:43 -0300
commit38cc11daa43b11b12a7774405accee1007de1adf (patch)
tree33c37e3fa103787e2f29a5658a05f0ec59e71baa /sysdeps
parent421749d693c4147017bc55f5ac3227c3a6e4bf31 (diff)
downloadglibc-38cc11daa43b11b12a7774405accee1007de1adf.tar.gz
glibc-38cc11daa43b11b12a7774405accee1007de1adf.tar.xz
glibc-38cc11daa43b11b12a7774405accee1007de1adf.zip
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.

As described in clock_gettime man-page [1] on 'Historical note for SMP
system', implementing CLOCK_{THREAD,PROCESS}_CPUTIME_ID with timer registers
is error-prone and susceptible to timing and accurary issues that the libc
can not deal without kernel support.

This allows removes unused code which, however, still incur in some runtime
overhead in thread creation (the struct pthread cpuclock_offset
initialization).

If hurd eventually wants to support them it should either either implement as
a kernel facility (or something related due its architecture) or in system
specific implementation.

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.

[1] http://man7.org/linux/man-pages/man2/clock_gettime.2.html
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/ldsodefs.h5
-rw-r--r--sysdeps/mach/hurd/dl-sysdep.c8
-rw-r--r--sysdeps/nptl/fork.c8
-rw-r--r--sysdeps/posix/clock_getres.c46
-rw-r--r--sysdeps/unix/clock_gettime.c65
-rw-r--r--sysdeps/unix/clock_nanosleep.c30
-rw-r--r--sysdeps/unix/clock_settime.c61
7 files changed, 8 insertions, 215 deletions
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index a7f6b82da6..b1fc5c31f9 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 07d64d8122..5cb347f5d1 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 14b69a6f89..3f357665bd 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 dac4761fcc..01024a3f55 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 33a1f3335c..10a6c96d9d 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 7722d1111c..b27608570c 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 dcf9ff660a..109a1ad872 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)
@@ -93,16 +45,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;
     }