446cf2
commit 77b6f5534778b5403c87fa5415625aeb4c3cbf44
446cf2
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
446cf2
Date:   Wed Jan 16 17:30:07 2019 +0000
446cf2
446cf2
    linux: Assume clock_getres CLOCK_{PROCESS,THREAD}_CPUTIME_ID
446cf2
    
446cf2
    The Linux 3.2 clock_getres kernel code (kernel/posix-cpu-timers.c)
446cf2
    issued for clock_getres CLOCK_PROCESS_CPUTIME_ID (process_cpu_clock_getres)
446cf2
    and CLOCK_THREAD_CPUTIME_ID (thread_cpu_clock_getres) call
446cf2
    posix_cpu_clock_getres. And it fails on check_clock only if an invalid
446cf2
    clock is used (not the case) or if we pass an invalid the pid/tid in
446cf2
    29 msb of clock_id (not the case either).
446cf2
    
446cf2
    This patch assumes that clock_getres syscall always support
446cf2
    CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID, so there is no need
446cf2
    to fallback to hp-timing support for _SC_MONOTONIC_CLOCK neither to issue
446cf2
    the syscall to certify the clock_id is supported bt the kernel.  This
446cf2
    allows simplify the sysconf support to always use the syscall.
446cf2
    
446cf2
    it also removes ia64 itc drift check and assume kernel handles it correctly.
446cf2
    
446cf2
    Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu.
446cf2
    
446cf2
            * sysdeps/unix/sysv/linux/ia64/has_cpuclock.c: Remove file.
446cf2
            * sysdeps/unix/sysv/linux/ia64/sysconf.c: Likewise.
446cf2
            * sysdeps/unix/sysv/linux/sysconf.c (has_cpuclock): Remove function.
446cf2
            (__sysconf): Assume kernel support for _SC_MONOTONIC_CLOCK,
446cf2
            _SC_CPUTIME, and _SC_THREAD_CPUTIME.
446cf2
446cf2
Conflicts:
446cf2
	sysdeps/unix/sysv/linux/ia64/has_cpuclock.c
446cf2
	sysdeps/unix/sysv/linux/ia64/sysconf.c
446cf2
	  (Removal after copyright year update.)
446cf2
446cf2
diff --git a/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c b/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c
446cf2
deleted file mode 100644
446cf2
index 75f3ef9f4d1366fb..0000000000000000
446cf2
--- a/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c
446cf2
+++ /dev/null
446cf2
@@ -1,51 +0,0 @@
446cf2
-/* Copyright (C) 2000-2018 Free Software Foundation, Inc.
446cf2
-   This file is part of the GNU C Library.
446cf2
-
446cf2
-   The GNU C Library is free software; you can redistribute it and/or
446cf2
-   modify it under the terms of the GNU Lesser General Public
446cf2
-   License as published by the Free Software Foundation; either
446cf2
-   version 2.1 of the License, or (at your option) any later version.
446cf2
-
446cf2
-   The GNU C Library is distributed in the hope that it will be useful,
446cf2
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
-   Lesser General Public License for more details.
446cf2
-
446cf2
-   You should have received a copy of the GNU Lesser General Public
446cf2
-   License along with the GNU C Library; if not, see
446cf2
-   <http://www.gnu.org/licenses/>.  */
446cf2
-
446cf2
-#include <errno.h>
446cf2
-#include <fcntl.h>
446cf2
-#include <unistd.h>
446cf2
-#include <sys/stat.h>
446cf2
-#include <sys/types.h>
446cf2
-#include <not-cancel.h>
446cf2
-
446cf2
-static int itc_usable;
446cf2
-
446cf2
-static int
446cf2
-has_cpuclock (void)
446cf2
-{
446cf2
-  if (__builtin_expect (itc_usable == 0, 0))
446cf2
-    {
446cf2
-      int newval = 1;
446cf2
-      int fd = __open_nocancel ("/proc/sal/itc_drift", O_RDONLY);
446cf2
-      if (__builtin_expect (fd != -1, 1))
446cf2
-	{
446cf2
-	  char buf[16];
446cf2
-	  /* We expect the file to contain a single digit followed by
446cf2
-	     a newline.  If the format changes we better not rely on
446cf2
-	     the file content.  */
446cf2
-	  if (__read_nocancel (fd, buf, sizeof buf) != 2
446cf2
-	      || buf[0] != '0' || buf[1] != '\n')
446cf2
-	    newval = -1;
446cf2
-
446cf2
-	  __close_nocancel_nostatus (fd);
446cf2
-	}
446cf2
-
446cf2
-      itc_usable = newval;
446cf2
-    }
446cf2
-
446cf2
-  return itc_usable;
446cf2
-}
446cf2
diff --git a/sysdeps/unix/sysv/linux/ia64/sysconf.c b/sysdeps/unix/sysv/linux/ia64/sysconf.c
446cf2
deleted file mode 100644
446cf2
index 6c39db5a4af3e15a..0000000000000000
446cf2
--- a/sysdeps/unix/sysv/linux/ia64/sysconf.c
446cf2
+++ /dev/null
446cf2
@@ -1,30 +0,0 @@
446cf2
-/* Get file-specific information about a file.  Linux/ia64 version.
446cf2
-   Copyright (C) 2003-2018 Free Software Foundation, Inc.
446cf2
-   This file is part of the GNU C Library.
446cf2
-
446cf2
-   The GNU C Library is free software; you can redistribute it and/or
446cf2
-   modify it under the terms of the GNU Lesser General Public
446cf2
-   License as published by the Free Software Foundation; either
446cf2
-   version 2.1 of the License, or (at your option) any later version.
446cf2
-
446cf2
-   The GNU C Library is distributed in the hope that it will be useful,
446cf2
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
-   Lesser General Public License for more details.
446cf2
-
446cf2
-   You should have received a copy of the GNU Lesser General Public
446cf2
-   License along with the GNU C Library; if not, see
446cf2
-   <http://www.gnu.org/licenses/>.  */
446cf2
-
446cf2
-#include <assert.h>
446cf2
-#include <stdbool.h>
446cf2
-#include <stdlib.h>
446cf2
-#include <unistd.h>
446cf2
-
446cf2
-
446cf2
-#include "has_cpuclock.c"
446cf2
-#define HAS_CPUCLOCK(name) (has_cpuclock () ? _POSIX_VERSION : -1)
446cf2
-
446cf2
-
446cf2
-/* Now the generic Linux version.  */
446cf2
-#include <sysdeps/unix/sysv/linux/sysconf.c>
446cf2
diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c
446cf2
index 4e49ebaa7a25748c..6fab1601034e4724 100644
446cf2
--- a/sysdeps/unix/sysv/linux/sysconf.c
446cf2
+++ b/sysdeps/unix/sysv/linux/sysconf.c
446cf2
@@ -35,34 +35,6 @@
446cf2
 static long int posix_sysconf (int name);
