public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Albert ARIBAUD (3ADEV)" <albert.aribaud@3adev.fr>
To: libc-alpha@sourceware.org
Cc: "Albert ARIBAUD (3ADEV)" <albert.aribaud@3adev.fr>
Subject: [[PATCH RFC 2]  17/63] Y2038: add function __clock_getres64
Date: Wed, 18 Apr 2018 20:19:00 -0000	[thread overview]
Message-ID: <20180418201819.15952-18-albert.aribaud@3adev.fr> (raw)
In-Reply-To: <20180418201819.15952-17-albert.aribaud@3adev.fr>

---
 include/time.h                         |  2 +
 sysdeps/posix/clock_getres.c           | 96 +++++++++++++++++++++++++++++++++-
 sysdeps/unix/sysv/linux/clock_getres.c | 60 +++++++++++++++++++++
 time/Versions                          |  1 +
 4 files changed, 158 insertions(+), 1 deletion(-)

diff --git a/include/time.h b/include/time.h
index 8101b638c6..37909fae9a 100644
--- a/include/time.h
+++ b/include/time.h
@@ -37,6 +37,8 @@ extern int __clock_gettime64 (clockid_t __clock_id,
 			      struct __timespec64 *__tp) __THROW;
 extern int __clock_settime64 (clockid_t __clock_id,
 			       const struct __timespec64 *__tp) __THROW;
+extern int __clock_getres64 (clockid_t __clock_id,
+			      struct __timespec64 *__res) __THROW;
 
 /* Now define the internal interfaces.  */
 struct tm;
diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c
index e7924e0891..28b16a6529 100644
--- a/sysdeps/posix/clock_getres.c
+++ b/sysdeps/posix/clock_getres.c
@@ -23,7 +23,6 @@
 #include <sys/param.h>
 #include <libc-internal.h>
 
-
 #if HP_TIMING_AVAIL
 static long int nsec;		/* Clock frequency of the processor.  */
 
@@ -53,6 +52,33 @@ hp_timing_getres (struct timespec *res)
 
   return 0;
 }
+
+static int
+hp_timing_getres64 (struct __timespec64 *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
@@ -73,6 +99,28 @@ realtime_getres (struct timespec *res)
   return -1;
 }
 
+/* Check that we are built with a 64-bit-time kernel */
+#ifdef __NR_clock_getres64
+
+static inline int
+realtime_getres64 (struct __timespec64 *res)
+{
+  long int clk_tck = sysconf (_SC_CLK_TCK);
+
+  if (__glibc_likely (clk_tck != -1))
+    {
+      /* This implementation assumes that the realtime clock has a
+	 resolution higher than 1 second.  This is the case for any
+	 reasonable implementation.  */
+      res->tv_sec = 0;
+      res->tv_nsec = 1000000000 / clk_tck;
+      return 0;
+    }
+
+  return -1;
+}
+
+#endif
 
 /* Get resolution of clock.  */
 int
@@ -116,3 +164,49 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
   return retval;
 }
 weak_alias (__clock_getres, clock_getres)
+
+int
+__clock_getres64 (clockid_t clock_id, struct __timespec64 *res)
+{
+  int retval = -1;
+
+  switch (clock_id)
+    {
+#ifdef SYSDEP_GETRES64
+      SYSDEP_GETRES64;
+#endif
+
+/* Check that we are built with a 64-bit-time kernel */
+#ifdef __NR_clock_getres64
+
+# ifndef HANDLED_REALTIME64
+    case CLOCK_REALTIME64:
+      retval = realtime_getres64 (res);
+      break;
+# endif	/* handled REALTIME */
+
+#endif
+
+    default:
+#ifdef SYSDEP_GETRES_CPU64
+      SYSDEP_GETRES_CPU64;
+#endif
+#if HP_TIMING_AVAIL
+      if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
+	  == CLOCK_THREAD_CPUTIME_ID)
+	retval = hp_timing_getres64 (res);
+      else
+#endif
+	__set_errno (EINVAL);
+      break;
+
+#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+    case CLOCK_PROCESS_CPUTIME_ID:
+    case CLOCK_THREAD_CPUTIME_ID:
+      retval = hp_timing_getres64 (res);
+      break;
+#endif
+    }
+
+  return retval;
+}
diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c
index 5d94f59afe..ecea873afe 100644
--- a/sysdeps/unix/sysv/linux/clock_getres.c
+++ b/sysdeps/unix/sysv/linux/clock_getres.c
@@ -48,4 +48,64 @@
 #define SYSDEP_GETRES_CPU SYSCALL_GETRES
 #define SYSDEP_GETRES_CPUTIME	/* Default catches them too.  */
 
+/* The 64-bit version */
+
+/* Check that we are built with a 64-bit-time kernel */
+#ifdef __NR_clock_getres64
+
+extern int __y2038_linux_support;
+
+#define SYSCALL_GETRES64 \
+  if (__y2038_linux_support)						      \
+    {									      \
+      retval = INLINE_VSYSCALL (clock_getres64, 2, clock_id, res);  	      \
+    }									      \
+  else									      \
+    {									      \
+      retval = -1;                                                 	      \
+      errno = ENOSYS;                                                 	      \
+    }									      \
+  if (retval == -1 && errno == ENOSYS)					      \
+    {									      \
+      retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, &ts32);	      \
+        if (retval==0)							      \
+        {								      \
+          timespec_to_timespec64(&ts32, res);	                	      \
+          res->tv_pad = 0;				               	      \
+        }								      \
+    }									      \
+  break
+
+#else
+
+#define SYSCALL_GETRES64 \
+  retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, &ts32);	      \
+    if (retval==0)							      \
+    {								      \
+      timespec_to_timespec64(&ts32, res);	                	      \
+      res->tv_pad = 0;				               	      \
+    }								      \
+  break
+
+#endif
+
+/* The REALTIME and MONOTONIC clock are definitely supported in the
+   kernel.  */
+#define SYSDEP_GETRES64							      \
+  SYSDEP_GETRES_CPUTIME64						      \
+  case CLOCK_REALTIME:							      \
+  case CLOCK_MONOTONIC:							      \
+  case CLOCK_MONOTONIC_RAW:						      \
+  case CLOCK_REALTIME_COARSE:						      \
+  case CLOCK_MONOTONIC_COARSE:						      \
+    SYSCALL_GETRES64
+
+/* We handled the REALTIME clock here.  */
+#define HANDLED_REALTIME64	1
+#define HANDLED_CPUTIME64	1
+
+#define SYSDEP_GETRES_CPU64 SYSCALL_GETRES64
+#define SYSDEP_GETRES_CPUTIME64 \
+  struct timespec ts32;
+
 #include <sysdeps/posix/clock_getres.c>
diff --git a/time/Versions b/time/Versions
index a00184daae..98ac0abfbe 100644
--- a/time/Versions
+++ b/time/Versions
@@ -76,5 +76,6 @@ libc {
     __vdso_clock_gettime64;
     __y2038_kernel_support;
     __clock_settime64;
+    __clock_getres64;
   }
 }
-- 
2.14.1

  reply	other threads:[~2018-04-18 20:19 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-18 20:18 [[PATCH RFC 2] 00/63] Make GLIBC Y2038-proof Albert ARIBAUD (3ADEV)
2018-04-18 20:18 ` [[PATCH RFC 2] 01/63] Y2038: add type __time64_t Albert ARIBAUD (3ADEV)
2018-04-18 20:18   ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:18     ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Albert ARIBAUD (3ADEV)
2018-04-18 20:18       ` [[PATCH RFC 2] 04/63] Y2038: add function __localtime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:18         ` [[PATCH RFC 2] 05/63] Y2038: add function __localtime64_r Albert ARIBAUD (3ADEV)
2018-04-18 20:19           ` [[PATCH RFC 2] 06/63] Y2038: add function __gmtime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19             ` [[PATCH RFC 2] 07/63] Y2038: add function __gmtime64_r Albert ARIBAUD (3ADEV)
2018-04-18 20:19               ` [[PATCH RFC 2] 08/63] Y2038: add function __ctime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19                 ` [[PATCH RFC 2] 09/63] Y2038: add function __ctime64_r Albert ARIBAUD (3ADEV)
2018-04-18 20:19                   ` [[PATCH RFC 2] 10/63] Y2038: implement 64-bit-time __mktime64() and timelocal() Albert ARIBAUD (3ADEV)
2018-04-18 20:19                     ` [[PATCH RFC 2] 11/63] Y2038: implement 64-bit-time __timegm64() Albert ARIBAUD (3ADEV)
2018-04-18 20:19                       ` [[PATCH RFC 2] 12/63] Y2038: add struct __timespec64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19                         ` [[PATCH RFC 2] 13/63] Y2038: add function __clock_gettime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19                           ` [[PATCH RFC 2] 14/63] Y2038: arm: implement clock_gettime64 as a VDSO symbol Albert ARIBAUD (3ADEV)
2018-04-18 20:19                             ` [[PATCH RFC 2] 15/63] Y2038: powerpc: " Albert ARIBAUD (3ADEV)
2018-04-18 20:19                               ` [[PATCH RFC 2] 16/63] Y2038: add function __clock_settime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19                                 ` Albert ARIBAUD (3ADEV) [this message]
2018-04-18 20:19                                   ` [[PATCH RFC 2] 18/63] Y2038: add function __clock_nanosleep64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                     ` [[PATCH RFC 2] 19/63] Y2038: add function __timespec_get64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                       ` [[PATCH RFC 2] 20/63] Y2038: add function __futimens64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                         ` [[PATCH RFC 2] 21/63] Y2038: add function __utimensat64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                           ` [[PATCH RFC 2] 22/63] Y2038: add function __sigtimedwait64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                             ` [[PATCH RFC 2] 23/63] Y2038: add struct __timeval64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                               ` [[PATCH RFC 2] 24/63] Y2038: add function __futimes64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                 ` [[PATCH RFC 2] 25/63] Y2038: add function __lutimes64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                   ` [[PATCH RFC 2] 26/63] Y2038: add struct __itimerspec64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                     ` [[PATCH RFC 2] 27/63] Y2038: add function __timer_gettime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                       ` [[PATCH RFC 2] 28/63] Y2038: add function __timer_settime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                         ` [[PATCH RFC 2] 29/63] Y2038: add function __timerfd_gettime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                           ` [[PATCH RFC 2] 30/63] Y2038: add function __timerfd_settime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                             ` [[PATCH RFC 2] 31/63] Y2038: add struct __stat64_t64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                               ` [[PATCH RFC 2] 32/63] Y2038: add function __fstat64_t64 (and __fxstat64_t64) Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                 ` [[PATCH RFC 2] 33/63] Y2038: add function __stat64_t64 (and __xstat64_t64) Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                   ` [[PATCH RFC 2] 34/63] Y2038: add function __lstat64_t64 (and __lxstat64_t64) Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                     ` [[PATCH RFC 2] 35/63] Y2038: add function __fstatat64_t64 (and __fxstatat_t64) Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                       ` [[PATCH RFC 2] 36/63] Y2038: add function __gettimeofday64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                         ` [[PATCH RFC 2] 37/63] Y2038: add function __settimeofday64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                           ` [[PATCH RFC 2] 38/63] Y2038: add function __time64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                             ` [[PATCH RFC 2] 39/63] Y2038: add function __stime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                               ` [[PATCH RFC 2] 40/63] Y2038: add function __utimes64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                                 ` [[PATCH RFC 2] 41/63] Y2038: add function __mq_timedreceived64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                                   ` [[PATCH RFC 2] 42/63] Y2038: add function __mq_timedsend64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                                     ` [[PATCH RFC 2] 43/63] Y2038: add function __msgctl64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                       ` [[PATCH RFC 2] 44/63] Y2038: add function __sched_rr_get_interval64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                                         ` [[PATCH RFC 2] 45/63] Y2038: add function __nanosleep64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                           ` [[PATCH RFC 2] 46/63] Y2038: add function __adjtime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                             ` [[PATCH RFC 2] 47/63] Y2038: add function __utime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                               ` [[PATCH RFC 2] 48/63] Y2038: add struct __itimerval64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                                 ` [[PATCH RFC 2] 49/63] Y2038: add function __getitimer64 Albert ARIBAUD (3ADEV)
2018-04-18 21:54                                                     ` [[PATCH RFC 2] 26/63] Y2038: add struct __itimerspec64 Joseph Myers
2018-04-18 21:53                                         ` [[PATCH RFC 2] 20/63] Y2038: add function __futimens64 Joseph Myers
2018-04-18 21:51                     ` [[PATCH RFC 2] 10/63] Y2038: implement 64-bit-time __mktime64() and timelocal() Joseph Myers
2018-04-19  1:02       ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Paul Eggert
2018-04-19  1:08       ` Paul Eggert
2018-04-19  6:52         ` Florian Weimer
2018-05-02  9:11           ` Albert ARIBAUD
2018-04-18 20:37     ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Paul Eggert
2018-04-19 13:04       ` Albert ARIBAUD
2018-04-19 21:36         ` Paul Eggert
2018-05-02  7:22           ` Albert ARIBAUD
2018-05-02  7:40             ` Albert ARIBAUD
2018-05-02  7:46             ` Florian Weimer
2018-05-02 11:26               ` Albert ARIBAUD
2018-05-02 19:07               ` Paul Eggert
2018-05-03 17:31                 ` Albert ARIBAUD
2018-05-03 17:53                   ` Paul Eggert
2018-05-22 20:58                     ` Albert ARIBAUD
2018-05-22 21:15                       ` Paul Eggert
2018-05-22 22:10                         ` Joseph Myers
2018-06-11 22:24                           ` Albert ARIBAUD
2018-06-11 22:39                             ` Joseph Myers
2018-05-02 15:45             ` Joseph Myers
2018-05-02 19:14             ` Paul Eggert
2018-04-18 21:50     ` Joseph Myers
2018-04-19 12:27       ` Albert ARIBAUD
2018-04-19 13:18         ` Joseph Myers
2018-05-02  7:25           ` Albert ARIBAUD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180418201819.15952-18-albert.aribaud@3adev.fr \
    --to=albert.aribaud@3adev.fr \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).