a2cf7d
commit 6e8ba7fd574f530afb9681f21604475d5756d773
a2cf7d
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
a2cf7d
Date:   Fri Feb 8 16:53:40 2019 +0000
a2cf7d
a2cf7d
    Remove __get_clockfreq
a2cf7d
    
a2cf7d
    With clock_getres, clock_gettime, and clock_settime refactor to remove the
a2cf7d
    generic CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID support through
a2cf7d
    hp-timing, there is no usage of internal __get_clockfreq.  This patch removes
a2cf7d
    both generic and Linux implementation..
a2cf7d
    
a2cf7d
    Checked with a build against aarch64-linux-gnu, i686-linux-gnu, ia64-linux-gnu,
a2cf7d
    sparc64-linux-gnu, powerpc-linux-gnu-power4.
a2cf7d
    
a2cf7d
            * include/libc-internal.h (__get_clockfreq): Remove prototype.
a2cf7d
            * rt/Makefile (clock-routines): Remove get_clockfreq.
a2cf7d
            * rt/get_clockfreq.c: Remove file.
a2cf7d
            * sysdeps/unix/sysv/linux/i386/get_clockfreq.c: Likewise.
a2cf7d
            * sysdeps/unix/sysv/linux/ia64/get_clockfreq.c: Likewise.
a2cf7d
            * sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c: Likewise.
a2cf7d
            * sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c: Move code to ...
a2cf7d
            * sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c: ... here.
a2cf7d
a2cf7d
Conflicts:
a2cf7d
	rt/get_clockfreq.c
a2cf7d
	sysdeps/unix/sysv/linux/i386/get_clockfreq.c
a2cf7d
	sysdeps/unix/sysv/linux/ia64/get_clockfreq.c
a2cf7d
	sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
a2cf7d
	  (Removal after copyright year change upstream.)
a2cf7d
	sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c
a2cf7d
	  (Likewise.  Missing backport of aa0e46636a5b71 ("Break
a2cf7d
	  further lines before not after operators.").)
a2cf7d
a2cf7d
diff --git a/include/libc-internal.h b/include/libc-internal.h
a2cf7d
index 2167990c52bd708b..2ec07d9355db1808 100644
a2cf7d
--- a/include/libc-internal.h
a2cf7d
+++ b/include/libc-internal.h
a2cf7d
@@ -36,9 +36,6 @@ libc_hidden_proto (__profile_frequency)
a2cf7d
 extern void __cyg_profile_func_enter (void *this_fn, void *call_site);
a2cf7d
 extern void __cyg_profile_func_exit (void *this_fn, void *call_site);
a2cf7d
 
a2cf7d
-/* Get frequency of the system processor.  */
a2cf7d
-extern hp_timing_t __get_clockfreq (void);
a2cf7d
-
a2cf7d
 /* Free all allocated resources.  */
a2cf7d
 extern void __libc_freeres (void);
a2cf7d
 libc_hidden_proto (__libc_freeres)
a2cf7d
diff --git a/rt/Makefile b/rt/Makefile
a2cf7d
index 6d6b896ee9817c5c..14f38ef74d262188 100644
a2cf7d
--- a/rt/Makefile
a2cf7d
+++ b/rt/Makefile
a2cf7d
@@ -28,7 +28,7 @@ aio-routines   := aio_cancel aio_error aio_fsync aio_misc aio_read	\
a2cf7d
 		  aio_read64 aio_return aio_suspend aio_write		\
a2cf7d
 		  aio_write64 lio_listio lio_listio64 aio_sigqueue	\
a2cf7d
 		  aio_notify
a2cf7d
-clock-routines := get_clockfreq clock_getcpuclockid			\
a2cf7d
+clock-routines := clock_getcpuclockid					\
a2cf7d
 		  clock_getres clock_gettime clock_settime		\
a2cf7d
 		  clock_nanosleep
a2cf7d
 timer-routines := timer_create timer_delete timer_getoverr		\
a2cf7d
diff --git a/rt/get_clockfreq.c b/rt/get_clockfreq.c
a2cf7d
deleted file mode 100644
a2cf7d
index e695a6018c0b8322..0000000000000000
a2cf7d
--- a/rt/get_clockfreq.c
a2cf7d
+++ /dev/null
a2cf7d
@@ -1,27 +0,0 @@
a2cf7d
-/* Get frequency of the system processor.
a2cf7d
-   Copyright (C) 2000-2018 Free Software Foundation, Inc.
a2cf7d
-   This file is part of the GNU C Library.
a2cf7d
-
a2cf7d
-   The GNU C Library is free software; you can redistribute it and/or
a2cf7d
-   modify it under the terms of the GNU Lesser General Public
a2cf7d
-   License as published by the Free Software Foundation; either
a2cf7d
-   version 2.1 of the License, or (at your option) any later version.
a2cf7d
-
a2cf7d
-   The GNU C Library is distributed in the hope that it will be useful,
a2cf7d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
a2cf7d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a2cf7d
-   Lesser General Public License for more details.
a2cf7d
-
a2cf7d
-   You should have received a copy of the GNU Lesser General Public
a2cf7d
-   License along with the GNU C Library; if not, see
a2cf7d
-   <http://www.gnu.org/licenses/>.  */
a2cf7d
-
a2cf7d
-#include <libc-internal.h>
a2cf7d
-
a2cf7d
-hp_timing_t
a2cf7d
-__get_clockfreq (void)
a2cf7d
-{
a2cf7d
-  /* There is no generic way to find this out since we have in general
a2cf7d
-     no counter register either.  */
a2cf7d
-  return 0;
a2cf7d
-}
a2cf7d
diff --git a/sysdeps/unix/sysv/linux/i386/get_clockfreq.c b/sysdeps/unix/sysv/linux/i386/get_clockfreq.c
a2cf7d
deleted file mode 100644
a2cf7d
index 633f186be80f10b0..0000000000000000
a2cf7d
--- a/sysdeps/unix/sysv/linux/i386/get_clockfreq.c
a2cf7d
+++ /dev/null
a2cf7d
@@ -1,88 +0,0 @@
a2cf7d
-/* Get frequency of the system processor.  i386/Linux version.
a2cf7d
-   Copyright (C) 2000-2018 Free Software Foundation, Inc.
a2cf7d
-   This file is part of the GNU C Library.
a2cf7d
-
a2cf7d
-   The GNU C Library is free software; you can redistribute it and/or
a2cf7d
-   modify it under the terms of the GNU Lesser General Public
a2cf7d
-   License as published by the Free Software Foundation; either
a2cf7d
-   version 2.1 of the License, or (at your option) any later version.
a2cf7d
-
a2cf7d
-   The GNU C Library is distributed in the hope that it will be useful,
a2cf7d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
a2cf7d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a2cf7d
-   Lesser General Public License for more details.
a2cf7d
-
a2cf7d
-   You should have received a copy of the GNU Lesser General Public
a2cf7d
-   License along with the GNU C Library; if not, see
a2cf7d
-   <http://www.gnu.org/licenses/>.  */
a2cf7d
-
a2cf7d
-#include <ctype.h>
a2cf7d
-#include <fcntl.h>
a2cf7d
-#include <string.h>
a2cf7d
-#include <unistd.h>
a2cf7d
-
a2cf7d
-hp_timing_t
a2cf7d
-__get_clockfreq (void)
a2cf7d
-{
a2cf7d
-  /* We read the information from the /proc filesystem.  It contains at
a2cf7d
-     least one line like
a2cf7d
-	cpu MHz         : 497.840237
a2cf7d
-     or also
a2cf7d
-	cpu MHz         : 497.841
a2cf7d
-     We search for this line and convert the number in an integer.  */
a2cf7d
-  static hp_timing_t result;
a2cf7d
-  int fd;
a2cf7d
-
a2cf7d
-  /* If this function was called before, we know the result.  */
a2cf7d
-  if (result != 0)
a2cf7d
-    return result;
a2cf7d
-
a2cf7d
-  fd = __open ("/proc/cpuinfo", O_RDONLY);
a2cf7d
-  if (__glibc_likely (fd != -1))
a2cf7d
-    {
a2cf7d
-      /* XXX AFAIK the /proc filesystem can generate "files" only up
a2cf7d
-         to a size of 4096 bytes.  */
a2cf7d
-      char buf[4096];
a2cf7d
-      ssize_t n;
a2cf7d
-
a2cf7d
-      n = __read (fd, buf, sizeof buf);
a2cf7d
-      if (__builtin_expect (n, 1) > 0)
a2cf7d
-	{
a2cf7d
-	  char *mhz = memmem (buf, n, "cpu MHz", 7);
a2cf7d
-
a2cf7d
-	  if (__glibc_likely (mhz != NULL))
a2cf7d
-	    {
a2cf7d
-	      char *endp = buf + n;
a2cf7d
-	      int seen_decpoint = 0;
a2cf7d
-	      int ndigits = 0;
a2cf7d
-
a2cf7d
-	      /* Search for the beginning of the string.  */
a2cf7d
-	      while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
a2cf7d
-		++mhz;
a2cf7d
-
a2cf7d
-	      while (mhz < endp && *mhz != '\n')
a2cf7d
-		{
a2cf7d
-		  if (*mhz >= '0' && *mhz <= '9')
a2cf7d
-		    {
a2cf7d
-		      result *= 10;
a2cf7d
-		      result += *mhz - '0';
a2cf7d
-		      if (seen_decpoint)
a2cf7d
-			++ndigits;
a2cf7d
-		    }
a2cf7d
-		  else if (*mhz == '.')
a2cf7d
-		    seen_decpoint = 1;
a2cf7d
-
a2cf7d
-		  ++mhz;
a2cf7d
-		}
a2cf7d
-
a2cf7d
-	      /* Compensate for missing digits at the end.  */
a2cf7d
-	      while (ndigits++ < 6)
a2cf7d
-		result *= 10;
a2cf7d
-	    }
a2cf7d
-	}
a2cf7d
-
a2cf7d
-      __close (fd);
a2cf7d
-    }
a2cf7d
-
a2cf7d
-  return result;
a2cf7d
-}
a2cf7d
diff --git a/sysdeps/unix/sysv/linux/ia64/get_clockfreq.c b/sysdeps/unix/sysv/linux/ia64/get_clockfreq.c
a2cf7d
deleted file mode 100644
a2cf7d
index f9d683a90247ac60..0000000000000000
a2cf7d
--- a/sysdeps/unix/sysv/linux/ia64/get_clockfreq.c
a2cf7d
+++ /dev/null
a2cf7d
@@ -1,87 +0,0 @@
a2cf7d
-/* Get frequency of the system processor.  IA-64/Linux version.
a2cf7d
-   Copyright (C) 2001-2018 Free Software Foundation, Inc.
a2cf7d
-   This file is part of the GNU C Library.
a2cf7d
-
a2cf7d
-   The GNU C Library is free software; you can redistribute it and/or
a2cf7d
-   modify it under the terms of the GNU Lesser General Public
a2cf7d
-   License as published by the Free Software Foundation; either
a2cf7d
-   version 2.1 of the License, or (at your option) any later version.
a2cf7d
-
a2cf7d
-   The GNU C Library is distributed in the hope that it will be useful,
a2cf7d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
a2cf7d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a2cf7d
-   Lesser General Public License for more details.
a2cf7d
-
a2cf7d
-   You should have received a copy of the GNU Lesser General Public
a2cf7d
-   License along with the GNU C Library; if not, see
a2cf7d
-   <http://www.gnu.org/licenses/>.  */
a2cf7d
-
a2cf7d
-#include <ctype.h>
a2cf7d
-#include <fcntl.h>
a2cf7d
-#include <string.h>
a2cf7d
-#include <unistd.h>
a2cf7d
-
a2cf7d
-
a2cf7d
-hp_timing_t
a2cf7d
-__get_clockfreq (void)
a2cf7d
-{
a2cf7d
-  /* We read the information from the /proc filesystem.  It contains at
a2cf7d
-     least one line like
a2cf7d
-	itc MHz    : 733.390988
a2cf7d
-     We search for this line and convert the number in an integer.  */
a2cf7d
-  static hp_timing_t result;
a2cf7d
-  int fd;
a2cf7d
-
a2cf7d
-  /* If this function was called before, we know the result.  */
a2cf7d
-  if (result != 0)
a2cf7d
-    return result;
a2cf7d
-
a2cf7d
-  fd = __open ("/proc/cpuinfo", O_RDONLY);
a2cf7d
-  if (__builtin_expect (fd != -1, 1))
a2cf7d
-    {
a2cf7d
-      /* XXX AFAIK the /proc filesystem can generate "files" only up
a2cf7d
-         to a size of 4096 bytes.  */
a2cf7d
-      char buf[4096];
a2cf7d
-      ssize_t n;
a2cf7d
-
a2cf7d
-      n = __read (fd, buf, sizeof buf);
a2cf7d
-      if (__builtin_expect (n, 1) > 0)
a2cf7d
-	{
a2cf7d
-	  char *mhz = memmem (buf, n, "itc MHz", 7);
a2cf7d
-
a2cf7d
-	  if (__builtin_expect (mhz != NULL, 1))
a2cf7d
-	    {
a2cf7d
-	      char *endp = buf + n;
a2cf7d
-	      int seen_decpoint = 0;
a2cf7d
-	      int ndigits = 0;
a2cf7d
-
a2cf7d
-	      /* Search for the beginning of the string.  */
a2cf7d
-	      while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
a2cf7d
-		++mhz;
a2cf7d
-
a2cf7d
-	      while (mhz < endp && *mhz != '\n')
a2cf7d
-		{
a2cf7d
-		  if (*mhz >= '0' && *mhz <= '9')
a2cf7d
-		    {
a2cf7d
-		      result *= 10;
a2cf7d
-		      result += *mhz - '0';
a2cf7d
-		      if (seen_decpoint)
a2cf7d
-			++ndigits;
a2cf7d
-		    }
a2cf7d
-		  else if (*mhz == '.')
a2cf7d
-		    seen_decpoint = 1;
a2cf7d
-
a2cf7d
-		  ++mhz;
a2cf7d
-		}
a2cf7d
-
a2cf7d
-	      /* Compensate for missing digits at the end.  */
a2cf7d
-	      while (ndigits++ < 6)
a2cf7d
-		result *= 10;
a2cf7d
-	    }
a2cf7d
-	}
a2cf7d
-
a2cf7d
-      __close (fd);
a2cf7d
-    }
a2cf7d
-
a2cf7d
-  return result;
a2cf7d
-}
a2cf7d
diff --git a/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c b/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
a2cf7d
deleted file mode 100644
a2cf7d
index 3a2216021bfb5408..0000000000000000
a2cf7d
--- a/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
a2cf7d
+++ /dev/null
a2cf7d
@@ -1,107 +0,0 @@
a2cf7d
-/* Get frequency of the system processor.  powerpc/Linux version.
a2cf7d
-   Copyright (C) 2000-2018 Free Software Foundation, Inc.
a2cf7d
-   This file is part of the GNU C Library.
a2cf7d
-
a2cf7d
-   The GNU C Library is free software; you can redistribute it and/or
a2cf7d
-   modify it under the terms of the GNU Lesser General Public
a2cf7d
-   License as published by the Free Software Foundation; either
a2cf7d
-   version 2.1 of the License, or (at your option) any later version.
a2cf7d
-
a2cf7d
-   The GNU C Library is distributed in the hope that it will be useful,
a2cf7d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
a2cf7d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a2cf7d
-   Lesser General Public License for more details.
a2cf7d
-
a2cf7d
-   You should have received a copy of the GNU Lesser General Public
a2cf7d
-   License along with the GNU C Library; if not, see
a2cf7d
-   <http://www.gnu.org/licenses/>.  */
a2cf7d
-
a2cf7d
-#include <ctype.h>
a2cf7d
-#include <fcntl.h>
a2cf7d
-#include <stdint.h>
a2cf7d
-#include <string.h>
a2cf7d
-#include <unistd.h>
a2cf7d
-#include <sysdep.h>
a2cf7d
-#include <libc-vdso.h>
a2cf7d
-#include <not-cancel.h>
a2cf7d
-
a2cf7d
-hp_timing_t
a2cf7d
-__get_clockfreq (void)
a2cf7d
-{
a2cf7d
-  hp_timing_t result = 0L;
a2cf7d
-
a2cf7d
-#ifdef SHARED
a2cf7d
-  /* The vDSO does not return an error (it clear cr0.so on returning).  */
a2cf7d
-  INTERNAL_SYSCALL_DECL (err);
a2cf7d
-  result =
a2cf7d
-    INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK (get_tbfreq, err, uint64_t, 0);
a2cf7d
-#else
a2cf7d
-  /* We read the information from the /proc filesystem.  /proc/cpuinfo
a2cf7d
-     contains at least one line like:
a2cf7d
-     timebase        : 33333333
a2cf7d
-     We search for this line and convert the number into an integer.  */
a2cf7d
-  int fd = __open_nocancel ("/proc/cpuinfo", O_RDONLY);
a2cf7d
-  if (__glibc_likely (fd != -1))
a2cf7d
-    return result;
a2cf7d
-
a2cf7d
-  /* The timebase will be in the 1st 1024 bytes for systems with up
a2cf7d
-     to 8 processors.  If the first read returns less then 1024
a2cf7d
-     bytes read,  we have the whole cpuinfo and can start the scan.
a2cf7d
-     Otherwise we will have to read more to insure we have the
a2cf7d
-     timebase value in the scan.  */
a2cf7d
-  char buf[1024];
a2cf7d
-  ssize_t n;
a2cf7d
-
a2cf7d
-  n = __read_nocancel (fd, buf, sizeof (buf));
a2cf7d
-  if (n == sizeof (buf))
a2cf7d
-    {
a2cf7d
-      /* We are here because the 1st read returned exactly sizeof
a2cf7d
-         (buf) bytes.  This implies that we are not at EOF and may
a2cf7d
-         not have read the timebase value yet.  So we need to read
a2cf7d
-         more bytes until we know we have EOF.  We copy the lower
a2cf7d
-         half of buf to the upper half and read sizeof (buf)/2
a2cf7d
-         bytes into the lower half of buf and repeat until we
a2cf7d
-         reach EOF.  We can assume that the timebase will be in
a2cf7d
-         the last 512 bytes of cpuinfo, so two 512 byte half_bufs
a2cf7d
-         will be sufficient to contain the timebase and will
a2cf7d
-         handle the case where the timebase spans the half_buf
a2cf7d
-         boundry.  */
a2cf7d
-      const ssize_t half_buf = sizeof (buf) / 2;
a2cf7d
-      while (n >= half_buf)
a2cf7d
-	{
a2cf7d
-	  memcpy (buf, buf + half_buf, half_buf);
a2cf7d
-	  n = __read_nocancel (fd, buf + half_buf, half_buf);
a2cf7d
-	}
a2cf7d
-      if (n >= 0)
a2cf7d
-	n += half_buf;
a2cf7d
-    }
a2cf7d
-  __close_nocancel (fd);
a2cf7d
-
a2cf7d
-  if (__glibc_likely (n > 0))
a2cf7d
-    {
a2cf7d
-      char *mhz = memmem (buf, n, "timebase", 7);
a2cf7d
-
a2cf7d
-      if (__glibc_likely (mhz != NULL))
a2cf7d
-	{
a2cf7d
-	  char *endp = buf + n;
a2cf7d
-
a2cf7d
-	  /* Search for the beginning of the string.  */
a2cf7d
-	  while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
a2cf7d
-	    ++mhz;
a2cf7d
-
a2cf7d
-	  while (mhz < endp && *mhz != '\n')
a2cf7d
-	    {
a2cf7d
-	      if (*mhz >= '0' && *mhz <= '9')
a2cf7d
-		{
a2cf7d
-		  result *= 10;
a2cf7d
-		  result += *mhz - '0';
a2cf7d
-		}
a2cf7d
-
a2cf7d
-	      ++mhz;
a2cf7d
-	    }
a2cf7d
-	}
a2cf7d
-    }
a2cf7d
-#endif
a2cf7d
-
a2cf7d
-  return result;
a2cf7d
-}
a2cf7d
diff --git a/sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c b/sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c
a2cf7d
index 6435e1f31529c7de..1177ccbc8faeafe7 100644
a2cf7d
--- a/sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c
a2cf7d
+++ b/sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c
a2cf7d
@@ -17,11 +17,90 @@
a2cf7d
    <http://www.gnu.org/licenses/>.  */
a2cf7d
 
a2cf7d
 #include <stdint.h>
a2cf7d
+#include <string.h>
a2cf7d
+
a2cf7d
 #include <libc-internal.h>
a2cf7d
+#include <not-cancel.h>
a2cf7d
+#include <libc-vdso.h>
a2cf7d
 
a2cf7d
 uint64_t
a2cf7d
 __get_timebase_freq (void)
a2cf7d
 {
a2cf7d
-  return (uint64_t) __get_clockfreq ();
a2cf7d
+  hp_timing_t result = 0L;
a2cf7d
+
a2cf7d
+#ifdef SHARED
a2cf7d
+  /* The vDSO does not return an error (it clear cr0.so on returning).  */
a2cf7d
+  INTERNAL_SYSCALL_DECL (err);
a2cf7d
+  result =
a2cf7d
+    INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK (get_tbfreq, err, uint64_t, 0);
a2cf7d
+#else
a2cf7d
+  /* We read the information from the /proc filesystem.  /proc/cpuinfo
a2cf7d
+     contains at least one line like:
a2cf7d
+     timebase        : 33333333
a2cf7d
+     We search for this line and convert the number into an integer.  */
a2cf7d
+  int fd = __open_nocancel ("/proc/cpuinfo", O_RDONLY);
a2cf7d
+  if (__glibc_likely (fd != -1))
a2cf7d
+    return result;
a2cf7d
+
a2cf7d
+  /* The timebase will be in the 1st 1024 bytes for systems with up
a2cf7d
+     to 8 processors.  If the first read returns less then 1024
a2cf7d
+     bytes read,  we have the whole cpuinfo and can start the scan.
a2cf7d
+     Otherwise we will have to read more to insure we have the
a2cf7d
+     timebase value in the scan.  */
a2cf7d
+  char buf[1024];
a2cf7d
+  ssize_t n;
a2cf7d
+
a2cf7d
+  n = __read_nocancel (fd, buf, sizeof (buf));
a2cf7d
+  if (n == sizeof (buf))
a2cf7d
+    {
a2cf7d
+      /* We are here because the 1st read returned exactly sizeof
a2cf7d
+         (buf) bytes.  This implies that we are not at EOF and may
a2cf7d
+         not have read the timebase value yet.  So we need to read
a2cf7d
+         more bytes until we know we have EOF.  We copy the lower
a2cf7d
+         half of buf to the upper half and read sizeof (buf)/2
a2cf7d
+         bytes into the lower half of buf and repeat until we
a2cf7d
+         reach EOF.  We can assume that the timebase will be in
a2cf7d
+         the last 512 bytes of cpuinfo, so two 512 byte half_bufs
a2cf7d
+         will be sufficient to contain the timebase and will
a2cf7d
+         handle the case where the timebase spans the half_buf
a2cf7d
+         boundry.  */
a2cf7d
+      const ssize_t half_buf = sizeof (buf) / 2;
a2cf7d
+      while (n >= half_buf)
a2cf7d
+	{
a2cf7d
+	  memcpy (buf, buf + half_buf, half_buf);
a2cf7d
+	  n = __read_nocancel (fd, buf + half_buf, half_buf);
a2cf7d
+	}
a2cf7d
+      if (n >= 0)
a2cf7d
+	n += half_buf;
a2cf7d
+    }
a2cf7d
+  __close_nocancel (fd);
a2cf7d
+
a2cf7d
+  if (__glibc_likely (n > 0))
a2cf7d
+    {
a2cf7d
+      char *mhz = memmem (buf, n, "timebase", 7);
a2cf7d
+
a2cf7d
+      if (__glibc_likely (mhz != NULL))
a2cf7d
+	{
a2cf7d
+	  char *endp = buf + n;
a2cf7d
+
a2cf7d
+	  /* Search for the beginning of the string.  */
a2cf7d
+	  while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
a2cf7d
+	    ++mhz;
a2cf7d
+
a2cf7d
+	  while (mhz < endp && *mhz != '\n')
a2cf7d
+	    {
a2cf7d
+	      if (*mhz >= '0' && *mhz <= '9')
a2cf7d
+		{
a2cf7d
+		  result *= 10;
a2cf7d
+		  result += *mhz - '0';
a2cf7d
+		}
a2cf7d
+
a2cf7d
+	      ++mhz;
a2cf7d
+	    }
a2cf7d
+	}
a2cf7d
+    }
a2cf7d
+#endif
a2cf7d
+
a2cf7d
+  return result;
a2cf7d
 }
a2cf7d
 weak_alias (__get_timebase_freq, __ppc_get_timebase_freq)
a2cf7d
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c b/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c
a2cf7d
deleted file mode 100644
a2cf7d
index 6838a77a769ddae8..0000000000000000
a2cf7d
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c
a2cf7d
+++ /dev/null
a2cf7d
@@ -1,250 +0,0 @@
a2cf7d
-/* Get frequency of the system processor.  sparc64 version.
a2cf7d
-   Copyright (C) 2001-2018 Free Software Foundation, Inc.
a2cf7d
-   This file is part of the GNU C Library.
a2cf7d
-
a2cf7d
-   The GNU C Library is free software; you can redistribute it and/or
a2cf7d
-   modify it under the terms of the GNU Lesser General Public
a2cf7d
-   License as published by the Free Software Foundation; either
a2cf7d
-   version 2.1 of the License, or (at your option) any later version.
a2cf7d
-
a2cf7d
-   The GNU C Library is distributed in the hope that it will be useful,
a2cf7d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
a2cf7d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a2cf7d
-   Lesser General Public License for more details.
a2cf7d
-
a2cf7d
-   You should have received a copy of the GNU Lesser General Public
a2cf7d
-   License along with the GNU C Library; if not, see
a2cf7d
-   <http://www.gnu.org/licenses/>.  */
a2cf7d
-
a2cf7d
-#include <ctype.h>
a2cf7d
-#include <fcntl.h>
a2cf7d
-#include <string.h>
a2cf7d
-#include <unistd.h>
a2cf7d
-#include <dirent.h>
a2cf7d
-#include <stdlib.h>
a2cf7d
-#include <inttypes.h>
a2cf7d
-#include <sys/ioctl.h>
a2cf7d
-#include <asm/openpromio.h>
a2cf7d
-
a2cf7d
-static hp_timing_t
a2cf7d
-__get_clockfreq_via_cpuinfo (void)
a2cf7d
-{
a2cf7d
-  hp_timing_t result;
a2cf7d
-  int fd;
a2cf7d
-
a2cf7d
-  result = 0;
a2cf7d
-
a2cf7d
-  fd = __open ("/proc/cpuinfo", O_RDONLY);
a2cf7d
-  if (fd != -1)
a2cf7d
-    {
a2cf7d
-      char buf[8192];
a2cf7d
-      ssize_t n;
a2cf7d
-
a2cf7d
-      n = __read (fd, buf, sizeof buf);
a2cf7d
-      if (n > 0)
a2cf7d
-	{
a2cf7d
-	  char *mhz = memmem (buf, n, "Cpu0ClkTck", 7);
a2cf7d
-
a2cf7d
-	  if (mhz != NULL)
a2cf7d
-	    {
a2cf7d
-	      char *endp = buf + n;
a2cf7d
-
a2cf7d
-	      /* Search for the beginning of the string.  */
a2cf7d
-	      while (mhz < endp
a2cf7d
-		     && (*mhz < '0' || *mhz > '9')
a2cf7d
-		     && (*mhz < 'a' || *mhz > 'f')
a2cf7d
-		     && *mhz != '\n')
a2cf7d
-		++mhz;
a2cf7d
-
a2cf7d
-	      while (mhz < endp && *mhz != '\n')
a2cf7d
-		{
a2cf7d
-		  if ((*mhz >= '0' && *mhz <= '9') ||
a2cf7d
-		      (*mhz >= 'a' && *mhz <= 'f'))
a2cf7d
-		    {
a2cf7d
-		      result <<= 4;
a2cf7d
-		      if (*mhz >= '0' && *mhz <= '9')
a2cf7d
-			result += *mhz - '0';
a2cf7d
-		      else
a2cf7d
-			result += (*mhz - 'a') + 10;
a2cf7d
-		    }
a2cf7d
-		  ++mhz;
a2cf7d
-		}
a2cf7d
-	    }
a2cf7d
-	}
a2cf7d
-
a2cf7d
-      __close (fd);
a2cf7d
-    }
a2cf7d
-
a2cf7d
-  return result;
a2cf7d
-}
a2cf7d
-
a2cf7d
-static hp_timing_t
a2cf7d
-__get_clockfreq_via_proc_openprom (void)
a2cf7d
-{
a2cf7d
-  hp_timing_t result;
a2cf7d
-  int obp_fd;
a2cf7d
-
a2cf7d
-  result = 0;
a2cf7d
-
a2cf7d
-  obp_fd = __open ("/proc/openprom", O_RDONLY);
a2cf7d
-  if (obp_fd != -1)
a2cf7d
-    {
a2cf7d
-      unsigned long int buf[4096 / sizeof (unsigned long int)];
a2cf7d
-      struct dirent64 *dirp = (struct dirent64 *) buf;
a2cf7d
-      ssize_t len;
a2cf7d
-
a2cf7d
-      while ((len = __getdents64 (obp_fd, (char *) dirp, sizeof (buf))) > 0)
a2cf7d
-	{
a2cf7d
-	  struct dirent64 *this_dirp = dirp;
a2cf7d
-
a2cf7d
-	  while (len > 0)
a2cf7d
-	    {
a2cf7d
-	      char node[strlen ("/proc/openprom/")
a2cf7d
-			+ _D_ALLOC_NAMLEN (this_dirp)
a2cf7d
-			+ strlen ("/clock-frequency")];
a2cf7d
-	      char *prop;
a2cf7d
-	      int fd;
a2cf7d
-
a2cf7d
-	      /* Note that
a2cf7d
-		   strlen("/clock-frequency") > strlen("/device_type")
a2cf7d
-	      */
a2cf7d
-	      __stpcpy (prop = __stpcpy (__stpcpy (node, "/proc/openprom/"),
a2cf7d
-					 this_dirp->d_name),
a2cf7d
-			"/device_type");
a2cf7d
-	      fd = __open (node, O_RDONLY);
a2cf7d
-	      if (fd != -1)
a2cf7d
-		{
a2cf7d
-		  char type_string[128];
a2cf7d
-		  int ret;
a2cf7d
-
a2cf7d
-		  ret = __read (fd, type_string, sizeof (type_string));
a2cf7d
-		  if (ret > 0 && strncmp (type_string, "'cpu'", 5) == 0)
a2cf7d
-		    {
a2cf7d
-		      int clkfreq_fd;
a2cf7d
-
a2cf7d
-		      __stpcpy (prop, "/clock-frequency");
a2cf7d
-		      clkfreq_fd = __open (node, O_RDONLY);
a2cf7d
-		      if (clkfreq_fd != -1)
a2cf7d
-			{
a2cf7d
-			  if (__read (clkfreq_fd, type_string,
a2cf7d
-				      sizeof (type_string)) > 0)
a2cf7d
-			    result = (hp_timing_t)
a2cf7d
-			      strtoumax (type_string, NULL, 16);
a2cf7d
-			  __close (clkfreq_fd);
a2cf7d
-			}
a2cf7d
-		    }
a2cf7d
-		  __close (fd);
a2cf7d
-		}
a2cf7d
-
a2cf7d
-	      if (result != 0)
a2cf7d
-		break;
a2cf7d
-
a2cf7d
-	      len -= this_dirp->d_reclen;
a2cf7d
-	      this_dirp = (struct dirent64 *)
a2cf7d
-		((char *) this_dirp + this_dirp->d_reclen);
a2cf7d
-	    }
a2cf7d
-	  if (result != 0)
a2cf7d
-	    break;
a2cf7d
-	}
a2cf7d
-      __close (obp_fd);
a2cf7d
-    }
a2cf7d
-
a2cf7d
-  return result;
a2cf7d
-}
a2cf7d
-
a2cf7d
-static void set_obp_int (struct openpromio *op, int val)
a2cf7d
-{
a2cf7d
-  char *cp = op->oprom_array;
a2cf7d
-  int *ip = (int *) cp;
a2cf7d
-
a2cf7d
-  *ip = val;
a2cf7d
-}
a2cf7d
-
a2cf7d
-static int get_obp_int (struct openpromio *op)
a2cf7d
-{
a2cf7d
-  char *cp = op->oprom_array;
a2cf7d
-  int *ip = (int *) cp;
a2cf7d
-
a2cf7d
-  return *ip;
a2cf7d
-}
a2cf7d
-
a2cf7d
-static hp_timing_t
a2cf7d
-__get_clockfreq_via_dev_openprom (void)
a2cf7d
-{
a2cf7d
-  hp_timing_t result;
a2cf7d
-  int obp_dev_fd;
a2cf7d
-
a2cf7d
-  result = 0;
a2cf7d
-
a2cf7d
-  obp_dev_fd = __open ("/dev/openprom", O_RDONLY);
a2cf7d
-  if (obp_dev_fd != -1)
a2cf7d
-    {
a2cf7d
-      char obp_buf[8192];
a2cf7d
-      struct openpromio *obp_cmd = (struct openpromio *)obp_buf;
a2cf7d
-      int ret;
a2cf7d
-
a2cf7d
-      obp_cmd->oprom_size =
a2cf7d
-	sizeof (obp_buf) - sizeof (unsigned int);
a2cf7d
-      set_obp_int (obp_cmd, 0);
a2cf7d
-      ret = __ioctl (obp_dev_fd, OPROMCHILD, (char *) obp_cmd);
a2cf7d
-      if (ret == 0)
a2cf7d
-	{
a2cf7d
-	  int cur_node = get_obp_int (obp_cmd);
a2cf7d
-
a2cf7d
-	  while (cur_node != 0 && cur_node != -1)
a2cf7d
-	    {
a2cf7d
-	      obp_cmd->oprom_size = sizeof (obp_buf) - sizeof (unsigned int);
a2cf7d
-	      strcpy (obp_cmd->oprom_array, "device_type");
a2cf7d
-	      ret = __ioctl (obp_dev_fd, OPROMGETPROP, (char *) obp_cmd);
a2cf7d
-	      if (ret == 0
a2cf7d
-		  && strncmp (obp_cmd->oprom_array, "cpu", 3) == 0)
a2cf7d
-		{
a2cf7d
-		  obp_cmd->oprom_size = (sizeof (obp_buf)
a2cf7d
-					 - sizeof (unsigned int));
a2cf7d
-		  strcpy (obp_cmd->oprom_array, "clock-frequency");
a2cf7d
-		  ret = __ioctl (obp_dev_fd, OPROMGETPROP, (char *) obp_cmd);
a2cf7d
-		  if (ret == 0)
a2cf7d
-		    result = (hp_timing_t) get_obp_int (obp_cmd);
a2cf7d
-		}
a2cf7d
-	      obp_cmd->oprom_size = sizeof (obp_buf) - sizeof (unsigned int);
a2cf7d
-	      set_obp_int (obp_cmd, cur_node);
a2cf7d
-	      ret = __ioctl (obp_dev_fd, OPROMNEXT, (char *) obp_cmd);
a2cf7d
-	      if (ret < 0)
a2cf7d
-		break;
a2cf7d
-	      cur_node = get_obp_int (obp_cmd);
a2cf7d
-	    }
a2cf7d
-	}
a2cf7d
-    }
a2cf7d
-
a2cf7d
-  return result;
a2cf7d
-}
a2cf7d
-
a2cf7d
-hp_timing_t
a2cf7d
-__get_clockfreq (void)
a2cf7d
-{
a2cf7d
-  static hp_timing_t result;
a2cf7d
-
a2cf7d
-  /* If this function was called before, we know the result.  */
a2cf7d
-  if (result != 0)
a2cf7d
-    return result;
a2cf7d
-
a2cf7d
-  /* We first read the information from the /proc/cpuinfo file.
a2cf7d
-     It contains at least one line like
a2cf7d
-	Cpu0ClkTick         : 000000002cb41780
a2cf7d
-     We search for this line and convert the number in an integer.  */
a2cf7d
-  result = __get_clockfreq_via_cpuinfo ();
a2cf7d
-  if (result != 0)
a2cf7d
-    return result;
a2cf7d
-
a2cf7d
-  /* If that did not work, try to find an OpenPROM node
a2cf7d
-     with device_type equal to 'cpu' using /dev/openprom
a2cf7d
-     and fetch the clock-frequency property from there.  */
a2cf7d
-  result = __get_clockfreq_via_dev_openprom ();
a2cf7d
-  if (result != 0)
a2cf7d
-    return result;
a2cf7d
-
a2cf7d
-  /* Finally, try the same lookup as above but using /proc/openprom.  */
a2cf7d
-  result = __get_clockfreq_via_proc_openprom ();
a2cf7d
-
a2cf7d
-  return result;
a2cf7d
-}