446cf2
 
446cf2
 
446cf2
-#ifndef HAS_CPUCLOCK
446cf2
-static long int
446cf2
-has_cpuclock (int name)
446cf2
-{
446cf2
-# if defined __NR_clock_getres || HP_TIMING_AVAIL
446cf2
-  /* If we have HP_TIMING, we will fall back on that if the system
446cf2
-     call does not work, so we support it either way.  */
446cf2
-#  if !HP_TIMING_AVAIL
446cf2
-  /* Check using the clock_getres system call.  */
446cf2
-  struct timespec ts;
446cf2
-  INTERNAL_SYSCALL_DECL (err);
446cf2
-  int r = INTERNAL_SYSCALL (clock_getres, err, 2,
446cf2
-			    (name == _SC_CPUTIME
446cf2
-			     ? CLOCK_PROCESS_CPUTIME_ID
446cf2
-			     : CLOCK_THREAD_CPUTIME_ID),
446cf2
-			    &ts);
446cf2
-  if (INTERNAL_SYSCALL_ERROR_P (r, err))
446cf2
-    return -1;
446cf2
-#  endif
446cf2
-  return _POSIX_VERSION;
446cf2
-# else
446cf2
-  return -1;
446cf2
-# endif
446cf2
-}
446cf2
-# define HAS_CPUCLOCK(name) has_cpuclock (name)
446cf2
-#endif
446cf2
-
446cf2
-
446cf2
 /* Get the value of the system variable NAME.  */
446cf2
 long int
446cf2
 __sysconf (int name)
446cf2
@@ -71,29 +43,20 @@ __sysconf (int name)
446cf2
 
446cf2
   switch (name)
446cf2
     {
446cf2
-      struct rlimit rlimit;
446cf2
-#ifdef __NR_clock_getres
446cf2
     case _SC_MONOTONIC_CLOCK:
446cf2
-      /* Check using the clock_getres system call.  */
446cf2
-      {
446cf2
-	struct timespec ts;
446cf2
-	INTERNAL_SYSCALL_DECL (err);
446cf2
-	int r;
446cf2
-	r = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
446cf2
-	return INTERNAL_SYSCALL_ERROR_P (r, err) ? -1 : _POSIX_VERSION;
446cf2
-      }
446cf2
-#endif
446cf2
-
446cf2
     case _SC_CPUTIME:
446cf2
     case _SC_THREAD_CPUTIME:
446cf2
-      return HAS_CPUCLOCK (name);
446cf2
+      return _POSIX_VERSION;
446cf2
 
446cf2
     case _SC_ARG_MAX:
446cf2
-      /* Use getrlimit to get the stack limit.  */
446cf2
-      if (__getrlimit (RLIMIT_STACK, &rlimit) == 0)
446cf2
-	return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
446cf2
+      {
446cf2
+        struct rlimit rlimit;
446cf2
+        /* Use getrlimit to get the stack limit.  */
446cf2
+        if (__getrlimit (RLIMIT_STACK, &rlimit) == 0)
446cf2
+	  return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
446cf2
 
446cf2
-      return legacy_ARG_MAX;
446cf2
+        return legacy_ARG_MAX;
446cf2
+      }
446cf2
 
446cf2
     case _SC_NGROUPS_MAX:
446cf2
       /* Try to read the information from the /proc/sys/kernel/ngroups_max
446cf2
@@ -102,11 +65,14 @@ __sysconf (int name)
446cf2
       break;
446cf2
 
446cf2
     case _SC_SIGQUEUE_MAX:
446cf2
-      if (__getrlimit (RLIMIT_SIGPENDING, &rlimit) == 0)
446cf2
-	return rlimit.rlim_cur;
446cf2
+      {
446cf2
+        struct rlimit rlimit;
446cf2
+        if (__getrlimit (RLIMIT_SIGPENDING, &rlimit) == 0)
446cf2
+	  return rlimit.rlim_cur;
446cf2
 
446cf2
-      /* The /proc/sys/kernel/rtsig-max file contains the answer.  */
446cf2
-      procfname = "/proc/sys/kernel/rtsig-max";
446cf2
+        /* The /proc/sys/kernel/rtsig-max file contains the answer.  */
446cf2
+        procfname = "/proc/sys/kernel/rtsig-max";
446cf2
+      }
446cf2
       break;
446cf2
 
446cf2
     default: