public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 03/12] Don’t use the argument to time.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
@ 2019-08-20 13:21 ` Zack Weinberg
  2019-08-20 17:09   ` Rafal Luzynski
  2019-08-20 18:08   ` [PATCH 03/12] Don’t use the argument to time Adhemerval Zanella
  2019-08-20 13:22 ` [PATCH 04/12] Use clock_settime to implement stime Zack Weinberg
                   ` (14 subsequent siblings)
  15 siblings, 2 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:21 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Unlike gettimeofday, I don’t think it makes sense to remove all the
internal uses of time.  Its callers don’t care about sub-second
resolution and would be unnecessarily complicated if they had to
declare a struct timespec instead of just a time_t.  However, a
handful of places were using the vestigial ‘result’ argument instead
of the return value, which is ever so slightly less efficient and also
looks weird.  Correct this.

	* misc/syslog.c (__vsyslog_internal)
	* time/getdate.c (__getdate_r)
	* time/tst_wcsftime.c (main):
	Use return value of time, not its argument.

	* string/strfry.c (strfry)
	* sysdeps/mach/sleep.c (__sleep):
	Remove unnecessary casts of NULL.
---
 misc/syslog.c        | 2 +-
 string/strfry.c      | 2 +-
 sysdeps/mach/sleep.c | 4 ++--
 time/getdate.c       | 2 +-
 time/tst_wcsftime.c  | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/misc/syslog.c b/misc/syslog.c
index 3a15da41ce..cf2deef533 100644
--- a/misc/syslog.c
+++ b/misc/syslog.c
@@ -205,7 +205,7 @@ __vsyslog_internal(int pri, const char *fmt, va_list ap,
 	  {
 	    __fsetlocking (f, FSETLOCKING_BYCALLER);
 	    fprintf (f, "<%d>", pri);
-	    (void) time (&now);
+	    now = time (NULL);
 	    f->_IO_write_ptr += __strftime_l (f->_IO_write_ptr,
 					      f->_IO_write_end
 					      - f->_IO_write_ptr,
diff --git a/string/strfry.c b/string/strfry.c
index af6087bee5..71686d45c2 100644
--- a/string/strfry.c
+++ b/string/strfry.c
@@ -30,7 +30,7 @@ strfry (char *string)
     {
       static char state[32];
       rdata.state = NULL;
-      __initstate_r (time ((time_t *) NULL) ^ getpid (),
+      __initstate_r (time (NULL) ^ getpid (),
 		     state, sizeof (state), &rdata);
       init = 1;
     }
diff --git a/sysdeps/mach/sleep.c b/sysdeps/mach/sleep.c
index 11e1bb87f3..c63ef926b7 100644
--- a/sysdeps/mach/sleep.c
+++ b/sysdeps/mach/sleep.c
@@ -33,10 +33,10 @@ __sleep (unsigned int seconds)
 
   recv = __mach_reply_port ();
 
-  before = time ((time_t *) NULL);
+  before = time (NULL);
   (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
 		     0, 0, recv, seconds * 1000, MACH_PORT_NULL);
-  after = time ((time_t *) NULL);
+  after = time (NULL);
   __mach_port_destroy (__mach_task_self (), recv);
 
   return seconds - (after - before);
diff --git a/time/getdate.c b/time/getdate.c
index aee96f7163..8a567c3fcd 100644
--- a/time/getdate.c
+++ b/time/getdate.c
@@ -219,7 +219,7 @@ __getdate_r (const char *string, struct tm *tp)
     return 7;
 
   /* Get current time.  */
-  time (&timer);
+  timer = time (NULL);
   __localtime_r (&timer, &tm);
 
   /* If only the weekday is given, today is assumed if the given day
diff --git a/time/tst_wcsftime.c b/time/tst_wcsftime.c
index 3f6f0d9f77..55c45f6a81 100644
--- a/time/tst_wcsftime.c
+++ b/time/tst_wcsftime.c
@@ -10,7 +10,7 @@ main (int argc, char *argv[])
   int result = 0;
   size_t n;
 
-  time (&t);
+  t = time (NULL);
   tp = gmtime (&t);
 
   n = wcsftime (buf, sizeof (buf) / sizeof (buf[0]),
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 04/12] Use clock_settime to implement stime.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
  2019-08-20 13:21 ` [PATCH 03/12] Don’t use the argument to time Zack Weinberg
@ 2019-08-20 13:22 ` Zack Weinberg
  2019-08-21 15:10   ` Adhemerval Zanella
  2019-08-20 13:22 ` [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime Zack Weinberg
                   ` (13 subsequent siblings)
  15 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:22 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Unconditionally, on all ports, use clock_settime to implement stime,
not settimeofday or a direct syscall.

Note that the former stub implementation of stime would return -1 with
errno set to EINVAL if passed a null pointer.  With this change, it
instead unconditionally dereferences the pointer, so any hypothetical
callers that passed NULL will now segfault.  I don’t think this will break
any non-contrived programs.

	* time/stime.c (stime): No longer a stub implementation.
	Call __clock_settime.

	* sysdeps/unix/stime.c: Delete file.
	* sysdeps/unix/sysv/linux/syscalls.list: Remove entry for stime.

	* include/time.h: Add libc_hidden_proto for __clock_settime.
	* rt/clock_settime.c, sysdeps/unix/sysv/linux/clock_settime.c:
	Add libc_hidden_def for __clock_settime.
---
 include/time.h                          |  1 +
 rt/clock_settime.c                      |  1 +
 sysdeps/unix/stime.c                    | 39 -------------------------
 sysdeps/unix/sysv/linux/clock_settime.c |  1 +
 sysdeps/unix/sysv/linux/syscalls.list   |  1 -
 time/stime.c                            | 15 +++-------
 6 files changed, 7 insertions(+), 51 deletions(-)
 delete mode 100644 sysdeps/unix/stime.c

diff --git a/include/time.h b/include/time.h
index ac3163c2a5..c0421c7a28 100644
--- a/include/time.h
+++ b/include/time.h
@@ -22,6 +22,7 @@ extern __typeof (clock_getres) __clock_getres;
 extern __typeof (clock_gettime) __clock_gettime;
 libc_hidden_proto (__clock_gettime)
 extern __typeof (clock_settime) __clock_settime;
+libc_hidden_proto (__clock_settime)
 extern __typeof (clock_nanosleep) __clock_nanosleep;
 extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
 
diff --git a/rt/clock_settime.c b/rt/clock_settime.c
index 891925ab2c..9c4f4fbc10 100644
--- a/rt/clock_settime.c
+++ b/rt/clock_settime.c
@@ -26,5 +26,6 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
   __set_errno (ENOSYS);
   return -1;
 }
+libc_hidden_def (__clock_settime)
 weak_alias (__clock_settime, clock_settime)
 stub_warning (clock_settime)
diff --git a/sysdeps/unix/stime.c b/sysdeps/unix/stime.c
deleted file mode 100644
index b0809be400..0000000000
--- a/sysdeps/unix/stime.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <stddef.h>		/* For NULL.  */
-#include <sys/time.h>
-#include <time.h>
-
-/* Set the system clock to *WHEN.  */
-
-int
-stime (const time_t *when)
-{
-  struct timeval tv;
-
-  if (when == NULL)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
-
-  tv.tv_sec = *when;
-  tv.tv_usec = 0;
-  return __settimeofday (&tv, (struct timezone *) 0);
-}
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index d837e3019c..ef1512cc91 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -34,4 +34,5 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
 
   return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
 }
+libc_hidden_def (__clock_settime)
 weak_alias (__clock_settime, clock_settime)
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index e374f97b5f..f6cb655e2c 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -62,7 +62,6 @@ setfsgid	EXTRA	setfsgid	i:i	setfsgid
 setfsuid	EXTRA	setfsuid	i:i	setfsuid
 setpgid		-	setpgid		i:ii	__setpgid	setpgid
 sigaltstack	-	sigaltstack	i:PP	__sigaltstack	sigaltstack
-stime		-	stime		i:p	stime
 sysinfo		EXTRA	sysinfo		i:p	__sysinfo	sysinfo
 swapon		-	swapon		i:si	__swapon	swapon
 swapoff		-	swapoff		i:s	__swapoff	swapoff
diff --git a/time/stime.c b/time/stime.c
index de58c49562..b4d692ca32 100644
--- a/time/stime.c
+++ b/time/stime.c
@@ -15,23 +15,16 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <time.h>
-#include <stddef.h>
 
 /* Set the system clock to *WHEN.  */
 
 int
 stime (const time_t *when)
 {
-  if (when == NULL)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
+  struct timespec ts;
+  ts.tv_sec = *when;
+  ts.tv_nsec = 0;
 
-  __set_errno (ENOSYS);
-  return -1;
+  return __clock_settime (CLOCK_REALTIME, &ts);
 }
-
-stub_warning (stime)
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (3 preceding siblings ...)
  2019-08-20 13:22 ` [PATCH 12/12] Revise the documentation of ‘simple calendar time’ Zack Weinberg
@ 2019-08-20 13:22 ` Zack Weinberg
  2019-08-20 18:06   ` Adhemerval Zanella
  2019-08-20 13:22 ` [PATCH 05/12] Use clock_settime to implement settimeofday Zack Weinberg
                   ` (10 subsequent siblings)
  15 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:22 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

gettimeofday and settimeofday are obsolete in POSIX and will not be
provided by Linux for future new architectures.  The preferred
interfaces are clock_gettime and clock_settime.

In preparation for implementing all the other time query/set
interfaces using clock_gettime and clock_settime, remove the
generic-Unix implementations of clock_gettime and clock_settime that
forwarded to gettimeofday and settimeofday.  Ports of glibc to
historic Unixes that provided these functions, but not clock_gettime
and clock_settime, are unlikely to be contributed anymore.

The removed implementations *were* being used on the Hurd.
Deal with this by converting the Hurd gettimeofday and settimeofday
implementations into clock_gettime and clock_settime implementations,
respectively.  (They still only supply microsecond resolution.
I don’t know enough about Hurd/Mach to know whether nanosecond-
resolution clocks are even available.)  This means Hurd temporarily
has no implementation of gettimeofday or settimeofday; this will be
corrected in subsequent patches.  (glibc will not fail to build in the
i386-gnu configuration, but gettimeofday and settimeofday will be
ENOSYS stubs.)

	* sysdeps/unix/clock_gettime.c, sysdeps/unix/clock_settime.c:
        Delete file.
        * sysdeps/mach/gettimeofday.c: Rename to .../clock_gettime.c
        and convert into an implementation of clock_gettime.
        * sysdeps/mach/hurd/settimeofday.c: Rename to .../clock_settime.c
        and convert into an implementation of clock_settime.
---
 .../mach/{gettimeofday.c => clock_gettime.c}  | 25 ++++----
 .../hurd/{settimeofday.c => clock_settime.c}  | 27 ++++----
 sysdeps/unix/clock_gettime.c                  | 64 -------------------
 sysdeps/unix/clock_settime.c                  | 54 ----------------
 4 files changed, 25 insertions(+), 145 deletions(-)
 rename sysdeps/mach/{gettimeofday.c => clock_gettime.c} (67%)
 rename sysdeps/mach/hurd/{settimeofday.c => clock_settime.c} (71%)
 delete mode 100644 sysdeps/unix/clock_gettime.c
 delete mode 100644 sysdeps/unix/clock_settime.c

diff --git a/sysdeps/mach/gettimeofday.c b/sysdeps/mach/clock_gettime.c
similarity index 67%
rename from sysdeps/mach/gettimeofday.c
rename to sysdeps/mach/clock_gettime.c
index 8d0dfbb7dc..0fe0619aa5 100644
--- a/sysdeps/mach/gettimeofday.c
+++ b/sysdeps/mach/clock_gettime.c
@@ -16,28 +16,31 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
-#include <stddef.h>
-#include <sys/time.h>
+#include <time.h>
 #include <mach.h>
 
-/* Get the current time of day and timezone information,
-   putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
+/* Get the current time of day, putting it into *TS.
    Returns 0 on success, -1 on errors.  */
 int
-__gettimeofday (struct timeval *tv, struct timezone *tz)
+__clock_gettime (clockid_t clock_id, struct timespec *ts)
 {
   kern_return_t err;
+  time_value_t tv;
 
-  if (tz != NULL)
-    *tz = (struct timezone){0, 0}; /* XXX */
+  if (clock_id != CLOCK_REALTIME)
+    {
+      errno = EINVAL;
+      return -1;
+    }
 
-  if (err = __host_get_time (__mach_host_self (), (time_value_t *) tv))
+  if (err = __host_get_time (__mach_host_self (), &tv))
     {
       errno = err;
       return -1;
     }
+
+  TIME_VALUE_TO_TIMESPEC (&tv, ts);
   return 0;
 }
-libc_hidden_def (__gettimeofday)
-weak_alias (__gettimeofday, gettimeofday)
-libc_hidden_weak (gettimeofday)
+weak_alias (__clock_gettime, clock_gettime)
+libc_hidden_def (__clock_gettime)
diff --git a/sysdeps/mach/hurd/settimeofday.c b/sysdeps/mach/hurd/clock_settime.c
similarity index 71%
rename from sysdeps/mach/hurd/settimeofday.c
rename to sysdeps/mach/hurd/clock_settime.c
index bd0ffd64ac..a642b82b3e 100644
--- a/sysdeps/mach/hurd/settimeofday.c
+++ b/sysdeps/mach/hurd/clock_settime.c
@@ -16,37 +16,32 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
+#include <time.h>
 #include <sys/time.h>
 #include <hurd.h>
 #include <hurd/port.h>
 
-/* Set the current time of day and timezone information.
+/* Set the current time of day.
    This call is restricted to the super-user.  */
 int
-__settimeofday (const struct timeval *tv, const struct timezone *tz)
+__clock_settime (clockid_t clock_id, const struct timespec *ts)
 {
   error_t err;
   mach_port_t hostpriv;
+  time_value_t tv;
 
-  if (tz != NULL)
-    {
-      errno = ENOSYS;
-      return -1;
-    }
+  if (clock_id != CLOCK_REALTIME)
+    return __hurd_fail (EINVAL);
 
   err = __get_privileged_ports (&hostpriv, NULL);
   if (err)
     return __hurd_fail (EPERM);
 
-  /* `time_value_t' and `struct timeval' are in fact identical with the
-     names changed.  */
-  err = __host_set_time (hostpriv, *(time_value_t *) tv);
+  TIMESPEC_TO_TIME_VALUE (&tv, ts);
+  err = __host_set_time (hostpriv, tv);
   __mach_port_deallocate (__mach_task_self (), hostpriv);
 
-  if (err)
-    return __hurd_fail (err);
-
-  return 0;
+  return __hurd_fail (err);
 }
-
-weak_alias (__settimeofday, settimeofday)
+libc_hidden_def (__clock_settime)
+weak_alias (__clock_settime, clock_settime)
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
deleted file mode 100644
index 10a6c96d9d..0000000000
--- a/sysdeps/unix/clock_gettime.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/* clock_gettime -- Get the current time from a POSIX clockid_t.  Unix version.
-   Copyright (C) 1999-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <stdint.h>
-#include <time.h>
-#include <sys/time.h>
-#include <libc-internal.h>
-#include <ldsodefs.h>
-
-
-static inline int
-realtime_gettime (struct timespec *tp)
-{
-  struct timeval tv;
-  int retval = __gettimeofday (&tv, NULL);
-  if (retval == 0)
-    /* Convert into `timespec'.  */
-    TIMEVAL_TO_TIMESPEC (&tv, tp);
-  return retval;
-}
-
-
-/* Get current value of CLOCK and store it in TP.  */
-int
-__clock_gettime (clockid_t clock_id, struct timespec *tp)
-{
-  int retval = -1;
-
-  switch (clock_id)
-    {
-    case CLOCK_REALTIME:
-      {
-	struct timeval tv;
-	retval = __gettimeofday (&tv, NULL);
-	if (retval == 0)
-	  TIMEVAL_TO_TIMESPEC (&tv, tp);
-      }
-      break;
-
-    default:
-      __set_errno (EINVAL);
-      break;
-    }
-
-  return retval;
-}
-weak_alias (__clock_gettime, clock_gettime)
-libc_hidden_def (__clock_gettime)
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
deleted file mode 100644
index 109a1ad872..0000000000
--- a/sysdeps/unix/clock_settime.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/* Copyright (C) 1999-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <time.h>
-#include <sys/time.h>
-#include <ldsodefs.h>
-
-
-/* Set CLOCK to value TP.  */
-int
-__clock_settime (clockid_t clock_id, const struct timespec *tp)
-{
-  int retval = -1;
-
-  /* Make sure the time cvalue is OK.  */
-  if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
-
-  switch (clock_id)
-    {
-    case CLOCK_REALTIME:
-      {
-	struct timeval tv;
-	TIMESPEC_TO_TIMEVAL (&tv, tp);
-	retval = __settimeofday (&tv, NULL);
-      }
-      break;
-
-    default:
-      __set_errno (EINVAL);
-      break;
-    }
-
-  return retval;
-}
-weak_alias (__clock_settime, clock_settime)
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 09/12] Finish move of clock_* functions to libc.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (5 preceding siblings ...)
  2019-08-20 13:22 ` [PATCH 05/12] Use clock_settime to implement settimeofday Zack Weinberg
@ 2019-08-20 13:22 ` Zack Weinberg
  2019-08-20 15:13   ` Joseph Myers
  2019-08-20 13:37 ` [PATCH 11/12] Linux/Alpha: don’t use timeval32 system calls Zack Weinberg
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:22 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

In glibc 2.17, the functions clock_getcpuclockid, clock_getres,
clock_gettime, clock_nanosleep, and clock_settime were moved from
librt.so to libc.so, leaving compatibility stubs behind.  Now that the
dynamic linker no longer insists on finding versioned symbols in the
same library that originally defined them, we do not need the stubs
anymore, and this means we don’t need GLIBC_PRIVATE __-prefix aliases for
most of the functions anymore either.  (clock_gettime is still called
all over the place internally and therefore still needs one.)

While I’m at it, move the clock_*.c files and their tests from rt/ to
time/.

	* rt/clock-compat.c: Delete file.
	* rt/clock_getcpuclockid.c: Move to time/clock_getcpuclockid.c.
	* rt/clock_getres.c: Move to time/clock_getres.c.
	* rt/clock_gettime.c: Move to time/clock_gettime.c.
	* rt/clock_nanosleep.c: Move to time/clock_nanosleep.c.
	* rt/clock_settime.c: Move to time/clock_settime.c.
	* rt/tst-clock.c: Move to time/tst-clock.c.
	* rt/tst-clock2.c: Move to time/tst-clock2.c.
	* rt/tst-clock_nanosleep.c: Move to time/tst-clock_nanosleep.c.
	* rt/tst-cpuclock1.c: Move to time/tst-cpuclock1.c.
	* include/time.h: Remove internal prototypes for __clock_getres,
	__clock_nanosleep, and __clock_getcpuclockid.

	* rt/Makefile (routines, clock-routines): Delete.
	(librt-routines): Remove clock-compat.
	(tests): Remove tst-clock, tst-clock2, tst-clock_nanosleep, and
	tst-cpuclock1.
	* time/Makefile (routines): Add clock_getcpuclockid, clock_getres,
	clock_gettime, clock_settime, and clock_nanosleep.
	(tests): Add tst-clock, tst-clock2, tst-clock_nanosleep, and
	tst-cpuclock1.

	* rt/Versions (libc GLIBC_PRIVATE): Remove __clock_getres,
	__clock_settime, __clock_getcpuclockid, and __clock_nanosleep.
	(librt GLIBC_2.2): Remove clock_getres, clock_gettime,
	clock_settime, clock_getcpuclockid, and clock_nanosleep.
	* sysdeps/**/librt.abilist: Update to match.
---
 include/time.h                                |  3 -
 rt/Makefile                                   | 15 ++---
 rt/Versions                                   |  7 +--
 rt/clock-compat.c                             | 63 -------------------
 sysdeps/mach/hurd/i386/librt.abilist          |  5 --
 sysdeps/unix/sysv/linux/alpha/librt.abilist   |  5 --
 sysdeps/unix/sysv/linux/arm/librt.abilist     |  5 --
 sysdeps/unix/sysv/linux/hppa/librt.abilist    |  5 --
 sysdeps/unix/sysv/linux/i386/librt.abilist    |  5 --
 sysdeps/unix/sysv/linux/ia64/librt.abilist    |  5 --
 .../sysv/linux/m68k/coldfire/librt.abilist    |  5 --
 .../unix/sysv/linux/m68k/m680x0/librt.abilist |  5 --
 .../unix/sysv/linux/microblaze/librt.abilist  |  5 --
 .../unix/sysv/linux/mips/mips32/librt.abilist |  5 --
 .../unix/sysv/linux/mips/mips64/librt.abilist |  5 --
 .../linux/powerpc/powerpc32/librt.abilist     |  5 --
 .../linux/powerpc/powerpc64/be/librt.abilist  |  5 --
 .../sysv/linux/s390/s390-32/librt.abilist     |  5 --
 .../sysv/linux/s390/s390-64/librt.abilist     |  5 --
 sysdeps/unix/sysv/linux/sh/librt.abilist      |  5 --
 .../sysv/linux/sparc/sparc32/librt.abilist    |  5 --
 .../sysv/linux/sparc/sparc64/librt.abilist    |  5 --
 .../unix/sysv/linux/x86_64/64/librt.abilist   |  5 --
 .../unix/sysv/linux/x86_64/x32/librt.abilist  |  5 --
 time/Makefile                                 |  8 ++-
 {rt => time}/clock_getcpuclockid.c            |  0
 {rt => time}/clock_getres.c                   |  0
 {rt => time}/clock_gettime.c                  |  0
 {rt => time}/clock_nanosleep.c                |  0
 {rt => time}/clock_settime.c                  |  0
 {rt => time}/tst-clock.c                      |  0
 {rt => time}/tst-clock2.c                     |  0
 {rt => time}/tst-clock_nanosleep.c            |  0
 {rt => time}/tst-cpuclock1.c                  |  0
 34 files changed, 11 insertions(+), 185 deletions(-)
 delete mode 100644 rt/clock-compat.c
 rename {rt => time}/clock_getcpuclockid.c (100%)
 rename {rt => time}/clock_getres.c (100%)
 rename {rt => time}/clock_gettime.c (100%)
 rename {rt => time}/clock_nanosleep.c (100%)
 rename {rt => time}/clock_settime.c (100%)
 rename {rt => time}/tst-clock.c (100%)
 rename {rt => time}/tst-clock2.c (100%)
 rename {rt => time}/tst-clock_nanosleep.c (100%)
 rename {rt => time}/tst-cpuclock1.c (100%)

diff --git a/include/time.h b/include/time.h
index c0421c7a28..dcf91855ad 100644
--- a/include/time.h
+++ b/include/time.h
@@ -18,13 +18,10 @@ libc_hidden_proto (localtime)
 libc_hidden_proto (strftime)
 libc_hidden_proto (strptime)
 
-extern __typeof (clock_getres) __clock_getres;
 extern __typeof (clock_gettime) __clock_gettime;
 libc_hidden_proto (__clock_gettime)
 extern __typeof (clock_settime) __clock_settime;
 libc_hidden_proto (__clock_settime)
-extern __typeof (clock_nanosleep) __clock_nanosleep;
-extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
 
 /* Now define the internal interfaces.  */
 struct tm;
diff --git a/rt/Makefile b/rt/Makefile
index 9ea8394565..e6fbc32438 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -28,9 +28,6 @@ aio-routines   := aio_cancel aio_error aio_fsync aio_misc aio_read	\
 		  aio_read64 aio_return aio_suspend aio_write		\
 		  aio_write64 lio_listio lio_listio64 aio_sigqueue	\
 		  aio_notify
-clock-routines := clock_getcpuclockid					\
-		  clock_getres clock_gettime clock_settime		\
-		  clock_nanosleep
 timer-routines := timer_create timer_delete timer_getoverr		\
 		  timer_gettime timer_settime
 shm-routines   := shm_open shm_unlink
@@ -38,22 +35,18 @@ mq-routines    := mq_open mq_close mq_unlink mq_getattr mq_setattr	\
 		  mq_notify mq_send mq_receive mq_timedsend		\
 		  mq_timedreceive
 
-routines = $(clock-routines)
-
 librt-routines = $(aio-routines) \
 		 $(timer-routines) \
-		 $(shm-routines) $(mq-routines) \
-		 clock-compat
+		 $(shm-routines) $(mq-routines)
 
-tests := tst-shm tst-clock tst-clock_nanosleep tst-timer tst-timer2 \
+tests := tst-shm tst-timer tst-timer2 \
 	 tst-aio tst-aio64 tst-aio2 tst-aio3 tst-aio4 tst-aio5 tst-aio6 \
 	 tst-aio7 tst-aio8 tst-aio9 tst-aio10 \
 	 tst-mqueue1 tst-mqueue2 tst-mqueue3 tst-mqueue4 \
 	 tst-mqueue5 tst-mqueue6 tst-mqueue7 tst-mqueue8 tst-mqueue9 \
 	 tst-timer3 tst-timer4 tst-timer5 \
-	 tst-cpuclock1 tst-cpuclock2 \
-	 tst-cputimer1 tst-cputimer2 tst-cputimer3 \
-	 tst-clock2 tst-shm-cancel
+	 tst-cpuclock2 tst-cputimer1 tst-cputimer2 tst-cputimer3 \
+	 tst-shm-cancel
 
 extra-libs := librt
 extra-libs-others := $(extra-libs)
diff --git a/rt/Versions b/rt/Versions
index 91e3fd2a20..c74d5162a1 100644
--- a/rt/Versions
+++ b/rt/Versions
@@ -5,8 +5,7 @@ libc {
     clock_nanosleep;
   }
   GLIBC_PRIVATE {
-    __clock_getres; __clock_gettime; __clock_settime; __clock_getcpuclockid;
-    __clock_nanosleep;
+    __clock_gettime;
   }
 }
 
@@ -18,10 +17,6 @@ librt {
     aio_suspend64; aio_write; aio_write64; lio_listio; lio_listio64;
   }
   GLIBC_2.2 {
-    # These have moved to libc and are still here only for compatibility.
-    clock_getres; clock_gettime; clock_settime; clock_getcpuclockid;
-    clock_nanosleep;
-
     # s*
     shm_open; shm_unlink;
 
diff --git a/rt/clock-compat.c b/rt/clock-compat.c
deleted file mode 100644
index d8ced3cdc1..0000000000
--- a/rt/clock-compat.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/* ABI compatibility redirects for clock_* symbols in librt.
-   Copyright (C) 2012-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <shlib-compat.h>
-
-/* The clock_* symbols were originally defined in librt and so
-   are part of its ABI.  As of 2.17, they have moved to libc.
-   So we supply definitions for librt that just redirect to
-   their libc counterparts.  */
-
-#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_17)
-
-#include <time.h>
-
-#if HAVE_IFUNC
-# undef INIT_ARCH
-# define INIT_ARCH()
-# define COMPAT_REDIRECT(name, proto, arglist) libc_ifunc (name, &__##name) \
-    compat_symbol (librt, name, name, GLIBC_2_2);
-#else
-# define COMPAT_REDIRECT(name, proto, arglist)				      \
-  int									      \
-  name proto								      \
-  {									      \
-    return __##name arglist;						      \
-  }									      \
-  compat_symbol (librt, name, name, GLIBC_2_2);
-#endif
-
-COMPAT_REDIRECT (clock_getres,
-		 (clockid_t clock_id, struct timespec *res),
-		 (clock_id, res))
-COMPAT_REDIRECT (clock_gettime,
-		 (clockid_t clock_id, struct timespec *tp),
-		 (clock_id, tp))
-COMPAT_REDIRECT (clock_settime,
-		 (clockid_t clock_id, const struct timespec *tp),
-		 (clock_id, tp))
-COMPAT_REDIRECT (clock_getcpuclockid,
-		 (pid_t pid, clockid_t *clock_id),
-		 (pid, clock_id))
-COMPAT_REDIRECT (clock_nanosleep,
-		 (clockid_t clock_id, int flags,
-		  const struct timespec *req,
-		  struct timespec *rem),
-		 (clock_id, flags, req, rem))
-
-#endif
diff --git a/sysdeps/mach/hurd/i386/librt.abilist b/sysdeps/mach/hurd/i386/librt.abilist
index d5fe32b3a9..3726e41f06 100644
--- a/sysdeps/mach/hurd/i386/librt.abilist
+++ b/sysdeps/mach/hurd/i386/librt.abilist
@@ -13,11 +13,6 @@ GLIBC_2.2.6 aio_suspend F
 GLIBC_2.2.6 aio_suspend64 F
 GLIBC_2.2.6 aio_write F
 GLIBC_2.2.6 aio_write64 F
-GLIBC_2.2.6 clock_getcpuclockid F
-GLIBC_2.2.6 clock_getres F
-GLIBC_2.2.6 clock_gettime F
-GLIBC_2.2.6 clock_nanosleep F
-GLIBC_2.2.6 clock_settime F
 GLIBC_2.2.6 lio_listio F
 GLIBC_2.2.6 lio_listio64 F
 GLIBC_2.2.6 shm_open F
diff --git a/sysdeps/unix/sysv/linux/alpha/librt.abilist b/sysdeps/unix/sysv/linux/alpha/librt.abilist
index d7a049cf60..71f86e03ce 100644
--- a/sysdeps/unix/sysv/linux/alpha/librt.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/arm/librt.abilist b/sysdeps/unix/sysv/linux/arm/librt.abilist
index cfbbd27557..3c0647b251 100644
--- a/sysdeps/unix/sysv/linux/arm/librt.abilist
+++ b/sysdeps/unix/sysv/linux/arm/librt.abilist
@@ -13,11 +13,6 @@ GLIBC_2.4 aio_suspend F
 GLIBC_2.4 aio_suspend64 F
 GLIBC_2.4 aio_write F
 GLIBC_2.4 aio_write64 F
-GLIBC_2.4 clock_getcpuclockid F
-GLIBC_2.4 clock_getres F
-GLIBC_2.4 clock_gettime F
-GLIBC_2.4 clock_nanosleep F
-GLIBC_2.4 clock_settime F
 GLIBC_2.4 lio_listio F
 GLIBC_2.4 lio_listio64 F
 GLIBC_2.4 mq_close F
diff --git a/sysdeps/unix/sysv/linux/hppa/librt.abilist b/sysdeps/unix/sysv/linux/hppa/librt.abilist
index 595f1b712a..bb03781dcc 100644
--- a/sysdeps/unix/sysv/linux/hppa/librt.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/i386/librt.abilist b/sysdeps/unix/sysv/linux/i386/librt.abilist
index 595f1b712a..bb03781dcc 100644
--- a/sysdeps/unix/sysv/linux/i386/librt.abilist
+++ b/sysdeps/unix/sysv/linux/i386/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/ia64/librt.abilist b/sysdeps/unix/sysv/linux/ia64/librt.abilist
index 804622a14a..08384c9065 100644
--- a/sysdeps/unix/sysv/linux/ia64/librt.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/librt.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/librt.abilist
index cfbbd27557..3c0647b251 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/librt.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/librt.abilist
@@ -13,11 +13,6 @@ GLIBC_2.4 aio_suspend F
 GLIBC_2.4 aio_suspend64 F
 GLIBC_2.4 aio_write F
 GLIBC_2.4 aio_write64 F
-GLIBC_2.4 clock_getcpuclockid F
-GLIBC_2.4 clock_getres F
-GLIBC_2.4 clock_gettime F
-GLIBC_2.4 clock_nanosleep F
-GLIBC_2.4 clock_settime F
 GLIBC_2.4 lio_listio F
 GLIBC_2.4 lio_listio64 F
 GLIBC_2.4 mq_close F
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/librt.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/librt.abilist
index 595f1b712a..bb03781dcc 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/librt.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/microblaze/librt.abilist b/sysdeps/unix/sysv/linux/microblaze/librt.abilist
index fb85d8729e..889dfbc0ee 100644
--- a/sysdeps/unix/sysv/linux/microblaze/librt.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/librt.abilist
@@ -14,11 +14,6 @@ GLIBC_2.18 aio_suspend F
 GLIBC_2.18 aio_suspend64 F
 GLIBC_2.18 aio_write F
 GLIBC_2.18 aio_write64 F
-GLIBC_2.18 clock_getcpuclockid F
-GLIBC_2.18 clock_getres F
-GLIBC_2.18 clock_gettime F
-GLIBC_2.18 clock_nanosleep F
-GLIBC_2.18 clock_settime F
 GLIBC_2.18 lio_listio F
 GLIBC_2.18 lio_listio64 F
 GLIBC_2.18 mq_close F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/librt.abilist b/sysdeps/unix/sysv/linux/mips/mips32/librt.abilist
index 84837c8a2e..1539c1cef9 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/librt.abilist
@@ -13,11 +13,6 @@ GLIBC_2.2 aio_suspend F
 GLIBC_2.2 aio_suspend64 F
 GLIBC_2.2 aio_write F
 GLIBC_2.2 aio_write64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 lio_listio F
 GLIBC_2.2 lio_listio64 F
 GLIBC_2.2 shm_open F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/librt.abilist b/sysdeps/unix/sysv/linux/mips/mips64/librt.abilist
index 84837c8a2e..1539c1cef9 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/librt.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/librt.abilist
@@ -13,11 +13,6 @@ GLIBC_2.2 aio_suspend F
 GLIBC_2.2 aio_suspend64 F
 GLIBC_2.2 aio_write F
 GLIBC_2.2 aio_write64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 lio_listio F
 GLIBC_2.2 lio_listio64 F
 GLIBC_2.2 shm_open F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
index 595f1b712a..bb03781dcc 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/librt.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/librt.abilist
index e76b7eb495..6a5bd96963 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/librt.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/librt.abilist
@@ -13,11 +13,6 @@ GLIBC_2.3 aio_suspend F
 GLIBC_2.3 aio_suspend64 F
 GLIBC_2.3 aio_write F
 GLIBC_2.3 aio_write64 F
-GLIBC_2.3 clock_getcpuclockid F
-GLIBC_2.3 clock_getres F
-GLIBC_2.3 clock_gettime F
-GLIBC_2.3 clock_nanosleep F
-GLIBC_2.3 clock_settime F
 GLIBC_2.3 lio_listio F
 GLIBC_2.3 lio_listio64 F
 GLIBC_2.3 shm_open F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/librt.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/librt.abilist
index 595f1b712a..bb03781dcc 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/librt.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/librt.abilist
index 41be3bb84b..5905498a48 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/librt.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/librt.abilist
@@ -13,11 +13,6 @@ GLIBC_2.2 aio_suspend F
 GLIBC_2.2 aio_suspend64 F
 GLIBC_2.2 aio_write F
 GLIBC_2.2 aio_write64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 lio_listio F
 GLIBC_2.2 lio_listio64 F
 GLIBC_2.2 shm_open F
diff --git a/sysdeps/unix/sysv/linux/sh/librt.abilist b/sysdeps/unix/sysv/linux/sh/librt.abilist
index 595f1b712a..bb03781dcc 100644
--- a/sysdeps/unix/sysv/linux/sh/librt.abilist
+++ b/sysdeps/unix/sysv/linux/sh/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/librt.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/librt.abilist
index cb874f4147..38f0aad791 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/librt.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/librt.abilist
index d7a049cf60..71f86e03ce 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/librt.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/librt.abilist
@@ -15,11 +15,6 @@ GLIBC_2.1 aio_write F
 GLIBC_2.1 aio_write64 F
 GLIBC_2.1 lio_listio F
 GLIBC_2.1 lio_listio64 F
-GLIBC_2.2 clock_getcpuclockid F
-GLIBC_2.2 clock_getres F
-GLIBC_2.2 clock_gettime F
-GLIBC_2.2 clock_nanosleep F
-GLIBC_2.2 clock_settime F
 GLIBC_2.2 shm_open F
 GLIBC_2.2 shm_unlink F
 GLIBC_2.2 timer_create F
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/librt.abilist b/sysdeps/unix/sysv/linux/x86_64/64/librt.abilist
index e2e8b60bf8..95e3f22daa 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/librt.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/librt.abilist
@@ -13,11 +13,6 @@ GLIBC_2.2.5 aio_suspend F
 GLIBC_2.2.5 aio_suspend64 F
 GLIBC_2.2.5 aio_write F
 GLIBC_2.2.5 aio_write64 F
-GLIBC_2.2.5 clock_getcpuclockid F
-GLIBC_2.2.5 clock_getres F
-GLIBC_2.2.5 clock_gettime F
-GLIBC_2.2.5 clock_nanosleep F
-GLIBC_2.2.5 clock_settime F
 GLIBC_2.2.5 lio_listio F
 GLIBC_2.2.5 lio_listio64 F
 GLIBC_2.2.5 shm_open F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/librt.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/librt.abilist
index 94e84e4dcf..66969fb9ab 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/librt.abilist
@@ -14,11 +14,6 @@ GLIBC_2.16 aio_suspend F
 GLIBC_2.16 aio_suspend64 F
 GLIBC_2.16 aio_write F
 GLIBC_2.16 aio_write64 F
-GLIBC_2.16 clock_getcpuclockid F
-GLIBC_2.16 clock_getres F
-GLIBC_2.16 clock_gettime F
-GLIBC_2.16 clock_nanosleep F
-GLIBC_2.16 clock_settime F
 GLIBC_2.16 lio_listio F
 GLIBC_2.16 lio_listio64 F
 GLIBC_2.16 mq_close F
diff --git a/time/Makefile b/time/Makefile
index d78bff85e6..7dddb5a858 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -36,14 +36,18 @@ routines := offtime asctime clock ctime ctime_r difftime \
 	    stime dysize timegm ftime			 \
 	    getdate strptime strptime_l			 \
 	    strftime wcsftime strftime_l wcsftime_l	 \
-	    timespec_get settimezone
+	    timespec_get settimezone 			 \
+	    clock_getcpuclockid clock_getres 		 \
+	    clock_gettime clock_settime clock_nanosleep
+
 aux :=	    era alt_digit lc-time-cleanup
 
 tests	:= test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
 	   tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \
 	   tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \
 	   tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \
-	   tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3
+	   tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3 \
+	   tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1
 
 include ../Rules
 
diff --git a/rt/clock_getcpuclockid.c b/time/clock_getcpuclockid.c
similarity index 100%
rename from rt/clock_getcpuclockid.c
rename to time/clock_getcpuclockid.c
diff --git a/rt/clock_getres.c b/time/clock_getres.c
similarity index 100%
rename from rt/clock_getres.c
rename to time/clock_getres.c
diff --git a/rt/clock_gettime.c b/time/clock_gettime.c
similarity index 100%
rename from rt/clock_gettime.c
rename to time/clock_gettime.c
diff --git a/rt/clock_nanosleep.c b/time/clock_nanosleep.c
similarity index 100%
rename from rt/clock_nanosleep.c
rename to time/clock_nanosleep.c
diff --git a/rt/clock_settime.c b/time/clock_settime.c
similarity index 100%
rename from rt/clock_settime.c
rename to time/clock_settime.c
diff --git a/rt/tst-clock.c b/time/tst-clock.c
similarity index 100%
rename from rt/tst-clock.c
rename to time/tst-clock.c
diff --git a/rt/tst-clock2.c b/time/tst-clock2.c
similarity index 100%
rename from rt/tst-clock2.c
rename to time/tst-clock2.c
diff --git a/rt/tst-clock_nanosleep.c b/time/tst-clock_nanosleep.c
similarity index 100%
rename from rt/tst-clock_nanosleep.c
rename to time/tst-clock_nanosleep.c
diff --git a/rt/tst-cpuclock1.c b/time/tst-cpuclock1.c
similarity index 100%
rename from rt/tst-cpuclock1.c
rename to time/tst-cpuclock1.c
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 12/12] Revise the documentation of ‘simple calendar time’.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (2 preceding siblings ...)
  2019-08-20 13:22 ` [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime Zack Weinberg
@ 2019-08-20 13:22 ` Zack Weinberg
  2019-08-20 18:50   ` Paul Eggert
  2019-08-20 13:22 ` [PATCH 01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday Zack Weinberg
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:22 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

This is a thorough revision of all the material relating to the
functions time, stime, gettimeofday, settimeofday, clock_gettime,
clock_getres, clock_settime, and difftime, spilling over into the
discussion of time-related data types (which now get their own
section) and touching the adjtime family as well (which deserves its
own thorough revision, but I’d have to do a bunch of research first).

Substantive changes are:

 * Document clock_gettime, clock_getres, and clock_settime.  (Only
   CLOCK_REALTIME and CLOCK_MONOTONIC are documented; the others are
   either a bit too Linux-specific, or have more to do with measuring
   CPU/processor time.  That section _also_ deserves its own thorough
   revision but again I’d have to do a bunch of research first.)

 * Present gettimeofday, settimeofday, and struct timeval as obsolete
   relative to clock_*.

 * Remove the documentation of struct timezone.  Matching POSIX,
   say that the type of the second argument to gettimeofday and
   settimeofday is [const] void *.

 * Clarify ISO C and POSIX’s requirements on time_t.  Clarify the
   circumstances under which difftime is equivalent to simple
   subtraction.

 * Consolidate documentation of most of the time-related data types
   into a new section “Time Types,” right after “Time Basics.”  (The
   exceptions are struct tm, which stays in “Broken-down Time,” and
   struct times, which stays in “Processor And CPU Time.”

 * The “Elapsed Time” section is now called “Calculating Elapsed Time”
   and includes only difftime and the discussion of how to compute
   timeval differences by hand.

 * Fold the “Simple Calendar Time,” “High Resolution Calendar,” and
   “High Accuracy Clock” sections together into two new sections titled
   “Getting the Time” and “Setting and Adjusting the Time.”

ChangeLog:
	* manual/time.texi: Major revision of text related to simple
	calendar time.  clock_gettime, clock_getres, and clock_settime
	are now documented.
	* manual/filesys.texi, manual/llio.texi, manual/threads.texi:
	Update cross-references to renamed sections in time.texi.

---
Large blocks of text are moved around, so the diff is not terribly
informative; reviewers may find it easier to apply the diff and then
read the changed sections of the rendered manual.

This patch also includes a NEWS update covering all of the
user-visible changes in this patch series.
---
 NEWS                |   53 ++-
 manual/filesys.texi |    2 +-
 manual/llio.texi    |   10 +-
 manual/threads.texi |    2 +-
 manual/time.texi    | 1062 ++++++++++++++++++++++++-------------------
 5 files changed, 655 insertions(+), 474 deletions(-)

diff --git a/NEWS b/NEWS
index 045720b3fb..721c3e4385 100644
--- a/NEWS
+++ b/NEWS
@@ -3,7 +3,7 @@ Copyright (C) 1992-2019 Free Software Foundation, Inc.
 See the end for copying conditions.
 
 Please send GNU C library bug reports via <https://sourceware.org/bugzilla/>
-using `glibc' in the "product" field.
+using ‘glibc’ in the "product" field.
 \f
 Version 2.31
 
@@ -25,6 +25,57 @@ Deprecated and removed features, and other changes affecting compatibility:
   Request 25 to TS 18661-1, as applied for C2X.  Existing binaries that pass
   floating-point arguments directly will continue to work.
 
+* On Linux-based systems, glibc now uses the clock_gettime and clock_settime
+  system calls to implement all of the other functions that get or set
+  the time: time, ftime, gettimeofday, stime, and settimeofday.
+
+  System calls and/or vDSO functions, if any, that directly implement these
+  functions will no longer be used, with one exception: ‘settimeofday’ may
+  still invoke the system call of the same name when its ‘tzp’ argument is
+  not a null pointer (see below).
+
+  This change was made because the Linux kernel maintainers intend to
+  provide only clock_gettime and clock_settime system calls on future new
+  architectures, and to deprecate the other system calls on existing
+  architectures.  It potentially breaks programs that use seccomp filters to
+  limit the set of system calls a process can use.
+
+* The ftime and gettimeofday functions will no longer report information
+  about a system-wide time zone.
+
+  This 4.2-BSD-era feature has been deprecated for many years, as it cannot
+  handle the full complexity of the world’s timezones, but hitherto we have
+  supported it on a best-effort basis.  Changes required to support 64-bit
+  time_t on 32-bit architectures have made this no longer practical.
+
+  As of this release, callers of ftime will always receive a ‘struct timeb’
+  whose timezone and dstflag fields are zero (as if the system were
+  operating on UTC).  Similarly, callers of gettimeofday with a non-null
+  ‘tzp’ argument will always receive a ‘struct timezone’ whose
+  tz_minuteswest and tz_dsttime fields are zero.
+
+* The settimeofday function _can_ still be used to set a system-wide time
+  zone when the operating system supports it.  This is because the Linux
+  kernel reused the API, on some architectures, to describe a system-wide
+  time-zone-like offset between the software clock maintained by the kernel,
+  and the “RTC” clock that keeps time when the system is shut down.
+
+  However, to reduce the odds of this offset being set by accident,
+  settimeofday can no longer be used to set the time and the offset
+  simultaneously; if both of its two arguments are non-null, the call
+  will fail (setting errno to EINVAL).
+
+  Callers attempting to set this offset should also be prepared for the call
+  to fail and set errno to ENOSYS; this already happens on the Hurd and on
+  some Linux architectures.  The Linux kernel maintainers are discussing a
+  more principled replacement for the reused API.  After a replacement
+  becomes available, we will change settimeofday to fail with ENOSYS on all
+  platforms when its ‘tzp’ argument is not a null pointer.
+
+  Note that settimeofday itself is obsolescent according to POSIX; programs
+  that set the system time should use clock_settime and/or ntp_adjtime
+  instead.
+
 Changes to build and runtime requirements:
 
   [Add changes to build and runtime requirements here]
diff --git a/manual/filesys.texi b/manual/filesys.texi
index d31dbb24b4..73e630842e 100644
--- a/manual/filesys.texi
+++ b/manual/filesys.texi
@@ -2899,7 +2899,7 @@ which extends its resolution.  These fields are called
 @code{st_atime_usec}, @code{st_mtime_usec}, and @code{st_ctime_usec};
 each has a value between 0 and 999,999, which indicates the time in
 microseconds.  They correspond to the @code{tv_usec} field of a
-@code{timeval} structure; see @ref{High-Resolution Calendar}.
+@code{timeval} structure; see @ref{Time Types}.
 
 The @code{utimes} function is like @code{utime}, but also lets you specify
 the fractional part of the file times.  The prototype for this function is
diff --git a/manual/llio.texi b/manual/llio.texi
index 447126b7eb..fe59002915 100644
--- a/manual/llio.texi
+++ b/manual/llio.texi
@@ -2094,11 +2094,11 @@ descriptors.  The usual thing is to pass @code{FD_SETSIZE} as the value
 of this argument.
 
 The @var{timeout} specifies the maximum time to wait.  If you pass a
-null pointer for this argument, it means to block indefinitely until one
-of the file descriptors is ready.  Otherwise, you should provide the
-time in @code{struct timeval} format; see @ref{High-Resolution
-Calendar}.  Specify zero as the time (a @code{struct timeval} containing
-all zeros) if you want to find out which descriptors are ready without
+null pointer for this argument, it means to block indefinitely until
+one of the file descriptors is ready.  Otherwise, you should provide
+the time in @code{struct timeval} format; see @ref{Time Types}.
+Specify zero as the time (a @code{struct timeval} containing all
+zeros) if you want to find out which descriptors are ready without
 waiting if none are ready.
 
 The normal return value from @code{select} is the total number of ready file
diff --git a/manual/threads.texi b/manual/threads.texi
index 0e5e84ab0a..bfe1e5b50b 100644
--- a/manual/threads.texi
+++ b/manual/threads.texi
@@ -128,7 +128,7 @@ function returns @math{0}; otherwise, the return value is non-zero.
 least until the elapsed time pointed to by @var{time_point} has been
 reached.  This function does not take an absolute time, but a duration
 that the thread is required to be blocked.  @xref{Time Basics}, and
-@ref{Elapsed Time}.
+@ref{Time Types}.
 
 The thread may wake early if a signal that is not ignored is received.
 In such a case, if @code{remaining} is not NULL, the remaining time
diff --git a/manual/time.texi b/manual/time.texi
index bfa46dd45b..b61d13c9ad 100644
--- a/manual/time.texi
+++ b/manual/time.texi
@@ -8,7 +8,8 @@ between different time representations.
 
 @menu
 * Time Basics::                 Concepts and definitions.
-* Elapsed Time::                Data types to represent elapsed times
+* Time Types::                  Data types to represent time.
+* Calculating Elapsed Time::    How to calculate the length of an interval.
 * Processor And CPU Time::      Time a program has spent executing.
 * Calendar Time::               Manipulation of ``real'' dates and times.
 * Setting an Alarm::            Sending a signal after a specified time.
@@ -55,100 +56,180 @@ especially when they are part of a sequence of regularly repeating
 events.
 @cindex period of time
 
-@dfn{CPU time} is like calendar time, except that it is based on the
-subset of the time continuum when a particular process is actively
-using a CPU.  CPU time is, therefore, relative to a process.
+A @dfn{simple calendar time} is a calendar time represented as an
+elapsed time since a fixed, implementation-specific calendar time
+called the @dfn{epoch}.  This representation is convenient for doing
+calculations on calendar times, such as finding the elapsed time
+between two calendar times.  Simple calendar times are independent of
+time zone; they represent the same instant in time regardless of where
+on the globe the computer is.
+@cindex simple time
+@cindex simple calendar time
+@cindex calendar time, simple
+@cindex epoch
+
+A @dfn{broken-down time} is a calendar time represented by its
+components in the Gregorian calendar: year, month, day, hour, minute,
+and second.  A broken-down time value is relative to a specific time
+zone, and so it is also sometimes called a @dfn{local time}.
+Broken-down times are most useful for input and output, as they are
+easier for people to understand, but more difficult to calculate with.
+@cindex broken-down time
+@cindex local time
+@cindex Gregorian calendar
+@cindex calendar, Gregorian
+
+@dfn{CPU time} measures the amount of time that a single process has
+actively used a CPU to perform computations.  It does not include the
+time that process has spent waiting for external events.  The system
+tracks the CPU time used by each process separately.
 @cindex CPU time
 
-@dfn{Processor time} is an amount of time that a CPU is in use.  In
-fact, it's a basic system resource, since there's a limit to how much
-can exist in any given interval (that limit is the elapsed time of the
-interval times the number of CPUs in the processor).  People often call
-this CPU time, but we reserve the latter term in this manual for the
-definition above.
+@dfn{Processor time} measures the amount of time @emph{any} CPU has
+been in use by @emph{any} process.  It is a basic system resource,
+since there's a limit to how much can exist in any given interval (the
+elapsed time of the interval times the number of CPUs in the computer)
+
+People often call this CPU time, but we reserve the latter term in
+this manual for the definition above.
 @cindex processor time
 
-@node Elapsed Time
-@section Elapsed Time
-@cindex elapsed time
+@node Time Types
+@section Time Types
 
-One way to represent an elapsed time is with a simple arithmetic data
-type, as with the following function to compute the elapsed time between
-two calendar times.  This function is declared in @file{time.h}.
+ISO C and POSIX define several data types for representing elapsed
+times, simple calendar times, and broken-down times.
 
-@deftypefun double difftime (time_t @var{time1}, time_t @var{time0})
+@deftp {Data Type} clock_t
 @standards{ISO, time.h}
-@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
-The @code{difftime} function returns the number of seconds of elapsed
-time between calendar time @var{time1} and calendar time @var{time0}, as
-a value of type @code{double}.  The difference ignores leap seconds
-unless leap second support is enabled.
+@code{clock_t} is used to measure processor and CPU time.  Its values
+are counts of @dfn{clock ticks} since some arbitrary event.  The
+number of clock ticks per second is system-specific.
+@xref{Processor And CPU Time}, for further detail.
+@cindex clock ticks
+@cindex ticks, clock
+@end deftp
 
-In @theglibc{}, you can simply subtract @code{time_t} values.  But on
-other systems, the @code{time_t} data type might use some other encoding
-where subtraction doesn't work directly.
-@end deftypefun
+@deftp {Data Type} time_t
+@standards{ISO, time.h}
+@code{time_t} is the simplest data type used to represent simple
+calendar time.
+
+In ISO C, @code{time_t} can be either an integer or a floating-point
+type, and the meaning of @code{time_t} values is not specified.  The
+only things a strictly conforming program can do with @code{time_t}
+values are: pass them to @code{difftime} to get the elapsed time
+between two simple calendar times (@pxref{Calculating Elapsed Time}),
+and pass them to the functions that convert them to broken-down time
+(@pxref{Broken-down Time}).
+
+On POSIX-conformant systems, @code{time_t} is an integer type and its
+values represent the number of seconds elapsed since the @dfn{epoch},
+which is 00:00:00 on January 1, 1970, Coordinated Universal Time.
+@Theglibc{} additionally guarantees that @code{time_t} is a signed
+type, and that negative values can be used to represent calendar times
+before the epoch.
+
+POSIX says that @code{time_t} values do not include leap seconds, but
+some systems interpret them as including leap seconds when the
+@code{TZ} environment variable is set a certain way
+(@pxref{TZ Variable}).  This only affects conversions to broken-down
+time.
+@cindex epoch
+@cindex leap seconds
+@cindex seconds, leap
+@end deftp
 
-@Theglibc{} provides two data types specifically for representing
-an elapsed time.  They are used by various @glibcadj{} functions, and
-you can use them for your own purposes too.  They're exactly the same
-except that one has a resolution in microseconds, and the other, newer
-one, is in nanoseconds.
+@deftp {Data Type} {struct timespec}
+@standards{POSIX.1, time.h}
+@cindex timespec
+@code{struct timespec} represents a simple calendar time, or an
+elapsed time, with sub-second resolution.  It is declared in
+@file{time.h} and has the following members:
+
+@table @code
+@item time_t tv_sec
+The number of whole seconds elapsed since the epoch (for a simple
+calendar time) or since some other starting point (for an elapsed
+time).
+
+@item long int tv_nsec
+The number of nanoseconds elapsed since the time given by the
+@code{tv_sec} member.
+
+When @code{struct timespec} values are produced by @glibcadj{}
+functions, the value in this field will always be greater than or
+equal to zero, and less than 1,000,000,000.
+When @code{struct timespec} values are supplied to @glibcadj{}
+functions, the value in this field must be in the same range.
+@end table
+@end deftp
 
 @deftp {Data Type} {struct timeval}
 @standards{BSD, sys/time.h}
 @cindex timeval
-The @code{struct timeval} structure represents an elapsed time.  It is
-declared in @file{sys/time.h} and has the following members:
+@code{struct timeval} is an older type for representing a simple
+calendar time, or an elapsed time, with sub-second resolution. It is
+almost the same as @code{struct timespec}, but provides only
+microsecond resolution.  It is declared in @file{sys/time.h} and has
+the following members:
 
 @table @code
 @item time_t tv_sec
-This represents the number of whole seconds of elapsed time.
+The number of whole seconds elapsed since the epoch (for a simple
+calendar time) or since some other starting point (for an elapsed
+time).
 
 @item long int tv_usec
-This is the rest of the elapsed time (a fraction of a second),
-represented as the number of microseconds.  It is always less than one
-million.
-
+The number of microseconds elapsed since the time given by the
+@code{tv_sec} member.
+
+When @code{struct timeval} values are produced by @glibcadj{}
+functions, the value in this field will always be greater than or
+equal to zero, and less than 1,000,000.
+When @code{struct timeval} values are supplied to @glibcadj{}
+functions, the value in this field must be in the same range.
 @end table
 @end deftp
 
-@deftp {Data Type} {struct timespec}
-@standards{POSIX.1, sys/time.h}
-@cindex timespec
-The @code{struct timespec} structure represents an elapsed time.  It is
-declared in @file{time.h} and has the following members:
+@deftp {Data Type} {struct tm}
+@standards{ISO, time.h}
+This is the data type used to represent a broken-down time.  It has
+separate fields for year, month, day, and so on.
+@xref{Broken-down Time}, for further details.
+@end deftp
 
-@table @code
-@item time_t tv_sec
-This represents the number of whole seconds of elapsed time.
+@node Calculating Elapsed Time
+@section Calculating Elapsed Time
 
-@item long int tv_nsec
-This is the rest of the elapsed time (a fraction of a second),
-represented as the number of nanoseconds.  It is always less than one
-billion.
+Often, one wishes to calculate an elapsed time as the difference
+between two simple calendar times.  @Theglibc{} provides only one
+function for this purpose.
 
-@end table
-@end deftp
+@deftypefun double difftime (time_t @var{end}, time_t @var{begin})
+@standards{ISO, time.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+The @code{difftime} function returns the number of seconds of elapsed
+time from calendar time @var{begin} to calendar time @var{end}, as
+a value of type @code{double}.  The calculation is unaware of whether
+or not @var{begin} and @var{end} are meant to include leap seconds.
+
+On POSIX-conformant systems, @samp{difftime (end, begin)} produces the
+same result as the expression @samp{(double)(end - begin)}.  But on
+other systems, @code{time_t} values might be encoded in a way that
+prevents subtraction from working directly.
+@end deftypefun
 
-It is often necessary to subtract two values of type @w{@code{struct
-timeval}} or @w{@code{struct timespec}}.  Here is the best way to do
-this.  It works even on some peculiar operating systems where the
-@code{tv_sec} member has an unsigned type.
+@Theglibc{} does not provide any functions for computing the
+difference between two values of type @w{@code{struct timeval}} or
+@w{@code{struct timespec}}.  Here is the recommended way to do this
+calculation by hand.  It works even on some peculiar operating systems
+where the @code{tv_sec} member has an unsigned type.
 
 @smallexample
 @include timeval_subtract.c.texi
 @end smallexample
 
-Common functions that use @code{struct timeval} are @code{gettimeofday}
-and @code{settimeofday}.
-
-
-There are no @glibcadj{} functions specifically oriented toward
-dealing with elapsed times, but the calendar time, processor time, and
-alarm and sleeping functions have a lot to do with them.
-
-
 @node Processor And CPU Time
 @section Processor And CPU Time
 
@@ -233,12 +314,6 @@ by the @code{clock} function.  POSIX requires that this value be one
 million independent of the actual resolution.
 @end deftypevr
 
-@deftp {Data Type} clock_t
-@standards{ISO, time.h}
-This is the type of the value returned by the @code{clock} function.
-Values of type @code{clock_t} are numbers of clock ticks.
-@end deftp
-
 @deftypefun clock_t clock (void)
 @standards{ISO, time.h}
 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
@@ -331,43 +406,15 @@ and @code{tms_stime} fields returned by @code{times}.
 @node Calendar Time
 @section Calendar Time
 
-This section describes facilities for keeping track of calendar time.
-@xref{Time Basics}.
-
-@Theglibc{} represents calendar time three ways:
-
-@itemize @bullet
-@item
-@dfn{Simple time} (the @code{time_t} data type) is a compact
-representation, typically giving the number of seconds of elapsed time
-since some implementation-specific base time.
-@cindex simple time
-
-@item
-There is also a "high-resolution time" representation.  Like simple
-time, this represents a calendar time as an elapsed time since a base
-time, but instead of measuring in whole seconds, it uses a @code{struct
-timeval} data type, which includes fractions of a second.  Use this time
-representation instead of simple time when you need greater precision.
-@cindex high-resolution time
-
-@item
-@dfn{Local time} or @dfn{broken-down time} (the @code{struct tm} data
-type) represents a calendar time as a set of components specifying the
-year, month, and so on in the Gregorian calendar, for a specific time
-zone.  This calendar time representation is usually used only to
-communicate with people.
-@cindex local time
-@cindex broken-down time
-@cindex Gregorian calendar
-@cindex calendar, Gregorian
-@end itemize
+This section describes the functions for getting, setting, and
+manipulating calendar times.
 
 @menu
-* Simple Calendar Time::        Facilities for manipulating calendar time.
-* High-Resolution Calendar::    A time representation with greater precision.
+* Getting the Time::            Functions for finding out what time it is.
+* Setting and Adjusting the Time::
+                                Functions for setting and adjusting
+                                  the system clock.
 * Broken-down Time::            Facilities for manipulating local time.
-* High Accuracy Clock::         Maintaining a high accuracy system clock.
 * Formatting Calendar Time::    Converting times to strings.
 * Parsing Date and Time::       Convert textual time and date information back
                                  into broken-down time values.
@@ -377,175 +424,419 @@ communicate with people.
 				 the time functions.
 @end menu
 
-@node Simple Calendar Time
-@subsection Simple Calendar Time
+@node Getting the Time
+@subsection Getting the Time
 
-This section describes the @code{time_t} data type for representing calendar
-time as simple time, and the functions which operate on simple time objects.
-These facilities are declared in the header file @file{time.h}.
-@pindex time.h
+@Theglibc{} provides several functions for getting the current
+calendar time, with different levels of resolution.
 
-@cindex epoch
-@deftp {Data Type} time_t
+@deftypefun time_t time (time_t *@var{result})
 @standards{ISO, time.h}
-This is the data type used to represent simple time.  Sometimes, it also
-represents an elapsed time.  When interpreted as a calendar time value,
-it represents the number of seconds elapsed since 00:00:00 on January 1,
-1970, Coordinated Universal Time.  (This calendar time is sometimes
-referred to as the @dfn{epoch}.)  POSIX requires that this count not
-include leap seconds, but on some systems this count includes leap seconds
-if you set @code{TZ} to certain values (@pxref{TZ Variable}).
-
-Note that a simple time has no concept of local time zone.  Calendar
-Time @var{T} is the same instant in time regardless of where on the
-globe the computer is.
-
-In @theglibc{}, @code{time_t} is equivalent to @code{long int}.
-In other systems, @code{time_t} might be either an integer or
-floating-point type.
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+This is the simplest function for getting the current calendar time.
+It returns the calendar time as a value of type @code{time_t}; on
+POSIX systems, that means it has a resolution of one second.  It
+uses the same clock as @w{@samp{clock_gettime (CLOCK_REALTIME)}}
+and @code{gettimeofday} (see below).
+
+If the argument @var{result} is not a null pointer, the calendar time
+value is also stored in @code{*@var{result}}.
+
+This function cannot fail.
+@end deftypefun
+
+Some applications need more precise timekeeping than is possible with
+a @code{time_t} alone.  Some applications also need more control over
+what is meant by ``the current time.''  For these applications, POSIX
+provides a function @code{clock_gettime} that can retrieve the time
+with up to nanosecond precision, from a variety of different clocks.
+Clocks can be system-wide, measuring time the same for all processes;
+or they can be per-process or per-thread, measuring CPU time consumed
+by a particular process, or some other similar resource.  Each clock
+has its own resolution and epoch.  You can find the resolution of a
+clock with the function @code{clock_getres}.  There is no function to
+get the epoch for a clock; either it is fixed and documented, or the
+clock is not meant to be used to measure absolute times.
+
+@deftp {Data Type} clockid_t
+@standards{POSIX.1, time.h}
+The type @code{clockid_t} is used for constants that indicate which of
+several system clocks one wishes to use.
 @end deftp
 
-The function @code{difftime} tells you the elapsed time between two
-simple calendar times, which is not always as easy to compute as just
-subtracting.  @xref{Elapsed Time}.
+All systems that support this family of functions will define at least
+this clock constant:
 
-@deftypefun time_t time (time_t *@var{result})
-@standards{ISO, time.h}
-@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
-The @code{time} function returns the current calendar time as a value of
-type @code{time_t}.  If the argument @var{result} is not a null pointer,
-the calendar time value is also stored in @code{*@var{result}}.  If the
-current calendar time is not available, the value
-@w{@code{(time_t)(-1)}} is returned.
+@deftypevr Macro clockid_t CLOCK_REALTIME
+@standards{POSIX.1, time.h}
+System-wide clock measuring calendar time.  This clock reports the
+same time as @code{time} (above) and @code{gettimeofday} (below) and
+uses the POSIX epoch, 00:00:00 on January 1, 1970, Coordinated
+Universal Time.
+@end deftypevr
+
+@cindex monotonic time
+A second clock constant which is not universal, but still very common,
+is for a clock measuring @dfn{monotonic time}.  Monotonic time is
+useful for measuring elapsed times, because it guarantees that those
+measurements are not affected by changes to the system clock.
+
+@deftypevr Macro clockid_t CLOCK_MONOTONIC
+@standards{POSIX.1, time.h}
+System-wide clock that continuously measures the advancement of
+calendar time, ignoring discontinuous changes to the system's
+setting for absolute calendar time.
+
+The epoch for this clock is an unspecified point in the past.
+The epoch may change if the system is rebooted or suspended.
+Therefore, @code{CLOCK_MONOTONIC} cannot be used to measure
+absolute time, only elapsed time.
+@end deftypevr
+
+Systems may support more than just these two clocks.
+
+@deftypefun int clock_gettime (clockid_t @var{clock}, struct timespec *@var{ts})
+@standards{POSIX.1, time.h}
+Get the current time accoding to the clock identified by @var{clock},
+storing it as seconds and nanoseconds in @code{*@var{ts}}.
+@xref{Time Types}, for a description of @code{struct timespec}.
+
+The return value is @code{0} on success and @code{-1} on failure.  The
+following @code{errno} error condition is defined for this function:
+
+@table @code
+@item EINVAL
+The clock identified by @var{clock} is not supported.
+@end table
 @end deftypefun
 
-@c The GNU C library implements stime() with a call to settimeofday() on
-@c Linux.
-@deftypefun int stime (const time_t *@var{newtime})
-@standards{SVID, time.h}
-@standards{XPG, time.h}
+@code{clock_gettime} reports the time scaled to seconds and
+nanoseconds, but the actual resolution of each clock may not be as
+fine as one nanosecond, and may not be the same for all clocks.  POSIX
+also provides a function for finding out the actual resolution of a
+clock:
+
+@deftypefun int clock_getres (clockid_t @var{clock}, struct timespec *@var{res})
+@standards{POSIX.1, time.h}
+Get the actual resolution of the clock identified by @var{clock},
+storing it in @code{*@var{ts}}.
+
+For instance, if the clock hardware for @code{CLOCK_REALTIME}
+uses a quartz crystal that oscillates at 32.768 kHz,
+then its resolution would be 30.518 microseconds,
+and @w{@samp{clock_getres (CLOCK_REALTIME, &r)}} would set
+@code{r.tv_sec} to 0 and @code{r.tv_nsec} to 30518.
+
+The return value is @code{0} on success and @code{-1} on failure.  The
+following @code{errno} error condition is defined for this function:
+
+@table @code
+@item EINVAL
+The clock identified by @var{clock} is not supported.
+@end table
+@end deftypefun
+
+These functions, and the constants that identify particular clocks,
+are declared in @file{time.h}.
+
+@strong{Portability Note:} On some systems, including systems that use
+older versions of @theglibc{}, programs that use @code{clock_gettime}
+or @code{clock_setres} must be linked with the @code{-lrt} library.
+This has not been necessary with @theglibc{} since version 2.17.
+
+@Theglibc{} also provides an older, but still widely used, function
+for getting the current time with a resolution of microseconds.  This
+function is declared in @file{sys/time.h}.
+
+@deftypefun int gettimeofday (struct timeval *@var{tp}, void *@var{tzp})
+@standards{BSD, sys/time.h}
 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
-@c On unix, this is implemented in terms of settimeofday.
-@code{stime} sets the system clock, i.e., it tells the system that the
-current calendar time is @var{newtime}, where @code{newtime} is
-interpreted as described in the above definition of @code{time_t}.
+Get the current calendar time, storing it as seconds and microseconds
+in @code{*@var{tp}}.  @xref{Time Types}, for a description of
+@code{struct timeval}.  @code{gettimeofday} uses the same clock as
+@code{time} and @w{@samp{clock_gettime (CLOCK_REALTIME)}}.
+
+On some historic systems, if @var{tzp} was not a null pointer,
+information about a system-wide time zone would be written to
+@code{*@var{tzp}}.  This feature is obsolete and not supported on
+@gnusystems{}.  You should always supply a null pointer for this
+argument.  Instead, use the facilities described in @ref{Time Zone
+Functions} and in @ref{Broken-down Time} for working with time zones.
+
+This function cannot fail, and its return value is always @code{0}.
+
+@strong{Portability Note:} As of the 2008 revision of POSIX, this
+function is considered obsolete.  @Theglibc{} will continue to provide
+this function indefinitely, but new programs should use
+@code{clock_gettime} instead.
+@end deftypefun
 
-@code{settimeofday} is a newer function which sets the system clock to
-better than one second precision.  @code{settimeofday} is generally a
-better choice than @code{stime}.  @xref{High-Resolution Calendar}.
+@node Setting and Adjusting the Time
+@subsection Setting and Adjusting the Time
 
-Only the superuser can set the system clock.
+The clock hardware inside a modern computer is quite reliable, but it
+can still be wrong.  The functions in this section allow one to set
+the system's idea of the current calendar time, and to adjust the rate
+at which the system counts seconds, so that the calendar time will
+both be accurate, and remain accurate.
 
-If the function succeeds, the return value is zero.  Otherwise, it is
-@code{-1} and @code{errno} is set accordingly:
+The functions in this section require special privileges to use.
+@xref{Users and Groups}.
+
+@deftypefun int clock_settime (clockid_t @var{clock}, const struct timespec *@var{ts})
+@standards{POSIX, time.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+Change the current calendar time, according to the clock identified by
+@var{clock}, to be the simple calendar time in @code{*@var{ts}}.
+
+Not all of the system's clocks can be changed.  For instance, the
+@code{CLOCK_REALTIME} clock can be changed (with the appropriate
+privileges), but the @code{CLOCK_MONOTONIC} clock cannot.
+
+Because simple calendar times are independent of time zone, this
+function should not be used when the time zone changes (e.g.@: if the
+computer is physically moved from one zone to another).  Instead, use
+the facilities described in @ref{Time Zone Functions} (but see below
+for an exception).
+
+@code{clock_settime} causes the clock to jump forwards or backwards,
+which can cause a variety of problems.  Changing the
+@code{CLOCK_REALTIME} clock with @code{clock_settime} does not affect
+when timers expire (@pxref{Setting an Alarm}) or when sleeping
+processes wake up (@pxref{Sleeping}), which avoids some of the
+problems.  Still, for small changes made while the system is running,
+it is better to use @code{ntp_adjtime} (below) to make a smooth
+transition from one time to another.
+
+The return value is @code{0} on success and @code{-1} on failure.  The
+following @code{errno} error conditions are defined for this function:
 
 @table @code
+@item EINVAL
+The clock identified by @var{clock} is not supported or cannot be set
+at all, or the simple calendar time in @code{*@var{ts}} is invalid
+(for instance, @code{ts->tv_nsec} is negative or greater than 999,999,999).
+
 @item EPERM
-The process is not superuser.
+This process does not have the privileges required to set the clock
+identified by @var{clock}.
 @end table
+
+@strong{Portability Note}: On some systems, including systems that use
+older versions of @theglibc{}, programs that use @code{clock_settime}
+must be linked with the @code{-lrt} library.  This has not been
+necessary with @theglibc{} since version 2.17.
 @end deftypefun
 
+@cindex time, high precision
+@cindex clock, high accuracy
+@cindex clock, disciplining
+@pindex sys/timex.h
+For systems that remain up and running for long periods, it is not
+enough to set the time once; one should also @dfn{discipline} the
+clock so that it does not drift away from the true calendar time.
 
+The @code{ntp_gettime} and @code{ntp_adjtime} functions provide an
+interface to monitor and discipline the system clock.  For example,
+you can fine-tune the rate at which the clock ``ticks,'' and make
+small adjustments to the current reported calendar time smoothly, by
+temporarily speeding up or slowing down the clock.
 
-@node High-Resolution Calendar
-@subsection High-Resolution Calendar
+These functions' names begin with @samp{ntp_} because they were
+designed for use by programs implementing the Network Time Protocol to
+synchronize a system's clock with other systems' clocks and/or with
+external high-precision clock hardware.
 
-The @code{time_t} data type used to represent simple times has a
-resolution of only one second.  Some applications need more precision.
+These functions, and the constants and structures they use, are
+declared in @file{sys/timex.h}.
 
-So, @theglibc{} also contains functions which are capable of
-representing calendar times to a higher resolution than one second.  The
-functions and the associated data types described in this section are
-declared in @file{sys/time.h}.
-@pindex sys/time.h
+@tindex struct ntptimeval
+@deftp {Data Type} {struct ntptimeval}
+This structure is used to report information about the system clock.
+It contains the following members:
+@table @code
+@item struct timeval time
+The current calendar time, as if retrieved by @code{gettimeofday}.
+The @code{struct timeval} data type is described in
+@ref{Time Types}.
 
-@deftp {Data Type} {struct timezone}
-@standards{BSD, sys/time.h}
-The @code{struct timezone} structure is used to hold minimal information
-about the local time zone.  It has the following members:
+@item long int maxerror
+This is the maximum error, measured in microseconds.  Unless updated
+via @code{ntp_adjtime} periodically, this value will reach some
+platform-specific maximum value.
+
+@item long int esterror
+This is the estimated error, measured in microseconds.  This value can
+be set by @code{ntp_adjtime} to indicate the estimated offset of the
+system clock from the true calendar time.
+@end table
+@end deftp
+
+@deftypefun int ntp_gettime (struct ntptimeval *@var{tptr})
+@standards{GNU, sys/timex.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c Wrapper for adjtimex.
+The @code{ntp_gettime} function sets the structure pointed to by
+@var{tptr} to current values.  The elements of the structure afterwards
+contain the values the timer implementation in the kernel assumes.  They
+might or might not be correct.  If they are not, an @code{ntp_adjtime}
+call is necessary.
 
+The return value is @code{0} on success and other values on failure.  The
+following @code{errno} error conditions are defined for this function:
+
+@vtable @code
+@item TIME_ERROR
+The precision clock model is not properly set up at the moment, thus the
+clock must be considered unsynchronized, and the values should be
+treated with care.
+@end vtable
+@end deftypefun
+
+@tindex struct timex
+@deftp {Data Type} {struct timex}
+This structure is used to control and monitor the system clock.  It
+contains the following members:
 @table @code
-@item int tz_minuteswest
-This is the number of minutes west of UTC.
+@item unsigned int modes
+This variable controls whether and which values are set.  Several
+symbolic constants have to be combined with @emph{binary or} to specify
+the effective mode.  These constants start with @code{MOD_}.
 
-@item int tz_dsttime
-If nonzero, Daylight Saving Time applies during some part of the year.
-@end table
+@item long int offset
+This value indicates the current offset of the system clock from the true
+calendar time.  The value is given in microseconds.  If bit
+@code{MOD_OFFSET} is set in @code{modes}, the offset (and possibly other
+dependent values) can be set.  The offset's absolute value must not
+exceed @code{MAXPHASE}.
+
+
+@item long int frequency
+This value indicates the difference in frequency between the true
+calendar time and the system clock.  The value is expressed as scaled
+PPM (parts per million, 0.0001%).  The scaling is @code{1 <<
+SHIFT_USEC}.  The value can be set with bit @code{MOD_FREQUENCY}, but
+the absolute value must not exceed @code{MAXFREQ}.
+
+@item long int maxerror
+This is the maximum error, measured in microseconds.  A new value can be
+set using bit @code{MOD_MAXERROR}.  Unless updated via
+@code{ntp_adjtime} periodically, this value will increase steadily
+and reach some platform-specific maximum value.
+
+@item long int esterror
+This is the estimated error, measured in microseconds.  This value can
+be set using bit @code{MOD_ESTERROR}.
+
+@item int status
+This variable reflects the various states of the clock machinery.  There
+are symbolic constants for the significant bits, starting with
+@code{STA_}.  Some of these flags can be updated using the
+@code{MOD_STATUS} bit.
+
+@item long int constant
+This value represents the bandwidth or stiffness of the PLL (phase
+locked loop) implemented in the kernel.  The value can be changed using
+bit @code{MOD_TIMECONST}.
+
+@item long int precision
+This value represents the accuracy or the maximum error when reading the
+system clock.  The value is expressed in microseconds.
+
+@item long int tolerance
+This value represents the maximum frequency error of the system clock in
+scaled PPM.  This value is used to increase the @code{maxerror} every
+second.
+
+@item struct timeval time
+The current calendar time.
+
+@item long int tick
+The elapsed time between clock ticks in microseconds.  A clock tick is a
+periodic timer interrupt on which the system clock is based.
+
+@item long int ppsfreq
+This is the first of a few optional variables that are present only if
+the system clock can use a PPS (pulse per second) signal to discipline
+the system clock.  The value is expressed in scaled PPM and it denotes
+the difference in frequency between the system clock and the PPS signal.
+
+@item long int jitter
+This value expresses a median filtered average of the PPS signal's
+dispersion in microseconds.
+
+@item int shift
+This value is a binary exponent for the duration of the PPS calibration
+interval, ranging from @code{PPS_SHIFT} to @code{PPS_SHIFTMAX}.
+
+@item long int stabil
+This value represents the median filtered dispersion of the PPS
+frequency in scaled PPM.
+
+@item long int jitcnt
+This counter represents the number of pulses where the jitter exceeded
+the allowed maximum @code{MAXTIME}.
+
+@item long int calcnt
+This counter reflects the number of successful calibration intervals.
+
+@item long int errcnt
+This counter represents the number of calibration errors (caused by
+large offsets or jitter).
 
-The @code{struct timezone} type is obsolete and should never be used.
-Instead, use the facilities described in @ref{Time Zone Functions}.
+@item long int stbcnt
+This counter denotes the number of calibrations where the stability
+exceeded the threshold.
+@end table
 @end deftp
 
-@deftypefun int gettimeofday (struct timeval *@var{tp}, struct timezone *@var{tzp})
-@standards{BSD, sys/time.h}
+@deftypefun int ntp_adjtime (struct timex *@var{tptr})
+@standards{GNU, sys/timex.h}
 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
-@c On most GNU/Linux systems this is a direct syscall, but the posix/
-@c implementation (not used on GNU/Linux or GNU/Hurd) relies on time and
-@c localtime_r, saving and restoring tzname in an unsafe manner.
-@c On some GNU/Linux variants, ifunc resolvers are used in shared libc
-@c for vdso resolution.  ifunc-vdso-revisit.
-The @code{gettimeofday} function returns the current calendar time as
-the elapsed time since the epoch in the @code{struct timeval} structure
-indicated by @var{tp}.  (@pxref{Elapsed Time} for a description of
-@code{struct timeval}).  Information about the time zone is returned in
-the structure pointed to by @var{tzp}.  If the @var{tzp} argument is a null
-pointer, time zone information is ignored.
+@c Alias to adjtimex syscall.
+The @code{ntp_adjtime} function sets the structure specified by
+@var{tptr} to current values.
+
+In addition, @code{ntp_adjtime} updates some settings to match what you
+pass to it in *@var{tptr}.  Use the @code{modes} element of *@var{tptr}
+to select what settings to update.  You can set @code{offset},
+@code{freq}, @code{maxerror}, @code{esterror}, @code{status},
+@code{constant}, and @code{tick}.
 
-The return value is @code{0} on success and @code{-1} on failure.  The
-following @code{errno} error condition is defined for this function:
+@code{modes} = zero means set nothing.
 
-@table @code
-@item ENOSYS
-The operating system does not support getting time zone information, and
-@var{tzp} is not a null pointer.  @gnusystems{} do not
-support using @w{@code{struct timezone}} to represent time zone
-information; that is an obsolete feature of 4.3 BSD.
-Instead, use the facilities described in @ref{Time Zone Functions}.
-@end table
-@end deftypefun
+Only the superuser can update settings.
 
-@deftypefun int settimeofday (const struct timeval *@var{tp}, const struct timezone *@var{tzp})
-@standards{BSD, sys/time.h}
-@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
-@c On HURD, it calls host_set_time with a privileged port.  On other
-@c unix systems, it's a syscall.
-The @code{settimeofday} function sets the current calendar time in the
-system clock according to the arguments.  As for @code{gettimeofday},
-the calendar time is represented as the elapsed time since the epoch.
-As for @code{gettimeofday}, time zone information is ignored if
-@var{tzp} is a null pointer.
-
-You must be a privileged user in order to use @code{settimeofday}.
-
-Some kernels automatically set the system clock from some source such as
-a hardware clock when they start up.  Others, including Linux, place the
-system clock in an ``invalid'' state (in which attempts to read the clock
-fail).  A call of @code{stime} removes the system clock from an invalid
-state, and system startup scripts typically run a program that calls
-@code{stime}.
-
-@code{settimeofday} causes a sudden jump forwards or backwards, which
-can cause a variety of problems in a system.  Use @code{adjtime} (below)
-to make a smooth transition from one time to another by temporarily
-speeding up or slowing down the clock.
-
-With a Linux kernel, @code{adjtimex} does the same thing and can also
-make permanent changes to the speed of the system clock so it doesn't
-need to be corrected as often.
+@c On Linux, ntp_adjtime() also does the adjtime() function if you set
+@c modes = ADJ_OFFSET_SINGLESHOT (in fact, that is how GNU libc implements
+@c adjtime()).  But this should be considered an internal function because
+@c it's so inconsistent with the rest of what ntp_adjtime() does and is
+@c forced in an ugly way into the struct timex.  So we don't document it
+@c and instead document adjtime() as the way to achieve the function.
 
-The return value is @code{0} on success and @code{-1} on failure.  The
+The return value is @code{0} on success and other values on failure.  The
 following @code{errno} error conditions are defined for this function:
 
 @table @code
+@item TIME_ERROR
+The high accuracy clock model is not properly set up at the moment, thus the
+clock must be considered unsynchronized, and the values should be
+treated with care.  Another reason could be that the specified new values
+are not allowed.
+
 @item EPERM
-This process cannot set the clock because it is not privileged.
+The process specified a settings update, but is not superuser.
 
-@item ENOSYS
-The operating system does not support setting time zone information, and
-@var{tzp} is not a null pointer.
 @end table
+
+For more details see RFC1305 (Network Time Protocol, Version 3) and
+related documents.
+
+@strong{Portability note:} Early versions of @theglibc{} did not
+have this function, but did have the synonymous @code{adjtimex}.
 @end deftypefun
 
+
 @c On Linux, GNU libc implements adjtime() as a call to adjtimex().
 @deftypefun int adjtime (const struct timeval *@var{delta}, struct timeval *@var{olddelta})
 @standards{BSD, sys/time.h}
@@ -553,10 +844,11 @@ The operating system does not support setting time zone information, and
 @c On hurd and mach, call host_adjust_time with a privileged port.  On
 @c Linux, it's implemented in terms of adjtimex.  On other unixen, it's
 @c a syscall.
-This function speeds up or slows down the system clock in order to make
-a gradual adjustment.  This ensures that the calendar time reported by
-the system clock is always monotonically increasing, which might not
-happen if you simply set the clock.
+This simpler version of @code{ntp_adjtime} speeds up or slows down the
+system clock for a short time, in order to correct it by a small
+amount.  This avoids a discontinuous change in the calendar time
+reported by the @code{CLOCK_REALTIME} clock, at the price of having to
+wait longer for the time to become correct.
 
 The @var{delta} argument specifies a relative adjustment to be made to
 the clock time.  If negative, the system clock is slowed down for a
@@ -567,37 +859,82 @@ If the @var{olddelta} argument is not a null pointer, the @code{adjtime}
 function returns information about any previous time adjustment that
 has not yet completed.
 
-This function is typically used to synchronize the clocks of computers
-in a local network.  You must be a privileged user to use it.
-
-With a Linux kernel, you can use the @code{adjtimex} function to
-permanently change the clock speed.
-
 The return value is @code{0} on success and @code{-1} on failure.  The
 following @code{errno} error condition is defined for this function:
 
 @table @code
 @item EPERM
-You do not have privilege to set the time.
+This process does not have the privileges required to adjust the
+@code{CLOCK_REALTIME} clock.
 @end table
 @end deftypefun
 
-@strong{Portability Note:}  The @code{gettimeofday}, @code{settimeofday},
-and @code{adjtime} functions are derived from BSD.
+For compatibility, @theglibc{} also provides several older functions
+for setting the time.  New programs should prefer to use the functions
+above.
+
+@deftypefun int stime (const time_t *@var{newtime})
+@standards{SVID, time.h}
+@standards{XPG, time.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+Change the @code{CLOCK_REALTIME} calendar time to be the simple
+calendar time in @code{*@var{newtime}}.  Calling this function is
+exactly the same as calling @w{@samp{clock_settime (CLOCK_REALTIME)}},
+except that the new time can only be set to a precision of one second.
+This function is declared in @file{time.h}.
 
+The return value is @code{0} on success and @code{-1} on failure.  The
+following @code{errno} error condition is defined for this function:
 
-Symbols for the following function are declared in @file{sys/timex.h}.
+@table @code
+@item EPERM
+This process does not have the privileges required to adjust the
+@code{CLOCK_REALTIME} clock.
+@end table
+@end deftypefun
 
 @deftypefun int adjtimex (struct timex *@var{timex})
 @standards{GNU, sys/timex.h}
 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
-@c It's a syscall, only available on linux.
+@code{adjtimex} is an older name for @code{ntp_adjtime}.
+This function is only available on @gnulinuxsystems{}.
+It is declared in @file{sys/timex.h}.
+@end deftypefun
+
+@deftypefun int settimeofday (const struct timeval *@var{tp}, const void *@var{tzp})
+@standards{BSD, sys/time.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+Change the @code{CLOCK_REALTIME} calendar time to be the simple
+calendar time in @code{*@var{newtime}}.  This function is declared in
+@file{sys/time.h}.
+
+When @var{tzp} is a null pointer, calling this function is exactly the
+same as calling @w{@samp{clock_settime (CLOCK_REALTIME)}}, except that
+the new time can only be set to a precision of one microsecond.
+
+When @var{tzp} is not a null pointer, the data it points to @emph{may}
+be used to set a system-wide idea of the current timezone.  This
+feature is obsolete and not supported on @gnusystems{}.  Instead, use
+the facilities described in @ref{Time Zone Functions} and in
+@ref{Broken-down Time} for working with time zones.
+
+The return value is @code{0} on success and @code{-1} on failure.  The
+following @code{errno} error conditions are defined for this function:
 
-@code{adjtimex} is functionally identical to @code{ntp_adjtime}.
-@xref{High Accuracy Clock}.
+@table @code
+@item EPERM
+This process does not have the privileges required to set the
+@code{CLOCK_REALTIME} clock.
 
-This function is present only with a Linux kernel.
+@item EINVAL
+Neither @var{tp} nor @var{tzp} is a null pointer.  (For historical
+reasons, it is not possible to set the current time and the current
+time zone in the same call.)
 
+@item ENOSYS
+The operating system does not support setting time zone information, and
+@var{tzp} is not a null pointer.
+@end table
 @end deftypefun
 
 @node Broken-down Time
@@ -605,13 +942,13 @@ This function is present only with a Linux kernel.
 @cindex broken-down time
 @cindex calendar time and broken-down time
 
-Calendar time is represented by the usual @glibcadj{} functions as an
-elapsed time since a fixed base calendar time.  This is convenient for
-computation, but has no relation to the way people normally think of
-calendar time.  By contrast, @dfn{broken-down time} is a binary
-representation of calendar time separated into year, month, day, and so
-on.  Broken-down time values are not useful for calculations, but they
-are useful for printing human readable time information.
+Simple calendar times represent absolute times as elapsed times since
+an epoch.  This is convenient for computation, but has no relation to
+the way people normally think of calendar time.  By contrast,
+@dfn{broken-down time} is a binary representation of calendar time
+separated into year, month, day, and so on.  Broken-down time values
+are not useful for calculations, but they are useful for printing
+human readable time information.
 
 A broken-down time value is always relative to a choice of time
 zone, and it also indicates which time zone that is.
@@ -937,213 +1274,6 @@ the @code{TZ} environment variable to UTC, call @code{mktime}, then set
 
 
 
-@node High Accuracy Clock
-@subsection High Accuracy Clock
-
-@cindex time, high precision
-@cindex clock, high accuracy
-@pindex sys/timex.h
-@c On Linux, GNU libc implements ntp_gettime() and npt_adjtime() as calls
-@c to adjtimex().
-The @code{ntp_gettime} and @code{ntp_adjtime} functions provide an
-interface to monitor and manipulate the system clock to maintain high
-accuracy time.  For example, you can fine tune the speed of the clock
-or synchronize it with another time source.
-
-A typical use of these functions is by a server implementing the Network
-Time Protocol to synchronize the clocks of multiple systems and high
-precision clocks.
-
-These functions are declared in @file{sys/timex.h}.
-
-@tindex struct ntptimeval
-@deftp {Data Type} {struct ntptimeval}
-This structure is used for information about the system clock.  It
-contains the following members:
-@table @code
-@item struct timeval time
-This is the current calendar time, expressed as the elapsed time since
-the epoch.  The @code{struct timeval} data type is described in
-@ref{Elapsed Time}.
-
-@item long int maxerror
-This is the maximum error, measured in microseconds.  Unless updated
-via @code{ntp_adjtime} periodically, this value will reach some
-platform-specific maximum value.
-
-@item long int esterror
-This is the estimated error, measured in microseconds.  This value can
-be set by @code{ntp_adjtime} to indicate the estimated offset of the
-system clock from the true calendar time.
-@end table
-@end deftp
-
-@deftypefun int ntp_gettime (struct ntptimeval *@var{tptr})
-@standards{GNU, sys/timex.h}
-@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
-@c Wrapper for adjtimex.
-The @code{ntp_gettime} function sets the structure pointed to by
-@var{tptr} to current values.  The elements of the structure afterwards
-contain the values the timer implementation in the kernel assumes.  They
-might or might not be correct.  If they are not, an @code{ntp_adjtime}
-call is necessary.
-
-The return value is @code{0} on success and other values on failure.  The
-following @code{errno} error conditions are defined for this function:
-
-@vtable @code
-@item TIME_ERROR
-The precision clock model is not properly set up at the moment, thus the
-clock must be considered unsynchronized, and the values should be
-treated with care.
-@end vtable
-@end deftypefun
-
-@tindex struct timex
-@deftp {Data Type} {struct timex}
-This structure is used to control and monitor the system clock.  It
-contains the following members:
-@table @code
-@item unsigned int modes
-This variable controls whether and which values are set.  Several
-symbolic constants have to be combined with @emph{binary or} to specify
-the effective mode.  These constants start with @code{MOD_}.
-
-@item long int offset
-This value indicates the current offset of the system clock from the true
-calendar time.  The value is given in microseconds.  If bit
-@code{MOD_OFFSET} is set in @code{modes}, the offset (and possibly other
-dependent values) can be set.  The offset's absolute value must not
-exceed @code{MAXPHASE}.
-
-
-@item long int frequency
-This value indicates the difference in frequency between the true
-calendar time and the system clock.  The value is expressed as scaled
-PPM (parts per million, 0.0001%).  The scaling is @code{1 <<
-SHIFT_USEC}.  The value can be set with bit @code{MOD_FREQUENCY}, but
-the absolute value must not exceed @code{MAXFREQ}.
-
-@item long int maxerror
-This is the maximum error, measured in microseconds.  A new value can be
-set using bit @code{MOD_MAXERROR}.  Unless updated via
-@code{ntp_adjtime} periodically, this value will increase steadily
-and reach some platform-specific maximum value.
-
-@item long int esterror
-This is the estimated error, measured in microseconds.  This value can
-be set using bit @code{MOD_ESTERROR}.
-
-@item int status
-This variable reflects the various states of the clock machinery.  There
-are symbolic constants for the significant bits, starting with
-@code{STA_}.  Some of these flags can be updated using the
-@code{MOD_STATUS} bit.
-
-@item long int constant
-This value represents the bandwidth or stiffness of the PLL (phase
-locked loop) implemented in the kernel.  The value can be changed using
-bit @code{MOD_TIMECONST}.
-
-@item long int precision
-This value represents the accuracy or the maximum error when reading the
-system clock.  The value is expressed in microseconds.
-
-@item long int tolerance
-This value represents the maximum frequency error of the system clock in
-scaled PPM.  This value is used to increase the @code{maxerror} every
-second.
-
-@item struct timeval time
-The current calendar time.
-
-@item long int tick
-The elapsed time between clock ticks in microseconds.  A clock tick is a
-periodic timer interrupt on which the system clock is based.
-
-@item long int ppsfreq
-This is the first of a few optional variables that are present only if
-the system clock can use a PPS (pulse per second) signal to discipline
-the system clock.  The value is expressed in scaled PPM and it denotes
-the difference in frequency between the system clock and the PPS signal.
-
-@item long int jitter
-This value expresses a median filtered average of the PPS signal's
-dispersion in microseconds.
-
-@item int shift
-This value is a binary exponent for the duration of the PPS calibration
-interval, ranging from @code{PPS_SHIFT} to @code{PPS_SHIFTMAX}.
-
-@item long int stabil
-This value represents the median filtered dispersion of the PPS
-frequency in scaled PPM.
-
-@item long int jitcnt
-This counter represents the number of pulses where the jitter exceeded
-the allowed maximum @code{MAXTIME}.
-
-@item long int calcnt
-This counter reflects the number of successful calibration intervals.
-
-@item long int errcnt
-This counter represents the number of calibration errors (caused by
-large offsets or jitter).
-
-@item long int stbcnt
-This counter denotes the number of calibrations where the stability
-exceeded the threshold.
-@end table
-@end deftp
-
-@deftypefun int ntp_adjtime (struct timex *@var{tptr})
-@standards{GNU, sys/timex.h}
-@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
-@c Alias to adjtimex syscall.
-The @code{ntp_adjtime} function sets the structure specified by
-@var{tptr} to current values.
-
-In addition, @code{ntp_adjtime} updates some settings to match what you
-pass to it in *@var{tptr}.  Use the @code{modes} element of *@var{tptr}
-to select what settings to update.  You can set @code{offset},
-@code{freq}, @code{maxerror}, @code{esterror}, @code{status},
-@code{constant}, and @code{tick}.
-
-@code{modes} = zero means set nothing.
-
-Only the superuser can update settings.
-
-@c On Linux, ntp_adjtime() also does the adjtime() function if you set
-@c modes = ADJ_OFFSET_SINGLESHOT (in fact, that is how GNU libc implements
-@c adjtime()).  But this should be considered an internal function because
-@c it's so inconsistent with the rest of what ntp_adjtime() does and is
-@c forced in an ugly way into the struct timex.  So we don't document it
-@c and instead document adjtime() as the way to achieve the function.
-
-The return value is @code{0} on success and other values on failure.  The
-following @code{errno} error conditions are defined for this function:
-
-@table @code
-@item TIME_ERROR
-The high accuracy clock model is not properly set up at the moment, thus the
-clock must be considered unsynchronized, and the values should be
-treated with care.  Another reason could be that the specified new values
-are not allowed.
-
-@item EPERM
-The process specified a settings update, but is not superuser.
-
-@end table
-
-For more details see RFC1305 (Network Time Protocol, Version 3) and
-related documents.
-
-@strong{Portability note:} Early versions of @theglibc{} did not
-have this function but did have the synonymous @code{adjtimex}.
-
-@end deftypefun
-
-
 @node Formatting Calendar Time
 @subsection Formatting Calendar Time
 
@@ -2694,7 +2824,7 @@ This is the period between now and the first timer interrupt.  If zero,
 the alarm is disabled.
 @end table
 
-The @code{struct timeval} data type is described in @ref{Elapsed Time}.
+The @code{struct timeval} data type is described in @ref{Time Types}.
 @end deftp
 
 @deftypefun int setitimer (int @var{which}, const struct itimerval *@var{new}, struct itimerval *@var{old})
@@ -2879,7 +3009,7 @@ The function returns as *@code{remaining} the elapsed time left in the
 interval for which you requested to sleep.  If the interval completed
 without getting interrupted by a signal, this is zero.
 
-@code{struct timespec} is described in @xref{Elapsed Time}.
+@code{struct timespec} is described in @ref{Time Types}.
 
 If the function returns because the interval is over the return value is
 zero.  If the function returns @math{-1} the global variable @code{errno}
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
  2019-08-20 13:21 ` [PATCH 03/12] Don’t use the argument to time Zack Weinberg
  2019-08-20 13:22 ` [PATCH 04/12] Use clock_settime to implement stime Zack Weinberg
@ 2019-08-20 13:22 ` Zack Weinberg
  2019-08-20 18:53   ` Paul Eggert
  2019-08-20 20:56   ` Adhemerval Zanella
  2019-08-20 13:22 ` [PATCH 12/12] Revise the documentation of ‘simple calendar time’ Zack Weinberg
                   ` (12 subsequent siblings)
  15 siblings, 2 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:22 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Since gettimeofday will shortly be implemented in terms of
clock_gettime on all platforms, internal code should use clock_gettime
directly; in addition to removing a layer of indirection, this will
allow us to remove the PLT-bypass gunk for gettimeofday.  In many
cases, the changed code does fewer conversions.

A few Hurd-specific files were changed to use __host_get_time instead
of __clock_gettime, as this seemed tidier.

With the exception of support/support_test_main.c, test cases are not
modified, mainly because I didn’t want to have to figure out which
test cases were testing gettimeofday specifically.

The definition of GETTIME in sysdeps/generic/memusage.h had a typo and
was not reading tv_sec at all.  I fixed this.  It appears nobody has been
generating malloc traces on a machine that doesn’t have a superseding
definition.

	* inet/deadline.c (__deadline_current_time)
	* login/logout.c (logout)
	* login/logwtmp.c (logwtmp)
	* nis/nis_call.c (__nisfind_server)
	* nptl/pthread_join_common.c (timedwait_tid)
	* nptl/pthread_mutex_timedlock.c (__pthread_mutex_clocklock_common)
	* nscd/nscd_helper.c (wait_on_socket, open_socket)
	* resolv/gai_misc.c (handle_requests)
	* resolv/gai_suspend.c (gai_suspend)
	* resolv/res_send.c (evNowTime)
	* sunrpc/auth_des.c (authdes_marshal, authdes_destroy)
	* sunrpc/auth_unix.c (authunix_create, authunix_refresh)
	* sunrpc/create_xid.c (_create_xid)
	* sunrpc/svcauth_des.c (_svcauth_des)
	* sysdeps/generic/memusage.h (GETTIME)
	* sysdeps/mach/nanosleep.c (__libc_nanosleep)
	* sysdeps/posix/tempname.c (RANDOM_BITS)
	* sysdeps/pthread/aio_misc.c (handle_fildes_io)
	* sysdeps/pthread/aio_suspend.c (aio_suspend):
	Use __clock_gettime(CLOCK_REALTIME) instead of __gettimeofday.
	Include time.h if necessary.

	* sysdeps/mach/hurd/getitimer.c (__getitimer)
	* sysdeps/mach/hurd/setitimer.c (setitimer_locked)
	* sysdeps/mach/hurd/times.c (__times):
	Use __host_get_time instead of __gettimeofday.
	Include mach.h if necessary.

	* sysdeps/mach/usleep.c (usleep): Remove unnecessary calls to
	__gettimeofday.

	* support/support_test_main.c (print_timestamp): Take a struct
	timespec argument, not a struct timeval.
	(signal_handler): Update to match.
	Use clock_gettime(CLOCK_REALTIME) instead of gettimeofday.

	* sysdeps/generic/memusage.h (GETTIME): Correct typo causing
	the seconds field of each timestamp to be ignored.
---
 inet/deadline.c                |  9 ++-------
 login/logout.c                 |  9 +++++----
 login/logwtmp.c                |  7 +++----
 nis/nis_call.c                 |  4 +++-
 nptl/pthread_join_common.c     |  7 +++----
 nptl/pthread_mutex_timedlock.c |  7 +++----
 nscd/nscd_helper.c             | 24 ++++++++++++------------
 resolv/gai_misc.c              |  6 +++---
 resolv/gai_suspend.c           |  6 +++---
 resolv/res_send.c              |  6 +-----
 sunrpc/auth_des.c              | 19 +++++++++++--------
 sunrpc/auth_unix.c             |  9 +++++----
 sunrpc/create_xid.c            |  6 +++---
 sunrpc/svcauth_des.c           |  7 ++++++-
 support/support_test_main.c    | 14 ++++++--------
 sysdeps/generic/memusage.h     | 16 ++++++++--------
 sysdeps/mach/hurd/getitimer.c  |  3 ++-
 sysdeps/mach/hurd/setitimer.c  |  3 ++-
 sysdeps/mach/hurd/times.c      |  6 +++---
 sysdeps/mach/nanosleep.c       | 33 +++++++++++++++++++++------------
 sysdeps/mach/usleep.c          |  5 -----
 sysdeps/posix/tempname.c       |  9 ++++-----
 sysdeps/pthread/aio_misc.c     |  6 +++---
 sysdeps/pthread/aio_suspend.c  |  6 +++---
 24 files changed, 115 insertions(+), 112 deletions(-)

diff --git a/inet/deadline.c b/inet/deadline.c
index ab275c266d..dee4637732 100644
--- a/inet/deadline.c
+++ b/inet/deadline.c
@@ -29,13 +29,8 @@ __deadline_current_time (void)
 {
   struct deadline_current_time result;
   if (__clock_gettime (CLOCK_MONOTONIC, &result.current) != 0)
-    {
-      struct timeval current_tv;
-      if (__gettimeofday (&current_tv, NULL) == 0)
-        __libc_fatal ("Fatal error: gettimeofday system call failed\n");
-      result.current.tv_sec = current_tv.tv_sec;
-      result.current.tv_nsec = current_tv.tv_usec * 1000;
-    }
+    if (__clock_gettime (CLOCK_REALTIME, &result.current) != 0)
+      __libc_fatal ("Fatal error: clock_gettime failed\n");
   assert (result.current.tv_sec >= 0);
   return result;
 }
diff --git a/login/logout.c b/login/logout.c
index 5015c1af0b..f1313ded77 100644
--- a/login/logout.c
+++ b/login/logout.c
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <string.h>
 #include <utmp.h>
+#include <time.h>
 #include <sys/time.h>
 
 int
@@ -45,10 +46,10 @@ logout (const char *line)
       /* Clear information about who & from where.  */
       memset (ut->ut_name, '\0', sizeof ut->ut_name);
       memset (ut->ut_host, '\0', sizeof ut->ut_host);
-      struct timeval tv;
-      __gettimeofday (&tv, NULL);
-      ut->ut_tv.tv_sec = tv.tv_sec;
-      ut->ut_tv.tv_usec = tv.tv_usec;
+
+      struct timespec ts;
+      __clock_gettime (CLOCK_REALTIME, &ts);
+      TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
       ut->ut_type = DEAD_PROCESS;
 
       if (pututline (ut) != NULL)
diff --git a/login/logwtmp.c b/login/logwtmp.c
index 50d14976c7..ec41375383 100644
--- a/login/logwtmp.c
+++ b/login/logwtmp.c
@@ -36,10 +36,9 @@ logwtmp (const char *line, const char *name, const char *host)
   strncpy (ut.ut_name, name, sizeof ut.ut_name);
   strncpy (ut.ut_host, host, sizeof ut.ut_host);
 
-  struct timeval tv;
-  __gettimeofday (&tv, NULL);
-  ut.ut_tv.tv_sec = tv.tv_sec;
-  ut.ut_tv.tv_usec = tv.tv_usec;
+  struct timespec ts;
+  __clock_gettime (CLOCK_REALTIME, &ts);
+  TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts);
 
   updwtmp (_PATH_WTMP, &ut);
 }
diff --git a/nis/nis_call.c b/nis/nis_call.c
index a48ecc39a8..db81fa3568 100644
--- a/nis/nis_call.c
+++ b/nis/nis_call.c
@@ -709,6 +709,7 @@ __nisfind_server (const_nis_name name, int search_parent,
   nis_error status;
   directory_obj *obj;
   struct timeval now;
+  struct timespec ts;
   unsigned int server_used = ~0;
   unsigned int current_ep = ~0;
 
@@ -718,7 +719,8 @@ __nisfind_server (const_nis_name name, int search_parent,
   if (*dir != NULL)
     return NIS_SUCCESS;
 
-  (void) gettimeofday (&now, NULL);
+  __clock_gettime (CLOCK_REALTIME, &ts);
+  TIMESPEC_TO_TIMEVAL (&now, &ts);
 
   if ((flags & NO_CACHE) == 0)
     *dir = nis_server_cache_search (name, search_parent, &server_used,
diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c
index 5224ee2110..f1b14266de 100644
--- a/nptl/pthread_join_common.c
+++ b/nptl/pthread_join_common.c
@@ -46,15 +46,14 @@ timedwait_tid (pid_t *tidp, const struct timespec *abstime)
   /* Repeat until thread terminated.  */
   while ((tid = *tidp) != 0)
     {
-      struct timeval tv;
       struct timespec rt;
 
       /* Get the current time.  */
-      __gettimeofday (&tv, NULL);
+      __clock_gettime (CLOCK_REALTIME, &rt);
 
       /* Compute relative timeout.  */
-      rt.tv_sec = abstime->tv_sec - tv.tv_sec;
-      rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+      rt.tv_sec = abstime->tv_sec - rt.tv_sec;
+      rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
       if (rt.tv_nsec < 0)
         {
           rt.tv_nsec += 1000000000;
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index 52c258e33d..2b194e5bee 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -567,15 +567,14 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
 			goto failpp;
 		      }
 
-		    struct timeval tv;
 		    struct timespec rt;
 
 		    /* Get the current time.  */
-		    (void) __gettimeofday (&tv, NULL);
+                    __clock_gettime (CLOCK_REALTIME, &rt);
 
 		    /* Compute relative timeout.  */
-		    rt.tv_sec = abstime->tv_sec - tv.tv_sec;
-		    rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+		    rt.tv_sec = abstime->tv_sec - rt.tv_sec;
+		    rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
 		    if (rt.tv_nsec < 0)
 		      {
 			rt.tv_nsec += 1000000000;
diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index 733c2a60cd..e12769ba03 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -59,9 +59,10 @@ wait_on_socket (int sock, long int usectmo)
       /* Handle the case where the poll() call is interrupted by a
 	 signal.  We cannot just use TEMP_FAILURE_RETRY since it might
 	 lead to infinite loops.  */
-      struct timeval now;
-      (void) __gettimeofday (&now, NULL);
-      long int end = now.tv_sec * 1000 + usectmo + (now.tv_usec + 500) / 1000;
+      struct timespec now;
+      __clock_gettime (CLOCK_REALTIME, &now);
+      long int end = (now.tv_sec * 1000 + usectmo +
+                      (now.tv_nsec + 500000) / 1000000);
       long int timeout = usectmo;
       while (1)
 	{
@@ -70,8 +71,9 @@ wait_on_socket (int sock, long int usectmo)
 	    break;
 
 	  /* Recompute the timeout time.  */
-	  (void) __gettimeofday (&now, NULL);
-	  timeout = end - (now.tv_sec * 1000 + (now.tv_usec + 500) / 1000);
+          __clock_gettime (CLOCK_REALTIME, &now);
+	  timeout = end - ((now.tv_sec * 1000 +
+                            (now.tv_nsec + 500000) / 1000000));
 	}
     }
 
@@ -191,9 +193,7 @@ open_socket (request_type type, const char *key, size_t keylen)
   memcpy (reqdata->key, key, keylen);
 
   bool first_try = true;
-  struct timeval tvend;
-  /* Fake initializing tvend.  */
-  asm ("" : "=m" (tvend));
+  struct timespec tvend = { 0, 0 };
   while (1)
     {
 #ifndef MSG_NOSIGNAL
@@ -212,18 +212,18 @@ open_socket (request_type type, const char *key, size_t keylen)
 
       /* The daemon is busy wait for it.  */
       int to;
-      struct timeval now;
-      (void) __gettimeofday (&now, NULL);
+      struct timespec now;
+      __clock_gettime (CLOCK_REALTIME, &now);
       if (first_try)
 	{
-	  tvend.tv_usec = now.tv_usec;
+	  tvend.tv_nsec = now.tv_nsec;
 	  tvend.tv_sec = now.tv_sec + 5;
 	  to = 5 * 1000;
 	  first_try = false;
 	}
       else
 	to = ((tvend.tv_sec - now.tv_sec) * 1000
-	      + (tvend.tv_usec - now.tv_usec) / 1000);
+	      + (tvend.tv_nsec - now.tv_nsec) / 1000000);
 
       struct pollfd fds[1];
       fds[0].fd = sock;
diff --git a/resolv/gai_misc.c b/resolv/gai_misc.c
index 69d7086ae6..5d1e310147 100644
--- a/resolv/gai_misc.c
+++ b/resolv/gai_misc.c
@@ -357,13 +357,13 @@ handle_requests (void *arg)
 	 something to arrive in it. */
       if (runp == NULL && optim.gai_idle_time >= 0)
 	{
-	  struct timeval now;
+	  struct timespec now;
 	  struct timespec wakeup_time;
 
 	  ++idle_thread_count;
-	  gettimeofday (&now, NULL);
+          __clock_gettime (CLOCK_REALTIME, &now);
 	  wakeup_time.tv_sec = now.tv_sec + optim.gai_idle_time;
-	  wakeup_time.tv_nsec = now.tv_usec * 1000;
+	  wakeup_time.tv_nsec = now.tv_nsec;
 	  if (wakeup_time.tv_nsec >= 1000000000)
 	    {
 	      wakeup_time.tv_nsec -= 1000000000;
diff --git a/resolv/gai_suspend.c b/resolv/gai_suspend.c
index eee3bcebe9..8f81e5a3dd 100644
--- a/resolv/gai_suspend.c
+++ b/resolv/gai_suspend.c
@@ -91,11 +91,11 @@ gai_suspend (const struct gaicb *const list[], int ent,
 	{
 	  /* We have to convert the relative timeout value into an
 	     absolute time value with pthread_cond_timedwait expects.  */
-	  struct timeval now;
+	  struct timespec now;
 	  struct timespec abstime;
 
-	  __gettimeofday (&now, NULL);
-	  abstime.tv_nsec = timeout->tv_nsec + now.tv_usec * 1000;
+          __clock_gettime (CLOCK_REALTIME, &now);
+	  abstime.tv_nsec = timeout->tv_nsec + now.tv_nsec;
 	  abstime.tv_sec = timeout->tv_sec + now.tv_sec;
 	  if (abstime.tv_nsec >= 1000000000)
 	    {
diff --git a/resolv/res_send.c b/resolv/res_send.c
index ed27f3abf8..0cd35f99d7 100644
--- a/resolv/res_send.c
+++ b/resolv/res_send.c
@@ -172,12 +172,8 @@ evCmpTime(struct timespec a, struct timespec b) {
 
 static void
 evNowTime(struct timespec *res) {
-	struct timeval now;
-
-	if (gettimeofday(&now, NULL) < 0)
+	if (__clock_gettime(CLOCK_REALTIME, res) < 0)
 		evConsTime(res, 0, 0);
-	else
-		TIMEVAL_TO_TIMESPEC (&now, res);
 }
 
 
diff --git a/sunrpc/auth_des.c b/sunrpc/auth_des.c
index 5b6f985bc2..9079b30397 100644
--- a/sunrpc/auth_des.c
+++ b/sunrpc/auth_des.c
@@ -41,6 +41,7 @@
 #include <rpc/xdr.h>
 #include <netinet/in.h>		/* XXX: just to get htonl() and ntohl() */
 #include <sys/socket.h>
+#include <time.h>
 #include <shlib-compat.h>
 
 #define MILLION		1000000L
@@ -246,15 +247,15 @@ authdes_marshal (AUTH *auth, XDR *xdrs)
   int status;
   int len;
   register int32_t *ixdr;
-  struct timeval tval;
+  struct timespec now;
 
   /*
    * Figure out the "time", accounting for any time difference
    * with the server if necessary.
    */
-  __gettimeofday (&tval, (struct timezone *) NULL);
-  ad->ad_timestamp.tv_sec = tval.tv_sec + ad->ad_timediff.tv_sec;
-  ad->ad_timestamp.tv_usec = tval.tv_usec + ad->ad_timediff.tv_usec;
+  __clock_gettime (CLOCK_REALTIME, &now);
+  ad->ad_timestamp.tv_sec = now.tv_sec + ad->ad_timediff.tv_sec;
+  ad->ad_timestamp.tv_usec = (now.tv_nsec / 1000) + ad->ad_timediff.tv_usec;
   if (ad->ad_timestamp.tv_usec >= MILLION)
     {
       ad->ad_timestamp.tv_usec -= MILLION;
@@ -445,21 +446,23 @@ authdes_destroy (AUTH *auth)
 static bool_t
 synchronize (struct sockaddr *syncaddr, struct rpc_timeval *timep)
 {
-  struct timeval mytime;
+  struct timespec mytime;
   struct rpc_timeval timeout;
+  long myusec;
 
   timeout.tv_sec = RTIME_TIMEOUT;
   timeout.tv_usec = 0;
   if (rtime ((struct sockaddr_in *) syncaddr, timep, &timeout) < 0)
     return FALSE;
 
-  __gettimeofday (&mytime, (struct timezone *) NULL);
+  __clock_gettime (CLOCK_REALTIME, &mytime);
   timep->tv_sec -= mytime.tv_sec;
-  if (mytime.tv_usec > timep->tv_usec)
+  myusec = mytime.tv_nsec / 1000;
+  if (myusec > timep->tv_usec)
     {
       timep->tv_sec -= 1;
       timep->tv_usec += MILLION;
     }
-  timep->tv_usec -= mytime.tv_usec;
+  timep->tv_usec -= myusec;
   return TRUE;
 }
diff --git a/sunrpc/auth_unix.c b/sunrpc/auth_unix.c
index b035fdd870..ff0d2eb933 100644
--- a/sunrpc/auth_unix.c
+++ b/sunrpc/auth_unix.c
@@ -43,6 +43,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <time.h>
 #include <libintl.h>
 #include <sys/param.h>
 #include <wchar.h>
@@ -96,7 +97,7 @@ authunix_create (char *machname, uid_t uid, gid_t gid, int len,
 {
   struct authunix_parms aup;
   char mymem[MAX_AUTH_BYTES];
-  struct timeval now;
+  struct timespec now;
   XDR xdrs;
   AUTH *auth;
   struct audata *au;
@@ -122,7 +123,7 @@ no_memory:
   /*
    * fill in param struct from the given params
    */
-  (void) __gettimeofday (&now, (struct timezone *) 0);
+  __clock_gettime (CLOCK_REALTIME, &now);
   aup.aup_time = now.tv_sec;
   aup.aup_machname = machname;
   aup.aup_uid = uid;
@@ -276,7 +277,7 @@ authunix_refresh (AUTH *auth)
 {
   struct audata *au = AUTH_PRIVATE (auth);
   struct authunix_parms aup;
-  struct timeval now;
+  struct timespec now;
   XDR xdrs;
   int stat;
 
@@ -297,7 +298,7 @@ authunix_refresh (AUTH *auth)
     goto done;
 
   /* update the time and serialize in place */
-  (void) __gettimeofday (&now, (struct timezone *) 0);
+  __clock_gettime (CLOCK_REALTIME, &now);
   aup.aup_time = now.tv_sec;
   xdrs.x_op = XDR_ENCODE;
   XDR_SETPOS (&xdrs, 0);
diff --git a/sunrpc/create_xid.c b/sunrpc/create_xid.c
index a44187f07c..8d1e722dad 100644
--- a/sunrpc/create_xid.c
+++ b/sunrpc/create_xid.c
@@ -39,10 +39,10 @@ _create_xid (void)
   pid_t pid = getpid ();
   if (is_initialized != pid)
     {
-      struct timeval now;
+      struct timespec now;
 
-      __gettimeofday (&now, (struct timezone *) 0);
-      __srand48_r (now.tv_sec ^ now.tv_usec ^ pid,
+      __clock_gettime (CLOCK_REALTIME, &now);
+      __srand48_r (now.tv_sec ^ now.tv_nsec ^ pid,
 		   &__rpc_lrand48_data);
       is_initialized = pid;
     }
diff --git a/sunrpc/svcauth_des.c b/sunrpc/svcauth_des.c
index c5a512d6f8..7607abc818 100644
--- a/sunrpc/svcauth_des.c
+++ b/sunrpc/svcauth_des.c
@@ -44,6 +44,7 @@
 #include <limits.h>
 #include <string.h>
 #include <stdint.h>
+#include <time.h>
 #include <sys/param.h>
 #include <netinet/in.h>
 #include <rpc/rpc.h>
@@ -295,7 +296,11 @@ _svcauth_des (register struct svc_req *rqst, register struct rpc_msg *msg)
 	debug ("timestamp before last seen");
 	return AUTH_REJECTEDVERF;	/* replay */
       }
-    __gettimeofday (&current, (struct timezone *) NULL);
+    {
+      struct timespec now;
+      __clock_gettime (CLOCK_REALTIME, &now);
+      TIMESPEC_TO_TIMEVAL (&current, &now);
+    }
     current.tv_sec -= window;	/* allow for expiration */
     if (!BEFORE (&current, &timestamp))
       {
diff --git a/support/support_test_main.c b/support/support_test_main.c
index 7e7b9edbb0..bc4502c030 100644
--- a/support/support_test_main.c
+++ b/support/support_test_main.c
@@ -88,16 +88,16 @@ static pid_t test_pid;
 static void (*cleanup_function) (void);
 
 static void
-print_timestamp (const char *what, struct timeval tv)
+print_timestamp (const char *what, struct timespec tv)
 {
   struct tm tm;
   if (gmtime_r (&tv.tv_sec, &tm) == NULL)
     printf ("%s: %lld.%06d\n",
-            what, (long long int) tv.tv_sec, (int) tv.tv_usec);
+            what, (long long int) tv.tv_sec, (int) tv.tv_nsec / 1000);
   else
     printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n",
             what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
-            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec);
+            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_nsec / 1000);
 }
 
 /* Timeout handler.  We kill the child and exit with an error.  */
@@ -110,8 +110,8 @@ signal_handler (int sig)
 
   /* Do this first to avoid further interference from the
      subprocess.  */
-  struct timeval now;
-  bool now_available = gettimeofday (&now, NULL) == 0;
+  struct timespec now;
+  bool now_available = clock_gettime (CLOCK_REALTIME, &now) == 0;
   struct stat64 st;
   bool st_available = fstat64 (STDOUT_FILENO, &st) == 0 && st.st_mtime != 0;
 
@@ -168,9 +168,7 @@ signal_handler (int sig)
   if (now_available)
     print_timestamp ("Termination time", now);
   if (st_available)
-    print_timestamp ("Last write to standard output",
-                     (struct timeval) { st.st_mtim.tv_sec,
-                         st.st_mtim.tv_nsec / 1000 });
+    print_timestamp ("Last write to standard output", st.st_mtim);
 
   /* Exit with an error.  */
   exit (1);
diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h
index 480bdf79ee..c29feb8edd 100644
--- a/sysdeps/generic/memusage.h
+++ b/sysdeps/generic/memusage.h
@@ -26,14 +26,14 @@
 #endif
 
 #ifndef GETTIME
-# define GETTIME(low,high) \
-  {									      \
-    struct timeval tval;						      \
-    uint64_t usecs;							      \
-    gettimeofday (&tval, NULL);						      \
-    usecs = (uint64_t) tval.tv_usec + (uint64_t) tval.tv_usec * 1000000;      \
-    low = usecs & 0xffffffff;						      \
-    high = usecs >> 32;							      \
+# define GETTIME(low,high)						   \
+  {									   \
+    struct timespec now;						   \
+    uint64_t usecs;							   \
+    __clock_gettime (CLOCK_REALTIME, &now);				   \
+    usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \
+    low = usecs & 0xffffffff;						   \
+    high = usecs >> 32;							   \
   }
 #endif
 
diff --git a/sysdeps/mach/hurd/getitimer.c b/sysdeps/mach/hurd/getitimer.c
index 69a0751ead..6a0fc3cb0d 100644
--- a/sysdeps/mach/hurd/getitimer.c
+++ b/sysdeps/mach/hurd/getitimer.c
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <sys/time.h>
 #include <hurd.h>
+#include <mach.h>
 
 /* XXX Temporary cheezoid implementation; see __setitmr.c.  */
 
@@ -61,7 +62,7 @@ __getitimer (enum __itimer_which which, struct itimerval *value)
     }
 
   /* Get the time now.  */
-  if (__gettimeofday (&elapsed, NULL) < 0)
+  if (__host_get_time (__mach_host_self (), (time_value_t *) &elapsed) < 0)
     return -1;
 
   /* Extract the current timer setting; and the time it was set, so we can
diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c
index 61e37c5f5d..c829a5869b 100644
--- a/sysdeps/mach/hurd/setitimer.c
+++ b/sysdeps/mach/hurd/setitimer.c
@@ -23,6 +23,7 @@
 #include <hurd/signal.h>
 #include <hurd/sigpreempt.h>
 #include <hurd/msg_request.h>
+#include <mach.h>
 #include <mach/message.h>
 
 /* XXX Temporary cheezoid implementation of ITIMER_REAL/SIGALRM.  */
@@ -239,7 +240,7 @@ setitimer_locked (const struct itimerval *new, struct itimerval *old,
   if ((newval.it_value.tv_sec | newval.it_value.tv_usec) != 0 || old != NULL)
     {
       /* Calculate how much time is remaining for the pending alarm.  */
-      if (__gettimeofday (&now, NULL) < 0)
+      if (__host_get_time (__mach_host_self (), (time_value_t *) &now) < 0)
 	{
 	  __spin_unlock (&_hurd_itimer_lock);
 	  _hurd_critical_section_unlock (crit);
diff --git a/sysdeps/mach/hurd/times.c b/sysdeps/mach/hurd/times.c
index 7758311d83..aafa7b15d9 100644
--- a/sysdeps/mach/hurd/times.c
+++ b/sysdeps/mach/hurd/times.c
@@ -42,7 +42,7 @@ __times (struct tms *tms)
   struct task_basic_info bi;
   struct task_thread_times_info tti;
   mach_msg_type_number_t count;
-  union { time_value_t tvt; struct timeval tv; } now;
+  time_value_t now;
   error_t err;
 
   count = TASK_BASIC_INFO_COUNT;
@@ -65,10 +65,10 @@ __times (struct tms *tms)
   /* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be.  */
   tms->tms_cutime = tms->tms_cstime = 0;
 
-  if (__gettimeofday (&now.tv, NULL) < 0)
+  if (__host_get_time (__mach_host_self (), &now) < 0)
     return -1;
 
-  return (clock_from_time_value (&now.tvt)
+  return (clock_from_time_value (&now)
 	  - clock_from_time_value (&bi.creation_time));
 }
 weak_alias (__times, times)
diff --git a/sysdeps/mach/nanosleep.c b/sysdeps/mach/nanosleep.c
index b4790aaf31..0be48db0d9 100644
--- a/sysdeps/mach/nanosleep.c
+++ b/sysdeps/mach/nanosleep.c
@@ -18,16 +18,26 @@
 
 #include <errno.h>
 #include <mach.h>
-#include <sys/time.h>
 #include <time.h>
 #include <unistd.h>
 
+# define timespec_sub(a, b, result)					      \
+  do {									      \
+    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;			      \
+    (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec;			      \
+    if ((result)->tv_nsec < 0) {					      \
+      --(result)->tv_sec;						      \
+      (result)->tv_nsec += 1000000000;					      \
+    }									      \
+  } while (0)
+
 int
 __libc_nanosleep (const struct timespec *requested_time,
-	     struct timespec *remaining)
+                  struct timespec *remaining)
 {
   mach_port_t recv;
-  struct timeval before, after;
+  struct timespec before, after;
+  error_t err;
 
   if (requested_time->tv_sec < 0
       || requested_time->tv_nsec < 0
@@ -43,20 +53,19 @@ __libc_nanosleep (const struct timespec *requested_time,
 
   recv = __mach_reply_port ();
 
-  if (remaining && __gettimeofday (&before, NULL) < 0)
+  if (remaining && __clock_gettime (CLOCK_REALTIME, &before) < 0)
     return -1;
-  error_t err = __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
-			    0, 0, recv, ms, MACH_PORT_NULL);
+
+  err = __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
+                    0, 0, recv, ms, MACH_PORT_NULL);
   __mach_port_destroy (mach_task_self (), recv);
   if (err == EMACH_RCV_INTERRUPTED)
     {
-      if (remaining && __gettimeofday (&after, NULL) >= 0)
+      if (remaining && __clock_gettime (CLOCK_REALTIME, &after) >= 0)
 	{
-	  struct timeval req_time, elapsed, rem;
-	  TIMESPEC_TO_TIMEVAL (&req_time, requested_time);
-	  timersub (&after, &before, &elapsed);
-	  timersub (&req_time, &elapsed, &rem);
-	  TIMEVAL_TO_TIMESPEC (&rem, remaining);
+	  struct timespec elapsed;
+	  timespec_sub (&after, &before, &elapsed);
+	  timespec_sub (requested_time, &elapsed, remaining);
 	}
 
       errno = EINTR;
diff --git a/sysdeps/mach/usleep.c b/sysdeps/mach/usleep.c
index 5d4bd205e1..8428ace6ef 100644
--- a/sysdeps/mach/usleep.c
+++ b/sysdeps/mach/usleep.c
@@ -25,17 +25,12 @@ int
 usleep (useconds_t useconds)
 {
   mach_port_t recv;
-  struct timeval before, after;
 
   recv = __mach_reply_port ();
 
-  if (__gettimeofday (&before, NULL) < 0)
-    return -1;
   (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
 		     0, 0, recv, (useconds + 999) / 1000, MACH_PORT_NULL);
   __mach_port_destroy (mach_task_self (), recv);
-  if (__gettimeofday (&after, NULL) < 0)
-    return -1;
 
   return 0;
 }
diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c
index 310df3c4ca..c3956498ce 100644
--- a/sysdeps/posix/tempname.c
+++ b/sysdeps/posix/tempname.c
@@ -50,7 +50,7 @@
 #include <string.h>
 
 #include <fcntl.h>
-#include <sys/time.h>
+#include <time.h>
 #include <stdint.h>
 #include <unistd.h>
 
@@ -63,7 +63,6 @@
 # define struct_stat64 struct stat
 # define __gen_tempname gen_tempname
 # define __getpid getpid
-# define __gettimeofday gettimeofday
 # define __mkdir mkdir
 # define __open open
 # define __lxstat64(version, file, buf) lstat (file, buf)
@@ -76,9 +75,9 @@
 # else
 # define RANDOM_BITS(Var) \
     {                                                                         \
-      struct timeval tv;                                                      \
-      __gettimeofday (&tv, NULL);                                             \
-      (Var) = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;                      \
+      struct timespec ts;                                                     \
+      clock_gettime (CLOCK_REALTIME, &ts);                                    \
+      (Var) = ((uint64_t) tv.tv_nsec << 16) ^ tv.tv_sec;                      \
     }
 #endif
 
diff --git a/sysdeps/pthread/aio_misc.c b/sysdeps/pthread/aio_misc.c
index 0180ddb3c3..49ab08de3a 100644
--- a/sysdeps/pthread/aio_misc.c
+++ b/sysdeps/pthread/aio_misc.c
@@ -614,13 +614,13 @@ handle_fildes_io (void *arg)
 	 something to arrive in it. */
       if (runp == NULL && optim.aio_idle_time >= 0)
 	{
-	  struct timeval now;
+	  struct timespec now;
 	  struct timespec wakeup_time;
 
 	  ++idle_thread_count;
-	  __gettimeofday (&now, NULL);
+          __clock_gettime (CLOCK_REALTIME, &now);
 	  wakeup_time.tv_sec = now.tv_sec + optim.aio_idle_time;
-	  wakeup_time.tv_nsec = now.tv_usec * 1000;
+	  wakeup_time.tv_nsec = now.tv_nsec;
 	  if (wakeup_time.tv_nsec >= 1000000000)
 	    {
 	      wakeup_time.tv_nsec -= 1000000000;
diff --git a/sysdeps/pthread/aio_suspend.c b/sysdeps/pthread/aio_suspend.c
index 06bd914672..fdd4087abb 100644
--- a/sysdeps/pthread/aio_suspend.c
+++ b/sysdeps/pthread/aio_suspend.c
@@ -183,11 +183,11 @@ aio_suspend (const struct aiocb *const list[], int nent,
 	{
 	  /* We have to convert the relative timeout value into an
 	     absolute time value with pthread_cond_timedwait expects.  */
-	  struct timeval now;
+	  struct timespec now;
 	  struct timespec abstime;
 
-	  __gettimeofday (&now, NULL);
-	  abstime.tv_nsec = timeout->tv_nsec + now.tv_usec * 1000;
+	  __clock_gettime (CLOCK_REALTIME, &now);
+	  abstime.tv_nsec = timeout->tv_nsec + now.tv_nsec;
 	  abstime.tv_sec = timeout->tv_sec + now.tv_sec;
 	  if (abstime.tv_nsec >= 1000000000)
 	    {
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 05/12] Use clock_settime to implement settimeofday.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (4 preceding siblings ...)
  2019-08-20 13:22 ` [PATCH 01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday Zack Weinberg
@ 2019-08-20 13:22 ` Zack Weinberg
  2019-08-20 13:22 ` [PATCH 09/12] Finish move of clock_* functions to libc Zack Weinberg
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:22 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Unconditionally, on all ports, use clock_settime to implement
settimeofday.  This is a little different from using clock_settime to
implement stime, because the vestigial “set time zone” feature of
settimeofday complicates matters.

The only remaining uses of this feature that aren’t just bugs are
using it to inform the Linux kernel of the offset between the hardware
clock and UTC, on systems where the hardware clock doesn’t run in
UTC (usually because of dual-booting with Windows).  They call
settimeofday with _only_ the timezone argument non-NULL.  Therefore,
glibc’s new behavior is: callers of settimeofday must supply one and
only one of the two arguments.  If both arguments are non-NULL, or
both arguments are NULL, the call fails and sets errno to EINVAL.

When only the timeval argument is supplied, settimeofday calls
__clock_settime(CLOCK_REALTIME), same as stime.

When only the timezone argument is supplied, settimeofday calls a new
internal function called __settimezone.  On Linux, only, this function
will pass the timezone structure to the settimeofday system call.  On
all other operating systems, and on Linux architectures that don’t
define __NR_settimeofday, __settimezone is a stub that always sets
errno to ENOSYS and returns -1.

Another complication is that the alpha-linux-gnu configuration has two
versions of settimeofday, GLIBC_2.0 and GLIBC_2.1, with the older
symbol using 32-bit time_t (yes, really).  The older symbol is
reimplemented from scratch (with the same semantics); the newer symbol
uses the generic implementation with some #ifdeffage to get the
versioning right.  Henceforth, __NR_osf_settimeofday will never be
used, and __NR_settimeofday only for the timezone feature.

There are no longer any internal callers of __settimeofday, so the
internal prototype is removed.

	* time/settimeofday.c (settimeofday): No longer a stub
	implementation.  Call __clock_settime or __settimezone depending
	on arguments.  Optionally override the default symbol version for
	settimeofday.
	* include/sys/time.h: Remove prototype for __settimeofday.
	Add prototype for __settimezone.
	* sysdeps/unix/syscalls.list: Remove entry for settimeofday.

	* time/settimezone.c: New file.
	(__settimezone): New stub implementation.
	* sysdeps/unix/sysv/linux/settimezone.c: New file.
	(__settimezone): Implement using settimeofday system call,
	if available.
	* time/Makefile (routines): Add settimezone.

	* sysdeps/unix/sysv/linux/alpha/syscalls.list:
	Remove entries for settimeofday and osf_settimeofday.
	* sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
	New file, defines settimeofday@GLIBC_2.0.
	* sysdeps/unix/sysv/linux/alpha/settimeofday.c:
	New file, defines settimeofday@@GLIBC_2.1.
---
 include/sys/time.h                            |  3 +-
 sysdeps/unix/syscalls.list                    |  1 -
 .../unix/sysv/linux/alpha/osf_settimeofday.c  | 55 +++++++++++++++++++
 sysdeps/unix/sysv/linux/alpha/settimeofday.c  | 22 ++++++++
 sysdeps/unix/sysv/linux/alpha/syscalls.list   |  2 -
 sysdeps/unix/sysv/linux/settimezone.c         | 39 +++++++++++++
 time/Makefile                                 |  2 +-
 time/settimeofday.c                           | 24 ++++++--
 time/settimezone.c                            | 28 ++++++++++
 9 files changed, 166 insertions(+), 10 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/settimeofday.c
 create mode 100644 sysdeps/unix/sysv/linux/settimezone.c
 create mode 100644 time/settimezone.c

diff --git a/include/sys/time.h b/include/sys/time.h
index 7ba0ca7c2d..a57752e8c7 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -24,8 +24,7 @@ extern int __gettimeofday (struct timeval *__tv,
 			   struct timezone *__tz);
 libc_hidden_proto (__gettimeofday)
 libc_hidden_proto (gettimeofday)
-extern int __settimeofday (const struct timeval *__tv,
-			   const struct timezone *__tz)
+extern int __settimezone (const struct timezone *__tz)
 	attribute_hidden;
 extern int __adjtime (const struct timeval *__delta,
 		      struct timeval *__olddelta);
diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
index 61e5360b4d..5fedd5733d 100644
--- a/sysdeps/unix/syscalls.list
+++ b/sysdeps/unix/syscalls.list
@@ -76,7 +76,6 @@ setreuid	-	setreuid	i:ii	__setreuid	setreuid
 setrlimit	-	setrlimit	i:ip	__setrlimit setrlimit
 setsid		-	setsid		i:	__setsid	setsid
 setsockopt	-	setsockopt	i:iiibn	setsockopt	__setsockopt
-settimeofday	-	settimeofday	i:PP	__settimeofday	settimeofday
 setuid		-	setuid		i:i	__setuid	setuid
 shutdown	-	shutdown	i:ii	shutdown
 sigaction	-	sigaction	i:ipp	__sigaction	sigaction
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
new file mode 100644
index 0000000000..a61fcab482
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
@@ -0,0 +1,55 @@
+/* settimeofday -- Set the current time of day.  Linux/Alpha/tv32 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
+struct timeval32
+{
+    int tv_sec, tv_usec;
+};
+
+/* Set the current time of day and timezone information.
+   This call is restricted to the super-user.  */
+int
+attribute_compat_text_section
+__settimeofday_tv32 (const struct timeval32 *tv32,
+                     const struct timezone *tz)
+{
+  if (__glibc_unlikely (tz != 0))
+    {
+      if (tv32 != 0)
+	{
+	  __set_errno (EINVAL);
+	  return -1;
+	}
+      return __settimezone (tz);
+    }
+
+  struct timespec ts;
+  ts.tv_sec = tv32->tv_sec;
+  ts.tv_nsec = tv32->tv_usec * 1000;
+  return __clock_settime (CLOCK_REALTIME, &ts);
+}
+
+compat_symbol (libc, __settimeofday_tv32, settimeofday, GLIBC_2_0);
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/settimeofday.c b/sysdeps/unix/sysv/linux/alpha/settimeofday.c
new file mode 100644
index 0000000000..36a6901e4e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/settimeofday.c
@@ -0,0 +1,22 @@
+/* settimeofday -- Set the current time of day.  Linux/Alpha/tv64 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* We can use the generic implementation, but we have to override its
+   default symbol version.  */
+#define VERSION_settimeofday GLIBC_2.1
+#include <time/settimeofday.c>
diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index 12cd021b60..f5a534ed68 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -24,7 +24,6 @@ pciconfig_iobase EXTRA	pciconfig_iobase 3	__pciconfig_iobase pciconfig_iobase
 
 # support old timeval32 entry points
 osf_gettimeofday -	osf_gettimeofday 2	__gettimeofday_tv32  __gettimeofday@GLIBC_2.0 gettimeofday@GLIBC_2.0
-osf_settimeofday -	osf_settimeofday 2	__settimeofday_tv32  settimeofday@GLIBC_2.0
 osf_getitimer	-	osf_getitimer	2	__getitimer_tv32  getitimer@GLIBC_2.0
 osf_setitimer	-	osf_setitimer	3	__setitimer_tv32  setitimer@GLIBC_2.0
 osf_utimes	-	osf_utimes	2	__utimes_tv32  utimes@GLIBC_2.0
@@ -33,7 +32,6 @@ osf_wait4	-	osf_wait4	4	__wait4_tv32  wait4@GLIBC_2.0
 
 # support new timeval64 entry points
 gettimeofday	-	gettimeofday	2	__GI___gettimeofday gettimeofday@@GLIBC_2.1 __gettimeofday@@GLIBC_2.1
-settimeofday	-	settimeofday	2	__settimeofday settimeofday@@GLIBC_2.1
 getitimer	-	getitimer	2	__getitimer getitimer@@GLIBC_2.1
 setitimer	-	setitimer	3	__setitimer setitimer@@GLIBC_2.1
 utimes		-	utimes		2	__utimes utimes@@GLIBC_2.1
diff --git a/sysdeps/unix/sysv/linux/settimezone.c b/sysdeps/unix/sysv/linux/settimezone.c
new file mode 100644
index 0000000000..823f4fe42f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/settimezone.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/time.h>
+#include <sysdep.h>
+
+/* Set the system-wide timezone.
+   This call is restricted to the super-user.
+   This operation is considered obsolete, kernel support may not be
+   available on all architectures.  */
+
+#ifdef __NR_settimeofday
+
+int
+__settimezone (const struct timezone *tz)
+{
+  return INLINE_SYSCALL_CALL (settimeofday, NULL, tz);
+}
+
+#else
+
+#include <time/settimezone.c>
+
+#endif
diff --git a/time/Makefile b/time/Makefile
index a428f55245..d78bff85e6 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -36,7 +36,7 @@ routines := offtime asctime clock ctime ctime_r difftime \
 	    stime dysize timegm ftime			 \
 	    getdate strptime strptime_l			 \
 	    strftime wcsftime strftime_l wcsftime_l	 \
-	    timespec_get
+	    timespec_get settimezone
 aux :=	    era alt_digit lc-time-cleanup
 
 tests	:= test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
diff --git a/time/settimeofday.c b/time/settimeofday.c
index 4620559652..78f666e352 100644
--- a/time/settimeofday.c
+++ b/time/settimeofday.c
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
+#include <time.h>
 #include <sys/time.h>
 
 /* Set the current time of day and timezone information.
@@ -23,9 +24,24 @@
 int
 __settimeofday (const struct timeval *tv, const struct timezone *tz)
 {
-  __set_errno (ENOSYS);
-  return -1;
+  if (__glibc_unlikely (tz != 0))
+    {
+      if (tv != 0)
+	{
+	  __set_errno (EINVAL);
+	  return -1;
+	}
+      return __settimezone (tz);
+    }
+
+  struct timespec ts;
+  TIMEVAL_TO_TIMESPEC (tv, &ts);
+  return __clock_settime (CLOCK_REALTIME, &ts);
 }
-stub_warning (settimeofday)
 
-weak_alias (__settimeofday, settimeofday)
+#ifdef VERSION_settimeofday
+weak_alias (__settimeofday, __settimeofday_w);
+default_symbol_version (__settimeofday_w, settimeofday, VERSION_settimeofday);
+#else
+weak_alias (__settimeofday, settimeofday);
+#endif
diff --git a/time/settimezone.c b/time/settimezone.c
new file mode 100644
index 0000000000..eb005da213
--- /dev/null
+++ b/time/settimezone.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/time.h>
+
+/* Set the system-wide timezone.
+   This call is restricted to the super-user.  */
+int
+__settimezone (const struct timezone *tz)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions
@ 2019-08-20 13:22 Zack Weinberg
  2019-08-20 13:21 ` [PATCH 03/12] Don’t use the argument to time Zack Weinberg
                   ` (15 more replies)
  0 siblings, 16 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:22 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

This patchset aims to make the Y2038 project a little easier by
implementing the other time-getting and time-setting functions
(time, ftime, stime, gettimeofday, and settimeofday) in terms of
clock_gettime and clock_settime.  Internal uses of (__)gettimeofday
are also all changed to __clock_gettime.  Internal uses of time() are
mostly left alone, since time() is easier and clearer when you don’t
care about sub-second resolution and don’t need a struct timespec for
some other reason.

As a consequence, gettimeofday will no longer report crude timezone
information under any circumstances.  If its ‘tzp’ argument is not
NULL, it will write zeroes to both fields of the ‘struct timezone’,
even if the gettimeofday system call exists and would have produced
different output.  Similarly, ftime will always write zeroes to the
timezone and dstflag fields of ‘struct timeb’.  Joseph Myers raised an
objection to this change; I rebutted the objection, and he did not
reply; I do not think either of us will persuade the other, so I’m
formally asking for a third maintainer to make a decision.

settimeofday _will_ still call the settimeofday system call and pass
down a non-null ‘tzp’ argument if it receives one, but, if _both_ of
its arguments are non-null, it will fail and set errno to EINVAL.
Also, its invocation of a settimeofday system call goes through an
internal sysdep function called __settimezone.  On the Hurd this is an
unconditional ENOSYS stub, and on Linux it’s an ENOSYS stub when
__NR_settimeofday is not defined.

Relatedly, there is a macro-based hack to issue warnings when
gettimeofday is called with a ‘tzp’ argument that is not a
compile-time null pointer.  I think this is probably a better option
at this stage than various suggested alternatives (e.g. renaming the
fields of ‘struct timezone’, or removing it from sys/time.h
altogether) because the remaining valid uses of settimeofday with
non-null ‘tzp’ should still be able to use struct timezone.  The hack
is in a separate patch because, well, it’s a hack and I’m hoping
someone has a better implementation idea.  (I tried an inline function
instead of a macro, but it threw false positives all over the place on
‘gettimeofday (&tv, 0)’...)

This patchset also includes an overhaul of Linux/Alpha’s GLIBC_2.0
compatibility symbols for several system calls that consume or produce
struct timeval.  It appears that early releases of glibc and/or Linux
for Alpha attempted to achieve some degree of binary compatibility
with OSF/1, but this came at the expense of using 32-bit time_t inside
struct timeval.  Up till now, we were invoking compatibility system
calls from the compatibility symbols.  This patch changes them to wrap
the 64-bit implementations and convert between 32-bit and 64-bit
struct timeval in user space.  If a 64-bit tv_sec value returned by
the kernel is found to be greater than INT32_MAX, the caller will
receive a saturated 32-bit struct timeval, { INT32_MAX, 0 }, and the
function will return -1 with errno set to EOVERFLOW.  Because many of
these calls are assumed unable to fail, we make sure to write all the
fields of any output data structure even when this happens.  I did
this partially because it simplified conversion of gettimeofday to
call clock_gettime, and partially as a worked example of the semantics
that I think are probably best for the 32-bit time_t compatibility
symbols we’re going to have to add for many other architectures.
Comments on these semantics are requested.

This patchset also includes a partial revision of manual/time.texi.
clock_gettime and clock_settime are now documented, and the
obsolescent status of stime, settimeofday, and gettimeofday is
clearer.  I only documented CLOCK_REALTIME and CLOCK_MONOTONIC,
because most of the other clock constants are either extremely
Linux-specific or they have to do with measuring CPU time, and I
didn’t touch the measuring-CPU-time part of time.texi.  (That part
also deserves a rewrite, but I don’t know enough about the topic and
this patchset is already long enough.)

Finally, there is a case for demoting ftime and stime to compatibility
symbols and removing their public prototypes (for ftime, we would stop
installing <sys/timeb.h> altogether).  I tried to investigate how much
this might break, using codesearch.debian.net, but the identifiers
‘ftime’ and ‘stime’ turn out to be heavily used for unrelated
purposes, so I didn’t get anywhere.

Zack Weinberg (12):
  Remove implementations of clock_[gs]ettime using [gs]ettimeofday.
  Change most internal uses of __gettimeofday to __clock_gettime.
  Don’t use the argument to time.
  Use clock_settime to implement stime.
  Use clock_settime to implement settimeofday.
  Use clock_gettime to implement time.
  Use clock_gettime to implement ftime.
  Use clock_gettime to implement gettimeofday.
  Finish move of clock_* functions to libc.
  Warn when gettimeofday is called with non-null tzp argument.
  Linux/Alpha: don’t use timeval32 system calls.
  Revise the documentation of ‘simple calendar time’.

 NEWS                                          |   53 +-
 include/sys/time.h                            |    7 +-
 include/time.h                                |    4 +-
 inet/deadline.c                               |    9 +-
 login/logout.c                                |    9 +-
 login/logwtmp.c                               |    7 +-
 manual/filesys.texi                           |    2 +-
 manual/llio.texi                              |   10 +-
 manual/threads.texi                           |    2 +-
 manual/time.texi                              | 1062 +++++++++--------
 misc/syslog.c                                 |    2 +-
 nis/nis_call.c                                |    4 +-
 nptl/pthread_join_common.c                    |    7 +-
 nptl/pthread_mutex_timedlock.c                |    7 +-
 nscd/nscd_helper.c                            |   24 +-
 resolv/gai_misc.c                             |    6 +-
 resolv/gai_suspend.c                          |    6 +-
 resolv/res_send.c                             |    6 +-
 rt/Makefile                                   |   15 +-
 rt/Versions                                   |    7 +-
 rt/clock-compat.c                             |   63 -
 string/strfry.c                               |    2 +-
 sunrpc/auth_des.c                             |   19 +-
 sunrpc/auth_unix.c                            |    9 +-
 sunrpc/create_xid.c                           |    6 +-
 sunrpc/svcauth_des.c                          |    7 +-
 support/support_test_main.c                   |   14 +-
 sysdeps/generic/memusage.h                    |   16 +-
 .../mach/{gettimeofday.c => clock_gettime.c}  |   25 +-
 .../hurd/{settimeofday.c => clock_settime.c}  |   27 +-
 sysdeps/mach/hurd/getitimer.c                 |    3 +-
 sysdeps/mach/hurd/i386/libc.abilist           |    1 -
 sysdeps/mach/hurd/i386/librt.abilist          |    5 -
 sysdeps/mach/hurd/setitimer.c                 |    3 +-
 sysdeps/mach/hurd/times.c                     |    6 +-
 sysdeps/mach/nanosleep.c                      |   33 +-
 sysdeps/mach/sleep.c                          |    4 +-
 sysdeps/mach/usleep.c                         |    5 -
 sysdeps/posix/gettimeofday.c                  |   67 --
 sysdeps/posix/tempname.c                      |    9 +-
 sysdeps/posix/time.c                          |   40 -
 sysdeps/pthread/aio_misc.c                    |    6 +-
 sysdeps/pthread/aio_suspend.c                 |    6 +-
 sysdeps/unix/clock_gettime.c                  |   64 -
 sysdeps/unix/make-syscalls.sh                 |    2 +-
 sysdeps/unix/syscalls.list                    |    2 -
 .../unix/sysv/linux/aarch64/gettimeofday.c    |   71 --
 sysdeps/unix/sysv/linux/aarch64/init-first.c  |    7 +-
 sysdeps/unix/sysv/linux/aarch64/libc-vdso.h   |    2 -
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |    1 -
 sysdeps/unix/sysv/linux/alpha/Makefile        |    2 +-
 sysdeps/unix/sysv/linux/alpha/Versions        |    1 -
 sysdeps/unix/sysv/linux/alpha/adjtime.c       |   70 +-
 .../linux/{time.c => alpha/gettimeofday.c}    |   31 +-
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |    2 -
 sysdeps/unix/sysv/linux/alpha/librt.abilist   |    5 -
 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c   |  135 +++
 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c |   48 +
 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c |   44 +
 .../unix/sysv/linux/alpha/osf_gettimeofday.c  |   53 +
 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c |   55 +
 .../unix/sysv/linux/alpha/osf_settimeofday.c  |   51 +
 .../ftime.c => sysv/linux/alpha/osf_utimes.c} |   34 +-
 .../linux/alpha/osf_wait4.c}                  |   51 +-
 sysdeps/unix/sysv/linux/alpha/settimeofday.c  |   22 +
 sysdeps/unix/sysv/linux/alpha/syscalls.list   |   13 +-
 sysdeps/unix/sysv/linux/alpha/tv32-compat.h   |  151 +++
 sysdeps/unix/sysv/linux/arm/init-first.c      |    7 +-
 sysdeps/unix/sysv/linux/arm/libc-vdso.h       |    2 -
 sysdeps/unix/sysv/linux/arm/libc.abilist      |    1 -
 sysdeps/unix/sysv/linux/arm/librt.abilist     |    5 -
 sysdeps/unix/sysv/linux/clock_settime.c       |    1 +
 sysdeps/unix/sysv/linux/csky/libc.abilist     |    1 -
 sysdeps/unix/sysv/linux/ftime.c               |    3 -
 sysdeps/unix/sysv/linux/gettimeofday.c        |   39 -
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |    1 -
 sysdeps/unix/sysv/linux/hppa/librt.abilist    |    5 -
 sysdeps/unix/sysv/linux/i386/gettimeofday.c   |   35 -
 sysdeps/unix/sysv/linux/i386/libc.abilist     |    1 -
 sysdeps/unix/sysv/linux/i386/librt.abilist    |    5 -
 sysdeps/unix/sysv/linux/i386/time.c           |   34 -
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |    1 -
 sysdeps/unix/sysv/linux/ia64/librt.abilist    |    5 -
 .../sysv/linux/m68k/coldfire/libc.abilist     |    1 -
 .../sysv/linux/m68k/coldfire/librt.abilist    |    5 -
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |    1 -
 .../unix/sysv/linux/m68k/m680x0/librt.abilist |    5 -
 .../unix/sysv/linux/microblaze/libc.abilist   |    1 -
 .../unix/sysv/linux/microblaze/librt.abilist  |    5 -
 sysdeps/unix/sysv/linux/mips/init-first.c     |    7 +-
 sysdeps/unix/sysv/linux/mips/libc-vdso.h      |    2 -
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |    1 -
 .../unix/sysv/linux/mips/mips32/librt.abilist |    5 -
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |    1 -
 .../unix/sysv/linux/mips/mips64/librt.abilist |    5 -
 .../sysv/linux/mips/mips64/n32/libc.abilist   |    1 -
 .../sysv/linux/mips/mips64/n64/libc.abilist   |    1 -
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |    1 -
 sysdeps/unix/sysv/linux/powerpc/Versions      |    1 -
 .../unix/sysv/linux/powerpc/gettimeofday.c    |   85 --
 sysdeps/unix/sysv/linux/powerpc/init-first.c  |   13 +-
 sysdeps/unix/sysv/linux/powerpc/libc-vdso.h   |    2 -
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |    1 -
 .../linux/powerpc/powerpc32/librt.abilist     |    5 -
 .../powerpc/powerpc32/nofpu/libc.abilist      |    1 -
 .../linux/powerpc/powerpc64/be/libc.abilist   |    1 -
 .../linux/powerpc/powerpc64/be/librt.abilist  |    5 -
 .../linux/powerpc/powerpc64/le/libc.abilist   |    1 -
 sysdeps/unix/sysv/linux/powerpc/time.c        |   84 --
 sysdeps/unix/sysv/linux/riscv/init-first.c    |   10 +-
 sysdeps/unix/sysv/linux/riscv/libc-vdso.h     |    2 -
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |    1 -
 sysdeps/unix/sysv/linux/s390/init-first.c     |    9 +-
 sysdeps/unix/sysv/linux/s390/libc-vdso.h      |    3 -
 .../unix/sysv/linux/s390/s390-32/libc.abilist |    1 -
 .../sysv/linux/s390/s390-32/librt.abilist     |    5 -
 .../unix/sysv/linux/s390/s390-64/libc.abilist |    1 -
 .../sysv/linux/s390/s390-64/librt.abilist     |    5 -
 sysdeps/unix/sysv/linux/settimezone.c         |   39 +
 sysdeps/unix/sysv/linux/sh/libc.abilist       |    1 -
 sysdeps/unix/sysv/linux/sh/librt.abilist      |    5 -
 sysdeps/unix/sysv/linux/sparc/init-first.c    |    8 +-
 sysdeps/unix/sysv/linux/sparc/libc-vdso.h     |    2 -
 .../sysv/linux/sparc/sparc32/libc.abilist     |    1 -
 .../sysv/linux/sparc/sparc32/librt.abilist    |    5 -
 .../sysv/linux/sparc/sparc64/libc.abilist     |    1 -
 .../sysv/linux/sparc/sparc64/librt.abilist    |    5 -
 sysdeps/unix/sysv/linux/sparc/sparc64/time.c  |    1 -
 sysdeps/unix/sysv/linux/syscalls.list         |    1 -
 sysdeps/unix/sysv/linux/x86/gettimeofday.c    |   61 -
 sysdeps/unix/sysv/linux/x86/time.c            |   59 -
 .../unix/sysv/linux/x86_64/64/libc.abilist    |    1 -
 .../unix/sysv/linux/x86_64/64/librt.abilist   |    5 -
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |    1 -
 .../unix/sysv/linux/x86_64/x32/librt.abilist  |    5 -
 .../unix/sysv/linux/x86_64/x32/syscalls.list  |    2 -
 time/Makefile                                 |    8 +-
 time/Versions                                 |    2 +-
 {rt => time}/clock_getcpuclockid.c            |    0
 {rt => time}/clock_getres.c                   |    0
 {rt => time}/clock_gettime.c                  |    0
 {rt => time}/clock_nanosleep.c                |    0
 {rt => time}/clock_settime.c                  |    1 +
 time/ftime.c                                  |   26 +-
 time/getdate.c                                |    2 +-
 time/gettimeofday.c                           |   30 +-
 time/settimeofday.c                           |   24 +-
 sysdeps/unix/stime.c => time/settimezone.c    |   23 +-
 time/stime.c                                  |   15 +-
 time/sys/time.h                               |   36 +-
 time/time.c                                   |   17 +-
 {rt => time}/tst-clock.c                      |    0
 {rt => time}/tst-clock2.c                     |    0
 {rt => time}/tst-clock_nanosleep.c            |    0
 {rt => time}/tst-cpuclock1.c                  |    0
 time/tst_wcsftime.c                           |    2 +-
 156 files changed, 1580 insertions(+), 1775 deletions(-)
 delete mode 100644 rt/clock-compat.c
 rename sysdeps/mach/{gettimeofday.c => clock_gettime.c} (67%)
 rename sysdeps/mach/hurd/{settimeofday.c => clock_settime.c} (71%)
 delete mode 100644 sysdeps/posix/gettimeofday.c
 delete mode 100644 sysdeps/posix/time.c
 delete mode 100644 sysdeps/unix/clock_gettime.c
 delete mode 100644 sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
 rename sysdeps/unix/sysv/linux/{time.c => alpha/gettimeofday.c} (64%)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
 rename sysdeps/unix/{bsd/ftime.c => sysv/linux/alpha/osf_utimes.c} (60%)
 rename sysdeps/unix/{clock_settime.c => sysv/linux/alpha/osf_wait4.c} (55%)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/settimeofday.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/tv32-compat.h
 delete mode 100644 sysdeps/unix/sysv/linux/ftime.c
 delete mode 100644 sysdeps/unix/sysv/linux/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/i386/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/i386/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/time.c
 create mode 100644 sysdeps/unix/sysv/linux/settimezone.c
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/x86/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/x86/time.c
 rename {rt => time}/clock_getcpuclockid.c (100%)
 rename {rt => time}/clock_getres.c (100%)
 rename {rt => time}/clock_gettime.c (100%)
 rename {rt => time}/clock_nanosleep.c (100%)
 rename {rt => time}/clock_settime.c (96%)
 rename sysdeps/unix/stime.c => time/settimezone.c (67%)
 rename {rt => time}/tst-clock.c (100%)
 rename {rt => time}/tst-clock2.c (100%)
 rename {rt => time}/tst-clock_nanosleep.c (100%)
 rename {rt => time}/tst-cpuclock1.c (100%)

-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 08/12] Use clock_gettime to implement gettimeofday.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (8 preceding siblings ...)
  2019-08-20 13:37 ` [PATCH 06/12] Use clock_gettime to implement time Zack Weinberg
@ 2019-08-20 13:37 ` Zack Weinberg
  2019-08-20 15:24   ` Joseph Myers
  2019-08-20 17:51   ` Adhemerval Zanella
  2019-08-20 13:37 ` [PATCH 07/12] Use clock_gettime to implement ftime Zack Weinberg
                   ` (5 subsequent siblings)
  15 siblings, 2 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:37 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Abstractly, this is the same change as using clock_gettime to
implement time, but the vestigial “get time zone” feature of
gettimeofday complicates matters a little.  Unlike settimeofday, there
are *no* known uses of this feature that are not bugs, so it is simply
dummied out.  (The per-process timezone support in ‘localtime’ and
friends is unrelated, and the programs that set the kernel’s offset
between the hardware clock and UTC do not need to read it back.)

Henceforth, if gettimeofday’s ‘struct timezone’ argument is not NULL,
it will write zeroes to both fields.  Any program that is actually
looking at this data will thus think it is running in UTC, which is
probably more correct than whatever it was doing before.

Hurd having already been converted, this patch only affects Linux and
hypothetical future ports.  Most Linux ports supplied a vDSO symbol
for gettimeofday, and some wrapped that with an ifunc, so this patch
deletes a lot of code.  For ease of future edits to the many copies of
_libc_vdso_platform_setup, the variable ‘p’ in each is now declared
separately from any use of it.

As with settimeofday, the alpha-linux-gnu configuration has two
versions, GLIBC_2.0 and GLIBC_2.1, with the older symbol using 32-bit
time_t (yes, really) and the same solution is implemented here.

__gettimeofday is no longer called by anyone, so remove its internal
prototype and its entries in Versions and .abilist files.  (It would
have been a GLIBC_PRIVATE symbol if the GLIBC_PRIVATE convention had
been invented back in the days of 2.0.)

	* time/gettimeofday.c: No longer a stub implementation.
	Call __clock_gettime.  If ‘tz’ argument is not NULL, clear the
	object it points to.  Remove libc_hidden_def for __gettimeofday
	and libc_hidden_weak for gettimeofday.  Optionally override the
	default symbol version for gettimeofday.
	* include/sys/time.h: Remove internal prototype and libc_hidden_proto
        for __gettimeofday, and libc_hidden_proto for gettimeofday.
	* time/Versions
	* sysdeps/unix/sysv/linux/alpha/Versions
	* sysdeps/**/libc.abilist: Remove entry for __gettimeofday.

	* sysdeps/unix/sysv/linux/aarch64/init-first.c
	* sysdeps/unix/sysv/linux/arm/init-first.c
	* sysdeps/unix/sysv/linux/mips/init-first.c
	* sysdeps/unix/sysv/linux/powerpc/init-first.c
	* sysdeps/unix/sysv/linux/riscv/init-first.c
	* sysdeps/unix/sysv/linux/s390/init-first.c
	* sysdeps/unix/sysv/linux/sparc/init-first.c:
	Do not define nor initialize VDSO_SYMBOL(gettimeofday).

	* sysdeps/unix/sysv/linux/aarch64/libc-vdso.h
	* sysdeps/unix/sysv/linux/arm/libc-vdso.h
	* sysdeps/unix/sysv/linux/mips/libc-vdso.h
	* sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
	* sysdeps/unix/sysv/linux/riscv/libc-vdso.h
	* sysdeps/unix/sysv/linux/s390/libc-vdso.h
	* sysdeps/unix/sysv/linux/sparc/libc-vdso.h:
	Do not declare VDSO_SYMBOL(gettimeofday).

	* sysdeps/unix/syscalls.list: Remove entry for gettimeofday.
	* sysdeps/unix/sysv/linux/alpha/syscalls.list:
	Remove entries for gettimeofday and osf_gettimeofday.
	* sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list:
	Remove entry for gettimeofday.

	* sysdeps/posix/gettimeofday.c
	* sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
	* sysdeps/unix/sysv/linux/gettimeofday.c
	* sysdeps/unix/sysv/linux/i386/gettimeofday.c
	* sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
	* sysdeps/unix/sysv/linux/x86/gettimeofday.c: Delete file.

	* sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c:
	New file, defines gettimeofday@GLIBC_2.0.
	* sysdeps/unix/sysv/linux/alpha/gettimeofday.c
	New file, defines gettimeofday@@GLIBC_2.1.

	* sysdeps/unix/make-syscalls.sh: Change an example in a comment
	from referring to gettimeofday, to referring to sigaction.
---
 include/sys/time.h                            |  4 -
 sysdeps/mach/hurd/i386/libc.abilist           |  1 -
 sysdeps/posix/gettimeofday.c                  | 67 ---------------
 sysdeps/unix/make-syscalls.sh                 |  2 +-
 sysdeps/unix/syscalls.list                    |  1 -
 .../unix/sysv/linux/aarch64/gettimeofday.c    | 71 ----------------
 sysdeps/unix/sysv/linux/aarch64/init-first.c  |  7 +-
 sysdeps/unix/sysv/linux/aarch64/libc-vdso.h   |  2 -
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |  1 -
 sysdeps/unix/sysv/linux/alpha/Versions        |  1 -
 .../sysv/linux/{i386 => alpha}/gettimeofday.c | 25 ++----
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |  2 -
 .../unix/sysv/linux/alpha/osf_gettimeofday.c  | 66 ++++++++++++++
 sysdeps/unix/sysv/linux/alpha/syscalls.list   |  2 -
 sysdeps/unix/sysv/linux/arm/init-first.c      |  7 +-
 sysdeps/unix/sysv/linux/arm/libc-vdso.h       |  2 -
 sysdeps/unix/sysv/linux/arm/libc.abilist      |  1 -
 sysdeps/unix/sysv/linux/csky/libc.abilist     |  1 -
 sysdeps/unix/sysv/linux/gettimeofday.c        | 39 ---------
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 -
 sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 -
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |  1 -
 .../sysv/linux/m68k/coldfire/libc.abilist     |  1 -
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 -
 .../unix/sysv/linux/microblaze/libc.abilist   |  1 -
 sysdeps/unix/sysv/linux/mips/init-first.c     |  7 +-
 sysdeps/unix/sysv/linux/mips/libc-vdso.h      |  2 -
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 -
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 -
 .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 -
 .../sysv/linux/mips/mips64/n64/libc.abilist   |  1 -
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 -
 .../unix/sysv/linux/powerpc/gettimeofday.c    | 85 -------------------
 sysdeps/unix/sysv/linux/powerpc/init-first.c  |  8 +-
 sysdeps/unix/sysv/linux/powerpc/libc-vdso.h   |  2 -
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 -
 .../powerpc/powerpc32/nofpu/libc.abilist      |  1 -
 .../linux/powerpc/powerpc64/be/libc.abilist   |  1 -
 .../linux/powerpc/powerpc64/le/libc.abilist   |  1 -
 sysdeps/unix/sysv/linux/riscv/init-first.c    | 10 +--
 sysdeps/unix/sysv/linux/riscv/libc-vdso.h     |  2 -
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |  1 -
 sysdeps/unix/sysv/linux/s390/init-first.c     |  9 +-
 sysdeps/unix/sysv/linux/s390/libc-vdso.h      |  3 -
 .../unix/sysv/linux/s390/s390-32/libc.abilist |  1 -
 .../unix/sysv/linux/s390/s390-64/libc.abilist |  1 -
 sysdeps/unix/sysv/linux/sh/libc.abilist       |  1 -
 sysdeps/unix/sysv/linux/sparc/init-first.c    |  8 +-
 sysdeps/unix/sysv/linux/sparc/libc-vdso.h     |  2 -
 .../sysv/linux/sparc/sparc32/libc.abilist     |  1 -
 .../sysv/linux/sparc/sparc64/libc.abilist     |  1 -
 sysdeps/unix/sysv/linux/x86/gettimeofday.c    | 61 -------------
 .../unix/sysv/linux/x86_64/64/libc.abilist    |  1 -
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |  1 -
 .../unix/sysv/linux/x86_64/x32/syscalls.list  |  1 -
 time/Versions                                 |  2 +-
 time/gettimeofday.c                           | 28 ++++--
 57 files changed, 108 insertions(+), 447 deletions(-)
 delete mode 100644 sysdeps/posix/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
 rename sysdeps/unix/sysv/linux/{i386 => alpha}/gettimeofday.c (58%)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/x86/gettimeofday.c

diff --git a/include/sys/time.h b/include/sys/time.h
index a57752e8c7..4a91622096 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -20,10 +20,6 @@
 # include <time/sys/time.h>
 
 # ifndef _ISOMAC
-extern int __gettimeofday (struct timeval *__tv,
-			   struct timezone *__tz);
-libc_hidden_proto (__gettimeofday)
-libc_hidden_proto (gettimeofday)
 extern int __settimezone (const struct timezone *__tz)
 	attribute_hidden;
 extern int __adjtime (const struct timeval *__delta,
diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist
index 1fc7ab2433..84345bf3e0 100644
--- a/sysdeps/mach/hurd/i386/libc.abilist
+++ b/sysdeps/mach/hurd/i386/libc.abilist
@@ -272,7 +272,6 @@ GLIBC_2.2.6 __getdelim F
 GLIBC_2.2.6 __getpagesize F
 GLIBC_2.2.6 __getpgid F
 GLIBC_2.2.6 __getpid F
-GLIBC_2.2.6 __gettimeofday F
 GLIBC_2.2.6 __gmtime_r F
 GLIBC_2.2.6 __h_errno_location F
 GLIBC_2.2.6 __hurd_fail F
diff --git a/sysdeps/posix/gettimeofday.c b/sysdeps/posix/gettimeofday.c
deleted file mode 100644
index 6ba625e13e..0000000000
--- a/sysdeps/posix/gettimeofday.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Copyright (C) 1991-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <time.h>
-#include <sys/time.h>
-
-/* Get the current time of day and timezone information,
-   putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
-   Returns 0 on success, -1 on errors.  */
-int
-__gettimeofday (struct timeval *tv, struct timezone *tz)
-{
-  if (tv == NULL)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
-
-  tv->tv_sec = (long int) time ((time_t *) NULL);
-  tv->tv_usec = 0L;
-
-  if (tz != NULL)
-    {
-      const time_t timer = tv->tv_sec;
-      struct tm tm;
-      const struct tm *tmp;
-
-      const long int save_timezone = __timezone;
-      const long int save_daylight = __daylight;
-      char *save_tzname[2];
-      save_tzname[0] = __tzname[0];
-      save_tzname[1] = __tzname[1];
-
-      tmp = localtime_r (&timer, &tm);
-
-      tz->tz_minuteswest = __timezone / 60;
-      tz->tz_dsttime = __daylight;
-
-      __timezone = save_timezone;
-      __daylight = save_daylight;
-      __tzname[0] = save_tzname[0];
-      __tzname[1] = save_tzname[1];
-
-      if (tmp == NULL)
-	return -1;
-    }
-
-  return 0;
-}
-libc_hidden_def (__gettimeofday)
-weak_alias (__gettimeofday, gettimeofday)
-libc_hidden_weak (gettimeofday)
diff --git a/sysdeps/unix/make-syscalls.sh b/sysdeps/unix/make-syscalls.sh
index 6a5c10d54e..2b8c9ea49c 100644
--- a/sysdeps/unix/make-syscalls.sh
+++ b/sysdeps/unix/make-syscalls.sh
@@ -27,7 +27,7 @@
 # n: scalar buffer length (e.g., 3rd arg to read)
 # N: pointer to value/return scalar buffer length (e.g., 6th arg to recvfrom)
 # p: non-NULL pointer to typed object (e.g., any non-void* arg)
-# P: optionally-NULL pointer to typed object (e.g., 2nd argument to gettimeofday)
+# P: optionally-NULL pointer to typed object (e.g., 3rd argument to sigaction)
 # s: non-NULL string (e.g., 1st arg to open)
 # S: optionally-NULL string (e.g., 1st arg to acct)
 # v: vararg scalar (e.g., optional 3rd arg to open)
diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
index 5fedd5733d..e28e801c7a 100644
--- a/sysdeps/unix/syscalls.list
+++ b/sysdeps/unix/syscalls.list
@@ -33,7 +33,6 @@ getrlimit	-	getrlimit	i:ip	__getrlimit	getrlimit
 getrusage	-	getrusage	i:ip	__getrusage	getrusage
 getsockname	-	getsockname	i:ibN	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	getsockopt
-gettimeofday	-	gettimeofday	i:pP	__gettimeofday	gettimeofday
 getuid		-	getuid		Ei:	__getuid	getuid
 ioctl		-	ioctl		i:iiI	__ioctl		ioctl
 kill		-	kill		i:ii	__kill		kill
diff --git a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
deleted file mode 100644
index 9180b50bf7..0000000000
--- a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/* Copyright (C) 2018-2019 Free Software Foundation, Inc.
-
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public License as
-   published by the Free Software Foundation; either version 2.1 of the
-   License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-/* Get the current time of day and timezone information,
-   putting it into *tv and *tz.  If tz is null, *tz is not filled.
-   Returns 0 on success, -1 on errors.  */
-
-#ifdef SHARED
-
-# define __gettimeofday __redirect___gettimeofday
-# include <sys/time.h>
-# undef __gettimeofday
-# define HAVE_VSYSCALL
-# include <dl-vdso.h>
-# include <sysdep-vdso.h>
-
-/* Used as a fallback in the ifunc resolver if VDSO is not available
-   and for libc.so internal __gettimeofday calls.  */
-
-static int
-__gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz)
-{
-  return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
-}
-
-/* PREPARE_VERSION_KNOWN will need an __LP64__ ifdef when ILP32 support
-   goes in.  See _libc_vdso_platform_setup in
-   sysdeps/unix/sysv/linux/aarch64/init-first.c.  */
-
-# undef INIT_ARCH
-# define INIT_ARCH() \
-	   PREPARE_VERSION_KNOWN (linux_version, LINUX_2_6_39); \
-	   void *vdso_gettimeofday = \
-	     _dl_vdso_vsym ("__kernel_gettimeofday", &linux_version);
-
-libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday,
-		   vdso_gettimeofday ?: (void *) __gettimeofday_vsyscall)
-
-__hidden_ver1 (__gettimeofday_vsyscall, __GI___gettimeofday,
-	       __gettimeofday_vsyscall);
-
-#else
-
-# include <sys/time.h>
-# include <sysdep.h>
-int
-__gettimeofday (struct timeval *tv, struct timezone *tz)
-{
-  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
-}
-libc_hidden_def (__gettimeofday)
-
-#endif
-
-weak_alias (__gettimeofday, gettimeofday)
-libc_hidden_weak (gettimeofday)
diff --git a/sysdeps/unix/sysv/linux/aarch64/init-first.c b/sysdeps/unix/sysv/linux/aarch64/init-first.c
index 80f7ed91ef..5e4e1fbf8c 100644
--- a/sysdeps/unix/sysv/linux/aarch64/init-first.c
+++ b/sysdeps/unix/sysv/linux/aarch64/init-first.c
@@ -19,23 +19,20 @@
 #include <dl-vdso.h>
 #include <libc-vdso.h>
 
-int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;
 int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *);
 
 static inline void
 _libc_vdso_platform_setup (void)
 {
+  void *p;
+
 #ifdef __LP64__
   PREPARE_VERSION_KNOWN (linux_version, LINUX_2_6_39);
 #else
   PREPARE_VERSION_KNOWN (linux_version, LINUX_4_9);
 #endif
 
-  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", &linux_version);
-  PTR_MANGLE (p);
-  VDSO_SYMBOL(gettimeofday) = p;
-
   p = _dl_vdso_vsym ("__kernel_clock_gettime", &linux_version);
   PTR_MANGLE (p);
   VDSO_SYMBOL(clock_gettime) = p;
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc-vdso.h b/sysdeps/unix/sysv/linux/aarch64/libc-vdso.h
index 3fcbaa9fce..285ca62fd3 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/aarch64/libc-vdso.h
@@ -22,8 +22,6 @@
 #include <sysdep.h>
 #include <sysdep-vdso.h>
 
-extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
-   attribute_hidden;
 extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 extern int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *);
 
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
index a4c31932cb..4d24c65074 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -216,7 +216,6 @@ GLIBC_2.17 __getpagesize F
 GLIBC_2.17 __getpgid F
 GLIBC_2.17 __getpid F
 GLIBC_2.17 __gets_chk F
-GLIBC_2.17 __gettimeofday F
 GLIBC_2.17 __getwd_chk F
 GLIBC_2.17 __gmtime_r F
 GLIBC_2.17 __h_errno_location F
diff --git a/sysdeps/unix/sysv/linux/alpha/Versions b/sysdeps/unix/sysv/linux/alpha/Versions
index 3b7971c2a3..a20d80c2ce 100644
--- a/sysdeps/unix/sysv/linux/alpha/Versions
+++ b/sysdeps/unix/sysv/linux/alpha/Versions
@@ -39,7 +39,6 @@ libc {
     # Linux/Alpha 64-bit timeval functions.
     __select; select;
     adjtime; adjtimex; __adjtimex;
-    __gettimeofday;
 
     # glob interface change
     glob; globfree;
diff --git a/sysdeps/unix/sysv/linux/i386/gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/gettimeofday.c
similarity index 58%
rename from sysdeps/unix/sysv/linux/i386/gettimeofday.c
rename to sysdeps/unix/sysv/linux/alpha/gettimeofday.c
index 185450ece6..46dc778427 100644
--- a/sysdeps/unix/sysv/linux/i386/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/gettimeofday.c
@@ -1,5 +1,5 @@
-/* gettimeofday - get the time.  Linux/i386 version.
-   Copyright (C) 2015-2019 Free Software Foundation, Inc.
+/* gettimeofday -- Get the current time of day.  Linux/Alpha/tv64 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -16,20 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef SHARED
-# define __gettimeofday __redirect___gettimeofday
-#endif
-
-#include <sys/time.h>
-
-#ifdef SHARED
-# undef __gettimeofday
-# define __gettimeofday_type __redirect___gettimeofday
-
-# undef libc_hidden_def
-# define libc_hidden_def(name) \
-  __hidden_ver1 (__gettimeofday_syscall, __GI___gettimeofday, \
-	       __gettimeofday_syscall);
-#endif
-
-#include <sysdeps/unix/sysv/linux/x86/gettimeofday.c>
+/* We can use the generic implementation, but we have to override its
+   default symbol version.  */
+#define VERSION_gettimeofday GLIBC_2.1
+#include <time/gettimeofday.c>
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index fe85a35620..3335f3b0f7 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -141,7 +141,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __ieee_get_fp_control F
@@ -1370,7 +1369,6 @@ GLIBC_2.1 __backtrace_symbols_fd F
 GLIBC_2.1 __duplocale F
 GLIBC_2.1 __freelocale F
 GLIBC_2.1 __fxstat64 F
-GLIBC_2.1 __gettimeofday F
 GLIBC_2.1 __isalnum_l F
 GLIBC_2.1 __isalpha_l F
 GLIBC_2.1 __isascii_l F
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
new file mode 100644
index 0000000000..9868dfd9c9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
@@ -0,0 +1,66 @@
+/* gettimeofday -- Get the current time of day.  Linux/Alpha/tv32 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
+#include <time.h>
+#include <sys/time.h>
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
+struct timeval32
+{
+    int tv_sec, tv_usec;
+};
+
+/* Get the current time of day, putting it into *TV.
+   If *TZ is not NULL, clear it.
+   Returns 0 on success, -1 on errors.  */
+
+int
+attribute_compat_text_section
+__gettimeofday_tv32 (struct timeval32 *tv32,
+                     struct timezone *tz)
+{
+  if (__glibc_unlikely (tz != 0))
+    memset (tz, 0, sizeof *tz);
+
+  struct timespec ts;
+  if (__clock_gettime (CLOCK_REALTIME, &ts))
+    return -1;
+
+  if (__glibc_unlikely (ts.tv_sec > (time_t)INT_MAX))
+    {
+      /* The clock has advanced past the time representable in a 32-bit
+         time_t.  Fail, but write a saturated value to the output first,
+         because callers don't typically expect gettimeofday to fail.  */
+      __set_errno (EOVERFLOW);
+      tv32->tv_sec  = INT_MAX;
+      tv32->tv_usec = 0;
+      return -1;
+    }
+
+  tv32->tv_sec = ts.tv_sec;
+  tv32->tv_usec = ts.tv_nsec / 1000;
+  return 0;
+}
+
+compat_symbol (libc, __gettimeofday_tv32, gettimeofday, GLIBC_2_0);
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index f5a534ed68..9ceed78c8d 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -23,7 +23,6 @@ pciconfig_write	EXTRA	pciconfig_write	5	pciconfig_write
 pciconfig_iobase EXTRA	pciconfig_iobase 3	__pciconfig_iobase pciconfig_iobase
 
 # support old timeval32 entry points
-osf_gettimeofday -	osf_gettimeofday 2	__gettimeofday_tv32  __gettimeofday@GLIBC_2.0 gettimeofday@GLIBC_2.0
 osf_getitimer	-	osf_getitimer	2	__getitimer_tv32  getitimer@GLIBC_2.0
 osf_setitimer	-	osf_setitimer	3	__setitimer_tv32  setitimer@GLIBC_2.0
 osf_utimes	-	osf_utimes	2	__utimes_tv32  utimes@GLIBC_2.0
@@ -31,7 +30,6 @@ osf_getrusage	-	osf_getrusage	2	__getrusage_tv32  getrusage@GLIBC_2.0
 osf_wait4	-	osf_wait4	4	__wait4_tv32  wait4@GLIBC_2.0
 
 # support new timeval64 entry points
-gettimeofday	-	gettimeofday	2	__GI___gettimeofday gettimeofday@@GLIBC_2.1 __gettimeofday@@GLIBC_2.1
 getitimer	-	getitimer	2	__getitimer getitimer@@GLIBC_2.1
 setitimer	-	setitimer	3	__setitimer setitimer@@GLIBC_2.1
 utimes		-	utimes		2	__utimes utimes@@GLIBC_2.1
diff --git a/sysdeps/unix/sysv/linux/arm/init-first.c b/sysdeps/unix/sysv/linux/arm/init-first.c
index e1846df661..c73970d06d 100644
--- a/sysdeps/unix/sysv/linux/arm/init-first.c
+++ b/sysdeps/unix/sysv/linux/arm/init-first.c
@@ -21,17 +21,14 @@
 #include <libc-vdso.h>
 #include <sysdep-vdso.h>
 
-int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;
 int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 
 static inline void
 _libc_vdso_platform_setup (void)
 {
-  PREPARE_VERSION_KNOWN (linux26, LINUX_2_6);
+  void *p;
 
-  void *p = _dl_vdso_vsym ("__vdso_gettimeofday", &linux26);
-  PTR_MANGLE (p);
-  VDSO_SYMBOL (gettimeofday) = p;
+  PREPARE_VERSION_KNOWN (linux26, LINUX_2_6);
 
   p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26);
   PTR_MANGLE (p);
diff --git a/sysdeps/unix/sysv/linux/arm/libc-vdso.h b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
index 8702165c6b..b7ae61def6 100644
--- a/sysdeps/unix/sysv/linux/arm/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
@@ -22,8 +22,6 @@
 
 #include <sysdep-vdso.h>
 
-extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
-   attribute_hidden;
 extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 
 #endif /* _LIBC_VDSO_H */
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index bc3df8dcea..d58f0f84e3 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -356,7 +356,6 @@ GLIBC_2.4 __getpagesize F
 GLIBC_2.4 __getpgid F
 GLIBC_2.4 __getpid F
 GLIBC_2.4 __gets_chk F
-GLIBC_2.4 __gettimeofday F
 GLIBC_2.4 __getwd_chk F
 GLIBC_2.4 __gmtime_r F
 GLIBC_2.4 __gnu_Unwind_Find_exidx F
diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist
index 9b3cee65bb..fcbfbd756b 100644
--- a/sysdeps/unix/sysv/linux/csky/libc.abilist
+++ b/sysdeps/unix/sysv/linux/csky/libc.abilist
@@ -216,7 +216,6 @@ GLIBC_2.29 __getpagesize F
 GLIBC_2.29 __getpgid F
 GLIBC_2.29 __getpid F
 GLIBC_2.29 __gets_chk F
-GLIBC_2.29 __gettimeofday F
 GLIBC_2.29 __getwd_chk F
 GLIBC_2.29 __gmtime_r F
 GLIBC_2.29 __h_errno_location F
diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c
deleted file mode 100644
index a74f03825a..0000000000
--- a/sysdeps/unix/sysv/linux/gettimeofday.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright (C) 2015-2019 Free Software Foundation, Inc.
-
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public License as
-   published by the Free Software Foundation; either version 2.1 of the
-   License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <sys/time.h>
-
-#undef __gettimeofday
-
-#ifdef HAVE_GETTIMEOFDAY_VSYSCALL
-# define HAVE_VSYSCALL
-#endif
-#include <sysdep-vdso.h>
-
-/* Get the current time of day and timezone information,
-   putting it into *tv and *tz.  If tz is null, *tz is not filled.
-   Returns 0 on success, -1 on errors.  */
-int
-__gettimeofday (struct timeval *tv, struct timezone *tz)
-{
-  return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
-}
-libc_hidden_def (__gettimeofday)
-weak_alias (__gettimeofday, gettimeofday)
-libc_hidden_weak (gettimeofday)
diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 75edece94a..8204979434 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -271,7 +271,6 @@ GLIBC_2.2 __getmntent_r F
 GLIBC_2.2 __getpagesize F
 GLIBC_2.2 __getpgid F
 GLIBC_2.2 __getpid F
-GLIBC_2.2 __gettimeofday F
 GLIBC_2.2 __gmtime_r F
 GLIBC_2.2 __h_errno_location F
 GLIBC_2.2 __isalnum_l F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index edeaf8e722..eddfaae9ee 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -139,7 +139,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist
index b5d460eeb2..8fa8bb37fe 100644
--- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
@@ -271,7 +271,6 @@ GLIBC_2.2 __getmntent_r F
 GLIBC_2.2 __getpagesize F
 GLIBC_2.2 __getpgid F
 GLIBC_2.2 __getpid F
-GLIBC_2.2 __gettimeofday F
 GLIBC_2.2 __gmtime_r F
 GLIBC_2.2 __h_errno_location F
 GLIBC_2.2 __isalnum_l F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index 05633b3cb8..572713c5ce 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -342,7 +342,6 @@ GLIBC_2.4 __getpagesize F
 GLIBC_2.4 __getpgid F
 GLIBC_2.4 __getpid F
 GLIBC_2.4 __gets_chk F
-GLIBC_2.4 __gettimeofday F
 GLIBC_2.4 __getwd_chk F
 GLIBC_2.4 __gmtime_r F
 GLIBC_2.4 __h_errno_location F
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index 47eb7b4608..c2da22311b 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -139,7 +139,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
index f7ced487f7..3c37a890f2 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
@@ -217,7 +217,6 @@ GLIBC_2.18 __getpagesize F
 GLIBC_2.18 __getpgid F
 GLIBC_2.18 __getpid F
 GLIBC_2.18 __gets_chk F
-GLIBC_2.18 __gettimeofday F
 GLIBC_2.18 __getwd_chk F
 GLIBC_2.18 __gmtime_r F
 GLIBC_2.18 __h_errno_location F
diff --git a/sysdeps/unix/sysv/linux/mips/init-first.c b/sysdeps/unix/sysv/linux/mips/init-first.c
index 25884ffd80..a7c3643cb8 100644
--- a/sysdeps/unix/sysv/linux/mips/init-first.c
+++ b/sysdeps/unix/sysv/linux/mips/init-first.c
@@ -20,17 +20,14 @@
 #include <dl-vdso.h>
 #include <libc-vdso.h>
 
-int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;
 int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 
 static inline void
 _libc_vdso_platform_setup (void)
 {
-  PREPARE_VERSION_KNOWN (linux26, LINUX_2_6);
+  void *p;
 
-  void *p = _dl_vdso_vsym ("__vdso_gettimeofday", &linux26);
-  PTR_MANGLE (p);
-  VDSO_SYMBOL (gettimeofday) = p;
+  PREPARE_VERSION_KNOWN (linux26, LINUX_2_6);
 
   p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26);
   PTR_MANGLE (p);
diff --git a/sysdeps/unix/sysv/linux/mips/libc-vdso.h b/sysdeps/unix/sysv/linux/mips/libc-vdso.h
index 344ea2d750..e0a8fe4a80 100644
--- a/sysdeps/unix/sysv/linux/mips/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/mips/libc-vdso.h
@@ -22,8 +22,6 @@
 
 #include <sysdep-vdso.h>
 
-extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
-   attribute_hidden;
 extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 
 #endif /* _LIBC_VDSO_H */
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index e49dc4272e..a56e887841 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -138,7 +138,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index daa3b60c5b..6b77079708 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -138,7 +138,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 457ce0b6f2..74d0cdd671 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -138,7 +138,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index 63d5c03bfb..e7173457f7 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -138,7 +138,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index 7fec0c9670..6384bba4ba 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -242,7 +242,6 @@ GLIBC_2.21 __getpagesize F
 GLIBC_2.21 __getpgid F
 GLIBC_2.21 __getpid F
 GLIBC_2.21 __gets_chk F
-GLIBC_2.21 __gettimeofday F
 GLIBC_2.21 __getwd_chk F
 GLIBC_2.21 __gmtime_r F
 GLIBC_2.21 __gtdf2 F
diff --git a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
deleted file mode 100644
index 463b678ad9..0000000000
--- a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* Copyright (C) 2005-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#if defined SHARED && !defined __powerpc64__
-# define __gettimeofday __redirect___gettimeofday
-#else
-# define __redirect___gettimeofday __gettimeofday
-#endif
-
-#include <sys/time.h>
-
-#ifdef SHARED
-
-# include <dl-vdso.h>
-# include <libc-vdso.h>
-# include <dl-machine.h>
-
-# ifndef __powerpc64__
-#  undef __gettimeofday
-
-int
-__gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz)
-{
-  return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
-}
-
-/* __GI___gettimeofday is defined as hidden and for ppc32 it enables the
-   compiler make a local call (symbol@local) for internal GLIBC usage. It
-   means the PLT won't be used and the ifunc resolver will be called directly.
-   For ppc64 a call to a function in another translation unit might use a
-   different toc pointer thus disallowing direct branchess and making internal
-   ifuncs calls safe.  */
-#  undef libc_hidden_def
-#  define libc_hidden_def(name)					\
-  __hidden_ver1 (__gettimeofday_vsyscall, __GI___gettimeofday,	\
-	       __gettimeofday_vsyscall);
-
-# endif /* !__powerpc64__  */
-
-static int
-__gettimeofday_syscall (struct timeval *tv, struct timezone *tz)
-{
-  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
-}
-
-# define INIT_ARCH()						\
-  PREPARE_VERSION_KNOWN (linux2615, LINUX_2_6_15);		\
-  void *vdso_gettimeofday = _dl_vdso_vsym ("__kernel_gettimeofday", &linux2615);
-
-/* If the vDSO is not available we fall back syscall.  */
-libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday,
-		   vdso_gettimeofday
-		   ? VDSO_IFUNC_RET (vdso_gettimeofday)
-		   : (void *) __gettimeofday_syscall);
-libc_hidden_def (__gettimeofday)
-
-#else
-
-# include <sysdep.h>
-# include <errno.h>
-
-int
-__gettimeofday (struct timeval *tv, struct timezone *tz)
-{
-  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
-}
-libc_hidden_def (__gettimeofday)
-
-#endif
-weak_alias (__gettimeofday, gettimeofday)
-libc_hidden_weak (gettimeofday)
diff --git a/sysdeps/unix/sysv/linux/powerpc/init-first.c b/sysdeps/unix/sysv/linux/powerpc/init-first.c
index 4f12b59e76..166bf3f2fe 100644
--- a/sysdeps/unix/sysv/linux/powerpc/init-first.c
+++ b/sysdeps/unix/sysv/linux/powerpc/init-first.c
@@ -19,8 +19,6 @@
 #include <dl-vdso.h>
 #include <libc-vdso.h>
 
-int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
-  attribute_hidden;
 int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *);
 unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void);
@@ -36,11 +34,9 @@ void *VDSO_SYMBOL(sigtramp_rt32);
 static inline void
 _libc_vdso_platform_setup (void)
 {
-  PREPARE_VERSION_KNOWN (linux2615, LINUX_2_6_15);
+  void *p;
 
-  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", &linux2615);
-  PTR_MANGLE (p);
-  VDSO_SYMBOL (gettimeofday) = p;
+  PREPARE_VERSION_KNOWN (linux2615, LINUX_2_6_15);
 
   p = _dl_vdso_vsym ("__kernel_clock_gettime", &linux2615);
   PTR_MANGLE (p);
diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
index f8184061c0..e233ea18a5 100644
--- a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
@@ -23,8 +23,6 @@
 #include <sysdep.h>
 #include <sysdep-vdso.h>
 
-extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
-  attribute_hidden;
 extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 extern int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *);
 extern unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void);
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index 9200a54309..ec3f7a3715 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -147,7 +147,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index ef7779905f..e8facd80b9 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -147,7 +147,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
index 2860df8ebc..0fbb6c46b9 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
@@ -319,7 +319,6 @@ GLIBC_2.3 __getmntent_r F
 GLIBC_2.3 __getpagesize F
 GLIBC_2.3 __getpgid F
 GLIBC_2.3 __getpid F
-GLIBC_2.3 __gettimeofday F
 GLIBC_2.3 __gmtime_r F
 GLIBC_2.3 __h_errno_location F
 GLIBC_2.3 __isalnum_l F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
index 2229a1dcc0..ad21ed22ab 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
@@ -215,7 +215,6 @@ GLIBC_2.17 __getpagesize F
 GLIBC_2.17 __getpgid F
 GLIBC_2.17 __getpid F
 GLIBC_2.17 __gets_chk F
-GLIBC_2.17 __gettimeofday F
 GLIBC_2.17 __getwd_chk F
 GLIBC_2.17 __gmtime_r F
 GLIBC_2.17 __h_errno_location F
diff --git a/sysdeps/unix/sysv/linux/riscv/init-first.c b/sysdeps/unix/sysv/linux/riscv/init-first.c
index 98a8ce33ad..014d770861 100644
--- a/sysdeps/unix/sysv/linux/riscv/init-first.c
+++ b/sysdeps/unix/sysv/linux/riscv/init-first.c
@@ -22,8 +22,6 @@
 
 long int (*VDSO_SYMBOL (getcpu)) (unsigned int *, unsigned int *, void *)
     attribute_hidden;
-long int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *)
-    attribute_hidden;
 long int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *)
     attribute_hidden;
 long int (*VDSO_SYMBOL (clock_getres)) (clockid_t, struct timespec *)
@@ -32,16 +30,14 @@ long int (*VDSO_SYMBOL (clock_getres)) (clockid_t, struct timespec *)
 static inline void
 _libc_vdso_platform_setup (void)
 {
+  void *p;
+
   PREPARE_VERSION_KNOWN (linux_version, LINUX_4_15);
 
-  void *p = _dl_vdso_vsym ("__vdso_getcpu", &linux_version);
+  p = _dl_vdso_vsym ("__vdso_getcpu", &linux_version);
   PTR_MANGLE (p);
   VDSO_SYMBOL (getcpu) = p;
 
-  p = _dl_vdso_vsym ("__vdso_gettimeofday", &linux_version);
-  PTR_MANGLE (p);
-  VDSO_SYMBOL (gettimeofday) = p;
-
   p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux_version);
   PTR_MANGLE (p);
   VDSO_SYMBOL (clock_gettime) = p;
diff --git a/sysdeps/unix/sysv/linux/riscv/libc-vdso.h b/sysdeps/unix/sysv/linux/riscv/libc-vdso.h
index 2373292ab9..e9a5b239b9 100644
--- a/sysdeps/unix/sysv/linux/riscv/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/riscv/libc-vdso.h
@@ -24,8 +24,6 @@
 
 extern long int (*VDSO_SYMBOL (getcpu)) (unsigned int *, unsigned int *, void *)
     attribute_hidden;
-extern long int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *)
-    attribute_hidden;
 extern long int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *)
     attribute_hidden;
 extern long int (*VDSO_SYMBOL (clock_getres)) (clockid_t, struct timespec *)
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index 31010e6cf7..0214f99ce4 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -218,7 +218,6 @@ GLIBC_2.27 __getpagesize F
 GLIBC_2.27 __getpgid F
 GLIBC_2.27 __getpid F
 GLIBC_2.27 __gets_chk F
-GLIBC_2.27 __gettimeofday F
 GLIBC_2.27 __getwd_chk F
 GLIBC_2.27 __gmtime_r F
 GLIBC_2.27 __h_errno_location F
diff --git a/sysdeps/unix/sysv/linux/s390/init-first.c b/sysdeps/unix/sysv/linux/s390/init-first.c
index a1ad9458e3..3a55935886 100644
--- a/sysdeps/unix/sysv/linux/s390/init-first.c
+++ b/sysdeps/unix/sysv/linux/s390/init-first.c
@@ -19,9 +19,6 @@
 #include <dl-vdso.h>
 #include <libc-vdso.h>
 
-long int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
-   attribute_hidden;
-
 long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
   __attribute__ ((nocommon));
 
@@ -34,11 +31,9 @@ long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *)
 static inline void
 _libc_vdso_platform_setup (void)
 {
-  PREPARE_VERSION_KNOWN (linux2629, LINUX_2_6_29);
+  void *p;
 
-  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", &linux2629);
-  PTR_MANGLE (p);
-  VDSO_SYMBOL (gettimeofday) = p;
+  PREPARE_VERSION_KNOWN (linux2629, LINUX_2_6_29);
 
   p = _dl_vdso_vsym ("__kernel_clock_gettime", &linux2629);
   PTR_MANGLE (p);
diff --git a/sysdeps/unix/sysv/linux/s390/libc-vdso.h b/sysdeps/unix/sysv/linux/s390/libc-vdso.h
index cc97601383..2cdf44583a 100644
--- a/sysdeps/unix/sysv/linux/s390/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/s390/libc-vdso.h
@@ -22,9 +22,6 @@
 
 #include <sysdep-vdso.h>
 
-extern long int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
-   attribute_hidden;
-
 extern long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 
 extern long int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *);
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index 576295deff..7dad6eba74 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -139,7 +139,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
index abf0473683..e3767a3df2 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
@@ -283,7 +283,6 @@ GLIBC_2.2 __getmntent_r F
 GLIBC_2.2 __getpagesize F
 GLIBC_2.2 __getpgid F
 GLIBC_2.2 __getpid F
-GLIBC_2.2 __gettimeofday F
 GLIBC_2.2 __gmtime_r F
 GLIBC_2.2 __h_errno_location F
 GLIBC_2.2 __isalnum_l F
diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
index 41977f6e9c..22b77a1b9a 100644
--- a/sysdeps/unix/sysv/linux/sh/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
@@ -272,7 +272,6 @@ GLIBC_2.2 __getmntent_r F
 GLIBC_2.2 __getpagesize F
 GLIBC_2.2 __getpgid F
 GLIBC_2.2 __getpid F
-GLIBC_2.2 __gettimeofday F
 GLIBC_2.2 __gmtime_r F
 GLIBC_2.2 __h_errno_location F
 GLIBC_2.2 __isalnum_l F
diff --git a/sysdeps/unix/sysv/linux/sparc/init-first.c b/sysdeps/unix/sysv/linux/sparc/init-first.c
index 643d6c7c88..520fc25808 100644
--- a/sysdeps/unix/sysv/linux/sparc/init-first.c
+++ b/sysdeps/unix/sysv/linux/sparc/init-first.c
@@ -20,19 +20,15 @@
 #include <dl-vdso.h>
 #include <libc-vdso.h>
 
-long int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *)
-    attribute_hidden;
 long int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *)
     attribute_hidden;
 
 static inline void
 _libc_vdso_platform_setup (void)
 {
-  PREPARE_VERSION_KNOWN (linux_version, LINUX_2_6);
+  void *p;
 
-  void *p = _dl_vdso_vsym ("__vdso_gettimeofday", &linux_version);
-  PTR_MANGLE (p);
-  VDSO_SYMBOL (gettimeofday) = p;
+  PREPARE_VERSION_KNOWN (linux_version, LINUX_2_6);
 
   p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux_version);
   PTR_MANGLE (p);
diff --git a/sysdeps/unix/sysv/linux/sparc/libc-vdso.h b/sysdeps/unix/sysv/linux/sparc/libc-vdso.h
index d20afcdf04..28d1229587 100644
--- a/sysdeps/unix/sysv/linux/sparc/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/sparc/libc-vdso.h
@@ -22,8 +22,6 @@
 
 #include <sysdep-vdso.h>
 
-extern long int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
-   attribute_hidden;
 extern long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 
 #endif /* _LIBC_VDSO_H */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 3d2f00ca52..a8803be2aa 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -144,7 +144,6 @@ GLIBC_2.0 __getdelim F
 GLIBC_2.0 __getpagesize F
 GLIBC_2.0 __getpgid F
 GLIBC_2.0 __getpid F
-GLIBC_2.0 __gettimeofday F
 GLIBC_2.0 __gmtime_r F
 GLIBC_2.0 __h_errno_location F
 GLIBC_2.0 __isinf F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index 2f20643e8e..6045532a26 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -310,7 +310,6 @@ GLIBC_2.2 __getmntent_r F
 GLIBC_2.2 __getpagesize F
 GLIBC_2.2 __getpgid F
 GLIBC_2.2 __getpid F
-GLIBC_2.2 __gettimeofday F
 GLIBC_2.2 __gmtime_r F
 GLIBC_2.2 __h_errno_location F
 GLIBC_2.2 __isalnum_l F
diff --git a/sysdeps/unix/sysv/linux/x86/gettimeofday.c b/sysdeps/unix/sysv/linux/x86/gettimeofday.c
deleted file mode 100644
index 8886ccd707..0000000000
--- a/sysdeps/unix/sysv/linux/x86/gettimeofday.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/* gettimeofday - get the time.  Linux/x86 version.
-   Copyright (C) 2015-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sys/time.h>
-
-#ifdef SHARED
-
-# include <dl-vdso.h>
-# include <errno.h>
-
-static int
-__gettimeofday_syscall (struct timeval *tv, struct timezone *tz)
-{
-  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
-}
-
-# ifndef __gettimeofday_type
-/* The i386 gettimeofday.c includes this file with a defined
-   __gettimeofday_type macro.  For x86_64 we have to define it to __gettimeofday
-   as the internal symbol is the ifunc'ed one.  */
-#  define __gettimeofday_type __gettimeofday
-# endif
-
-# undef INIT_ARCH
-# define INIT_ARCH() PREPARE_VERSION_KNOWN (linux26, LINUX_2_6)
-/* If the vDSO is not available we fall back to syscall.  */
-libc_ifunc_hidden (__gettimeofday_type, __gettimeofday,
-		   (_dl_vdso_vsym ("__vdso_gettimeofday", &linux26)
-		    ?: &__gettimeofday_syscall))
-libc_hidden_def (__gettimeofday)
-
-#else
-
-# include <sysdep.h>
-# include <errno.h>
-
-int
-__gettimeofday (struct timeval *tv, struct timezone *tz)
-{
-  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
-}
-libc_hidden_def (__gettimeofday)
-
-#endif
-weak_alias (__gettimeofday, gettimeofday)
-libc_hidden_weak (gettimeofday)
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 59f85d9373..2cfe09dfe1 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -270,7 +270,6 @@ GLIBC_2.2.5 __getmntent_r F
 GLIBC_2.2.5 __getpagesize F
 GLIBC_2.2.5 __getpgid F
 GLIBC_2.2.5 __getpid F
-GLIBC_2.2.5 __gettimeofday F
 GLIBC_2.2.5 __gmtime_r F
 GLIBC_2.2.5 __h_errno_location F
 GLIBC_2.2.5 __isalnum_l F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index 67a4e238d6..72eed1ab3f 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -217,7 +217,6 @@ GLIBC_2.16 __getpagesize F
 GLIBC_2.16 __getpgid F
 GLIBC_2.16 __getpid F
 GLIBC_2.16 __gets_chk F
-GLIBC_2.16 __gettimeofday F
 GLIBC_2.16 __getwd_chk F
 GLIBC_2.16 __gmtime_r F
 GLIBC_2.16 __h_errno_location F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
index c0cfa7b0da..58ea31d1fd 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
@@ -1,5 +1,4 @@
 # File name	Caller	Syscall name	# args	Strong name	Weak names
 
-gettimeofday	-	gettimeofday:__vdso_gettimeofday@LINUX_2.6	i:pP	__gettimeofday	gettimeofday
 personality	EXTRA	personality	Ei:i	__personality	personality
 posix_fadvise64	-	fadvise64	Vi:iiii	posix_fadvise	posix_fadvise64
diff --git a/time/Versions b/time/Versions
index fd838181e4..cd2e0725f4 100644
--- a/time/Versions
+++ b/time/Versions
@@ -7,7 +7,7 @@ libc {
     __adjtimex;
 
     # functions used in other libraries
-    __gmtime_r; __gettimeofday;
+    __gmtime_r;
 
     # variables in normal name space
     daylight; timezone; tzname;
diff --git a/time/gettimeofday.c b/time/gettimeofday.c
index 1004ec8911..22a996a220 100644
--- a/time/gettimeofday.c
+++ b/time/gettimeofday.c
@@ -15,20 +15,30 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
+#include <string.h>
+#include <time.h>
 #include <sys/time.h>
 
-/* Get the current time of day and timezone information,
-   putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
+/* Get the current time of day, putting it into *TV.
+   If *TZ is not NULL, clear it.
    Returns 0 on success, -1 on errors.  */
 int
 __gettimeofday (struct timeval *tv, struct timezone *tz)
 {
-  __set_errno (ENOSYS);
-  return -1;
+  if (__glibc_unlikely (tz != 0))
+    memset (tz, 0, sizeof *tz);
+
+  struct timespec ts;
+  if (__clock_gettime (CLOCK_REALTIME, &ts))
+    return -1;
+
+  TIMESPEC_TO_TIMEVAL (tv, &ts);
+  return 0;
 }
-libc_hidden_def (__gettimeofday)
-weak_alias (__gettimeofday, gettimeofday)
-libc_hidden_weak (gettimeofday)
 
-stub_warning (gettimeofday)
+#ifdef VERSION_gettimeofday
+weak_alias (__gettimeofday, __gettimeofday_w);
+default_symbol_version (__gettimeofday_w, gettimeofday, VERSION_gettimeofday);
+#else
+weak_alias (__gettimeofday, gettimeofday)
+#endif
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 11/12] Linux/Alpha: don’t use timeval32 system calls.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (6 preceding siblings ...)
  2019-08-20 13:22 ` [PATCH 09/12] Finish move of clock_* functions to libc Zack Weinberg
@ 2019-08-20 13:37 ` Zack Weinberg
  2019-08-21 18:50   ` Adhemerval Zanella
  2019-08-20 13:37 ` [PATCH 06/12] Use clock_gettime to implement time Zack Weinberg
                   ` (7 subsequent siblings)
  15 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:37 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Linux/Alpha has two versions of several system call wrappers that take
or return data of type ‘struct timeval’ (possibly nested inside a
larger structure).  The GLIBC_2.0 version is a compat symbol that
calls __NR_osf_foo or __NR_old_foo and uses a struct timeval with a
32-bit tv_sec field.  The GLIBC_2.1 version is used for current code,
calls __NR_foo, and uses a struct timeval with a 64-bit tv_sec field.

This patch changes all of the remaining compat symbols of this type to
be wrappers around their GLIBC_2.1 counterparts.  (gettimeofday
already received this treatment in an earlier patch in this series.)
The compat symbols that copy out a 32-bit struct timeval all check for
overflow.  After the Y2038 deadline, they will fail with errno set to
EOVERFLOW, but only after copying out as much as they can, and filling
in the overflowed ‘struct timeval’(s) with tv_sec set to INT32_MAX and
tv_nsec set to zero.

The new header file tv32-compat.h is currently Alpha-specific but I
don’t know any reason why it couldn’t be reused to aid in writing
wrappers for all affected architectures.

	* sysdeps/unix/sysv/linux/alpha/tv32-compat.h: New file declaring
	types and helper functions for 32/64-bit time_t conversion.

	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove entries for
	osf_getitimer, osf_setitimer, osf_utimes, osf_getrusage, and osf_wait4.

	* sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
	* sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
	* sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
	* sysdeps/unix/sysv/linux/alpha/osf_utimes.c
	* sysdeps/unix/sysv/linux/alpha/osf_wait4.c:
	New files defining compatibility symbols formerly defined by
	alpha/syscalls.list.

	* sysdeps/unix/sysv/linux/alpha/adjtime.c: Split the compat code to...
	* sysdeps/unix/sysv/linux/alpha/osf_adjtime.c: ...this new file.

	* sysdeps/unix/sysv/linux/alpha/Makefile (sysdep_routines):
        Add osf_adjtime.

	* sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
	* sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c:
	Use tv32-compat.h helpers.
---
 sysdeps/unix/sysv/linux/alpha/Makefile        |   2 +-
 sysdeps/unix/sysv/linux/alpha/adjtime.c       |  70 +-------
 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c   | 135 ++++++++++++++++
 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c |  48 ++++++
 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c |  44 +++++
 .../unix/sysv/linux/alpha/osf_gettimeofday.c  |  27 +---
 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c |  55 +++++++
 .../unix/sysv/linux/alpha/osf_settimeofday.c  |  12 +-
 sysdeps/unix/sysv/linux/alpha/osf_utimes.c    |  36 +++++
 sysdeps/unix/sysv/linux/alpha/osf_wait4.c     |  47 ++++++
 sysdeps/unix/sysv/linux/alpha/syscalls.list   |   9 +-
 sysdeps/unix/sysv/linux/alpha/tv32-compat.h   | 151 ++++++++++++++++++
 12 files changed, 536 insertions(+), 100 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_utimes.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_wait4.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/tv32-compat.h

diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile
index fdd089af71..2e132e474b 100644
--- a/sysdeps/unix/sysv/linux/alpha/Makefile
+++ b/sysdeps/unix/sysv/linux/alpha/Makefile
@@ -9,7 +9,7 @@ sysdep_routines += ieee_get_fp_control ieee_set_fp_control \
 		   ioperm
 
 # Support old timeval32 entry points
-sysdep_routines += osf_gettimeofday osf_settimeofday \
+sysdep_routines += osf_adjtime osf_gettimeofday osf_settimeofday \
 		   osf_getitimer osf_setitimer osf_utimes \
 		   osf_getrusage osf_wait4
 
diff --git a/sysdeps/unix/sysv/linux/alpha/adjtime.c b/sysdeps/unix/sysv/linux/alpha/adjtime.c
index 65641e9c4d..f67f522300 100644
--- a/sysdeps/unix/sysv/linux/alpha/adjtime.c
+++ b/sysdeps/unix/sysv/linux/alpha/adjtime.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1998-2019 Free Software Foundation, Inc.
+/* adjtime -- adjust the system clock.  Linux/Alpha/tv64 version.
+   Copyright (C) 1998-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -15,76 +16,19 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <shlib-compat.h>
 #include <sysdep.h>
 #include <sys/time.h>
+#include <shlib-compat.h>
 
-
-#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
-struct timeval32
-{
-    int tv_sec, tv_usec;
-};
-
-struct timex32 {
-	unsigned int modes;	/* mode selector */
-	long offset;		/* time offset (usec) */
-	long freq;		/* frequency offset (scaled ppm) */
-	long maxerror;		/* maximum error (usec) */
-	long esterror;		/* estimated error (usec) */
-	int status;		/* clock command/status */
-	long constant;		/* pll time constant */
-	long precision;		/* clock precision (usec) (read only) */
-	long tolerance;		/* clock frequency tolerance (ppm)
-				 * (read only)
-				 */
-	struct timeval32 time;	/* (read only) */
-	long tick;		/* (modified) usecs between clock ticks */
-
-	long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
-	long jitter;            /* pps jitter (us) (ro) */
-	int shift;              /* interval duration (s) (shift) (ro) */
-	long stabil;            /* pps stability (scaled ppm) (ro) */
-	long jitcnt;            /* jitter limit exceeded (ro) */
-	long calcnt;            /* calibration intervals (ro) */
-	long errcnt;            /* calibration errors (ro) */
-	long stbcnt;            /* stability limit exceeded (ro) */
-
-	int  :32; int  :32; int  :32; int  :32;
-	int  :32; int  :32; int  :32; int  :32;
-	int  :32; int  :32; int  :32; int  :32;
-};
-
-#define TIMEVAL		timeval32
-#define TIMEX		timex32
-#define ADJTIME		attribute_compat_text_section __adjtime_tv32
-#define ADJTIMEX(x)	INLINE_SYSCALL (old_adjtimex, 1, x)
-#define ADJTIMEX32(x)	INLINE_SYSCALL (old_adjtimex, 1, x)
-
-#include <sysdeps/unix/sysv/linux/adjtime.c>
-
-int attribute_compat_text_section
-__adjtimex_tv32 (struct timex32 *tx) { return ADJTIMEX (tx); }
-
-strong_alias (__adjtimex_tv32, __adjtimex_tv32_1);
-strong_alias (__adjtimex_tv32, __adjtimex_tv32_2);
-compat_symbol (libc, __adjtimex_tv32_1, __adjtimex, GLIBC_2_0);
-compat_symbol (libc, __adjtimex_tv32_2, adjtimex, GLIBC_2_0);
-compat_symbol (libc, __adjtime_tv32, adjtime, GLIBC_2_0);
-#endif /* SHLIB_COMPAT */
-
-#undef TIMEVAL
-#undef TIMEX
-#undef ADJTIME
-#undef ADJTIMEX
-#define TIMEVAL		timeval
-#define TIMEX		timex
 #define ADJTIMEX(x)	INLINE_SYSCALL (adjtimex, 1, x)
 
 #include <sysdeps/unix/sysv/linux/adjtime.c>
 
 int
-__adjtimex_tv64 (struct timex *tx) { return ADJTIMEX (tx); }
+__adjtimex_tv64 (struct timex *tx)
+{
+  return ADJTIMEX (tx);
+}
 
 libc_hidden_ver (__adjtimex_tv64, __adjtimex)
 strong_alias (__adjtimex_tv64, __adjtimex_tv64p);
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
new file mode 100644
index 0000000000..57c77c3072
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
@@ -0,0 +1,135 @@
+/* adjtime -- adjust the system clock.  Linux/Alpha/tv32 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
+#include <errno.h>
+#include <tv32-compat.h>
+
+struct timex32 {
+	unsigned int modes;	/* mode selector */
+	long offset;		/* time offset (usec) */
+	long freq;		/* frequency offset (scaled ppm) */
+	long maxerror;		/* maximum error (usec) */
+	long esterror;		/* estimated error (usec) */
+	int status;		/* clock command/status */
+	long constant;		/* pll time constant */
+	long precision;		/* clock precision (usec) (read only) */
+	long tolerance;		/* clock frequency tolerance (ppm)
+				 * (read only)
+				 */
+	struct timeval32 time;	/* (read only) */
+	long tick;		/* (modified) usecs between clock ticks */
+
+	long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
+	long jitter;            /* pps jitter (us) (ro) */
+	int shift;              /* interval duration (s) (shift) (ro) */
+	long stabil;            /* pps stability (scaled ppm) (ro) */
+	long jitcnt;            /* jitter limit exceeded (ro) */
+	long calcnt;            /* calibration intervals (ro) */
+	long errcnt;            /* calibration errors (ro) */
+	long stbcnt;            /* stability limit exceeded (ro) */
+
+	int  :32; int  :32; int  :32; int  :32;
+	int  :32; int  :32; int  :32; int  :32;
+	int  :32; int  :32; int  :32; int  :32;
+};
+
+int attribute_compat_text_section
+__adjtime_tv32 (const struct timeval32 *itv, struct timeval32 *otv)
+{
+  struct timeval itv64, otv64;
+  TV32_TO_TV64 (&itv64, itv);
+  if (__adjtime (&itv64, &otv64))
+    return -1;
+  if (TV64_TO_TV32 (otv, &itv64))
+    {
+      __set_errno (EOVERFLOW);
+      return -1;
+    }
+  return 0;
+}
+
+int attribute_compat_text_section
+__adjtimex_tv32 (struct timex32 *tx)
+{
+  struct timex tx64;
+  memset (&tx64, 0, sizeof tx64);
+  tx64.modes     = tx->modes;
+  tx64.offset    = tx->offset;
+  tx64.freq      = tx->freq;
+  tx64.maxerror  = tx->maxerror;
+  tx64.esterror  = tx->esterror;
+  tx64.status    = tx->status;
+  tx64.constant  = tx->constant;
+  tx64.precision = tx->precision;
+  tx64.tolerance = tx->tolerance;
+  tx64.tick      = tx->tick;
+  tx64.ppsfreq   = tx->ppsfreq;
+  tx64.jitter    = tx->jitter;
+  tx64.shift     = tx->shift;
+  tx64.stabil    = tx->stabil;
+  tx64.jitcnt    = tx->jitcnt;
+  tx64.calcnt    = tx->calcnt;
+  tx64.errcnt    = tx->errcnt;
+  tx64.stbcnt    = tx->stbcnt;
+  TV32_TO_TV64 (&tx64.time, &tx->time);
+
+  int status = __adjtimex (&tx64);
+  if (status < 0)
+    return status;
+
+  memset (tx, 0, sizeof *tx);
+  tx->modes     = tx64.modes;
+  tx->offset    = tx64.offset;
+  tx->freq      = tx64.freq;
+  tx->maxerror  = tx64.maxerror;
+  tx->esterror  = tx64.esterror;
+  tx->status    = tx64.status;
+  tx->constant  = tx64.constant;
+  tx->precision = tx64.precision;
+  tx->tolerance = tx64.tolerance;
+  tx->tick      = tx64.tick;
+  tx->ppsfreq   = tx64.ppsfreq;
+  tx->jitter    = tx64.jitter;
+  tx->shift     = tx64.shift;
+  tx->stabil    = tx64.stabil;
+  tx->jitcnt    = tx64.jitcnt;
+  tx->calcnt    = tx64.calcnt;
+  tx->errcnt    = tx64.errcnt;
+  tx->stbcnt    = tx64.stbcnt;
+  if (TV64_TO_TV32 (&tx->time, &tx64.time))
+    {
+      __set_errno (EOVERFLOW);
+      return -1;
+    }
+
+  return status;
+}
+
+strong_alias (__adjtimex_tv32, __adjtimex_tv32_1);
+strong_alias (__adjtimex_tv32, __adjtimex_tv32_2);
+compat_symbol (libc, __adjtimex_tv32_1, __adjtimex, GLIBC_2_0);
+compat_symbol (libc, __adjtimex_tv32_2, adjtimex, GLIBC_2_0);
+compat_symbol (libc, __adjtime_tv32, adjtime, GLIBC_2_0);
+
+#endif /* SHLIB_COMPAT */
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
new file mode 100644
index 0000000000..d15d8f5be4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
@@ -0,0 +1,48 @@
+/* getitimer -- Get the state of an interval timer.  Linux/Alpha/tv32 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
+#include <errno.h>
+#include <tv32-compat.h>
+
+int
+__getitimer_tv32 (int which, struct itimerval32 *curr_value)
+{
+  struct itimerval curr_value_64;
+  if (__getitimer (which, &curr_value_64))
+    return -1;
+
+  /* Make sure both fields of the output are filled in, even if one of them
+     overflows.  */
+  int e;
+  e  = TV64_TO_TV32 (&curr_value->it_interval, &curr_value_64.it_interval);
+  e |= TV64_TO_TV32 (&curr_value->it_value, &curr_value_64.it_value);
+  if (e)
+    {
+      __set_errno (EOVERFLOW);
+      return -1;
+    }
+  return 0;
+}
+
+compat_symbol (libc, __getitimer_tv32, getitimer, GLIBC_2_0);
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
new file mode 100644
index 0000000000..ac094dddbf
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
@@ -0,0 +1,44 @@
+/* utimes -- change file timestamps.  Linux/Alpha/tv32 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
+#include <errno.h>
+#include <tv32-compat.h>
+
+int
+__getrusage_tv32 (int who, struct rusage32 *usage32)
+{
+  struct rusage usage64;
+  if (__getrusage (who, &usage64))
+    return -1;
+
+  if (RUSAGE64_TO_RUSAGE32 (usage32, &usage64))
+    {
+      __set_errno (EOVERFLOW);
+      return -1;
+    }
+  return 0;
+}
+
+compat_symbol (libc, __getrusage_tv32, getrusage, GLIBC_2_0);
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
index 9868dfd9c9..cc4c4eebdf 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
@@ -16,19 +16,15 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <limits.h>
-#include <string.h>
-#include <time.h>
 #include <sys/time.h>
 #include <shlib-compat.h>
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
-struct timeval32
-{
-    int tv_sec, tv_usec;
-};
+#include <time.h>
+#include <errno.h>
+#include <string.h>
+#include <tv32-compat.h>
 
 /* Get the current time of day, putting it into *TV.
    If *TZ is not NULL, clear it.
@@ -36,29 +32,20 @@ struct timeval32
 
 int
 attribute_compat_text_section
-__gettimeofday_tv32 (struct timeval32 *tv32,
-                     struct timezone *tz)
+__gettimeofday_tv32 (struct timeval32 *restrict tv32, void *restrict tz)
 {
   if (__glibc_unlikely (tz != 0))
-    memset (tz, 0, sizeof *tz);
+    memset (tz, 0, sizeof (struct timezone));
 
   struct timespec ts;
   if (__clock_gettime (CLOCK_REALTIME, &ts))
     return -1;
 
-  if (__glibc_unlikely (ts.tv_sec > (time_t)INT_MAX))
+  if (TS64_TO_TV32 (tv32, &ts))
     {
-      /* The clock has advanced past the time representable in a 32-bit
-         time_t.  Fail, but write a saturated value to the output first,
-         because callers don't typically expect gettimeofday to fail.  */
       __set_errno (EOVERFLOW);
-      tv32->tv_sec  = INT_MAX;
-      tv32->tv_usec = 0;
       return -1;
     }
-
-  tv32->tv_sec = ts.tv_sec;
-  tv32->tv_usec = ts.tv_nsec / 1000;
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
new file mode 100644
index 0000000000..48d5bbcd75
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
@@ -0,0 +1,55 @@
+/* getitimer -- Get the state of an interval timer.  Linux/Alpha/tv32 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
+#include <errno.h>
+#include <tv32-compat.h>
+
+int
+__setitimer_tv32 (int which, const struct itimerval32 *restrict new_value,
+		  struct itimerval32 *restrict old_value)
+{
+  struct itimerval new_value_64;
+  TV32_TO_TV64 (&new_value_64.it_interval, &new_value->it_interval);
+  TV32_TO_TV64 (&new_value_64.it_value, &new_value->it_value);
+
+  if (!old_value)
+    return __setitimer (which, &new_value_64, 0);
+
+  struct itimerval old_value_64;
+  if (__setitimer (which, &new_value_64, &old_value_64))
+    return -1;
+
+  /* Write all fields of 'old_value' even on error.  */
+  int e = 0;
+  e |= TV64_TO_TV32 (&old_value->it_interval, &old_value_64.it_interval);
+  e |= TV64_TO_TV32 (&old_value->it_value, &old_value_64.it_value);
+  if (e)
+    {
+      __set_errno (EOVERFLOW);
+      return -1;
+    }
+  return 0;
+}
+
+compat_symbol (libc, __setitimer_tv32, setitimer, GLIBC_2_0);
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
index a61fcab482..d793b24dbf 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
@@ -16,17 +16,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <time.h>
 #include <sys/time.h>
 #include <shlib-compat.h>
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
-struct timeval32
-{
-    int tv_sec, tv_usec;
-};
+#include <errno.h>
+#include <time.h>
+#include <tv32-compat.h>
 
 /* Set the current time of day and timezone information.
    This call is restricted to the super-user.  */
@@ -46,8 +43,7 @@ __settimeofday_tv32 (const struct timeval32 *tv32,
     }
 
   struct timespec ts;
-  ts.tv_sec = tv32->tv_sec;
-  ts.tv_nsec = tv32->tv_usec * 1000;
+  TV32_TO_TS64 (&ts, tv32);
   return __clock_settime (CLOCK_REALTIME, &ts);
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
new file mode 100644
index 0000000000..7ed483ffb8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
@@ -0,0 +1,36 @@
+/* utimes -- change file timestamps.  Linux/Alpha/tv32 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
+#include <tv32-compat.h>
+
+int
+__utimes_tv32 (const char *filename, const struct timeval32 times32[2])
+{
+  struct timeval times[2];
+  TV32_TO_TV64 (&times[0], &times32[0]);
+  TV32_TO_TV64 (&times[1], &times32[1]);
+  return __utimes (filename, times);
+}
+
+compat_symbol (libc, __utimes_tv32, utimes, GLIBC_2_0);
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_wait4.c b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
new file mode 100644
index 0000000000..6ad3f1d510
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
@@ -0,0 +1,47 @@
+/* wait4 -- wait for process to change state.  Linux/Alpha/tv32 version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
+#include <errno.h>
+#include <string.h>
+#include <tv32-compat.h>
+
+pid_t
+__wait4_tv32 (pid_t pid, int *status, int options, struct rusage32 *usage32)
+{
+  struct rusage usage64;
+  pid_t child = __wait4 (pid, status, options, &usage64);
+  if (child < 0)
+    return child;
+
+  if (RUSAGE64_TO_RUSAGE32 (usage32, &usage64))
+    {
+      __set_errno (EOVERFLOW);
+      return -1;
+    }
+  return child;
+}
+
+compat_symbol (libc, __wait4_tv32, wait4, GLIBC_2_0);
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index 9ceed78c8d..0e472b4542 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -22,14 +22,7 @@ pciconfig_read	EXTRA	pciconfig_read	5	pciconfig_read
 pciconfig_write	EXTRA	pciconfig_write	5	pciconfig_write
 pciconfig_iobase EXTRA	pciconfig_iobase 3	__pciconfig_iobase pciconfig_iobase
 
-# support old timeval32 entry points
-osf_getitimer	-	osf_getitimer	2	__getitimer_tv32  getitimer@GLIBC_2.0
-osf_setitimer	-	osf_setitimer	3	__setitimer_tv32  setitimer@GLIBC_2.0
-osf_utimes	-	osf_utimes	2	__utimes_tv32  utimes@GLIBC_2.0
-osf_getrusage	-	osf_getrusage	2	__getrusage_tv32  getrusage@GLIBC_2.0
-osf_wait4	-	osf_wait4	4	__wait4_tv32  wait4@GLIBC_2.0
-
-# support new timeval64 entry points
+# new timeval64 entry points (see osf_* for the GLIBC_2.0 versions)
 getitimer	-	getitimer	2	__getitimer getitimer@@GLIBC_2.1
 setitimer	-	setitimer	3	__setitimer setitimer@@GLIBC_2.1
 utimes		-	utimes		2	__utimes utimes@@GLIBC_2.1
diff --git a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h b/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
new file mode 100644
index 0000000000..926e8ce017
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
@@ -0,0 +1,151 @@
+/* Compatibility definitions for `struct timeval' with 32-bit time_t.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _TV32_COMPAT_H
+#define _TV32_COMPAT_H 1
+
+#include <features.h>
+
+#include <bits/types.h>
+#include <bits/types/time_t.h>
+#include <bits/types/struct_timeval.h>
+#include <bits/types/struct_timespec.h>
+#include <bits/types/struct_rusage.h>
+
+#include <stdint.h> // for INT32_MAX
+#include <string.h> // for memset
+
+/* A version of 'struct timeval' with 32-bit time_t.  */
+struct timeval32
+{
+  int32_t tv_sec;
+  int32_t tv_usec;
+};
+
+/* Structures containing 'struct timeval' with 32-bit time_t.  */
+struct itimerval32
+{
+  struct timeval32 it_interval;
+  struct timeval32 it_value;
+};
+
+struct rusage32
+{
+  struct timeval32 ru_utime;	/* user time used */
+  struct timeval32 ru_stime;	/* system time used */
+  long ru_maxrss;		/* maximum resident set size */
+  long ru_ixrss;		/* integral shared memory size */
+  long ru_idrss;		/* integral unshared data size */
+  long ru_isrss;		/* integral unshared stack size */
+  long ru_minflt;		/* page reclaims */
+  long ru_majflt;		/* page faults */
+  long ru_nswap;		/* swaps */
+  long ru_inblock;		/* block input operations */
+  long ru_oublock;		/* block output operations */
+  long ru_msgsnd;		/* messages sent */
+  long ru_msgrcv;		/* messages received */
+  long ru_nsignals;		/* signals received */
+  long ru_nvcsw;		/* voluntary context switches */
+  long ru_nivcsw;		/* involuntary " */
+};
+
+/* Conversion functions.  If the seconds field of a timeval32 would
+   overflow, they write { INT32_MAX, 0 } to the output and return -1;
+   otherwise they return 0.  */
+
+__extern_always_inline void
+TV32_TO_TV64 (struct timeval *restrict tv64,
+              const struct timeval32 *restrict tv32)
+{
+  tv64->tv_sec = tv32->tv_sec;
+  tv64->tv_usec = tv32->tv_usec;
+}
+
+__extern_always_inline void
+TV32_TO_TS64 (struct timespec *restrict ts64,
+              const struct timeval32 *restrict tv32)
+{
+  ts64->tv_sec = tv32->tv_sec;
+  ts64->tv_nsec = tv32->tv_usec * 1000;
+}
+
+__extern_always_inline int
+TV64_TO_TV32 (struct timeval32 *restrict tv32,
+              const struct timeval *restrict tv64)
+{
+  if (__glibc_unlikely (tv64->tv_sec > (time_t) INT32_MAX))
+    {
+      tv32->tv_sec = INT32_MAX;
+      tv32->tv_usec = 0;
+      return -1;
+    }
+  else
+    {
+      tv32->tv_sec = tv64->tv_sec;
+      tv32->tv_usec = tv64->tv_usec;
+      return 0;
+    }
+}
+
+__extern_always_inline int
+TS64_TO_TV32 (struct timeval32 *restrict tv32,
+              const struct timespec *restrict ts64)
+{
+  if (__glibc_unlikely (ts64->tv_sec > (time_t) INT32_MAX))
+    {
+      tv32->tv_sec = INT32_MAX;
+      tv32->tv_usec = 0;
+      return -1;
+    }
+  else
+    {
+      tv32->tv_sec = ts64->tv_sec;
+      tv32->tv_usec = ts64->tv_nsec / 1000;
+      return 0;
+    }
+}
+
+__extern_always_inline int
+RUSAGE64_TO_RUSAGE32 (struct rusage32 *restrict r32,
+                      const struct rusage *restrict r64)
+{
+  /* Fill out the entire structure even on failure.  */
+  memset (r32, 0, sizeof *r32);
+
+  int e = 0;
+  e |= TV64_TO_TV32 (&r32->ru_utime, &r64->ru_utime);
+  e |= TV64_TO_TV32 (&r32->ru_stime, &r64->ru_stime);
+  r32->ru_maxrss   = r64->ru_maxrss;
+  r32->ru_ixrss    = r64->ru_ixrss;
+  r32->ru_idrss    = r64->ru_idrss;
+  r32->ru_isrss    = r64->ru_isrss;
+  r32->ru_minflt   = r64->ru_minflt;
+  r32->ru_majflt   = r64->ru_majflt;
+  r32->ru_nswap    = r64->ru_nswap;
+  r32->ru_inblock  = r64->ru_inblock;
+  r32->ru_oublock  = r64->ru_oublock;
+  r32->ru_msgsnd   = r64->ru_msgsnd;
+  r32->ru_msgrcv   = r64->ru_msgrcv;
+  r32->ru_nsignals = r64->ru_nsignals;
+  r32->ru_nvcsw    = r64->ru_nvcsw;
+  r32->ru_nivcsw   = r64->ru_nivcsw;
+
+  return e;
+}
+
+#endif /* tv32-compat.h */
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 06/12] Use clock_gettime to implement time.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (7 preceding siblings ...)
  2019-08-20 13:37 ` [PATCH 11/12] Linux/Alpha: don’t use timeval32 system calls Zack Weinberg
@ 2019-08-20 13:37 ` Zack Weinberg
  2019-08-20 18:02   ` Adhemerval Zanella
  2019-08-20 13:37 ` [PATCH 08/12] Use clock_gettime to implement gettimeofday Zack Weinberg
                   ` (6 subsequent siblings)
  15 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:37 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Most ports were using gettimeofday to implement time, or they were
making a direct (v)syscall.  Unconditionally switch to using
clock_gettime instead.  All sysdeps implementations of time are
removed.

	* time/time.c (time): No longer a stub implementation.
        Call __clock_gettime.

	* sysdeps/unix/sysv/linux/powerpc/Versions (GLIBC_PRIVATE):
	Remove __vdso_time.
	* sysdeps/unix/sysv/linux/powerpc/init-first.c (__vdso_time): Delete.
	(_libc_vdso_platform_setup): Don’t initialize __vdso_time.
	* sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list: Remove entry
	for time.

	* sysdeps/posix/time.c
	* sysdeps/unix/sysv/linux/time.c
	* sysdeps/unix/sysv/linux/i386/time.c
	* sysdeps/unix/sysv/linux/powerpc/time.c
	* sysdeps/unix/sysv/linux/sparc/sparc64/time.c
	* sysdeps/unix/sysv/linux/x86/time.c:
	Delete file.
---
 sysdeps/posix/time.c                          | 40 ---------
 sysdeps/unix/sysv/linux/i386/time.c           | 34 --------
 sysdeps/unix/sysv/linux/powerpc/Versions      |  1 -
 sysdeps/unix/sysv/linux/powerpc/init-first.c  |  5 --
 sysdeps/unix/sysv/linux/powerpc/time.c        | 84 -------------------
 sysdeps/unix/sysv/linux/sparc/sparc64/time.c  |  1 -
 sysdeps/unix/sysv/linux/time.c                | 41 ---------
 sysdeps/unix/sysv/linux/x86/time.c            | 59 -------------
 .../unix/sysv/linux/x86_64/x32/syscalls.list  |  1 -
 time/time.c                                   | 17 ++--
 10 files changed, 10 insertions(+), 273 deletions(-)
 delete mode 100644 sysdeps/posix/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/i386/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/x86/time.c

diff --git a/sysdeps/posix/time.c b/sysdeps/posix/time.c
deleted file mode 100644
index e1b3bc8d4c..0000000000
--- a/sysdeps/posix/time.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Copyright (C) 1991-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <stddef.h>		/* For NULL.  */
-#include <time.h>
-#include <sys/time.h>
-
-
-/* Return the current time as a `time_t' and also put it in *T if T is
-   not NULL.  Time is represented as seconds from Jan 1 00:00:00 1970.  */
-time_t
-time (time_t *t)
-{
-  struct timeval tv;
-  time_t result;
-
-  if (__gettimeofday (&tv, (struct timezone *) NULL))
-    result = (time_t) -1;
-  else
-    result = (time_t) tv.tv_sec;
-
-  if (t != NULL)
-    *t = result;
-  return result;
-}
-libc_hidden_def (time)
diff --git a/sysdeps/unix/sysv/linux/i386/time.c b/sysdeps/unix/sysv/linux/i386/time.c
deleted file mode 100644
index 440e3e6ab4..0000000000
--- a/sysdeps/unix/sysv/linux/i386/time.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* time -- Get number of seconds since Epoch.  Linux/i386 version.
-   Copyright (C) 2015-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#ifdef SHARED
-# define time __redirect_time
-#endif
-
-#include <time.h>
-
-#ifdef SHARED
-# undef time
-# define time_type __redirect_time
-
-# undef libc_hidden_def
-# define libc_hidden_def(name)  \
-  __hidden_ver1 (__time_syscall, __GI_time, __time_syscall);
-#endif
-
-#include <sysdeps/unix/sysv/linux/x86/time.c>
diff --git a/sysdeps/unix/sysv/linux/powerpc/Versions b/sysdeps/unix/sysv/linux/powerpc/Versions
index 8ebeea15a1..859e0d7daf 100644
--- a/sysdeps/unix/sysv/linux/powerpc/Versions
+++ b/sysdeps/unix/sysv/linux/powerpc/Versions
@@ -10,7 +10,6 @@ libc {
     __vdso_clock_gettime;
     __vdso_clock_getres;
     __vdso_getcpu;
-    __vdso_time;
   }
 }
 libm {
diff --git a/sysdeps/unix/sysv/linux/powerpc/init-first.c b/sysdeps/unix/sysv/linux/powerpc/init-first.c
index 831f910788..4f12b59e76 100644
--- a/sysdeps/unix/sysv/linux/powerpc/init-first.c
+++ b/sysdeps/unix/sysv/linux/powerpc/init-first.c
@@ -25,7 +25,6 @@ int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
 int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *);
 unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void);
 int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *);
-time_t (*VDSO_SYMBOL(time)) (time_t *);
 
 #if defined(__PPC64__) || defined(__powerpc64__)
 void *VDSO_SYMBOL(sigtramp_rt64);
@@ -59,10 +58,6 @@ _libc_vdso_platform_setup (void)
   PTR_MANGLE (p);
   VDSO_SYMBOL (getcpu) = p;
 
-  p = _dl_vdso_vsym ("__kernel_time", &linux2615);
-  PTR_MANGLE (p);
-  VDSO_SYMBOL (time) = p;
-
   /* PPC64 uses only one signal trampoline symbol, while PPC32 will use
      two depending if SA_SIGINFO is used (__kernel_sigtramp_rt32) or not
      (__kernel_sigtramp32).
diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c
deleted file mode 100644
index cb3e8b9a73..0000000000
--- a/sysdeps/unix/sysv/linux/powerpc/time.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/* time system call for Linux/PowerPC.
-   Copyright (C) 2013-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#ifdef SHARED
-# ifndef __powerpc64__
-#  define time __redirect_time
-# else
-#  define __redirect_time time
-# endif
-
-# include <time.h>
-# include <sysdep.h>
-# include <dl-vdso.h>
-# include <libc-vdso.h>
-# include <dl-machine.h>
-
-# ifndef __powerpc64__
-#  undef time
-
-time_t
-__time_vsyscall (time_t *t)
-{
-  return INLINE_VSYSCALL (time, 1, t);
-}
-
-/* __GI_time is defined as hidden and for ppc32 it enables the
-   compiler make a local call (symbol@local) for internal GLIBC usage. It
-   means the PLT won't be used and the ifunc resolver will be called directly.
-   For ppc64 a call to a function in another translation unit might use a
-   different toc pointer thus disallowing direct branchess and making internal
-   ifuncs calls safe.  */
-#  undef libc_hidden_def
-#  define libc_hidden_def(name)					\
-  __hidden_ver1 (__time_vsyscall, __GI_time, __time_vsyscall);
-
-# endif /* !__powerpc64__  */
-
-static time_t
-time_syscall (time_t *t)
-{
-  struct timeval tv;
-  time_t result;
-
-  if (INLINE_VSYSCALL (gettimeofday, 2, &tv, NULL) < 0)
-    result = (time_t) -1;
-  else
-    result = (time_t) tv.tv_sec;
-
-  if (t != NULL)
-    *t = result;
-  return result;
-}
-
-# define INIT_ARCH()						\
-  PREPARE_VERSION_KNOWN (linux2615, LINUX_2_6_15);		\
-  void *vdso_time = _dl_vdso_vsym ("__kernel_time", &linux2615);
-
-/* If the vDSO is not available we fall back to the syscall.  */
-libc_ifunc_hidden (__redirect_time, time,
-		   vdso_time
-		   ? VDSO_IFUNC_RET (vdso_time)
-		   : (void *) time_syscall);
-libc_hidden_def (time)
-
-#else
-
-#include <sysdeps/posix/time.c>
-
-#endif /* !SHARED */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/time.c b/sysdeps/unix/sysv/linux/sparc/sparc64/time.c
deleted file mode 100644
index 509b580c55..0000000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/time.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/posix/time.c>
diff --git a/sysdeps/unix/sysv/linux/time.c b/sysdeps/unix/sysv/linux/time.c
deleted file mode 100644
index 1978f6d817..0000000000
--- a/sysdeps/unix/sysv/linux/time.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Copyright (C) 2005-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <stddef.h>
-#include <time.h>
-
-#include <sysdep.h>
-
-#ifdef __NR_time
-
-time_t
-time (time_t *t)
-{
-  INTERNAL_SYSCALL_DECL (err);
-  time_t res = INTERNAL_SYSCALL (time, err, 1, NULL);
-  /* There cannot be any error.  */
-  if (t != NULL)
-    *t = res;
-  return res;
-}
-libc_hidden_def (time)
-
-#else
-
-# include <sysdeps/posix/time.c>
-
-#endif
diff --git a/sysdeps/unix/sysv/linux/x86/time.c b/sysdeps/unix/sysv/linux/x86/time.c
deleted file mode 100644
index 3d72488500..0000000000
--- a/sysdeps/unix/sysv/linux/x86/time.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* time -- Get number of seconds since Epoch.  Linux/x86 version.
-   Copyright (C) 2015-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <time.h>
-
-#ifdef SHARED
-
-#include <dl-vdso.h>
-#include <errno.h>
-
-static time_t
-__time_syscall (time_t *t)
-{
-  INTERNAL_SYSCALL_DECL (err);
-  return INTERNAL_SYSCALL (time, err, 1, t);
-}
-
-# ifndef time_type
-/* The i386 time.c includes this file with a defined time_type macro.
-   For x86_64 we have to define it to time as the internal symbol is the
-   ifunc'ed one.  */
-#  define time_type time
-# endif
-
-#undef INIT_ARCH
-#define INIT_ARCH() PREPARE_VERSION_KNOWN (linux26, LINUX_2_6);
-/* If the vDSO is not available we fall back on the syscall.  */
-libc_ifunc_hidden (time_type, time,
-		   (_dl_vdso_vsym ("__vdso_time", &linux26)
-		    ?:  &__time_syscall))
-libc_hidden_def (time)
-
-#else
-
-# include <sysdep.h>
-
-time_t
-time (time_t *t)
-{
-  INTERNAL_SYSCALL_DECL (err);
-  return INTERNAL_SYSCALL (time, err, 1, t);
-}
-
-#endif
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
index b44f6f99e9..c0cfa7b0da 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
@@ -3,4 +3,3 @@
 gettimeofday	-	gettimeofday:__vdso_gettimeofday@LINUX_2.6	i:pP	__gettimeofday	gettimeofday
 personality	EXTRA	personality	Ei:i	__personality	personality
 posix_fadvise64	-	fadvise64	Vi:iiii	posix_fadvise	posix_fadvise64
-time		-	time:__vdso_time@LINUX_2.6			Ei:P	time
diff --git a/time/time.c b/time/time.c
index 88612d6c76..b60b8b9db8 100644
--- a/time/time.c
+++ b/time/time.c
@@ -15,19 +15,22 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <time.h>
 
 /* Return the time now, and store it in *TIMER if not NULL.  */
 time_t
 time (time_t *timer)
 {
-  __set_errno (ENOSYS);
+  struct timespec ts;
+  time_t res;
 
-  if (timer != NULL)
-    *timer = (time_t) -1;
-  return (time_t) -1;
+  if (__clock_gettime (CLOCK_REALTIME, &ts))
+    res = -1;
+  else
+    res = ts.tv_sec;
+
+  if (timer)
+    *timer = res;
+  return res;
 }
 libc_hidden_def (time)
-
-stub_warning (time)
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 07/12] Use clock_gettime to implement ftime.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (9 preceding siblings ...)
  2019-08-20 13:37 ` [PATCH 08/12] Use clock_gettime to implement gettimeofday Zack Weinberg
@ 2019-08-20 13:37 ` Zack Weinberg
  2019-08-21 15:18   ` Adhemerval Zanella
  2019-08-20 13:56 ` [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument Zack Weinberg
                   ` (4 subsequent siblings)
  15 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:37 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

ftime is an obsolete variation on gettimeofday, offering only
millisecond time resolution; it was probably a system call in ooold
versions of BSD Unix.  For historic reasons, we had three
implementations of it.  These are all consolidated into time/ftime.c.

Like gettimeofday, ftime tries to report the time zone, and using that
information is always a bug.  This patch dummies out the reported
timezone information; the ‘timezone’ and ‘dstflag’ fields of the
returned ‘struct timeb’ will always be zero.

(There is an argument for turning this function into a compat symbol,
and not installing sys/timeb.h anymore.  Thoughts?)

	* time/ftime.c (ftime): Replace implementation with the code
	formerly in sysdeps/unix/bsd/ftime.c, then change that code to use
	__clock_gettime instead of __gettimeofday.  Always set the
	timezone and dstflag fields of the ‘timebuf’ argument to zero.

	* sysdeps/unix/bsd/ftime.c
	* sysdeps/unix/sysv/linux/ftime.c: Delete file.
---
 sysdeps/unix/bsd/ftime.c        | 40 ---------------------------------
 sysdeps/unix/sysv/linux/ftime.c |  3 ---
 time/ftime.c                    | 26 ++++++++++-----------
 3 files changed, 12 insertions(+), 57 deletions(-)
 delete mode 100644 sysdeps/unix/bsd/ftime.c
 delete mode 100644 sysdeps/unix/sysv/linux/ftime.c

diff --git a/sysdeps/unix/bsd/ftime.c b/sysdeps/unix/bsd/ftime.c
deleted file mode 100644
index 3a1c6e9b01..0000000000
--- a/sysdeps/unix/bsd/ftime.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Copyright (C) 1994-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sys/timeb.h>
-#include <sys/time.h>
-
-int
-ftime (struct timeb *timebuf)
-{
-  struct timeval tv;
-  struct timezone tz;
-
-  if (__gettimeofday (&tv, &tz) < 0)
-    return -1;
-
-  timebuf->time = tv.tv_sec;
-  timebuf->millitm = (tv.tv_usec + 500) / 1000;
-  if (timebuf->millitm == 1000)
-    {
-      ++timebuf->time;
-      timebuf->millitm = 0;
-    }
-  timebuf->timezone = tz.tz_minuteswest;
-  timebuf->dstflag = tz.tz_dsttime;
-  return 0;
-}
diff --git a/sysdeps/unix/sysv/linux/ftime.c b/sysdeps/unix/sysv/linux/ftime.c
deleted file mode 100644
index 5a5949f608..0000000000
--- a/sysdeps/unix/sysv/linux/ftime.c
+++ /dev/null
@@ -1,3 +0,0 @@
-/* Linux defines the ftime system call but doesn't actually implement
-   it.  Use the BSD implementation.  */
-#include <sysdeps/unix/bsd/ftime.c>
diff --git a/time/ftime.c b/time/ftime.c
index 6c2a256048..de8d043893 100644
--- a/time/ftime.c
+++ b/time/ftime.c
@@ -15,27 +15,25 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <time.h>
 #include <sys/timeb.h>
+#include <time.h>
 
 int
 ftime (struct timeb *timebuf)
 {
-  int save = errno;
-  struct tm tp;
+  struct timespec ts;
 
-  __set_errno (0);
-  if (time (&timebuf->time) == (time_t) -1 && errno != 0)
+  if (__clock_gettime (CLOCK_REALTIME, &ts) < 0)
     return -1;
-  timebuf->millitm = 0;
-
-  if (__localtime_r (&timebuf->time, &tp) == NULL)
-    return -1;
-
-  timebuf->timezone = tp.tm_gmtoff / 60;
-  timebuf->dstflag = tp.tm_isdst;
 
-  __set_errno (save);
+  timebuf->time = ts.tv_sec;
+  timebuf->millitm = (ts.tv_nsec + 500000) / 1000000;
+  if (timebuf->millitm == 1000)
+    {
+      ++timebuf->time;
+      timebuf->millitm = 0;
+    }
+  timebuf->timezone = 0;
+  timebuf->dstflag = 0;
   return 0;
 }
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument.
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (10 preceding siblings ...)
  2019-08-20 13:37 ` [PATCH 07/12] Use clock_gettime to implement ftime Zack Weinberg
@ 2019-08-20 13:56 ` Zack Weinberg
  2019-08-20 18:52   ` Paul Eggert
  2019-08-21 15:30   ` Adhemerval Zanella
  2019-08-20 15:10 ` [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Joseph Myers
                   ` (3 subsequent siblings)
  15 siblings, 2 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 13:56 UTC (permalink / raw)
  To: libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

At this stage I don’t think we can issue warnings for settimeofday
with a non-null tzp argument, nor for arbitrary use of struct
timezone.  But we can warn about gettimeofday with non-null tzp.

This uses a macro instead of an inline (fortify-style) function
because I got false positives with an inline, even with GCC 9.

	* time/sys/time.h (__timezone_ptr_t): Delete.
	(gettimeofday): Always declare second argument with type ‘void *’.
	When possible, wrap with a macro that detects non-null and
	non-constant second argument and issues a warning.
	Improve commentary.
	(settimeofday): Improve commentary.

	* time/gettimeofday.c (gettimeofday):
	Declare second argument as type ‘void *’.
---
 time/gettimeofday.c |  4 ++--
 time/sys/time.h     | 36 +++++++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/time/gettimeofday.c b/time/gettimeofday.c
index 22a996a220..bd1fc3cb5e 100644
--- a/time/gettimeofday.c
+++ b/time/gettimeofday.c
@@ -23,10 +23,10 @@
    If *TZ is not NULL, clear it.
    Returns 0 on success, -1 on errors.  */
 int
-__gettimeofday (struct timeval *tv, struct timezone *tz)
+__gettimeofday (struct timeval *restrict tv, void *restrict tz)
 {
   if (__glibc_unlikely (tz != 0))
-    memset (tz, 0, sizeof *tz);
+    memset (tz, 0, sizeof (struct timezone));
 
   struct timespec ts;
   if (__clock_gettime (CLOCK_REALTIME, &ts))
diff --git a/time/sys/time.h b/time/sys/time.h
index 5dbc7fc627..1b6c112274 100644
--- a/time/sys/time.h
+++ b/time/sys/time.h
@@ -54,23 +54,37 @@ struct timezone
     int tz_minuteswest;		/* Minutes west of GMT.  */
     int tz_dsttime;		/* Nonzero if DST is ever in effect.  */
   };
-
-typedef struct timezone *__restrict __timezone_ptr_t;
-#else
-typedef void *__restrict __timezone_ptr_t;
 #endif
 
-/* Get the current time of day and timezone information,
-   putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
-   Returns 0 on success, -1 on errors.
-   NOTE: This form of timezone information is obsolete.
-   Use the functions and variables declared in <time.h> instead.  */
+/* Get the current time of day, putting it into *TV.
+   If TZ is not null, *TZ must be a struct timezone, and both fields
+   will be set to zero.
+   Calling this function with a non-null TZ is obsolete;
+   use localtime etc. instead.
+   This function itself is semi-obsolete;
+   most callers should use time or clock_gettime instead. */
 extern int gettimeofday (struct timeval *__restrict __tv,
-			 __timezone_ptr_t __tz) __THROW __nonnull ((1));
+			 void *__restrict __tz) __THROW __nonnull ((1));
+
+#if __GNUC_PREREQ (4,3)
+/* Issue a warning for use of gettimeofday with a non-null __tz argument.  */
+__warndecl (__warn_gettimeofday_timezone,
+            "gettimeofday with non-null or non-constant timezone parameter;"
+            " this is obsolete and inaccurate, use localtime instead");
+
+#define gettimeofday(__tv, __tz)                        \
+  (((!__builtin_constant_p (__tz) || (__tz) != 0)       \
+    ? __warn_gettimeofday_timezone ()                   \
+    : (void) 0),                                        \
+   (gettimeofday) (__tv, __tz))
+#endif
 
 #ifdef __USE_MISC
 /* Set the current time of day and timezone information.
-   This call is restricted to the super-user.  */
+   This call is restricted to the super-user.
+   Setting the timezone in this way is obsolete, but we don't yet
+   warn about it because it still has some uses for which there is
+   no alternative.  */
 extern int settimeofday (const struct timeval *__tv,
 			 const struct timezone *__tz)
      __THROW;
-- 
2.23.0.rc1

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (11 preceding siblings ...)
  2019-08-20 13:56 ` [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument Zack Weinberg
@ 2019-08-20 15:10 ` Joseph Myers
  2019-08-20 15:21   ` Zack Weinberg
  2019-08-20 18:47 ` Alistair Francis
                   ` (2 subsequent siblings)
  15 siblings, 1 reply; 74+ messages in thread
From: Joseph Myers @ 2019-08-20 15:10 UTC (permalink / raw)
  To: Zack Weinberg
  Cc: libc-alpha, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

On Tue, 20 Aug 2019, Zack Weinberg wrote:

> Finally, there is a case for demoting ftime and stime to compatibility
> symbols and removing their public prototypes (for ftime, we would stop
> installing <sys/timeb.h> altogether).

Yes, I think that would make sense.  If we do that, we don't then need to 
add any _TIME_BITS=64 support for those functions.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 09/12] Finish move of clock_* functions to libc.
  2019-08-20 13:22 ` [PATCH 09/12] Finish move of clock_* functions to libc Zack Weinberg
@ 2019-08-20 15:13   ` Joseph Myers
  2019-08-20 15:19     ` Zack Weinberg
  2019-08-20 15:21     ` Florian Weimer
  0 siblings, 2 replies; 74+ messages in thread
From: Joseph Myers @ 2019-08-20 15:13 UTC (permalink / raw)
  To: Zack Weinberg
  Cc: libc-alpha, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

[-- Attachment #1: Type: text/plain, Size: 1133 bytes --]

On Tue, 20 Aug 2019, Zack Weinberg wrote:

> In glibc 2.17, the functions clock_getcpuclockid, clock_getres,
> clock_gettime, clock_nanosleep, and clock_settime were moved from
> librt.so to libc.so, leaving compatibility stubs behind.  Now that the
> dynamic linker no longer insists on finding versioned symbols in the
> same library that originally defined them, we do not need the stubs
> anymore, and this means we don’t need GLIBC_PRIVATE __-prefix aliases for
> most of the functions anymore either.  (clock_gettime is still called
> all over the place internally and therefore still needs one.)

But my understanding is that moving a function to libc like that only 
works if libc has the symbol *at the same version* as it had in the 
library from which it was removed.  And I don't see anything in this patch 
to add the older symbol version for these functions to libc (in the 
implementation and the ABI test baselines) (so libc would then have these 
functions at two symbol versions on most platforms, with both versions 
pointing to the same function implementations).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 09/12] Finish move of clock_* functions to libc.
  2019-08-20 15:13   ` Joseph Myers
@ 2019-08-20 15:19     ` Zack Weinberg
  2019-08-20 15:21     ` Florian Weimer
  1 sibling, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 15:19 UTC (permalink / raw)
  To: Joseph Myers; +Cc: GNU C Library, Florian Weimer

On Tue, Aug 20, 2019 at 11:13 AM Joseph Myers <joseph@codesourcery.com> wrote:
> On Tue, 20 Aug 2019, Zack Weinberg wrote:
>
> > In glibc 2.17, the functions clock_getcpuclockid, clock_getres,
> > clock_gettime, clock_nanosleep, and clock_settime were moved from
> > librt.so to libc.so, leaving compatibility stubs behind.  Now that the
> > dynamic linker no longer insists on finding versioned symbols in the
> > same library that originally defined them, we do not need the stubs
> > anymore, and this means we don’t need GLIBC_PRIVATE __-prefix aliases for
> > most of the functions anymore either.  (clock_gettime is still called
> > all over the place internally and therefore still needs one.)
>
> But my understanding is that moving a function to libc like that only
> works if libc has the symbol *at the same version* as it had in the
> library from which it was removed.  And I don't see anything in this patch
> to add the older symbol version for these functions to libc (in the
> implementation and the ABI test baselines) (so libc would then have these
> functions at two symbol versions on most platforms, with both versions
> pointing to the same function implementations).

I thought so too, at first, but Florian's patches to remove forwarding
stubs from libpthread have not been adding older symbol versions to
libc.so either, so that made me think it wasn't necessary after all.
Florian, can you comment?

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 09/12] Finish move of clock_* functions to libc.
  2019-08-20 15:13   ` Joseph Myers
  2019-08-20 15:19     ` Zack Weinberg
@ 2019-08-20 15:21     ` Florian Weimer
  2019-08-20 15:25       ` Zack Weinberg
  1 sibling, 1 reply; 74+ messages in thread
From: Florian Weimer @ 2019-08-20 15:21 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Zack Weinberg, libc-alpha, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

* Joseph Myers:

> On Tue, 20 Aug 2019, Zack Weinberg wrote:
>
>> In glibc 2.17, the functions clock_getcpuclockid, clock_getres,
>> clock_gettime, clock_nanosleep, and clock_settime were moved from
>> librt.so to libc.so, leaving compatibility stubs behind.  Now that the
>> dynamic linker no longer insists on finding versioned symbols in the
>> same library that originally defined them, we do not need the stubs
>> anymore, and this means we don’t need GLIBC_PRIVATE __-prefix aliases for
>> most of the functions anymore either.  (clock_gettime is still called
>> all over the place internally and therefore still needs one.)
>
> But my understanding is that moving a function to libc like that only 
> works if libc has the symbol *at the same version* as it had in the 
> library from which it was removed.

Correct.  We also need to add a new symbol version (at the next glibc
release) for the symbols, so that applications which use the functions
from libc directly are correctly depending on a glibc version which
actually has these symbols in libc.  My understanding is that this part
already happened in glibc 2.17, so the new symbol versions are not
required in this particularly instance, but the compatibility symbols
are definitely needed.

The pthread cleanup patches I posted replace existing forwarders, which
were added at the same time to libc and libpthread, so these
requirements are not apparent in these patches.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions
  2019-08-20 15:10 ` [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Joseph Myers
@ 2019-08-20 15:21   ` Zack Weinberg
  0 siblings, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 15:21 UTC (permalink / raw)
  To: Joseph Myers
  Cc: GNU C Library, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

On Tue, Aug 20, 2019 at 11:10 AM Joseph Myers <joseph@codesourcery.com> wrote:
> On Tue, 20 Aug 2019, Zack Weinberg wrote:
>
> > Finally, there is a case for demoting ftime and stime to compatibility
> > symbols and removing their public prototypes (for ftime, we would stop
> > installing <sys/timeb.h> altogether).
>
> Yes, I think that would make sense.  If we do that, we don't then need to
> add any _TIME_BITS=64 support for those functions.

OK, I will add a patch to this branch that does that.  (The changes
already made to those functions in this patchset are still necessary,
since we will need to keep the implementations around.)

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 08/12] Use clock_gettime to implement gettimeofday.
  2019-08-20 13:37 ` [PATCH 08/12] Use clock_gettime to implement gettimeofday Zack Weinberg
@ 2019-08-20 15:24   ` Joseph Myers
  2019-08-22 13:01     ` Zack Weinberg
  2019-08-20 17:51   ` Adhemerval Zanella
  1 sibling, 1 reply; 74+ messages in thread
From: Joseph Myers @ 2019-08-20 15:24 UTC (permalink / raw)
  To: Zack Weinberg
  Cc: libc-alpha, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

On Tue, 20 Aug 2019, Zack Weinberg wrote:

> __gettimeofday is no longer called by anyone, so remove its internal
> prototype and its entries in Versions and .abilist files.  (It would
> have been a GLIBC_PRIVATE symbol if the GLIBC_PRIVATE convention had
> been invented back in the days of 2.0.)

That's not obviously safe.  The choice of which internal symbols to move 
to GLIBC_PRIVATE when GLIBC_PRIVATE was introduced

2002-02-01  Jakub Jelinek  <jakub@redhat.com>

        * Versions.def (libc): Add GLIBC_PRIVATE.
        [...]

was clearly a deliberate choice (as was the choice of which symbols in 
glibc 2.0 not to export at a public symbol version when symbol versioning 
was introduced in 2.1).  __gettimeofday is certainly the kind of symbol 
that could have been used by a library with its own namespace concerns 
(cf. past discussions of how we might enable libstdc++ to be 
namespace-clean), although maybe more likely to have been used by an 
application that should be using gettimeofday.

Perhaps someone set up to do so could check large sets of current and past 
distribution binaries for any reference to the __gettimeofday symbol in 
executable / shared library dynamic symbol tables, as evidence for whether 
such an ABI change is safe or not?

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 09/12] Finish move of clock_* functions to libc.
  2019-08-20 15:21     ` Florian Weimer
@ 2019-08-20 15:25       ` Zack Weinberg
  0 siblings, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 15:25 UTC (permalink / raw)
  To: Florian Weimer
  Cc: Joseph Myers, GNU C Library, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

On Tue, Aug 20, 2019 at 11:21 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> The pthread cleanup patches I posted replace existing forwarders, which
> were added at the same time to libc and libpthread, so these
> requirements are not apparent in these patches.

Oh, I see.  I'll fix this in the next revision of the patch series.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 03/12] Don’t use the argument to time.
  2019-08-20 13:21 ` [PATCH 03/12] Don’t use the argument to time Zack Weinberg
@ 2019-08-20 17:09   ` Rafal Luzynski
  2019-08-20 17:21     ` Zack Weinberg
  2019-08-20 17:36     ` Joseph Myers
  2019-08-20 18:08   ` [PATCH 03/12] Don’t use the argument to time Adhemerval Zanella
  1 sibling, 2 replies; 74+ messages in thread
From: Rafal Luzynski @ 2019-08-20 17:09 UTC (permalink / raw)
  To: Zack Weinberg, libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Zack, I think that your email software replaces the plain ASCII
apostrophe character "'" (ASCII/Unicode 0x0027) with the right single
quotation mark character "’" (Unicode 0x2019).  I am not sure if
we want this in the git comments if possible to keep the plain
ASCII.  This applies to other patches as well.

Please disregard this message if this is not a problem.

20.08.2019 15:21 Zack Weinberg <zackw@panix.com> wrote:
> 
> Unlike gettimeofday, I don’t think it makes sense to remove all the

Here is an example: --------^

Regards,

Rafal

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 03/12] Don’t use the argument to time.
  2019-08-20 17:09   ` Rafal Luzynski
@ 2019-08-20 17:21     ` Zack Weinberg
  2019-08-20 17:36     ` Joseph Myers
  1 sibling, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 17:21 UTC (permalink / raw)
  To: Rafal Luzynski; +Cc: GNU C Library, Arnd Bergmann

On Tue, Aug 20, 2019 at 1:09 PM Rafal Luzynski
<digitalfreak@lingonborough.com> wrote:
> Zack, I think that your email software replaces the plain ASCII
> apostrophe character "'" (ASCII/Unicode 0x0027) with the right single
> quotation mark character "’" (Unicode 0x2019).  I am not sure if
> we want this in the git comments if possible to keep the plain
> ASCII.  This applies to other patches as well.

That was actually my text editor when I wrote the commit messages in
the first place, but it's a fair question anyway.  What _is_ our
policy on non-ASCII characters in general, and "smart" / "typographic"
quote marks in particular, in commit messages and ChangeLogs?

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 03/12] Don’t use the argument to time.
  2019-08-20 17:09   ` Rafal Luzynski
  2019-08-20 17:21     ` Zack Weinberg
@ 2019-08-20 17:36     ` Joseph Myers
  2019-08-22  9:42       ` Rafal Luzynski
  1 sibling, 1 reply; 74+ messages in thread
From: Joseph Myers @ 2019-08-20 17:36 UTC (permalink / raw)
  To: Rafal Luzynski
  Cc: Zack Weinberg, libc-alpha, Florian Weimer, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

[-- Attachment #1: Type: text/plain, Size: 712 bytes --]

On Tue, 20 Aug 2019, Rafal Luzynski wrote:

> Zack, I think that your email software replaces the plain ASCII
> apostrophe character "'" (ASCII/Unicode 0x0027) with the right single
> quotation mark character "’" (Unicode 0x2019).  I am not sure if
> we want this in the git comments if possible to keep the plain
> ASCII.  This applies to other patches as well.

Clearly such characters should be allowed in the names of committers, for 
example.  We have the known and previously discussed bug in the commit 
hooks that they mark glibc-cvs messages as text/plain; charset="us-ascii" 
even when that's inaccurate, but I think that should be fixed in the 
hooks.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 08/12] Use clock_gettime to implement gettimeofday.
  2019-08-20 13:37 ` [PATCH 08/12] Use clock_gettime to implement gettimeofday Zack Weinberg
  2019-08-20 15:24   ` Joseph Myers
@ 2019-08-20 17:51   ` Adhemerval Zanella
  1 sibling, 0 replies; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-20 17:51 UTC (permalink / raw)
  To: libc-alpha



On 20/08/2019 10:21, Zack Weinberg wrote:
> Abstractly, this is the same change as using clock_gettime to
> implement time, but the vestigial “get time zone” feature of
> gettimeofday complicates matters a little.  Unlike settimeofday, there
> are *no* known uses of this feature that are not bugs, so it is simply
> dummied out.  (The per-process timezone support in ‘localtime’ and
> friends is unrelated, and the programs that set the kernel’s offset
> between the hardware clock and UTC do not need to read it back.)
> 
> Henceforth, if gettimeofday’s ‘struct timezone’ argument is not NULL,
> it will write zeroes to both fields.  Any program that is actually
> looking at this data will thus think it is running in UTC, which is
> probably more correct than whatever it was doing before.
> 
> Hurd having already been converted, this patch only affects Linux and
> hypothetical future ports.  Most Linux ports supplied a vDSO symbol
> for gettimeofday, and some wrapped that with an ifunc, so this patch
> deletes a lot of code.  For ease of future edits to the many copies of
> _libc_vdso_platform_setup, the variable ‘p’ in each is now declared
> separately from any use of it.

I personally would prefer to make gettimeofday implementation use 
clock_gettime internally regardless, it has the clear code simplification 
advantage, and it allows an architecture provide only clock_gettime as vDSO 
to optimize all get time related functions.

However some architecture does implement it with vDSO as latency optimization
and I think we should consult with arch maintainers to see if this change is 
indeed acceptable. 

On my vDSO refactor for gettimeofday [1], I tried to keep current code
as is and the fallback code is still calling __NR_gettimeofday (since
all current architectures support the syscall).

[1] https://sourceware.org/ml/libc-alpha/2019-07/msg00158.html

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 06/12] Use clock_gettime to implement time.
  2019-08-20 13:37 ` [PATCH 06/12] Use clock_gettime to implement time Zack Weinberg
@ 2019-08-20 18:02   ` Adhemerval Zanella
  2019-08-22 12:58     ` Zack Weinberg
  0 siblings, 1 reply; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-20 18:02 UTC (permalink / raw)
  To: libc-alpha



On 20/08/2019 10:21, Zack Weinberg wrote:
> Most ports were using gettimeofday to implement time, or they were
> making a direct (v)syscall.  Unconditionally switch to using
> clock_gettime instead.  All sysdeps implementations of time are
> removed.

I was the one that added the powerpc kernel and glibc vDSO support, 
mostly to keep on par with x86_64; and although I am no longer the
powerpc maintainer I see the optimization now is just complexity 
without much gain. 

The decrease latency gain from direct vDSO implementation or iFUNC 
does not make much sense due time return granularity. And think the
same applies for x86.

> 
> 	* time/time.c (time): No longer a stub implementation.
>         Call __clock_gettime.
> 
> 	* sysdeps/unix/sysv/linux/powerpc/Versions (GLIBC_PRIVATE):
> 	Remove __vdso_time.
> 	* sysdeps/unix/sysv/linux/powerpc/init-first.c (__vdso_time): Delete.
> 	(_libc_vdso_platform_setup): Don’t initialize __vdso_time.
> 	* sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list: Remove entry
> 	for time.
> 
> 	* sysdeps/posix/time.c
> 	* sysdeps/unix/sysv/linux/time.c
> 	* sysdeps/unix/sysv/linux/i386/time.c
> 	* sysdeps/unix/sysv/linux/powerpc/time.c
> 	* sysdeps/unix/sysv/linux/sparc/sparc64/time.c
> 	* sysdeps/unix/sysv/linux/x86/time.c:
> 	Delete file.

LGTM with a nit below regarding time generic implementation.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/posix/time.c                          | 40 ---------
>  sysdeps/unix/sysv/linux/i386/time.c           | 34 --------
>  sysdeps/unix/sysv/linux/powerpc/Versions      |  1 -
>  sysdeps/unix/sysv/linux/powerpc/init-first.c  |  5 --
>  sysdeps/unix/sysv/linux/powerpc/time.c        | 84 -------------------
>  sysdeps/unix/sysv/linux/sparc/sparc64/time.c  |  1 -
>  sysdeps/unix/sysv/linux/time.c                | 41 ---------
>  sysdeps/unix/sysv/linux/x86/time.c            | 59 -------------
>  .../unix/sysv/linux/x86_64/x32/syscalls.list  |  1 -
>  time/time.c                                   | 17 ++--
>  10 files changed, 10 insertions(+), 273 deletions(-)
>  delete mode 100644 sysdeps/posix/time.c
>  delete mode 100644 sysdeps/unix/sysv/linux/i386/time.c
>  delete mode 100644 sysdeps/unix/sysv/linux/powerpc/time.c
>  delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/time.c
>  delete mode 100644 sysdeps/unix/sysv/linux/time.c
>  delete mode 100644 sysdeps/unix/sysv/linux/x86/time.c
> 
> diff --git a/sysdeps/posix/time.c b/sysdeps/posix/time.c
> deleted file mode 100644
> index e1b3bc8d4c..0000000000
> --- a/sysdeps/posix/time.c
> +++ /dev/null
> @@ -1,40 +0,0 @@
> -/* Copyright (C) 1991-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#include <stddef.h>		/* For NULL.  */
> -#include <time.h>
> -#include <sys/time.h>
> -
> -
> -/* Return the current time as a `time_t' and also put it in *T if T is
> -   not NULL.  Time is represented as seconds from Jan 1 00:00:00 1970.  */
> -time_t
> -time (time_t *t)
> -{
> -  struct timeval tv;
> -  time_t result;
> -
> -  if (__gettimeofday (&tv, (struct timezone *) NULL))
> -    result = (time_t) -1;
> -  else
> -    result = (time_t) tv.tv_sec;
> -
> -  if (t != NULL)
> -    *t = result;
> -  return result;
> -}
> -libc_hidden_def (time)

Ok.

> diff --git a/sysdeps/unix/sysv/linux/i386/time.c b/sysdeps/unix/sysv/linux/i386/time.c
> deleted file mode 100644
> index 440e3e6ab4..0000000000
> --- a/sysdeps/unix/sysv/linux/i386/time.c
> +++ /dev/null
> @@ -1,34 +0,0 @@
> -/* time -- Get number of seconds since Epoch.  Linux/i386 version.
> -   Copyright (C) 2015-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#ifdef SHARED
> -# define time __redirect_time
> -#endif
> -
> -#include <time.h>
> -
> -#ifdef SHARED
> -# undef time
> -# define time_type __redirect_time
> -
> -# undef libc_hidden_def
> -# define libc_hidden_def(name)  \
> -  __hidden_ver1 (__time_syscall, __GI_time, __time_syscall);
> -#endif
> -
> -#include <sysdeps/unix/sysv/linux/x86/time.c>

Ok.

> diff --git a/sysdeps/unix/sysv/linux/powerpc/Versions b/sysdeps/unix/sysv/linux/powerpc/Versions
> index 8ebeea15a1..859e0d7daf 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/Versions
> +++ b/sysdeps/unix/sysv/linux/powerpc/Versions
> @@ -10,7 +10,6 @@ libc {
>      __vdso_clock_gettime;
>      __vdso_clock_getres;
>      __vdso_getcpu;
> -    __vdso_time;
>    }
>  }
>  libm {

Ok.

> diff --git a/sysdeps/unix/sysv/linux/powerpc/init-first.c b/sysdeps/unix/sysv/linux/powerpc/init-first.c
> index 831f910788..4f12b59e76 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/init-first.c
> +++ b/sysdeps/unix/sysv/linux/powerpc/init-first.c
> @@ -25,7 +25,6 @@ int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
>  int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *);
>  unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void);
>  int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *);
> -time_t (*VDSO_SYMBOL(time)) (time_t *);
>  
>  #if defined(__PPC64__) || defined(__powerpc64__)
>  void *VDSO_SYMBOL(sigtramp_rt64);
> @@ -59,10 +58,6 @@ _libc_vdso_platform_setup (void)
>    PTR_MANGLE (p);
>    VDSO_SYMBOL (getcpu) = p;
>  
> -  p = _dl_vdso_vsym ("__kernel_time", &linux2615);
> -  PTR_MANGLE (p);
> -  VDSO_SYMBOL (time) = p;
> -
>    /* PPC64 uses only one signal trampoline symbol, while PPC32 will use
>       two depending if SA_SIGINFO is used (__kernel_sigtramp_rt32) or not
>       (__kernel_sigtramp32).

Ok.

> diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c
> deleted file mode 100644
> index cb3e8b9a73..0000000000
> --- a/sysdeps/unix/sysv/linux/powerpc/time.c
> +++ /dev/null
> @@ -1,84 +0,0 @@
> -/* time system call for Linux/PowerPC.
> -   Copyright (C) 2013-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#ifdef SHARED
> -# ifndef __powerpc64__
> -#  define time __redirect_time
> -# else
> -#  define __redirect_time time
> -# endif
> -
> -# include <time.h>
> -# include <sysdep.h>
> -# include <dl-vdso.h>
> -# include <libc-vdso.h>
> -# include <dl-machine.h>
> -
> -# ifndef __powerpc64__
> -#  undef time
> -
> -time_t
> -__time_vsyscall (time_t *t)
> -{
> -  return INLINE_VSYSCALL (time, 1, t);
> -}
> -
> -/* __GI_time is defined as hidden and for ppc32 it enables the
> -   compiler make a local call (symbol@local) for internal GLIBC usage. It
> -   means the PLT won't be used and the ifunc resolver will be called directly.
> -   For ppc64 a call to a function in another translation unit might use a
> -   different toc pointer thus disallowing direct branchess and making internal
> -   ifuncs calls safe.  */
> -#  undef libc_hidden_def
> -#  define libc_hidden_def(name)					\
> -  __hidden_ver1 (__time_vsyscall, __GI_time, __time_vsyscall);
> -
> -# endif /* !__powerpc64__  */
> -
> -static time_t
> -time_syscall (time_t *t)
> -{
> -  struct timeval tv;
> -  time_t result;
> -
> -  if (INLINE_VSYSCALL (gettimeofday, 2, &tv, NULL) < 0)
> -    result = (time_t) -1;
> -  else
> -    result = (time_t) tv.tv_sec;
> -
> -  if (t != NULL)
> -    *t = result;
> -  return result;
> -}
> -
> -# define INIT_ARCH()						\
> -  PREPARE_VERSION_KNOWN (linux2615, LINUX_2_6_15);		\
> -  void *vdso_time = _dl_vdso_vsym ("__kernel_time", &linux2615);
> -
> -/* If the vDSO is not available we fall back to the syscall.  */
> -libc_ifunc_hidden (__redirect_time, time,
> -		   vdso_time
> -		   ? VDSO_IFUNC_RET (vdso_time)
> -		   : (void *) time_syscall);
> -libc_hidden_def (time)
> -
> -#else
> -
> -#include <sysdeps/posix/time.c>
> -
> -#endif /* !SHARED */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/time.c b/sysdeps/unix/sysv/linux/sparc/sparc64/time.c
> deleted file mode 100644
> index 509b580c55..0000000000
> --- a/sysdeps/unix/sysv/linux/sparc/sparc64/time.c
> +++ /dev/null
> @@ -1 +0,0 @@
> -#include <sysdeps/posix/time.c>

Ok.

> diff --git a/sysdeps/unix/sysv/linux/time.c b/sysdeps/unix/sysv/linux/time.c
> deleted file mode 100644
> index 1978f6d817..0000000000
> --- a/sysdeps/unix/sysv/linux/time.c
> +++ /dev/null
> @@ -1,41 +0,0 @@
> -/* Copyright (C) 2005-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#include <stddef.h>
> -#include <time.h>
> -
> -#include <sysdep.h>
> -
> -#ifdef __NR_time
> -
> -time_t
> -time (time_t *t)
> -{
> -  INTERNAL_SYSCALL_DECL (err);
> -  time_t res = INTERNAL_SYSCALL (time, err, 1, NULL);
> -  /* There cannot be any error.  */
> -  if (t != NULL)
> -    *t = res;
> -  return res;
> -}
> -libc_hidden_def (time)
> -
> -#else
> -
> -# include <sysdeps/posix/time.c>
> -
> -#endif

Ok.

> diff --git a/sysdeps/unix/sysv/linux/x86/time.c b/sysdeps/unix/sysv/linux/x86/time.c
> deleted file mode 100644
> index 3d72488500..0000000000
> --- a/sysdeps/unix/sysv/linux/x86/time.c
> +++ /dev/null
> @@ -1,59 +0,0 @@
> -/* time -- Get number of seconds since Epoch.  Linux/x86 version.
> -   Copyright (C) 2015-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#include <time.h>
> -
> -#ifdef SHARED
> -
> -#include <dl-vdso.h>
> -#include <errno.h>
> -
> -static time_t
> -__time_syscall (time_t *t)
> -{
> -  INTERNAL_SYSCALL_DECL (err);
> -  return INTERNAL_SYSCALL (time, err, 1, t);
> -}
> -
> -# ifndef time_type
> -/* The i386 time.c includes this file with a defined time_type macro.
> -   For x86_64 we have to define it to time as the internal symbol is the
> -   ifunc'ed one.  */
> -#  define time_type time
> -# endif
> -
> -#undef INIT_ARCH
> -#define INIT_ARCH() PREPARE_VERSION_KNOWN (linux26, LINUX_2_6);
> -/* If the vDSO is not available we fall back on the syscall.  */
> -libc_ifunc_hidden (time_type, time,
> -		   (_dl_vdso_vsym ("__vdso_time", &linux26)
> -		    ?:  &__time_syscall))
> -libc_hidden_def (time)
> -
> -#else
> -
> -# include <sysdep.h>
> -
> -time_t
> -time (time_t *t)
> -{
> -  INTERNAL_SYSCALL_DECL (err);
> -  return INTERNAL_SYSCALL (time, err, 1, t);
> -}
> -
> -#endif

Ok.

> diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
> index b44f6f99e9..c0cfa7b0da 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
> +++ b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
> @@ -3,4 +3,3 @@
>  gettimeofday	-	gettimeofday:__vdso_gettimeofday@LINUX_2.6	i:pP	__gettimeofday	gettimeofday
>  personality	EXTRA	personality	Ei:i	__personality	personality
>  posix_fadvise64	-	fadvise64	Vi:iiii	posix_fadvise	posix_fadvise64

Ok.

> -time		-	time:__vdso_time@LINUX_2.6			Ei:P	time
> diff --git a/time/time.c b/time/time.c
> index 88612d6c76..b60b8b9db8 100644
> --- a/time/time.c
> +++ b/time/time.c
> @@ -15,19 +15,22 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <errno.h>
>  #include <time.h>
>  
>  /* Return the time now, and store it in *TIMER if not NULL.  */
>  time_t
>  time (time_t *timer)
>  {
> -  __set_errno (ENOSYS);
> +  struct timespec ts;
> +  time_t res;
>  
> -  if (timer != NULL)
> -    *timer = (time_t) -1;
> -  return (time_t) -1;
> +  if (__clock_gettime (CLOCK_REALTIME, &ts))

No implicit check. Also I think we can assume CLOCK_REALTIME support on
all current architectures (including Hurd), so there is no actually need
to check clock_gettime return value.

> +    res = -1;
> +  else
> +    res = ts.tv_sec;
> +
> +  if (timer)
> +    *timer = res;
> +  return res;
>  }
>  libc_hidden_def (time)
> -
> -stub_warning (time)
> 

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday.
  2019-08-20 13:22 ` [PATCH 01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday Zack Weinberg
@ 2019-08-20 18:06   ` Adhemerval Zanella
  2019-08-22 12:54     ` Zack Weinberg
  0 siblings, 1 reply; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-20 18:06 UTC (permalink / raw)
  To: libc-alpha



On 20/08/2019 10:21, Zack Weinberg wrote:
> gettimeofday and settimeofday are obsolete in POSIX and will not be
> provided by Linux for future new architectures.  The preferred
> interfaces are clock_gettime and clock_settime.
> 
> In preparation for implementing all the other time query/set
> interfaces using clock_gettime and clock_settime, remove the
> generic-Unix implementations of clock_gettime and clock_settime that
> forwarded to gettimeofday and settimeofday.  Ports of glibc to
> historic Unixes that provided these functions, but not clock_gettime
> and clock_settime, are unlikely to be contributed anymore.
> 
> The removed implementations *were* being used on the Hurd.
> Deal with this by converting the Hurd gettimeofday and settimeofday
> implementations into clock_gettime and clock_settime implementations,
> respectively.  (They still only supply microsecond resolution.
> I don’t know enough about Hurd/Mach to know whether nanosecond-
> resolution clocks are even available.)  This means Hurd temporarily
> has no implementation of gettimeofday or settimeofday; this will be
> corrected in subsequent patches.  (glibc will not fail to build in the
> i386-gnu configuration, but gettimeofday and settimeofday will be
> ENOSYS stubs.)

I would prefer to avoid patch that might break the ABI, couldn't you
attach this change with the one that fix it for Hurd as well?

> 
> 	* sysdeps/unix/clock_gettime.c, sysdeps/unix/clock_settime.c:
>         Delete file.
>         * sysdeps/mach/gettimeofday.c: Rename to .../clock_gettime.c
>         and convert into an implementation of clock_gettime.

I would prefer to just use the full path (makes it more readable).

>         * sysdeps/mach/hurd/settimeofday.c: Rename to .../clock_settime.c
>         and convert into an implementation of clock_settime.

Ditto.

> ---
>  .../mach/{gettimeofday.c => clock_gettime.c}  | 25 ++++----
>  .../hurd/{settimeofday.c => clock_settime.c}  | 27 ++++----
>  sysdeps/unix/clock_gettime.c                  | 64 -------------------
>  sysdeps/unix/clock_settime.c                  | 54 ----------------
>  4 files changed, 25 insertions(+), 145 deletions(-)
>  rename sysdeps/mach/{gettimeofday.c => clock_gettime.c} (67%)
>  rename sysdeps/mach/hurd/{settimeofday.c => clock_settime.c} (71%)
>  delete mode 100644 sysdeps/unix/clock_gettime.c
>  delete mode 100644 sysdeps/unix/clock_settime.c
> 
> diff --git a/sysdeps/mach/gettimeofday.c b/sysdeps/mach/clock_gettime.c
> similarity index 67%
> rename from sysdeps/mach/gettimeofday.c
> rename to sysdeps/mach/clock_gettime.c
> index 8d0dfbb7dc..0fe0619aa5 100644
> --- a/sysdeps/mach/gettimeofday.c
> +++ b/sysdeps/mach/clock_gettime.c
> @@ -16,28 +16,31 @@
>     <http://www.gnu.org/licenses/>.  */
>  
>  #include <errno.h>
> -#include <stddef.h>
> -#include <sys/time.h>
> +#include <time.h>
>  #include <mach.h>
>  
> -/* Get the current time of day and timezone information,
> -   putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
> +/* Get the current time of day, putting it into *TS.
>     Returns 0 on success, -1 on errors.  */
>  int
> -__gettimeofday (struct timeval *tv, struct timezone *tz)
> +__clock_gettime (clockid_t clock_id, struct timespec *ts)
>  {
>    kern_return_t err;
> +  time_value_t tv;
>  
> -  if (tz != NULL)
> -    *tz = (struct timezone){0, 0}; /* XXX */
> +  if (clock_id != CLOCK_REALTIME)
> +    {
> +      errno = EINVAL;
> +      return -1;
> +    }
>  
> -  if (err = __host_get_time (__mach_host_self (), (time_value_t *) tv))
> +  if (err = __host_get_time (__mach_host_self (), &tv))
>      {
>        errno = err;
>        return -1;
>      }
> +
> +  TIME_VALUE_TO_TIMESPEC (&tv, ts);
>    return 0;
>  }
> -libc_hidden_def (__gettimeofday)
> -weak_alias (__gettimeofday, gettimeofday)
> -libc_hidden_weak (gettimeofday)
> +weak_alias (__clock_gettime, clock_gettime)
> +libc_hidden_def (__clock_gettime)
> diff --git a/sysdeps/mach/hurd/settimeofday.c b/sysdeps/mach/hurd/clock_settime.c
> similarity index 71%
> rename from sysdeps/mach/hurd/settimeofday.c
> rename to sysdeps/mach/hurd/clock_settime.c
> index bd0ffd64ac..a642b82b3e 100644
> --- a/sysdeps/mach/hurd/settimeofday.c
> +++ b/sysdeps/mach/hurd/clock_settime.c
> @@ -16,37 +16,32 @@
>     <http://www.gnu.org/licenses/>.  */
>  
>  #include <errno.h>
> +#include <time.h>
>  #include <sys/time.h>
>  #include <hurd.h>
>  #include <hurd/port.h>
>  
> -/* Set the current time of day and timezone information.
> +/* Set the current time of day.
>     This call is restricted to the super-user.  */
>  int
> -__settimeofday (const struct timeval *tv, const struct timezone *tz)
> +__clock_settime (clockid_t clock_id, const struct timespec *ts)
>  {
>    error_t err;
>    mach_port_t hostpriv;
> +  time_value_t tv;
>  
> -  if (tz != NULL)
> -    {
> -      errno = ENOSYS;
> -      return -1;
> -    }
> +  if (clock_id != CLOCK_REALTIME)
> +    return __hurd_fail (EINVAL);
>  
>    err = __get_privileged_ports (&hostpriv, NULL);
>    if (err)
>      return __hurd_fail (EPERM);
>  
> -  /* `time_value_t' and `struct timeval' are in fact identical with the
> -     names changed.  */
> -  err = __host_set_time (hostpriv, *(time_value_t *) tv);
> +  TIMESPEC_TO_TIME_VALUE (&tv, ts);
> +  err = __host_set_time (hostpriv, tv);
>    __mach_port_deallocate (__mach_task_self (), hostpriv);
>  
> -  if (err)
> -    return __hurd_fail (err);
> -
> -  return 0;
> +  return __hurd_fail (err);
>  }
> -
> -weak_alias (__settimeofday, settimeofday)
> +libc_hidden_def (__clock_settime)
> +weak_alias (__clock_settime, clock_settime)
> diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
> deleted file mode 100644
> index 10a6c96d9d..0000000000
> --- a/sysdeps/unix/clock_gettime.c
> +++ /dev/null
> @@ -1,64 +0,0 @@
> -/* clock_gettime -- Get the current time from a POSIX clockid_t.  Unix version.
> -   Copyright (C) 1999-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#include <errno.h>
> -#include <stdint.h>
> -#include <time.h>
> -#include <sys/time.h>
> -#include <libc-internal.h>
> -#include <ldsodefs.h>
> -
> -
> -static inline int
> -realtime_gettime (struct timespec *tp)
> -{
> -  struct timeval tv;
> -  int retval = __gettimeofday (&tv, NULL);
> -  if (retval == 0)
> -    /* Convert into `timespec'.  */
> -    TIMEVAL_TO_TIMESPEC (&tv, tp);
> -  return retval;
> -}
> -
> -
> -/* Get current value of CLOCK and store it in TP.  */
> -int
> -__clock_gettime (clockid_t clock_id, struct timespec *tp)
> -{
> -  int retval = -1;
> -
> -  switch (clock_id)
> -    {
> -    case CLOCK_REALTIME:
> -      {
> -	struct timeval tv;
> -	retval = __gettimeofday (&tv, NULL);
> -	if (retval == 0)
> -	  TIMEVAL_TO_TIMESPEC (&tv, tp);
> -      }
> -      break;
> -
> -    default:
> -      __set_errno (EINVAL);
> -      break;
> -    }
> -
> -  return retval;
> -}
> -weak_alias (__clock_gettime, clock_gettime)
> -libc_hidden_def (__clock_gettime)
> diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
> deleted file mode 100644
> index 109a1ad872..0000000000
> --- a/sysdeps/unix/clock_settime.c
> +++ /dev/null
> @@ -1,54 +0,0 @@
> -/* Copyright (C) 1999-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#include <errno.h>
> -#include <time.h>
> -#include <sys/time.h>
> -#include <ldsodefs.h>
> -
> -
> -/* Set CLOCK to value TP.  */
> -int
> -__clock_settime (clockid_t clock_id, const struct timespec *tp)
> -{
> -  int retval = -1;
> -
> -  /* Make sure the time cvalue is OK.  */
> -  if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
> -    {
> -      __set_errno (EINVAL);
> -      return -1;
> -    }
> -
> -  switch (clock_id)
> -    {
> -    case CLOCK_REALTIME:
> -      {
> -	struct timeval tv;
> -	TIMESPEC_TO_TIMEVAL (&tv, tp);
> -	retval = __settimeofday (&tv, NULL);
> -      }
> -      break;
> -
> -    default:
> -      __set_errno (EINVAL);
> -      break;
> -    }
> -
> -  return retval;
> -}
> -weak_alias (__clock_settime, clock_settime)
> 

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 03/12] Don’t use the argument to time.
  2019-08-20 13:21 ` [PATCH 03/12] Don’t use the argument to time Zack Weinberg
  2019-08-20 17:09   ` Rafal Luzynski
@ 2019-08-20 18:08   ` Adhemerval Zanella
  2019-08-21 12:29     ` Zack Weinberg
  1 sibling, 1 reply; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-20 18:08 UTC (permalink / raw)
  To: libc-alpha



On 20/08/2019 10:21, Zack Weinberg wrote:
> Unlike gettimeofday, I don’t think it makes sense to remove all the
> internal uses of time.  Its callers don’t care about sub-second
> resolution and would be unnecessarily complicated if they had to
> declare a struct timespec instead of just a time_t.  However, a
> handful of places were using the vestigial ‘result’ argument instead
> of the return value, which is ever so slightly less efficient and also
> looks weird.  Correct this.
> 
> 	* misc/syslog.c (__vsyslog_internal)
> 	* time/getdate.c (__getdate_r)
> 	* time/tst_wcsftime.c (main):
> 	Use return value of time, not its argument.
> 
> 	* string/strfry.c (strfry)
> 	* sysdeps/mach/sleep.c (__sleep):
> 	Remove unnecessary casts of NULL.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  misc/syslog.c        | 2 +-
>  string/strfry.c      | 2 +-
>  sysdeps/mach/sleep.c | 4 ++--
>  time/getdate.c       | 2 +-
>  time/tst_wcsftime.c  | 2 +-
>  5 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/misc/syslog.c b/misc/syslog.c
> index 3a15da41ce..cf2deef533 100644
> --- a/misc/syslog.c
> +++ b/misc/syslog.c
> @@ -205,7 +205,7 @@ __vsyslog_internal(int pri, const char *fmt, va_list ap,
>  	  {
>  	    __fsetlocking (f, FSETLOCKING_BYCALLER);
>  	    fprintf (f, "<%d>", pri);
> -	    (void) time (&now);
> +	    now = time (NULL);
>  	    f->_IO_write_ptr += __strftime_l (f->_IO_write_ptr,
>  					      f->_IO_write_end
>  					      - f->_IO_write_ptr,

Ok.

> diff --git a/string/strfry.c b/string/strfry.c
> index af6087bee5..71686d45c2 100644
> --- a/string/strfry.c
> +++ b/string/strfry.c
> @@ -30,7 +30,7 @@ strfry (char *string)
>      {
>        static char state[32];
>        rdata.state = NULL;
> -      __initstate_r (time ((time_t *) NULL) ^ getpid (),
> +      __initstate_r (time (NULL) ^ getpid (),
>  		     state, sizeof (state), &rdata);
>        init = 1;
>      }

Ok.

> diff --git a/sysdeps/mach/sleep.c b/sysdeps/mach/sleep.c
> index 11e1bb87f3..c63ef926b7 100644
> --- a/sysdeps/mach/sleep.c
> +++ b/sysdeps/mach/sleep.c
> @@ -33,10 +33,10 @@ __sleep (unsigned int seconds)
>  
>    recv = __mach_reply_port ();
>  
> -  before = time ((time_t *) NULL);
> +  before = time (NULL);
>    (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
>  		     0, 0, recv, seconds * 1000, MACH_PORT_NULL);
> -  after = time ((time_t *) NULL);
> +  after = time (NULL);
>    __mach_port_destroy (__mach_task_self (), recv);
>  
>    return seconds - (after - before);

Ok.

> diff --git a/time/getdate.c b/time/getdate.c
> index aee96f7163..8a567c3fcd 100644
> --- a/time/getdate.c
> +++ b/time/getdate.c
> @@ -219,7 +219,7 @@ __getdate_r (const char *string, struct tm *tp)
>      return 7;
>  
>    /* Get current time.  */
> -  time (&timer);
> +  timer = time (NULL);
>    __localtime_r (&timer, &tm);
>  
>    /* If only the weekday is given, today is assumed if the given day

Ok.

> diff --git a/time/tst_wcsftime.c b/time/tst_wcsftime.c
> index 3f6f0d9f77..55c45f6a81 100644
> --- a/time/tst_wcsftime.c
> +++ b/time/tst_wcsftime.c
> @@ -10,7 +10,7 @@ main (int argc, char *argv[])
>    int result = 0;
>    size_t n;
>  
> -  time (&t);
> +  t = time (NULL);
>    tp = gmtime (&t);
>  
>    n = wcsftime (buf, sizeof (buf) / sizeof (buf[0]),
> 

Ok.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (12 preceding siblings ...)
  2019-08-20 15:10 ` [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Joseph Myers
@ 2019-08-20 18:47 ` Alistair Francis
  2019-08-20 18:55 ` Paul Eggert
  2019-08-21  8:00 ` Lukasz Majewski
  15 siblings, 0 replies; 74+ messages in thread
From: Alistair Francis @ 2019-08-20 18:47 UTC (permalink / raw)
  To: Zack Weinberg
  Cc: GNU C Library, Joseph Myers, Florian Weimer, Lukasz Majewski,
	Stepan Golosunov, Arnd Bergmann

On Tue, Aug 20, 2019 at 6:21 AM Zack Weinberg <zackw@panix.com> wrote:
>
> This patchset aims to make the Y2038 project a little easier by
> implementing the other time-getting and time-setting functions
> (time, ftime, stime, gettimeofday, and settimeofday) in terms of
> clock_gettime and clock_settime.  Internal uses of (__)gettimeofday
> are also all changed to __clock_gettime.  Internal uses of time() are
> mostly left alone, since time() is easier and clearer when you don’t
> care about sub-second resolution and don’t need a struct timespec for
> some other reason.

Thanks for the series, this should help. I'll rebase my work ontop of
this once it's merged into master.

>
> As a consequence, gettimeofday will no longer report crude timezone
> information under any circumstances.  If its ‘tzp’ argument is not
> NULL, it will write zeroes to both fields of the ‘struct timezone’,
> even if the gettimeofday system call exists and would have produced
> different output.  Similarly, ftime will always write zeroes to the
> timezone and dstflag fields of ‘struct timeb’.  Joseph Myers raised an
> objection to this change; I rebutted the objection, and he did not
> reply; I do not think either of us will persuade the other, so I’m
> formally asking for a third maintainer to make a decision.

I like this and think it makes a lot of sense.

Alistair

>
> settimeofday _will_ still call the settimeofday system call and pass
> down a non-null ‘tzp’ argument if it receives one, but, if _both_ of
> its arguments are non-null, it will fail and set errno to EINVAL.
> Also, its invocation of a settimeofday system call goes through an
> internal sysdep function called __settimezone.  On the Hurd this is an
> unconditional ENOSYS stub, and on Linux it’s an ENOSYS stub when
> __NR_settimeofday is not defined.
>
> Relatedly, there is a macro-based hack to issue warnings when
> gettimeofday is called with a ‘tzp’ argument that is not a
> compile-time null pointer.  I think this is probably a better option
> at this stage than various suggested alternatives (e.g. renaming the
> fields of ‘struct timezone’, or removing it from sys/time.h
> altogether) because the remaining valid uses of settimeofday with
> non-null ‘tzp’ should still be able to use struct timezone.  The hack
> is in a separate patch because, well, it’s a hack and I’m hoping
> someone has a better implementation idea.  (I tried an inline function
> instead of a macro, but it threw false positives all over the place on
> ‘gettimeofday (&tv, 0)’...)
>
> This patchset also includes an overhaul of Linux/Alpha’s GLIBC_2.0
> compatibility symbols for several system calls that consume or produce
> struct timeval.  It appears that early releases of glibc and/or Linux
> for Alpha attempted to achieve some degree of binary compatibility
> with OSF/1, but this came at the expense of using 32-bit time_t inside
> struct timeval.  Up till now, we were invoking compatibility system
> calls from the compatibility symbols.  This patch changes them to wrap
> the 64-bit implementations and convert between 32-bit and 64-bit
> struct timeval in user space.  If a 64-bit tv_sec value returned by
> the kernel is found to be greater than INT32_MAX, the caller will
> receive a saturated 32-bit struct timeval, { INT32_MAX, 0 }, and the
> function will return -1 with errno set to EOVERFLOW.  Because many of
> these calls are assumed unable to fail, we make sure to write all the
> fields of any output data structure even when this happens.  I did
> this partially because it simplified conversion of gettimeofday to
> call clock_gettime, and partially as a worked example of the semantics
> that I think are probably best for the 32-bit time_t compatibility
> symbols we’re going to have to add for many other architectures.
> Comments on these semantics are requested.
>
> This patchset also includes a partial revision of manual/time.texi.
> clock_gettime and clock_settime are now documented, and the
> obsolescent status of stime, settimeofday, and gettimeofday is
> clearer.  I only documented CLOCK_REALTIME and CLOCK_MONOTONIC,
> because most of the other clock constants are either extremely
> Linux-specific or they have to do with measuring CPU time, and I
> didn’t touch the measuring-CPU-time part of time.texi.  (That part
> also deserves a rewrite, but I don’t know enough about the topic and
> this patchset is already long enough.)
>
> Finally, there is a case for demoting ftime and stime to compatibility
> symbols and removing their public prototypes (for ftime, we would stop
> installing <sys/timeb.h> altogether).  I tried to investigate how much
> this might break, using codesearch.debian.net, but the identifiers
> ‘ftime’ and ‘stime’ turn out to be heavily used for unrelated
> purposes, so I didn’t get anywhere.
>
> Zack Weinberg (12):
>   Remove implementations of clock_[gs]ettime using [gs]ettimeofday.
>   Change most internal uses of __gettimeofday to __clock_gettime.
>   Don’t use the argument to time.
>   Use clock_settime to implement stime.
>   Use clock_settime to implement settimeofday.
>   Use clock_gettime to implement time.
>   Use clock_gettime to implement ftime.
>   Use clock_gettime to implement gettimeofday.
>   Finish move of clock_* functions to libc.
>   Warn when gettimeofday is called with non-null tzp argument.
>   Linux/Alpha: don’t use timeval32 system calls.
>   Revise the documentation of ‘simple calendar time’.
>
>  NEWS                                          |   53 +-
>  include/sys/time.h                            |    7 +-
>  include/time.h                                |    4 +-
>  inet/deadline.c                               |    9 +-
>  login/logout.c                                |    9 +-
>  login/logwtmp.c                               |    7 +-
>  manual/filesys.texi                           |    2 +-
>  manual/llio.texi                              |   10 +-
>  manual/threads.texi                           |    2 +-
>  manual/time.texi                              | 1062 +++++++++--------
>  misc/syslog.c                                 |    2 +-
>  nis/nis_call.c                                |    4 +-
>  nptl/pthread_join_common.c                    |    7 +-
>  nptl/pthread_mutex_timedlock.c                |    7 +-
>  nscd/nscd_helper.c                            |   24 +-
>  resolv/gai_misc.c                             |    6 +-
>  resolv/gai_suspend.c                          |    6 +-
>  resolv/res_send.c                             |    6 +-
>  rt/Makefile                                   |   15 +-
>  rt/Versions                                   |    7 +-
>  rt/clock-compat.c                             |   63 -
>  string/strfry.c                               |    2 +-
>  sunrpc/auth_des.c                             |   19 +-
>  sunrpc/auth_unix.c                            |    9 +-
>  sunrpc/create_xid.c                           |    6 +-
>  sunrpc/svcauth_des.c                          |    7 +-
>  support/support_test_main.c                   |   14 +-
>  sysdeps/generic/memusage.h                    |   16 +-
>  .../mach/{gettimeofday.c => clock_gettime.c}  |   25 +-
>  .../hurd/{settimeofday.c => clock_settime.c}  |   27 +-
>  sysdeps/mach/hurd/getitimer.c                 |    3 +-
>  sysdeps/mach/hurd/i386/libc.abilist           |    1 -
>  sysdeps/mach/hurd/i386/librt.abilist          |    5 -
>  sysdeps/mach/hurd/setitimer.c                 |    3 +-
>  sysdeps/mach/hurd/times.c                     |    6 +-
>  sysdeps/mach/nanosleep.c                      |   33 +-
>  sysdeps/mach/sleep.c                          |    4 +-
>  sysdeps/mach/usleep.c                         |    5 -
>  sysdeps/posix/gettimeofday.c                  |   67 --
>  sysdeps/posix/tempname.c                      |    9 +-
>  sysdeps/posix/time.c                          |   40 -
>  sysdeps/pthread/aio_misc.c                    |    6 +-
>  sysdeps/pthread/aio_suspend.c                 |    6 +-
>  sysdeps/unix/clock_gettime.c                  |   64 -
>  sysdeps/unix/make-syscalls.sh                 |    2 +-
>  sysdeps/unix/syscalls.list                    |    2 -
>  .../unix/sysv/linux/aarch64/gettimeofday.c    |   71 --
>  sysdeps/unix/sysv/linux/aarch64/init-first.c  |    7 +-
>  sysdeps/unix/sysv/linux/aarch64/libc-vdso.h   |    2 -
>  sysdeps/unix/sysv/linux/aarch64/libc.abilist  |    1 -
>  sysdeps/unix/sysv/linux/alpha/Makefile        |    2 +-
>  sysdeps/unix/sysv/linux/alpha/Versions        |    1 -
>  sysdeps/unix/sysv/linux/alpha/adjtime.c       |   70 +-
>  .../linux/{time.c => alpha/gettimeofday.c}    |   31 +-
>  sysdeps/unix/sysv/linux/alpha/libc.abilist    |    2 -
>  sysdeps/unix/sysv/linux/alpha/librt.abilist   |    5 -
>  sysdeps/unix/sysv/linux/alpha/osf_adjtime.c   |  135 +++
>  sysdeps/unix/sysv/linux/alpha/osf_getitimer.c |   48 +
>  sysdeps/unix/sysv/linux/alpha/osf_getrusage.c |   44 +
>  .../unix/sysv/linux/alpha/osf_gettimeofday.c  |   53 +
>  sysdeps/unix/sysv/linux/alpha/osf_setitimer.c |   55 +
>  .../unix/sysv/linux/alpha/osf_settimeofday.c  |   51 +
>  .../ftime.c => sysv/linux/alpha/osf_utimes.c} |   34 +-
>  .../linux/alpha/osf_wait4.c}                  |   51 +-
>  sysdeps/unix/sysv/linux/alpha/settimeofday.c  |   22 +
>  sysdeps/unix/sysv/linux/alpha/syscalls.list   |   13 +-
>  sysdeps/unix/sysv/linux/alpha/tv32-compat.h   |  151 +++
>  sysdeps/unix/sysv/linux/arm/init-first.c      |    7 +-
>  sysdeps/unix/sysv/linux/arm/libc-vdso.h       |    2 -
>  sysdeps/unix/sysv/linux/arm/libc.abilist      |    1 -
>  sysdeps/unix/sysv/linux/arm/librt.abilist     |    5 -
>  sysdeps/unix/sysv/linux/clock_settime.c       |    1 +
>  sysdeps/unix/sysv/linux/csky/libc.abilist     |    1 -
>  sysdeps/unix/sysv/linux/ftime.c               |    3 -
>  sysdeps/unix/sysv/linux/gettimeofday.c        |   39 -
>  sysdeps/unix/sysv/linux/hppa/libc.abilist     |    1 -
>  sysdeps/unix/sysv/linux/hppa/librt.abilist    |    5 -
>  sysdeps/unix/sysv/linux/i386/gettimeofday.c   |   35 -
>  sysdeps/unix/sysv/linux/i386/libc.abilist     |    1 -
>  sysdeps/unix/sysv/linux/i386/librt.abilist    |    5 -
>  sysdeps/unix/sysv/linux/i386/time.c           |   34 -
>  sysdeps/unix/sysv/linux/ia64/libc.abilist     |    1 -
>  sysdeps/unix/sysv/linux/ia64/librt.abilist    |    5 -
>  .../sysv/linux/m68k/coldfire/libc.abilist     |    1 -
>  .../sysv/linux/m68k/coldfire/librt.abilist    |    5 -
>  .../unix/sysv/linux/m68k/m680x0/libc.abilist  |    1 -
>  .../unix/sysv/linux/m68k/m680x0/librt.abilist |    5 -
>  .../unix/sysv/linux/microblaze/libc.abilist   |    1 -
>  .../unix/sysv/linux/microblaze/librt.abilist  |    5 -
>  sysdeps/unix/sysv/linux/mips/init-first.c     |    7 +-
>  sysdeps/unix/sysv/linux/mips/libc-vdso.h      |    2 -
>  .../sysv/linux/mips/mips32/fpu/libc.abilist   |    1 -
>  .../unix/sysv/linux/mips/mips32/librt.abilist |    5 -
>  .../sysv/linux/mips/mips32/nofpu/libc.abilist |    1 -
>  .../unix/sysv/linux/mips/mips64/librt.abilist |    5 -
>  .../sysv/linux/mips/mips64/n32/libc.abilist   |    1 -
>  .../sysv/linux/mips/mips64/n64/libc.abilist   |    1 -
>  sysdeps/unix/sysv/linux/nios2/libc.abilist    |    1 -
>  sysdeps/unix/sysv/linux/powerpc/Versions      |    1 -
>  .../unix/sysv/linux/powerpc/gettimeofday.c    |   85 --
>  sysdeps/unix/sysv/linux/powerpc/init-first.c  |   13 +-
>  sysdeps/unix/sysv/linux/powerpc/libc-vdso.h   |    2 -
>  .../linux/powerpc/powerpc32/fpu/libc.abilist  |    1 -
>  .../linux/powerpc/powerpc32/librt.abilist     |    5 -
>  .../powerpc/powerpc32/nofpu/libc.abilist      |    1 -
>  .../linux/powerpc/powerpc64/be/libc.abilist   |    1 -
>  .../linux/powerpc/powerpc64/be/librt.abilist  |    5 -
>  .../linux/powerpc/powerpc64/le/libc.abilist   |    1 -
>  sysdeps/unix/sysv/linux/powerpc/time.c        |   84 --
>  sysdeps/unix/sysv/linux/riscv/init-first.c    |   10 +-
>  sysdeps/unix/sysv/linux/riscv/libc-vdso.h     |    2 -
>  .../unix/sysv/linux/riscv/rv64/libc.abilist   |    1 -
>  sysdeps/unix/sysv/linux/s390/init-first.c     |    9 +-
>  sysdeps/unix/sysv/linux/s390/libc-vdso.h      |    3 -
>  .../unix/sysv/linux/s390/s390-32/libc.abilist |    1 -
>  .../sysv/linux/s390/s390-32/librt.abilist     |    5 -
>  .../unix/sysv/linux/s390/s390-64/libc.abilist |    1 -
>  .../sysv/linux/s390/s390-64/librt.abilist     |    5 -
>  sysdeps/unix/sysv/linux/settimezone.c         |   39 +
>  sysdeps/unix/sysv/linux/sh/libc.abilist       |    1 -
>  sysdeps/unix/sysv/linux/sh/librt.abilist      |    5 -
>  sysdeps/unix/sysv/linux/sparc/init-first.c    |    8 +-
>  sysdeps/unix/sysv/linux/sparc/libc-vdso.h     |    2 -
>  .../sysv/linux/sparc/sparc32/libc.abilist     |    1 -
>  .../sysv/linux/sparc/sparc32/librt.abilist    |    5 -
>  .../sysv/linux/sparc/sparc64/libc.abilist     |    1 -
>  .../sysv/linux/sparc/sparc64/librt.abilist    |    5 -
>  sysdeps/unix/sysv/linux/sparc/sparc64/time.c  |    1 -
>  sysdeps/unix/sysv/linux/syscalls.list         |    1 -
>  sysdeps/unix/sysv/linux/x86/gettimeofday.c    |   61 -
>  sysdeps/unix/sysv/linux/x86/time.c            |   59 -
>  .../unix/sysv/linux/x86_64/64/libc.abilist    |    1 -
>  .../unix/sysv/linux/x86_64/64/librt.abilist   |    5 -
>  .../unix/sysv/linux/x86_64/x32/libc.abilist   |    1 -
>  .../unix/sysv/linux/x86_64/x32/librt.abilist  |    5 -
>  .../unix/sysv/linux/x86_64/x32/syscalls.list  |    2 -
>  time/Makefile                                 |    8 +-
>  time/Versions                                 |    2 +-
>  {rt => time}/clock_getcpuclockid.c            |    0
>  {rt => time}/clock_getres.c                   |    0
>  {rt => time}/clock_gettime.c                  |    0
>  {rt => time}/clock_nanosleep.c                |    0
>  {rt => time}/clock_settime.c                  |    1 +
>  time/ftime.c                                  |   26 +-
>  time/getdate.c                                |    2 +-
>  time/gettimeofday.c                           |   30 +-
>  time/settimeofday.c                           |   24 +-
>  sysdeps/unix/stime.c => time/settimezone.c    |   23 +-
>  time/stime.c                                  |   15 +-
>  time/sys/time.h                               |   36 +-
>  time/time.c                                   |   17 +-
>  {rt => time}/tst-clock.c                      |    0
>  {rt => time}/tst-clock2.c                     |    0
>  {rt => time}/tst-clock_nanosleep.c            |    0
>  {rt => time}/tst-cpuclock1.c                  |    0
>  time/tst_wcsftime.c                           |    2 +-
>  156 files changed, 1580 insertions(+), 1775 deletions(-)
>  delete mode 100644 rt/clock-compat.c
>  rename sysdeps/mach/{gettimeofday.c => clock_gettime.c} (67%)
>  rename sysdeps/mach/hurd/{settimeofday.c => clock_settime.c} (71%)
>  delete mode 100644 sysdeps/posix/gettimeofday.c
>  delete mode 100644 sysdeps/posix/time.c
>  delete mode 100644 sysdeps/unix/clock_gettime.c
>  delete mode 100644 sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
>  rename sysdeps/unix/sysv/linux/{time.c => alpha/gettimeofday.c} (64%)
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
>  rename sysdeps/unix/{bsd/ftime.c => sysv/linux/alpha/osf_utimes.c} (60%)
>  rename sysdeps/unix/{clock_settime.c => sysv/linux/alpha/osf_wait4.c} (55%)
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/settimeofday.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/tv32-compat.h
>  delete mode 100644 sysdeps/unix/sysv/linux/ftime.c
>  delete mode 100644 sysdeps/unix/sysv/linux/gettimeofday.c
>  delete mode 100644 sysdeps/unix/sysv/linux/i386/gettimeofday.c
>  delete mode 100644 sysdeps/unix/sysv/linux/i386/time.c
>  delete mode 100644 sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
>  delete mode 100644 sysdeps/unix/sysv/linux/powerpc/time.c
>  create mode 100644 sysdeps/unix/sysv/linux/settimezone.c
>  delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/time.c
>  delete mode 100644 sysdeps/unix/sysv/linux/x86/gettimeofday.c
>  delete mode 100644 sysdeps/unix/sysv/linux/x86/time.c
>  rename {rt => time}/clock_getcpuclockid.c (100%)
>  rename {rt => time}/clock_getres.c (100%)
>  rename {rt => time}/clock_gettime.c (100%)
>  rename {rt => time}/clock_nanosleep.c (100%)
>  rename {rt => time}/clock_settime.c (96%)
>  rename sysdeps/unix/stime.c => time/settimezone.c (67%)
>  rename {rt => time}/tst-clock.c (100%)
>  rename {rt => time}/tst-clock2.c (100%)
>  rename {rt => time}/tst-clock_nanosleep.c (100%)
>  rename {rt => time}/tst-cpuclock1.c (100%)
>
> --
> 2.23.0.rc1
>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 12/12] Revise the documentation of ‘simple calendar time’.
  2019-08-20 13:22 ` [PATCH 12/12] Revise the documentation of ‘simple calendar time’ Zack Weinberg
@ 2019-08-20 18:50   ` Paul Eggert
  2019-08-20 19:38     ` Joseph Myers
  2019-08-20 20:19     ` Zack Weinberg
  0 siblings, 2 replies; 74+ messages in thread
From: Paul Eggert @ 2019-08-20 18:50 UTC (permalink / raw)
  To: Zack Weinberg, libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Zack Weinberg wrote:
> +@code{clock_t} is used to measure processor and CPU time.  Its values
> +are counts of @dfn{clock ticks} since some arbitrary event.  The
> +number of clock ticks per second is system-specific.

Also mention here that ISO C and POSIX both say that clock_t may be an an 
integer or a floating-point type.


> +POSIX says that @code{time_t} values do not include leap seconds, but
> +some systems interpret them as including leap seconds when the
> +@code{TZ} environment variable is set a certain way
> +(@pxref{TZ Variable}).

This gives the misleading impression that one can set 
TZ='right/America/Los_Angeles' (or whatever) on a system where the kernel 
follows POSIX rules, and your process will then be consistent within itself and 
will be leap-second aware. This doesn't work, as some conversions will be messed 
up due to libc's references to files like /usr/share/zoneinfo/posixrules and 
/usr/share/zoneinfo/UTC0 that still disregard leap seconds (the latter file 
typically isn't even installed on typical glibc systems, which means no leap 
seconds will be used). For example, on Fedora, this shell script:

   for cmd in 'date' 'date -u'; do
     for prefix in '' right/; do
       TZ=${prefix}America/Los_Angeles $cmd
     done
   done

outputs this:

   Tue Aug 20 11:35:41 PDT 2019
   Tue Aug 20 11:35:14 PDT 2019
   Tue Aug 20 18:35:41 UTC 2019
   Tue Aug 20 18:35:41 UTC 2019

where plain "date" respects the TZ leap second setting, but "date -u" ignores it 
and always uses POSIX time_t.

If you want leap seconds with glibc, you must arrange for the kernel clock to 
count leap seconds and you must discard the normal /usr/share/zoneinfo directory 
and replace it with leap-second-aware TZif files.  So I suggest replacing the 
above with this:

POSIX says that @code{time_t} values do not include leap seconds, but
some systems interpret them as including leap seconds if configured appropriately.


> +@deftypefun double difftime (time_t @var{end}, time_t @var{begin})
> +@standards{ISO, time.h}
> +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
> +The @code{difftime} function returns the number of seconds of elapsed
> +time from calendar time @var{begin} to calendar time @var{end}, as
> +a value of type @code{double}.  The calculation is unaware of whether
> +or not @var{begin} and @var{end} are meant to include leap seconds.

Remove "or not".

> +On POSIX-conformant systems, @samp{difftime (end, begin)} produces the
> +same result as the expression @samp{(double)(end - begin)}.  But on
> +other systems, @code{time_t} values might be encoded in a way that
> +prevents subtraction from working directly.

Not so: for example, on a 64-bit time_t POSIX host with the extreme values begin 
== -2**63 and end == (2**63 - 1), (end - begin) typically overflows and yields 
-1 whereas difftime (end, begin) typically rounds the mathematically-correct 
value (2**64 - 1) to double as 2**64. I suggest something like this instead:

On POSIX-conformant systems, @samp{difftime (end, begin)} is the
mathematical difference between @var{end} and @var{begin}, converted to
@samp{double}; although this computation does not suffer from integer overflow
the result is not exact if the difference is large enough.  On
other systems, @code{time_t} values might be encoded in a way that
prevents subtraction from working directly.


> +@deftypefun time_t time (time_t *@var{result})
> +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
> +This is the simplest function for getting the current calendar time.
> +It returns the calendar time as a value of type @code{time_t}; on
> +POSIX systems, that means it has a resolution of one second.  It
> +uses the same clock as @w{@samp{clock_gettime (CLOCK_REALTIME)}}
> +and @code{gettimeofday} (see below).

Remove "and @code{gettimeofday}", as we shouldn't be cluttering the manual with 
unnecessary references to an obsolescent function.

> +System-wide clock measuring calendar time.  This clock reports the
> +same time as @code{time} (above) and @code{gettimeofday} (below)

Similarly, remove "and @code{gettimeofday} (below)" here.


> +For instance, if the clock hardware for @code{CLOCK_REALTIME}
> +uses a quartz crystal that oscillates at 32.768 kHz,
> +then its resolution would be 30.518 microseconds,

Change "30.518 microseconds" to "30517.578125 nanoseconds", the exact value and 
a sharper way to explain the rounding that occurs with the "30518" that follows.


> +Because simple calendar times are independent of time zone, this
> +function should not be used when the time zone changes (e.g.@: if the
> +computer is physically moved from one zone to another).  Instead, use
> +the facilities described in @ref{Time Zone Functions} (but see below
> +for an exception).

I suggest removing "(but see below for an exception)", as it's confusing here. 
The later section can say that it's an exception.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument.
  2019-08-20 13:56 ` [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument Zack Weinberg
@ 2019-08-20 18:52   ` Paul Eggert
  2019-08-20 19:03     ` Zack Weinberg
  2019-08-21 15:30   ` Adhemerval Zanella
  1 sibling, 1 reply; 74+ messages in thread
From: Paul Eggert @ 2019-08-20 18:52 UTC (permalink / raw)
  To: Zack Weinberg, libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Zack Weinberg wrote:
> -    memset (tz, 0, sizeof *tz);
> +    memset (tz, 0, sizeof (struct timezone));

This change isn't necessary, and I prefer the previous version as it's easier to 
audit.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime.
  2019-08-20 13:22 ` [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime Zack Weinberg
@ 2019-08-20 18:53   ` Paul Eggert
  2019-08-22 12:55     ` Zack Weinberg
  2019-08-20 20:56   ` Adhemerval Zanella
  1 sibling, 1 reply; 74+ messages in thread
From: Paul Eggert @ 2019-08-20 18:53 UTC (permalink / raw)
  To: Zack Weinberg, libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Zack Weinberg wrote:
> +      long int end = (now.tv_sec * 1000 + usectmo +
> +                      (now.tv_nsec + 500000) / 1000000);

The usual GNU style is to put that trailing "+" at the start of the next line 
instead, here and elsewhere.


> --- a/support/support_test_main.c
> +++ b/support/support_test_main.c
> @@ -88,16 +88,16 @@ static pid_t test_pid;
>  static void (*cleanup_function) (void);
>  
>  static void
> -print_timestamp (const char *what, struct timeval tv)
> +print_timestamp (const char *what, struct timespec tv)
>  {
>    struct tm tm;
>    if (gmtime_r (&tv.tv_sec, &tm) == NULL)
>      printf ("%s: %lld.%06d\n",
> -            what, (long long int) tv.tv_sec, (int) tv.tv_usec);
> +            what, (long long int) tv.tv_sec, (int) tv.tv_nsec / 1000);
>    else
>      printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n",
>              what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
> -            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec);
> +            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_nsec / 1000);
>  }

Since the goal of this test code is to print the timestamp, the code should 
simply use %09d in the format and not divide by 1000.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (13 preceding siblings ...)
  2019-08-20 18:47 ` Alistair Francis
@ 2019-08-20 18:55 ` Paul Eggert
  2019-08-21  8:00 ` Lukasz Majewski
  15 siblings, 0 replies; 74+ messages in thread
From: Paul Eggert @ 2019-08-20 18:55 UTC (permalink / raw)
  To: Zack Weinberg, libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

Zack Weinberg wrote:

> If a 64-bit tv_sec value returned by
> the kernel is found to be greater than INT32_MAX, the caller will
> receive a saturated 32-bit struct timeval, { INT32_MAX, 0 },

Shouldn't that saturated value be { INT32_MAX, 999999 }?

PS. Thanks for all this work. The idea looks good.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument.
  2019-08-20 18:52   ` Paul Eggert
@ 2019-08-20 19:03     ` Zack Weinberg
  2019-08-20 19:06       ` Paul Eggert
  0 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 19:03 UTC (permalink / raw)
  To: Paul Eggert
  Cc: GNU C Library, Joseph Myers, Florian Weimer, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

On Tue, Aug 20, 2019 at 2:52 PM Paul Eggert <eggert@cs.ucla.edu> wrote:
>
> Zack Weinberg wrote:
> > -    memset (tz, 0, sizeof *tz);
> > +    memset (tz, 0, sizeof (struct timezone));
>
> This change isn't necessary, and I prefer the previous version as it's easier to
> audit.

I think you missed that this change also makes the type of `tz` be
`void *` (consistent with POSIX) so the older construct will not work
anymore.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument.
  2019-08-20 19:03     ` Zack Weinberg
@ 2019-08-20 19:06       ` Paul Eggert
  0 siblings, 0 replies; 74+ messages in thread
From: Paul Eggert @ 2019-08-20 19:06 UTC (permalink / raw)
  To: Zack Weinberg
  Cc: GNU C Library, Joseph Myers, Florian Weimer, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

Zack Weinberg wrote:
>>> -    memset (tz, 0, sizeof *tz);
>>> +    memset (tz, 0, sizeof (struct timezone));
>> This change isn't necessary, and I prefer the previous version as it's easier to
>> audit.
> I think you missed that this change also makes the type of `tz` be
> `void *` (consistent with POSIX) so the older construct will not work
> anymore.
> 
> zw

Ah, right you are. Sorry about the noise.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 12/12] Revise the documentation of ‘simple calendar time’.
  2019-08-20 18:50   ` Paul Eggert
@ 2019-08-20 19:38     ` Joseph Myers
  2019-08-20 19:55       ` Zack Weinberg
  2019-08-20 20:19     ` Zack Weinberg
  1 sibling, 1 reply; 74+ messages in thread
From: Joseph Myers @ 2019-08-20 19:38 UTC (permalink / raw)
  To: Paul Eggert
  Cc: Zack Weinberg, libc-alpha, Florian Weimer, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

On Tue, 20 Aug 2019, Paul Eggert wrote:

> Zack Weinberg wrote:
> > +@code{clock_t} is used to measure processor and CPU time.  Its values
> > +are counts of @dfn{clock ticks} since some arbitrary event.  The
> > +number of clock ticks per second is system-specific.
> 
> Also mention here that ISO C and POSIX both say that clock_t may be an an
> integer or a floating-point type.

I think the key fact about clock_t is that it (and so the functions using 
it) should be avoided because of limited range on many systems and 
getrusage should be used instead.  That's mentioned in the manual, but 
perhaps not given enough emphasis.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 12/12] Revise the documentation of ‘simple calendar time’.
  2019-08-20 19:38     ` Joseph Myers
@ 2019-08-20 19:55       ` Zack Weinberg
  0 siblings, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 19:55 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Paul Eggert, GNU C Library, Florian Weimer, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

On Tue, Aug 20, 2019 at 3:38 PM Joseph Myers <joseph@codesourcery.com> wrote:
> On Tue, 20 Aug 2019, Paul Eggert wrote:
> > Zack Weinberg wrote:
> > > +@code{clock_t} is used to measure processor and CPU time.  Its values
> > > +are counts of @dfn{clock ticks} since some arbitrary event.  The
> > > +number of clock ticks per second is system-specific.
> >
> > Also mention here that ISO C and POSIX both say that clock_t may be an an
> > integer or a floating-point type.
>
> I think the key fact about clock_t is that it (and so the functions using
> it) should be avoided because of limited range on many systems and
> getrusage should be used instead.  That's mentioned in the manual, but
> perhaps not given enough emphasis.

I don't want to revise the processor-and-CPU-time sections of
time.texi in this patch series, and I think that anything more than I
wrote but less than a complete revision of those sections would only
make things more confusing than they already are.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 12/12] Revise the documentation of ‘simple calendar time’.
  2019-08-20 18:50   ` Paul Eggert
  2019-08-20 19:38     ` Joseph Myers
@ 2019-08-20 20:19     ` Zack Weinberg
  2019-08-20 20:23       ` Zack Weinberg
  1 sibling, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 20:19 UTC (permalink / raw)
  To: Paul Eggert
  Cc: GNU C Library, Joseph Myers, Florian Weimer, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

On Tue, Aug 20, 2019 at 2:50 PM Paul Eggert <eggert@cs.ucla.edu> wrote:

BTW, thank you for reviewing documentation changes.

> Zack Weinberg wrote:
> > +@code{clock_t} is used to measure processor and CPU time.  Its values
> > +are counts of @dfn{clock ticks} since some arbitrary event.  The
> > +number of clock ticks per second is system-specific.
>
> Also mention here that ISO C and POSIX both say that clock_t may be an an
> integer or a floating-point type.

OK.

> > +POSIX says that @code{time_t} values do not include leap seconds, but
> > +some systems interpret them as including leap seconds when the
> > +@code{TZ} environment variable is set a certain way
> > +(@pxref{TZ Variable}).
>
> This gives the misleading impression that one can set
> TZ='right/America/Los_Angeles' (or whatever) on a system where the
> kernel follows POSIX rules, and your process will then be consistent
> within itself and will be leap-second aware.
...
> If you want leap seconds with glibc, you must arrange for the kernel
> clock to count leap seconds and you must discard the normal
> /usr/share/zoneinfo directory and replace it with leap-second-aware
> TZif files.  So I suggest replacing the above with this:
>
> POSIX says that @code{time_t} values do not include leap seconds,
> but some systems interpret them as including leap seconds if
> configured appropriately.

Thanks, I didn't know any of this detail.  I will make this change.

> > +@deftypefun double difftime (time_t @var{end}, time_t @var{begin})
> > +@standards{ISO, time.h}
> > +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
> > +The @code{difftime} function returns the number of seconds of elapsed
> > +time from calendar time @var{begin} to calendar time @var{end}, as
> > +a value of type @code{double}.  The calculation is unaware of whether
> > +or not @var{begin} and @var{end} are meant to include leap seconds.
>
> Remove "or not".

*shrug* OK.

> > +On POSIX-conformant systems, @samp{difftime (end, begin)} produces the
> > +same result as the expression @samp{(double)(end - begin)}.  But on
> > +other systems, @code{time_t} values might be encoded in a way that
> > +prevents subtraction from working directly.
>
> Not so: for example, on a 64-bit time_t POSIX host with the extreme
> values begin == -2**63 and end == (2**63 - 1), (end - begin)
> typically overflows and yields -1 whereas difftime (end, begin)
> typically rounds the mathematically-correct value (2**64 - 1) to
> double as 2**64.

Blech, you're right.  This means this chunk of the manual has always
been wrong; it used to say "on GNU systems you can simply subtract
time_t values."

> I suggest something like this instead:
>
> On POSIX-conformant systems, @samp{difftime (end, begin)} is the
> mathematical difference between @var{end} and @var{begin}, converted to
> @samp{double}; although this computation does not suffer from integer overflow
> the result is not exact if the difference is large enough.  On
> other systems, @code{time_t} values might be encoded in a way that
> prevents subtraction from working directly.

I might try to wordsmith this a little more but I'll make a change
along these lines.

> > +@deftypefun time_t time (time_t *@var{result})
> > +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
> > +This is the simplest function for getting the current calendar time.
> > +It returns the calendar time as a value of type @code{time_t}; on
> > +POSIX systems, that means it has a resolution of one second.  It
> > +uses the same clock as @w{@samp{clock_gettime (CLOCK_REALTIME)}}
> > +and @code{gettimeofday} (see below).
>
> Remove "and @code{gettimeofday}", as we shouldn't be cluttering the
> manual with unnecessary references to an obsolescent function.

I think it is actually quite important to make it clear in the
documentation of all three functions that time, gettimeofday, and
clock_gettime(CLOCK_REALTIME) all use the same "clock".  They can't be
set independently, "simple calendar times" retrieved from one of them
are directly comparable to times retrieved from another, and so on.

And gettimeofday may be formally obsolescent per POSIX, but
practically speaking it's going to be with us for many years to come.

> > +For instance, if the clock hardware for @code{CLOCK_REALTIME}
> > +uses a quartz crystal that oscillates at 32.768 kHz,
> > +then its resolution would be 30.518 microseconds,
>
> Change "30.518 microseconds" to "30517.578125 nanoseconds"

Rounding where I did was intentional.  A 32.768kHz crystal oscillator
typically has a tolerance of ±20 parts per million, which _sounds_
tiny but works out to be more than half of the final digit of the
nominal frequency (32.768 ± 0.0006 kHz).  30.518µs is therefore
correctly rounded, giving any more digits would be false precision.
Using microseconds for the intermediate figure was also intentional;
it emphasizes that the resolution of the clock is a real number
independent of the units in which clock_getres reports it.

> > +Because simple calendar times are independent of time zone, this
> > +function should not be used when the time zone changes (e.g.@: if the
> > +computer is physically moved from one zone to another).  Instead, use
> > +the facilities described in @ref{Time Zone Functions} (but see below
> > +for an exception).
>
> I suggest removing "(but see below for an exception)", as it's
> confusing here.  The later section can say that it's an exception.

OK.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 12/12] Revise the documentation of ‘simple calendar time’.
  2019-08-20 20:19     ` Zack Weinberg
@ 2019-08-20 20:23       ` Zack Weinberg
  0 siblings, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-20 20:23 UTC (permalink / raw)
  To: Paul Eggert
  Cc: GNU C Library, Joseph Myers, Florian Weimer, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

On Tue, Aug 20, 2019 at 4:18 PM Zack Weinberg <zackw@panix.com> wrote:
> Using microseconds for the intermediate figure was also intentional;
> it emphasizes that the resolution of the clock is a real number
> independent of the units in which clock_getres reports it.

I meant to say "physical measurement" where I wrote "real number", here.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime.
  2019-08-20 13:22 ` [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime Zack Weinberg
  2019-08-20 18:53   ` Paul Eggert
@ 2019-08-20 20:56   ` Adhemerval Zanella
  2019-08-21 21:09     ` Zack Weinberg
  1 sibling, 1 reply; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-20 20:56 UTC (permalink / raw)
  To: libc-alpha



On 20/08/2019 10:21, Zack Weinberg wrote:
> Since gettimeofday will shortly be implemented in terms of
> clock_gettime on all platforms, internal code should use clock_gettime
> directly; in addition to removing a layer of indirection, this will
> allow us to remove the PLT-bypass gunk for gettimeofday.  In many
> cases, the changed code does fewer conversions.
> 
> A few Hurd-specific files were changed to use __host_get_time instead
> of __clock_gettime, as this seemed tidier.
> 
> With the exception of support/support_test_main.c, test cases are not
> modified, mainly because I didn’t want to have to figure out which
> test cases were testing gettimeofday specifically.
> 
> The definition of GETTIME in sysdeps/generic/memusage.h had a typo and
> was not reading tv_sec at all.  I fixed this.  It appears nobody has been
> generating malloc traces on a machine that doesn’t have a superseding
> definition.
> 
> 	* inet/deadline.c (__deadline_current_time)
> 	* login/logout.c (logout)
> 	* login/logwtmp.c (logwtmp)
> 	* nis/nis_call.c (__nisfind_server)
> 	* nptl/pthread_join_common.c (timedwait_tid)
> 	* nptl/pthread_mutex_timedlock.c (__pthread_mutex_clocklock_common)
> 	* nscd/nscd_helper.c (wait_on_socket, open_socket)
> 	* resolv/gai_misc.c (handle_requests)
> 	* resolv/gai_suspend.c (gai_suspend)
> 	* resolv/res_send.c (evNowTime)
> 	* sunrpc/auth_des.c (authdes_marshal, authdes_destroy)
> 	* sunrpc/auth_unix.c (authunix_create, authunix_refresh)
> 	* sunrpc/create_xid.c (_create_xid)
> 	* sunrpc/svcauth_des.c (_svcauth_des)
> 	* sysdeps/generic/memusage.h (GETTIME)
> 	* sysdeps/mach/nanosleep.c (__libc_nanosleep)
> 	* sysdeps/posix/tempname.c (RANDOM_BITS)
> 	* sysdeps/pthread/aio_misc.c (handle_fildes_io)
> 	* sysdeps/pthread/aio_suspend.c (aio_suspend):
> 	Use __clock_gettime(CLOCK_REALTIME) instead of __gettimeofday.
> 	Include time.h if necessary.
> 
> 	* sysdeps/mach/hurd/getitimer.c (__getitimer)
> 	* sysdeps/mach/hurd/setitimer.c (setitimer_locked)
> 	* sysdeps/mach/hurd/times.c (__times):
> 	Use __host_get_time instead of __gettimeofday.
> 	Include mach.h if necessary.
> 
> 	* sysdeps/mach/usleep.c (usleep): Remove unnecessary calls to
> 	__gettimeofday.
> 
> 	* support/support_test_main.c (print_timestamp): Take a struct
> 	timespec argument, not a struct timeval.
> 	(signal_handler): Update to match.
> 	Use clock_gettime(CLOCK_REALTIME) instead of gettimeofday.
> 
> 	* sysdeps/generic/memusage.h (GETTIME): Correct typo causing
> 	the seconds field of each timestamp to be ignored.
> ---
>  inet/deadline.c                |  9 ++-------
>  login/logout.c                 |  9 +++++----
>  login/logwtmp.c                |  7 +++----
>  nis/nis_call.c                 |  4 +++-
>  nptl/pthread_join_common.c     |  7 +++----
>  nptl/pthread_mutex_timedlock.c |  7 +++----
>  nscd/nscd_helper.c             | 24 ++++++++++++------------
>  resolv/gai_misc.c              |  6 +++---
>  resolv/gai_suspend.c           |  6 +++---
>  resolv/res_send.c              |  6 +-----
>  sunrpc/auth_des.c              | 19 +++++++++++--------
>  sunrpc/auth_unix.c             |  9 +++++----
>  sunrpc/create_xid.c            |  6 +++---
>  sunrpc/svcauth_des.c           |  7 ++++++-
>  support/support_test_main.c    | 14 ++++++--------
>  sysdeps/generic/memusage.h     | 16 ++++++++--------
>  sysdeps/mach/hurd/getitimer.c  |  3 ++-
>  sysdeps/mach/hurd/setitimer.c  |  3 ++-
>  sysdeps/mach/hurd/times.c      |  6 +++---
>  sysdeps/mach/nanosleep.c       | 33 +++++++++++++++++++++------------
>  sysdeps/mach/usleep.c          |  5 -----
>  sysdeps/posix/tempname.c       |  9 ++++-----
>  sysdeps/pthread/aio_misc.c     |  6 +++---
>  sysdeps/pthread/aio_suspend.c  |  6 +++---
>  24 files changed, 115 insertions(+), 112 deletions(-)
> 
> diff --git a/inet/deadline.c b/inet/deadline.c
> index ab275c266d..dee4637732 100644
> --- a/inet/deadline.c
> +++ b/inet/deadline.c
> @@ -29,13 +29,8 @@ __deadline_current_time (void)
>  {
>    struct deadline_current_time result;
>    if (__clock_gettime (CLOCK_MONOTONIC, &result.current) != 0)
> -    {
> -      struct timeval current_tv;
> -      if (__gettimeofday (&current_tv, NULL) == 0)
> -        __libc_fatal ("Fatal error: gettimeofday system call failed\n");
> -      result.current.tv_sec = current_tv.tv_sec;
> -      result.current.tv_nsec = current_tv.tv_usec * 1000;
> -    }
> +    if (__clock_gettime (CLOCK_REALTIME, &result.current) != 0)
> +      __libc_fatal ("Fatal error: clock_gettime failed\n");
>    assert (result.current.tv_sec >= 0);
>    return result;
>  }

I think it is a fair assumption that CLOCK_REALTIME is always supported, as it
is also specific by POSIX.1-2017. It allows simplify it further and remove the
libc_fatal fallback code.

> diff --git a/login/logout.c b/login/logout.c
> index 5015c1af0b..f1313ded77 100644
> --- a/login/logout.c
> +++ b/login/logout.c
> @@ -19,6 +19,7 @@
>  #include <errno.h>
>  #include <string.h>
>  #include <utmp.h>
> +#include <time.h>
>  #include <sys/time.h>
>  
>  int
> @@ -45,10 +46,10 @@ logout (const char *line)
>        /* Clear information about who & from where.  */
>        memset (ut->ut_name, '\0', sizeof ut->ut_name);
>        memset (ut->ut_host, '\0', sizeof ut->ut_host);
> -      struct timeval tv;
> -      __gettimeofday (&tv, NULL);
> -      ut->ut_tv.tv_sec = tv.tv_sec;
> -      ut->ut_tv.tv_usec = tv.tv_usec;
> +
> +      struct timespec ts;
> +      __clock_gettime (CLOCK_REALTIME, &ts);
> +      TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
>        ut->ut_type = DEAD_PROCESS;
>  
>        if (pututline (ut) != NULL)

Ok.

> diff --git a/login/logwtmp.c b/login/logwtmp.c
> index 50d14976c7..ec41375383 100644
> --- a/login/logwtmp.c
> +++ b/login/logwtmp.c
> @@ -36,10 +36,9 @@ logwtmp (const char *line, const char *name, const char *host)
>    strncpy (ut.ut_name, name, sizeof ut.ut_name);
>    strncpy (ut.ut_host, host, sizeof ut.ut_host);
>  
> -  struct timeval tv;
> -  __gettimeofday (&tv, NULL);
> -  ut.ut_tv.tv_sec = tv.tv_sec;
> -  ut.ut_tv.tv_usec = tv.tv_usec;
> +  struct timespec ts;
> +  __clock_gettime (CLOCK_REALTIME, &ts);
> +  TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts);
>  
>    updwtmp (_PATH_WTMP, &ut);
>  }

Ok.

> diff --git a/nis/nis_call.c b/nis/nis_call.c
> index a48ecc39a8..db81fa3568 100644
> --- a/nis/nis_call.c
> +++ b/nis/nis_call.c
> @@ -709,6 +709,7 @@ __nisfind_server (const_nis_name name, int search_parent,
>    nis_error status;
>    directory_obj *obj;
>    struct timeval now;
> +  struct timespec ts;
>    unsigned int server_used = ~0;
>    unsigned int current_ep = ~0;
>  
> @@ -718,7 +719,8 @@ __nisfind_server (const_nis_name name, int search_parent,
>    if (*dir != NULL)
>      return NIS_SUCCESS;
>  
> -  (void) gettimeofday (&now, NULL);
> +  __clock_gettime (CLOCK_REALTIME, &ts);
> +  TIMESPEC_TO_TIMEVAL (&now, &ts);
>  
>    if ((flags & NO_CACHE) == 0)
>      *dir = nis_server_cache_search (name, search_parent, &server_used,

Ok.

> diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c
> index 5224ee2110..f1b14266de 100644
> --- a/nptl/pthread_join_common.c
> +++ b/nptl/pthread_join_common.c
> @@ -46,15 +46,14 @@ timedwait_tid (pid_t *tidp, const struct timespec *abstime)
>    /* Repeat until thread terminated.  */
>    while ((tid = *tidp) != 0)
>      {
> -      struct timeval tv;
>        struct timespec rt;
>  
>        /* Get the current time.  */
> -      __gettimeofday (&tv, NULL);
> +      __clock_gettime (CLOCK_REALTIME, &rt);
>  
>        /* Compute relative timeout.  */
> -      rt.tv_sec = abstime->tv_sec - tv.tv_sec;
> -      rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
> +      rt.tv_sec = abstime->tv_sec - rt.tv_sec;
> +      rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
>        if (rt.tv_nsec < 0)
>          {
>            rt.tv_nsec += 1000000000;

I think we can simplify it even more by adding a cancellable lll_futex_clock_wait_bitset
variant and change to just:

  /* Repeat until thread terminated.  */
  while ((tid = *tidp) != 0)
    {
      if (lll_futex_clock_wait_bitset_cancel (tidp, tid, CLOCK_REALTIME,
                                              abstime, LLL_SHARED)
          == -ETIMEDOUT)
        return ETIMEDOUT;
    }

  

> diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
> index 52c258e33d..2b194e5bee 100644
> --- a/nptl/pthread_mutex_timedlock.c
> +++ b/nptl/pthread_mutex_timedlock.c
> @@ -567,15 +567,14 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
>  			goto failpp;
>  		      }
>  
> -		    struct timeval tv;
>  		    struct timespec rt;
>  
>  		    /* Get the current time.  */
> -		    (void) __gettimeofday (&tv, NULL);
> +                    __clock_gettime (CLOCK_REALTIME, &rt);
>  
>  		    /* Compute relative timeout.  */
> -		    rt.tv_sec = abstime->tv_sec - tv.tv_sec;
> -		    rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
> +		    rt.tv_sec = abstime->tv_sec - rt.tv_sec;
> +		    rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
>  		    if (rt.tv_nsec < 0)
>  		      {
>  			rt.tv_nsec += 1000000000;

With cancelable lll_futex_clock_wait_bitset we can simplify it:

                if (oldval != ceilval)
                  {
                    /* Reject invalid timeouts.  */
                    if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
                      {
                        result = EINVAL;
                        goto failpp;
                      }

                    lll_futex_clock_wait_bitset_cancel (&mutex->__data.__lock,
                                                        ceilval | 2,
                                                        CLOCK_REALTIME, &rt,
                                                        PTHREAD_MUTEX_PSHARED (mutex));
                  }
 

> diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
> index 733c2a60cd..e12769ba03 100644
> --- a/nscd/nscd_helper.c
> +++ b/nscd/nscd_helper.c
> @@ -59,9 +59,10 @@ wait_on_socket (int sock, long int usectmo)
>        /* Handle the case where the poll() call is interrupted by a
>  	 signal.  We cannot just use TEMP_FAILURE_RETRY since it might
>  	 lead to infinite loops.  */
> -      struct timeval now;
> -      (void) __gettimeofday (&now, NULL);
> -      long int end = now.tv_sec * 1000 + usectmo + (now.tv_usec + 500) / 1000;
> +      struct timespec now;
> +      __clock_gettime (CLOCK_REALTIME, &now);
> +      long int end = (now.tv_sec * 1000 + usectmo +
> +                      (now.tv_nsec + 500000) / 1000000);
>        long int timeout = usectmo;
>        while (1)
>  	{
> @@ -70,8 +71,9 @@ wait_on_socket (int sock, long int usectmo)
>  	    break;
>  
>  	  /* Recompute the timeout time.  */
> -	  (void) __gettimeofday (&now, NULL);
> -	  timeout = end - (now.tv_sec * 1000 + (now.tv_usec + 500) / 1000);
> +          __clock_gettime (CLOCK_REALTIME, &now);
> +	  timeout = end - ((now.tv_sec * 1000 +
> +                            (now.tv_nsec + 500000) / 1000000));
>  	}
>      }
>  

Couldn't we use the support/timespec-* to operate with struct timespec
along with a helper function to get get current time? It has add and sub
operation that already handle overflow, so the above code could be 
simplified to:

---
static inline struct timespec
timespec_now (void)
{
  struct timespec r;
  __clock_gettime (CLOCK_REALTIME, &r);
  return r;
}

[...]

static int
wait_on_socket (int sock, long int usectmo)
{ 
  struct pollfd fds[1];
  fds[0].fd = sock;
  fds[0].events = POLLIN | POLLERR | POLLHUP;
  int n = __poll (fds, 1, usectmo);
  if (n == -1 && __glibc_unlikely (errno == EINTR))
    { 
      /* Handle the case where the poll() call is interrupted by a
         signal.  We cannot just use TEMP_FAILURE_RETRY since it might
         lead to infinite loops.  */

      struct timespec timeout = make_timespec (usectmo, 0);
      struct timespec end = timespec_add (timespec_now (), timeout);
      
      while (1)
        { 
          n = __ppoll (fds, 1, &timeout, NULL);
          if (n != -1 || errno != EINTR)
            break;

          /* Recompute the timeout time.  */
	  timeout = timespec_sub (end, timespec_now());
        }
    }

  return n;
}


> @@ -191,9 +193,7 @@ open_socket (request_type type, const char *key, size_t keylen)
>    memcpy (reqdata->key, key, keylen);
>  
>    bool first_try = true;
> -  struct timeval tvend;
> -  /* Fake initializing tvend.  */
> -  asm ("" : "=m" (tvend));
> +  struct timespec tvend = { 0, 0 };
>    while (1)
>      {
>  #ifndef MSG_NOSIGNAL
> @@ -212,18 +212,18 @@ open_socket (request_type type, const char *key, size_t keylen)
>  
>        /* The daemon is busy wait for it.  */
>        int to;
> -      struct timeval now;
> -      (void) __gettimeofday (&now, NULL);
> +      struct timespec now;
> +      __clock_gettime (CLOCK_REALTIME, &now);
>        if (first_try)
>  	{
> -	  tvend.tv_usec = now.tv_usec;
> +	  tvend.tv_nsec = now.tv_nsec;
>  	  tvend.tv_sec = now.tv_sec + 5;
>  	  to = 5 * 1000;
>  	  first_try = false;
>  	}
>        else
>  	to = ((tvend.tv_sec - now.tv_sec) * 1000
> -	      + (tvend.tv_usec - now.tv_usec) / 1000);
> +	      + (tvend.tv_nsec - now.tv_nsec) / 1000000);
>  
>        struct pollfd fds[1];
>        fds[0].fd = sock;

Same as before, with helper timespec function we can simplify to:

  struct timeval tvend;
  while (1)
    {
#ifndef MSG_NOSIGNAL
# define MSG_NOSIGNAL 0
#endif
      ssize_t wres = TEMP_FAILURE_RETRY (__send (sock, reqdata,
                                                 real_sizeof_reqdata,
                                                 MSG_NOSIGNAL));
      if (__glibc_likely (wres == (ssize_t) real_sizeof_reqdata))
        /* We managed to send the request.  */
        return sock;

      if (wres != -1 || errno != EAGAIN)
        /* Something is really wrong, no chance to continue.  */
        break;

      /* The daemon is busy wait for it.  */
      struct timespec to;
      if (first_try)
	{
	  tvend = timespec_add (timespec_now (), make_timespec (5, 0));
	  to = tvend;
	}
      else
	to = timespec_sub (tvend, timespec_now ());

      struct pollfd fds[1];
      fds[0].fd = sock;
      fds[0].events = POLLOUT | POLLERR | POLLHUP;
      if (__ppoll (fds, 1, &to, NULL) <= 0)
        /* The connection timed out or broke down.  */
        break;

      /* We try to write again.  */
    }




> diff --git a/resolv/gai_misc.c b/resolv/gai_misc.c
> index 69d7086ae6..5d1e310147 100644
> --- a/resolv/gai_misc.c
> +++ b/resolv/gai_misc.c
> @@ -357,13 +357,13 @@ handle_requests (void *arg)
>  	 something to arrive in it. */
>        if (runp == NULL && optim.gai_idle_time >= 0)
>  	{
> -	  struct timeval now;
> +	  struct timespec now;
>  	  struct timespec wakeup_time;
>  
>  	  ++idle_thread_count;
> -	  gettimeofday (&now, NULL);
> +          __clock_gettime (CLOCK_REALTIME, &now);
>  	  wakeup_time.tv_sec = now.tv_sec + optim.gai_idle_time;
> -	  wakeup_time.tv_nsec = now.tv_usec * 1000;
> +	  wakeup_time.tv_nsec = now.tv_nsec;
>  	  if (wakeup_time.tv_nsec >= 1000000000)
>  	    {
>  	      wakeup_time.tv_nsec -= 1000000000;

With timespec helper function it can be simplified with:

      /* If the runlist is empty, then we sleep for a while, waiting for
         something to arrive in it. */
      if (runp == NULL && optim.gai_idle_time >= 0)
        { 
          struct timespec wakeup_time;
          ++idle_thread_count;

	  wakeup_time = timespec_add (timespec_now (), 
				      make_timespec (optim.gai_idle_time, 0));
          pthread_cond_timedwait (&__gai_new_request_notification,
                                  &__gai_requests_mutex, &wakeup_time);
          --idle_thread_count;
          runp = requests;
          while (runp != NULL && runp->running != 0)
            runp = runp->next;
        }


> diff --git a/resolv/gai_suspend.c b/resolv/gai_suspend.c
> index eee3bcebe9..8f81e5a3dd 100644
> --- a/resolv/gai_suspend.c
> +++ b/resolv/gai_suspend.c
> @@ -91,11 +91,11 @@ gai_suspend (const struct gaicb *const list[], int ent,
>  	{
>  	  /* We have to convert the relative timeout value into an
>  	     absolute time value with pthread_cond_timedwait expects.  */
> -	  struct timeval now;
> +	  struct timespec now;
>  	  struct timespec abstime;
>  
> -	  __gettimeofday (&now, NULL);
> -	  abstime.tv_nsec = timeout->tv_nsec + now.tv_usec * 1000;
> +          __clock_gettime (CLOCK_REALTIME, &now);
> +	  abstime.tv_nsec = timeout->tv_nsec + now.tv_nsec;
>  	  abstime.tv_sec = timeout->tv_sec + now.tv_sec;
>  	  if (abstime.tv_nsec >= 1000000000)
>  	    {

As before.

> diff --git a/resolv/res_send.c b/resolv/res_send.c
> index ed27f3abf8..0cd35f99d7 100644
> --- a/resolv/res_send.c
> +++ b/resolv/res_send.c
> @@ -172,12 +172,8 @@ evCmpTime(struct timespec a, struct timespec b) {
>  
>  static void
>  evNowTime(struct timespec *res) {
> -	struct timeval now;
> -
> -	if (gettimeofday(&now, NULL) < 0)
> +	if (__clock_gettime(CLOCK_REALTIME, res) < 0)
>  		evConsTime(res, 0, 0);
> -	else
> -		TIMEVAL_TO_TIMESPEC (&now, res);
>  }
>  
>  

I think we can assume CLOCK_REALTIME always succeed.

> diff --git a/sunrpc/auth_des.c b/sunrpc/auth_des.c
> index 5b6f985bc2..9079b30397 100644
> --- a/sunrpc/auth_des.c
> +++ b/sunrpc/auth_des.c
> @@ -41,6 +41,7 @@
>  #include <rpc/xdr.h>
>  #include <netinet/in.h>		/* XXX: just to get htonl() and ntohl() */
>  #include <sys/socket.h>
> +#include <time.h>
>  #include <shlib-compat.h>
>  
>  #define MILLION		1000000L
> @@ -246,15 +247,15 @@ authdes_marshal (AUTH *auth, XDR *xdrs)
>    int status;
>    int len;
>    register int32_t *ixdr;
> -  struct timeval tval;
> +  struct timespec now;
>  
>    /*
>     * Figure out the "time", accounting for any time difference
>     * with the server if necessary.
>     */
> -  __gettimeofday (&tval, (struct timezone *) NULL);
> -  ad->ad_timestamp.tv_sec = tval.tv_sec + ad->ad_timediff.tv_sec;
> -  ad->ad_timestamp.tv_usec = tval.tv_usec + ad->ad_timediff.tv_usec;
> +  __clock_gettime (CLOCK_REALTIME, &now);
> +  ad->ad_timestamp.tv_sec = now.tv_sec + ad->ad_timediff.tv_sec;
> +  ad->ad_timestamp.tv_usec = (now.tv_nsec / 1000) + ad->ad_timediff.tv_usec;
>    if (ad->ad_timestamp.tv_usec >= MILLION)
>      {
>        ad->ad_timestamp.tv_usec -= MILLION;

Ok (I think we probably should handle overflow here).

> @@ -445,21 +446,23 @@ authdes_destroy (AUTH *auth)
>  static bool_t
>  synchronize (struct sockaddr *syncaddr, struct rpc_timeval *timep)
>  {
> -  struct timeval mytime;
> +  struct timespec mytime;
>    struct rpc_timeval timeout;
> +  long myusec;
>  
>    timeout.tv_sec = RTIME_TIMEOUT;
>    timeout.tv_usec = 0;
>    if (rtime ((struct sockaddr_in *) syncaddr, timep, &timeout) < 0)
>      return FALSE;
>  
> -  __gettimeofday (&mytime, (struct timezone *) NULL);
> +  __clock_gettime (CLOCK_REALTIME, &mytime);
>    timep->tv_sec -= mytime.tv_sec;
> -  if (mytime.tv_usec > timep->tv_usec)
> +  myusec = mytime.tv_nsec / 1000;
> +  if (myusec > timep->tv_usec)
>      {
>        timep->tv_sec -= 1;
>        timep->tv_usec += MILLION;
>      }
> -  timep->tv_usec -= mytime.tv_usec;
> +  timep->tv_usec -= myusec;
>    return TRUE;
>  }

Ok (I think we probably should handle overflow here).

> diff --git a/sunrpc/auth_unix.c b/sunrpc/auth_unix.c
> index b035fdd870..ff0d2eb933 100644
> --- a/sunrpc/auth_unix.c
> +++ b/sunrpc/auth_unix.c
> @@ -43,6 +43,7 @@
>  #include <stdio.h>
>  #include <string.h>
>  #include <unistd.h>
> +#include <time.h>
>  #include <libintl.h>
>  #include <sys/param.h>
>  #include <wchar.h>
> @@ -96,7 +97,7 @@ authunix_create (char *machname, uid_t uid, gid_t gid, int len,
>  {
>    struct authunix_parms aup;
>    char mymem[MAX_AUTH_BYTES];
> -  struct timeval now;
> +  struct timespec now;
>    XDR xdrs;
>    AUTH *auth;
>    struct audata *au;
> @@ -122,7 +123,7 @@ no_memory:
>    /*
>     * fill in param struct from the given params
>     */
> -  (void) __gettimeofday (&now, (struct timezone *) 0);
> +  __clock_gettime (CLOCK_REALTIME, &now);
>    aup.aup_time = now.tv_sec;
>    aup.aup_machname = machname;
>    aup.aup_uid = uid;

With a helper we can just simplify to:

     aup.aup_time = timespec_now ().tv_sec;

> @@ -276,7 +277,7 @@ authunix_refresh (AUTH *auth)
>  {
>    struct audata *au = AUTH_PRIVATE (auth);
>    struct authunix_parms aup;
> -  struct timeval now;
> +  struct timespec now;
>    XDR xdrs;
>    int stat;
>  
> @@ -297,7 +298,7 @@ authunix_refresh (AUTH *auth)
>      goto done;
>  
>    /* update the time and serialize in place */
> -  (void) __gettimeofday (&now, (struct timezone *) 0);
> +  __clock_gettime (CLOCK_REALTIME, &now);
>    aup.aup_time = now.tv_sec;
>    xdrs.x_op = XDR_ENCODE;
>    XDR_SETPOS (&xdrs, 0);

As before.

> diff --git a/sunrpc/create_xid.c b/sunrpc/create_xid.c
> index a44187f07c..8d1e722dad 100644
> --- a/sunrpc/create_xid.c
> +++ b/sunrpc/create_xid.c
> @@ -39,10 +39,10 @@ _create_xid (void)
>    pid_t pid = getpid ();
>    if (is_initialized != pid)
>      {
> -      struct timeval now;
> +      struct timespec now;
>  
> -      __gettimeofday (&now, (struct timezone *) 0);
> -      __srand48_r (now.tv_sec ^ now.tv_usec ^ pid,
> +      __clock_gettime (CLOCK_REALTIME, &now);
> +      __srand48_r (now.tv_sec ^ now.tv_nsec ^ pid,
>  		   &__rpc_lrand48_data);
>        is_initialized = pid;
>      }

Ok.

> diff --git a/sunrpc/svcauth_des.c b/sunrpc/svcauth_des.c
> index c5a512d6f8..7607abc818 100644
> --- a/sunrpc/svcauth_des.c
> +++ b/sunrpc/svcauth_des.c
> @@ -44,6 +44,7 @@
>  #include <limits.h>
>  #include <string.h>
>  #include <stdint.h>
> +#include <time.h>
>  #include <sys/param.h>
>  #include <netinet/in.h>
>  #include <rpc/rpc.h>
> @@ -295,7 +296,11 @@ _svcauth_des (register struct svc_req *rqst, register struct rpc_msg *msg)
>  	debug ("timestamp before last seen");
>  	return AUTH_REJECTEDVERF;	/* replay */
>        }
> -    __gettimeofday (&current, (struct timezone *) NULL);
> +    {
> +      struct timespec now;
> +      __clock_gettime (CLOCK_REALTIME, &now);
> +      TIMESPEC_TO_TIMEVAL (&current, &now);
> +    }
>      current.tv_sec -= window;	/* allow for expiration */
>      if (!BEFORE (&current, &timestamp))
>        {

Ok.

> diff --git a/support/support_test_main.c b/support/support_test_main.c
> index 7e7b9edbb0..bc4502c030 100644
> --- a/support/support_test_main.c
> +++ b/support/support_test_main.c
> @@ -88,16 +88,16 @@ static pid_t test_pid;
>  static void (*cleanup_function) (void);
>  
>  static void
> -print_timestamp (const char *what, struct timeval tv)
> +print_timestamp (const char *what, struct timespec tv)
>  {
>    struct tm tm;
>    if (gmtime_r (&tv.tv_sec, &tm) == NULL)
>      printf ("%s: %lld.%06d\n",
> -            what, (long long int) tv.tv_sec, (int) tv.tv_usec);
> +            what, (long long int) tv.tv_sec, (int) tv.tv_nsec / 1000);
>    else
>      printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n",
>              what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
> -            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec);
> +            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_nsec / 1000);
>  }
>  
>  /* Timeout handler.  We kill the child and exit with an error.  */
> @@ -110,8 +110,8 @@ signal_handler (int sig)
>  
>    /* Do this first to avoid further interference from the
>       subprocess.  */
> -  struct timeval now;
> -  bool now_available = gettimeofday (&now, NULL) == 0;
> +  struct timespec now;
> +  bool now_available = clock_gettime (CLOCK_REALTIME, &now) == 0;
>    struct stat64 st;
>    bool st_available = fstat64 (STDOUT_FILENO, &st) == 0 && st.st_mtime != 0;
>  
> @@ -168,9 +168,7 @@ signal_handler (int sig)
>    if (now_available)
>      print_timestamp ("Termination time", now);
>    if (st_available)
> -    print_timestamp ("Last write to standard output",
> -                     (struct timeval) { st.st_mtim.tv_sec,
> -                         st.st_mtim.tv_nsec / 1000 });
> +    print_timestamp ("Last write to standard output", st.st_mtim);
>  
>    /* Exit with an error.  */
>    exit (1);

Same as Paul has said about printing timestamps.

> diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h
> index 480bdf79ee..c29feb8edd 100644
> --- a/sysdeps/generic/memusage.h
> +++ b/sysdeps/generic/memusage.h
> @@ -26,14 +26,14 @@
>  #endif
>  
>  #ifndef GETTIME
> -# define GETTIME(low,high) \
> -  {									      \
> -    struct timeval tval;						      \
> -    uint64_t usecs;							      \
> -    gettimeofday (&tval, NULL);						      \
> -    usecs = (uint64_t) tval.tv_usec + (uint64_t) tval.tv_usec * 1000000;      \
> -    low = usecs & 0xffffffff;						      \
> -    high = usecs >> 32;							      \
> +# define GETTIME(low,high)						   \
> +  {									   \
> +    struct timespec now;						   \
> +    uint64_t usecs;							   \
> +    __clock_gettime (CLOCK_REALTIME, &now);				   \
> +    usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \
> +    low = usecs & 0xffffffff;						   \
> +    high = usecs >> 32;							   \
>    }
>  #endif
>  

I think it should have a space after the cast type. 

> diff --git a/sysdeps/mach/hurd/getitimer.c b/sysdeps/mach/hurd/getitimer.c
> index 69a0751ead..6a0fc3cb0d 100644
> --- a/sysdeps/mach/hurd/getitimer.c
> +++ b/sysdeps/mach/hurd/getitimer.c
> @@ -19,6 +19,7 @@
>  #include <errno.h>
>  #include <sys/time.h>
>  #include <hurd.h>
> +#include <mach.h>
>  
>  /* XXX Temporary cheezoid implementation; see __setitmr.c.  */
>  
> @@ -61,7 +62,7 @@ __getitimer (enum __itimer_which which, struct itimerval *value)
>      }
>  
>    /* Get the time now.  */
> -  if (__gettimeofday (&elapsed, NULL) < 0)
> +  if (__host_get_time (__mach_host_self (), (time_value_t *) &elapsed) < 0)
>      return -1;
>  
>    /* Extract the current timer setting; and the time it was set, so we can

Looks ok (I can't really check if Hurd change is fully correct though).

> diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c
> index 61e37c5f5d..c829a5869b 100644
> --- a/sysdeps/mach/hurd/setitimer.c
> +++ b/sysdeps/mach/hurd/setitimer.c
> @@ -23,6 +23,7 @@
>  #include <hurd/signal.h>
>  #include <hurd/sigpreempt.h>
>  #include <hurd/msg_request.h>
> +#include <mach.h>
>  #include <mach/message.h>
>  
>  /* XXX Temporary cheezoid implementation of ITIMER_REAL/SIGALRM.  */
> @@ -239,7 +240,7 @@ setitimer_locked (const struct itimerval *new, struct itimerval *old,
>    if ((newval.it_value.tv_sec | newval.it_value.tv_usec) != 0 || old != NULL)
>      {
>        /* Calculate how much time is remaining for the pending alarm.  */
> -      if (__gettimeofday (&now, NULL) < 0)
> +      if (__host_get_time (__mach_host_self (), (time_value_t *) &now) < 0)
>  	{
>  	  __spin_unlock (&_hurd_itimer_lock);
>  	  _hurd_critical_section_unlock (crit);

Looks ok.

> diff --git a/sysdeps/mach/hurd/times.c b/sysdeps/mach/hurd/times.c
> index 7758311d83..aafa7b15d9 100644
> --- a/sysdeps/mach/hurd/times.c
> +++ b/sysdeps/mach/hurd/times.c
> @@ -42,7 +42,7 @@ __times (struct tms *tms)
>    struct task_basic_info bi;
>    struct task_thread_times_info tti;
>    mach_msg_type_number_t count;
> -  union { time_value_t tvt; struct timeval tv; } now;
> +  time_value_t now;
>    error_t err;
>  
>    count = TASK_BASIC_INFO_COUNT;
> @@ -65,10 +65,10 @@ __times (struct tms *tms)
>    /* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be.  */
>    tms->tms_cutime = tms->tms_cstime = 0;
>  
> -  if (__gettimeofday (&now.tv, NULL) < 0)
> +  if (__host_get_time (__mach_host_self (), &now) < 0)
>      return -1;
>  
> -  return (clock_from_time_value (&now.tvt)
> +  return (clock_from_time_value (&now)
>  	  - clock_from_time_value (&bi.creation_time));
>  }
>  weak_alias (__times, times)

Looks ok.

> diff --git a/sysdeps/mach/nanosleep.c b/sysdeps/mach/nanosleep.c
> index b4790aaf31..0be48db0d9 100644
> --- a/sysdeps/mach/nanosleep.c
> +++ b/sysdeps/mach/nanosleep.c
> @@ -18,16 +18,26 @@
>  
>  #include <errno.h>
>  #include <mach.h>
> -#include <sys/time.h>
>  #include <time.h>
>  #include <unistd.h>
>  
> +# define timespec_sub(a, b, result)					      \
> +  do {									      \
> +    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;			      \
> +    (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec;			      \
> +    if ((result)->tv_nsec < 0) {					      \
> +      --(result)->tv_sec;						      \
> +      (result)->tv_nsec += 1000000000;					      \
> +    }									      \
> +  } while (0)
> +

As before, I would prefer to use the support/timerspec_* routines intead of
reimplement them.

>  int
>  __libc_nanosleep (const struct timespec *requested_time,
> -	     struct timespec *remaining)
> +                  struct timespec *remaining)
>  {
>    mach_port_t recv;
> -  struct timeval before, after;
> +  struct timespec before, after;
> +  error_t err;
>  
>    if (requested_time->tv_sec < 0
>        || requested_time->tv_nsec < 0
> @@ -43,20 +53,19 @@ __libc_nanosleep (const struct timespec *requested_time,
>  
>    recv = __mach_reply_port ();
>  
> -  if (remaining && __gettimeofday (&before, NULL) < 0)
> +  if (remaining && __clock_gettime (CLOCK_REALTIME, &before) < 0)
>      return -1;
> -  error_t err = __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
> -			    0, 0, recv, ms, MACH_PORT_NULL);
> +
> +  err = __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
> +                    0, 0, recv, ms, MACH_PORT_NULL);
>    __mach_port_destroy (mach_task_self (), recv);
>    if (err == EMACH_RCV_INTERRUPTED)
>      {
> -      if (remaining && __gettimeofday (&after, NULL) >= 0)
> +      if (remaining && __clock_gettime (CLOCK_REALTIME, &after) >= 0)
>  	{
> -	  struct timeval req_time, elapsed, rem;
> -	  TIMESPEC_TO_TIMEVAL (&req_time, requested_time);
> -	  timersub (&after, &before, &elapsed);
> -	  timersub (&req_time, &elapsed, &rem);
> -	  TIMEVAL_TO_TIMESPEC (&rem, remaining);
> +	  struct timespec elapsed;
> +	  timespec_sub (&after, &before, &elapsed);
> +	  timespec_sub (requested_time, &elapsed, remaining);
>  	}
>  
>        errno = EINTR;
> diff --git a/sysdeps/mach/usleep.c b/sysdeps/mach/usleep.c
> index 5d4bd205e1..8428ace6ef 100644
> --- a/sysdeps/mach/usleep.c
> +++ b/sysdeps/mach/usleep.c
> @@ -25,17 +25,12 @@ int
>  usleep (useconds_t useconds)
>  {
>    mach_port_t recv;
> -  struct timeval before, after;
>  
>    recv = __mach_reply_port ();
>  
> -  if (__gettimeofday (&before, NULL) < 0)
> -    return -1;
>    (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
>  		     0, 0, recv, (useconds + 999) / 1000, MACH_PORT_NULL);
>    __mach_port_destroy (mach_task_self (), recv);
> -  if (__gettimeofday (&after, NULL) < 0)
> -    return -1;
>  
>    return 0;
>  }

Looks ok.

> diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c
> index 310df3c4ca..c3956498ce 100644
> --- a/sysdeps/posix/tempname.c
> +++ b/sysdeps/posix/tempname.c
> @@ -50,7 +50,7 @@
>  #include <string.h>
>  
>  #include <fcntl.h>
> -#include <sys/time.h>
> +#include <time.h>
>  #include <stdint.h>
>  #include <unistd.h>
>  
> @@ -63,7 +63,6 @@
>  # define struct_stat64 struct stat
>  # define __gen_tempname gen_tempname
>  # define __getpid getpid
> -# define __gettimeofday gettimeofday
>  # define __mkdir mkdir
>  # define __open open
>  # define __lxstat64(version, file, buf) lstat (file, buf)
> @@ -76,9 +75,9 @@
>  # else
>  # define RANDOM_BITS(Var) \
>      {                                                                         \
> -      struct timeval tv;                                                      \
> -      __gettimeofday (&tv, NULL);                                             \
> -      (Var) = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;                      \
> +      struct timespec ts;                                                     \
> +      clock_gettime (CLOCK_REALTIME, &ts);                                    \
> +      (Var) = ((uint64_t) tv.tv_nsec << 16) ^ tv.tv_sec;                      \
>      }
>  #endif
>  

It should be __clock_gettime.

> diff --git a/sysdeps/pthread/aio_misc.c b/sysdeps/pthread/aio_misc.c
> index 0180ddb3c3..49ab08de3a 100644
> --- a/sysdeps/pthread/aio_misc.c
> +++ b/sysdeps/pthread/aio_misc.c
> @@ -614,13 +614,13 @@ handle_fildes_io (void *arg)
>  	 something to arrive in it. */
>        if (runp == NULL && optim.aio_idle_time >= 0)
>  	{
> -	  struct timeval now;
> +	  struct timespec now;
>  	  struct timespec wakeup_time;
>  
>  	  ++idle_thread_count;
> -	  __gettimeofday (&now, NULL);
> +          __clock_gettime (CLOCK_REALTIME, &now);
>  	  wakeup_time.tv_sec = now.tv_sec + optim.aio_idle_time;
> -	  wakeup_time.tv_nsec = now.tv_usec * 1000;
> +	  wakeup_time.tv_nsec = now.tv_nsec;
>  	  if (wakeup_time.tv_nsec >= 1000000000)
>  	    {
>  	      wakeup_time.tv_nsec -= 1000000000;

As before, I think we can simplify to:

	  wakeup_time = timespec_add (timespec_now (), 
				      make_timespec (optim.aio_idle_time, 0));
          pthread_cond_timedwait (&__aio_new_request_notification,
                                  &__aio_requests_mutex,
                                  &wakeup_time);


> diff --git a/sysdeps/pthread/aio_suspend.c b/sysdeps/pthread/aio_suspend.c
> index 06bd914672..fdd4087abb 100644
> --- a/sysdeps/pthread/aio_suspend.c
> +++ b/sysdeps/pthread/aio_suspend.c
> @@ -183,11 +183,11 @@ aio_suspend (const struct aiocb *const list[], int nent,
>  	{
>  	  /* We have to convert the relative timeout value into an
>  	     absolute time value with pthread_cond_timedwait expects.  */
> -	  struct timeval now;
> +	  struct timespec now;
>  	  struct timespec abstime;
>  
> -	  __gettimeofday (&now, NULL);
> -	  abstime.tv_nsec = timeout->tv_nsec + now.tv_usec * 1000;
> +	  __clock_gettime (CLOCK_REALTIME, &now);
> +	  abstime.tv_nsec = timeout->tv_nsec + now.tv_nsec;
>  	  abstime.tv_sec = timeout->tv_sec + now.tv_sec;
>  	  if (abstime.tv_nsec >= 1000000000)
>  	    {
> 

As before, I think we can simplify to:

	  abstime = timespec_add (timespec_now (), timeout); 
          result = pthread_cond_timedwait (&cond, &__aio_requests_mutex,
                                           &abstime);

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions
  2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
                   ` (14 preceding siblings ...)
  2019-08-20 18:55 ` Paul Eggert
@ 2019-08-21  8:00 ` Lukasz Majewski
  15 siblings, 0 replies; 74+ messages in thread
From: Lukasz Majewski @ 2019-08-21  8:00 UTC (permalink / raw)
  To: Zack Weinberg
  Cc: libc-alpha, Joseph Myers, Florian Weimer, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

[-- Attachment #1: Type: text/plain, Size: 17439 bytes --]

Hi Zack,

> This patchset aims to make the Y2038 project a little easier by
> implementing the other time-getting and time-setting functions
> (time, ftime, stime, gettimeofday, and settimeofday) in terms of
> clock_gettime and clock_settime.  Internal uses of (__)gettimeofday
> are also all changed to __clock_gettime.  Internal uses of time() are
> mostly left alone, since time() is easier and clearer when you don’t
> care about sub-second resolution and don’t need a struct timespec for
> some other reason.
> 
> As a consequence, gettimeofday will no longer report crude timezone
> information under any circumstances.  If its ‘tzp’ argument is not
> NULL, it will write zeroes to both fields of the ‘struct timezone’,
> even if the gettimeofday system call exists and would have produced
> different output.  Similarly, ftime will always write zeroes to the
> timezone and dstflag fields of ‘struct timeb’.  Joseph Myers raised an
> objection to this change; I rebutted the objection, and he did not
> reply; I do not think either of us will persuade the other, so I’m
> formally asking for a third maintainer to make a decision.
> 
> settimeofday _will_ still call the settimeofday system call and pass
> down a non-null ‘tzp’ argument if it receives one, but, if _both_ of
> its arguments are non-null, it will fail and set errno to EINVAL.
> Also, its invocation of a settimeofday system call goes through an
> internal sysdep function called __settimezone.  On the Hurd this is an
> unconditional ENOSYS stub, and on Linux it’s an ENOSYS stub when
> __NR_settimeofday is not defined.
> 
> Relatedly, there is a macro-based hack to issue warnings when
> gettimeofday is called with a ‘tzp’ argument that is not a
> compile-time null pointer.  I think this is probably a better option
> at this stage than various suggested alternatives (e.g. renaming the
> fields of ‘struct timezone’, or removing it from sys/time.h
> altogether) because the remaining valid uses of settimeofday with
> non-null ‘tzp’ should still be able to use struct timezone.  The hack
> is in a separate patch because, well, it’s a hack and I’m hoping
> someone has a better implementation idea.  (I tried an inline function
> instead of a macro, but it threw false positives all over the place on
> ‘gettimeofday (&tv, 0)’...)
> 
> This patchset also includes an overhaul of Linux/Alpha’s GLIBC_2.0
> compatibility symbols for several system calls that consume or produce
> struct timeval.  It appears that early releases of glibc and/or Linux
> for Alpha attempted to achieve some degree of binary compatibility
> with OSF/1, but this came at the expense of using 32-bit time_t inside
> struct timeval.  Up till now, we were invoking compatibility system
> calls from the compatibility symbols.  This patch changes them to wrap
> the 64-bit implementations and convert between 32-bit and 64-bit
> struct timeval in user space.  If a 64-bit tv_sec value returned by
> the kernel is found to be greater than INT32_MAX, the caller will
> receive a saturated 32-bit struct timeval, { INT32_MAX, 0 }, and the
> function will return -1 with errno set to EOVERFLOW.  Because many of
> these calls are assumed unable to fail, we make sure to write all the
> fields of any output data structure even when this happens.  I did
> this partially because it simplified conversion of gettimeofday to
> call clock_gettime, and partially as a worked example of the semantics
> that I think are probably best for the 32-bit time_t compatibility
> symbols we’re going to have to add for many other architectures.
> Comments on these semantics are requested.
> 
> This patchset also includes a partial revision of manual/time.texi.
> clock_gettime and clock_settime are now documented, and the
> obsolescent status of stime, settimeofday, and gettimeofday is
> clearer.  I only documented CLOCK_REALTIME and CLOCK_MONOTONIC,
> because most of the other clock constants are either extremely
> Linux-specific or they have to do with measuring CPU time, and I
> didn’t touch the measuring-CPU-time part of time.texi.  (That part
> also deserves a rewrite, but I don’t know enough about the topic and
> this patchset is already long enough.)
> 
> Finally, there is a case for demoting ftime and stime to compatibility
> symbols and removing their public prototypes (for ftime, we would stop
> installing <sys/timeb.h> altogether).  I tried to investigate how much
> this might break, using codesearch.debian.net, but the identifiers
> ‘ftime’ and ‘stime’ turn out to be heavily used for unrelated
> purposes, so I didn’t get anywhere.
> 

Thanks for your work. This simplifies things a lot as the more rarely
used/obsolete functions/syscalls are replaced with clock_settime or
clock_gettime.

> Zack Weinberg (12):
>   Remove implementations of clock_[gs]ettime using [gs]ettimeofday.
>   Change most internal uses of __gettimeofday to __clock_gettime.
>   Don’t use the argument to time.
>   Use clock_settime to implement stime.
>   Use clock_settime to implement settimeofday.
>   Use clock_gettime to implement time.
>   Use clock_gettime to implement ftime.
>   Use clock_gettime to implement gettimeofday.
>   Finish move of clock_* functions to libc.
>   Warn when gettimeofday is called with non-null tzp argument.
>   Linux/Alpha: don’t use timeval32 system calls.
>   Revise the documentation of ‘simple calendar time’.
> 
>  NEWS                                          |   53 +-
>  include/sys/time.h                            |    7 +-
>  include/time.h                                |    4 +-
>  inet/deadline.c                               |    9 +-
>  login/logout.c                                |    9 +-
>  login/logwtmp.c                               |    7 +-
>  manual/filesys.texi                           |    2 +-
>  manual/llio.texi                              |   10 +-
>  manual/threads.texi                           |    2 +-
>  manual/time.texi                              | 1062
> +++++++++-------- misc/syslog.c                                 |
> 2 +- nis/nis_call.c                                |    4 +-
>  nptl/pthread_join_common.c                    |    7 +-
>  nptl/pthread_mutex_timedlock.c                |    7 +-
>  nscd/nscd_helper.c                            |   24 +-
>  resolv/gai_misc.c                             |    6 +-
>  resolv/gai_suspend.c                          |    6 +-
>  resolv/res_send.c                             |    6 +-
>  rt/Makefile                                   |   15 +-
>  rt/Versions                                   |    7 +-
>  rt/clock-compat.c                             |   63 -
>  string/strfry.c                               |    2 +-
>  sunrpc/auth_des.c                             |   19 +-
>  sunrpc/auth_unix.c                            |    9 +-
>  sunrpc/create_xid.c                           |    6 +-
>  sunrpc/svcauth_des.c                          |    7 +-
>  support/support_test_main.c                   |   14 +-
>  sysdeps/generic/memusage.h                    |   16 +-
>  .../mach/{gettimeofday.c => clock_gettime.c}  |   25 +-
>  .../hurd/{settimeofday.c => clock_settime.c}  |   27 +-
>  sysdeps/mach/hurd/getitimer.c                 |    3 +-
>  sysdeps/mach/hurd/i386/libc.abilist           |    1 -
>  sysdeps/mach/hurd/i386/librt.abilist          |    5 -
>  sysdeps/mach/hurd/setitimer.c                 |    3 +-
>  sysdeps/mach/hurd/times.c                     |    6 +-
>  sysdeps/mach/nanosleep.c                      |   33 +-
>  sysdeps/mach/sleep.c                          |    4 +-
>  sysdeps/mach/usleep.c                         |    5 -
>  sysdeps/posix/gettimeofday.c                  |   67 --
>  sysdeps/posix/tempname.c                      |    9 +-
>  sysdeps/posix/time.c                          |   40 -
>  sysdeps/pthread/aio_misc.c                    |    6 +-
>  sysdeps/pthread/aio_suspend.c                 |    6 +-
>  sysdeps/unix/clock_gettime.c                  |   64 -
>  sysdeps/unix/make-syscalls.sh                 |    2 +-
>  sysdeps/unix/syscalls.list                    |    2 -
>  .../unix/sysv/linux/aarch64/gettimeofday.c    |   71 --
>  sysdeps/unix/sysv/linux/aarch64/init-first.c  |    7 +-
>  sysdeps/unix/sysv/linux/aarch64/libc-vdso.h   |    2 -
>  sysdeps/unix/sysv/linux/aarch64/libc.abilist  |    1 -
>  sysdeps/unix/sysv/linux/alpha/Makefile        |    2 +-
>  sysdeps/unix/sysv/linux/alpha/Versions        |    1 -
>  sysdeps/unix/sysv/linux/alpha/adjtime.c       |   70 +-
>  .../linux/{time.c => alpha/gettimeofday.c}    |   31 +-
>  sysdeps/unix/sysv/linux/alpha/libc.abilist    |    2 -
>  sysdeps/unix/sysv/linux/alpha/librt.abilist   |    5 -
>  sysdeps/unix/sysv/linux/alpha/osf_adjtime.c   |  135 +++
>  sysdeps/unix/sysv/linux/alpha/osf_getitimer.c |   48 +
>  sysdeps/unix/sysv/linux/alpha/osf_getrusage.c |   44 +
>  .../unix/sysv/linux/alpha/osf_gettimeofday.c  |   53 +
>  sysdeps/unix/sysv/linux/alpha/osf_setitimer.c |   55 +
>  .../unix/sysv/linux/alpha/osf_settimeofday.c  |   51 +
>  .../ftime.c => sysv/linux/alpha/osf_utimes.c} |   34 +-
>  .../linux/alpha/osf_wait4.c}                  |   51 +-
>  sysdeps/unix/sysv/linux/alpha/settimeofday.c  |   22 +
>  sysdeps/unix/sysv/linux/alpha/syscalls.list   |   13 +-
>  sysdeps/unix/sysv/linux/alpha/tv32-compat.h   |  151 +++
>  sysdeps/unix/sysv/linux/arm/init-first.c      |    7 +-
>  sysdeps/unix/sysv/linux/arm/libc-vdso.h       |    2 -
>  sysdeps/unix/sysv/linux/arm/libc.abilist      |    1 -
>  sysdeps/unix/sysv/linux/arm/librt.abilist     |    5 -
>  sysdeps/unix/sysv/linux/clock_settime.c       |    1 +
>  sysdeps/unix/sysv/linux/csky/libc.abilist     |    1 -
>  sysdeps/unix/sysv/linux/ftime.c               |    3 -
>  sysdeps/unix/sysv/linux/gettimeofday.c        |   39 -
>  sysdeps/unix/sysv/linux/hppa/libc.abilist     |    1 -
>  sysdeps/unix/sysv/linux/hppa/librt.abilist    |    5 -
>  sysdeps/unix/sysv/linux/i386/gettimeofday.c   |   35 -
>  sysdeps/unix/sysv/linux/i386/libc.abilist     |    1 -
>  sysdeps/unix/sysv/linux/i386/librt.abilist    |    5 -
>  sysdeps/unix/sysv/linux/i386/time.c           |   34 -
>  sysdeps/unix/sysv/linux/ia64/libc.abilist     |    1 -
>  sysdeps/unix/sysv/linux/ia64/librt.abilist    |    5 -
>  .../sysv/linux/m68k/coldfire/libc.abilist     |    1 -
>  .../sysv/linux/m68k/coldfire/librt.abilist    |    5 -
>  .../unix/sysv/linux/m68k/m680x0/libc.abilist  |    1 -
>  .../unix/sysv/linux/m68k/m680x0/librt.abilist |    5 -
>  .../unix/sysv/linux/microblaze/libc.abilist   |    1 -
>  .../unix/sysv/linux/microblaze/librt.abilist  |    5 -
>  sysdeps/unix/sysv/linux/mips/init-first.c     |    7 +-
>  sysdeps/unix/sysv/linux/mips/libc-vdso.h      |    2 -
>  .../sysv/linux/mips/mips32/fpu/libc.abilist   |    1 -
>  .../unix/sysv/linux/mips/mips32/librt.abilist |    5 -
>  .../sysv/linux/mips/mips32/nofpu/libc.abilist |    1 -
>  .../unix/sysv/linux/mips/mips64/librt.abilist |    5 -
>  .../sysv/linux/mips/mips64/n32/libc.abilist   |    1 -
>  .../sysv/linux/mips/mips64/n64/libc.abilist   |    1 -
>  sysdeps/unix/sysv/linux/nios2/libc.abilist    |    1 -
>  sysdeps/unix/sysv/linux/powerpc/Versions      |    1 -
>  .../unix/sysv/linux/powerpc/gettimeofday.c    |   85 --
>  sysdeps/unix/sysv/linux/powerpc/init-first.c  |   13 +-
>  sysdeps/unix/sysv/linux/powerpc/libc-vdso.h   |    2 -
>  .../linux/powerpc/powerpc32/fpu/libc.abilist  |    1 -
>  .../linux/powerpc/powerpc32/librt.abilist     |    5 -
>  .../powerpc/powerpc32/nofpu/libc.abilist      |    1 -
>  .../linux/powerpc/powerpc64/be/libc.abilist   |    1 -
>  .../linux/powerpc/powerpc64/be/librt.abilist  |    5 -
>  .../linux/powerpc/powerpc64/le/libc.abilist   |    1 -
>  sysdeps/unix/sysv/linux/powerpc/time.c        |   84 --
>  sysdeps/unix/sysv/linux/riscv/init-first.c    |   10 +-
>  sysdeps/unix/sysv/linux/riscv/libc-vdso.h     |    2 -
>  .../unix/sysv/linux/riscv/rv64/libc.abilist   |    1 -
>  sysdeps/unix/sysv/linux/s390/init-first.c     |    9 +-
>  sysdeps/unix/sysv/linux/s390/libc-vdso.h      |    3 -
>  .../unix/sysv/linux/s390/s390-32/libc.abilist |    1 -
>  .../sysv/linux/s390/s390-32/librt.abilist     |    5 -
>  .../unix/sysv/linux/s390/s390-64/libc.abilist |    1 -
>  .../sysv/linux/s390/s390-64/librt.abilist     |    5 -
>  sysdeps/unix/sysv/linux/settimezone.c         |   39 +
>  sysdeps/unix/sysv/linux/sh/libc.abilist       |    1 -
>  sysdeps/unix/sysv/linux/sh/librt.abilist      |    5 -
>  sysdeps/unix/sysv/linux/sparc/init-first.c    |    8 +-
>  sysdeps/unix/sysv/linux/sparc/libc-vdso.h     |    2 -
>  .../sysv/linux/sparc/sparc32/libc.abilist     |    1 -
>  .../sysv/linux/sparc/sparc32/librt.abilist    |    5 -
>  .../sysv/linux/sparc/sparc64/libc.abilist     |    1 -
>  .../sysv/linux/sparc/sparc64/librt.abilist    |    5 -
>  sysdeps/unix/sysv/linux/sparc/sparc64/time.c  |    1 -
>  sysdeps/unix/sysv/linux/syscalls.list         |    1 -
>  sysdeps/unix/sysv/linux/x86/gettimeofday.c    |   61 -
>  sysdeps/unix/sysv/linux/x86/time.c            |   59 -
>  .../unix/sysv/linux/x86_64/64/libc.abilist    |    1 -
>  .../unix/sysv/linux/x86_64/64/librt.abilist   |    5 -
>  .../unix/sysv/linux/x86_64/x32/libc.abilist   |    1 -
>  .../unix/sysv/linux/x86_64/x32/librt.abilist  |    5 -
>  .../unix/sysv/linux/x86_64/x32/syscalls.list  |    2 -
>  time/Makefile                                 |    8 +-
>  time/Versions                                 |    2 +-
>  {rt => time}/clock_getcpuclockid.c            |    0
>  {rt => time}/clock_getres.c                   |    0
>  {rt => time}/clock_gettime.c                  |    0
>  {rt => time}/clock_nanosleep.c                |    0
>  {rt => time}/clock_settime.c                  |    1 +
>  time/ftime.c                                  |   26 +-
>  time/getdate.c                                |    2 +-
>  time/gettimeofday.c                           |   30 +-
>  time/settimeofday.c                           |   24 +-
>  sysdeps/unix/stime.c => time/settimezone.c    |   23 +-
>  time/stime.c                                  |   15 +-
>  time/sys/time.h                               |   36 +-
>  time/time.c                                   |   17 +-
>  {rt => time}/tst-clock.c                      |    0
>  {rt => time}/tst-clock2.c                     |    0
>  {rt => time}/tst-clock_nanosleep.c            |    0
>  {rt => time}/tst-cpuclock1.c                  |    0
>  time/tst_wcsftime.c                           |    2 +-
>  156 files changed, 1580 insertions(+), 1775 deletions(-)
>  delete mode 100644 rt/clock-compat.c
>  rename sysdeps/mach/{gettimeofday.c => clock_gettime.c} (67%)
>  rename sysdeps/mach/hurd/{settimeofday.c => clock_settime.c} (71%)
>  delete mode 100644 sysdeps/posix/gettimeofday.c
>  delete mode 100644 sysdeps/posix/time.c
>  delete mode 100644 sysdeps/unix/clock_gettime.c
>  delete mode 100644 sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
>  rename sysdeps/unix/sysv/linux/{time.c => alpha/gettimeofday.c} (64%)
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
>  rename sysdeps/unix/{bsd/ftime.c => sysv/linux/alpha/osf_utimes.c}
> (60%) rename sysdeps/unix/{clock_settime.c =>
> sysv/linux/alpha/osf_wait4.c} (55%) create mode 100644
> sysdeps/unix/sysv/linux/alpha/settimeofday.c create mode 100644
> sysdeps/unix/sysv/linux/alpha/tv32-compat.h delete mode 100644
> sysdeps/unix/sysv/linux/ftime.c delete mode 100644
> sysdeps/unix/sysv/linux/gettimeofday.c delete mode 100644
> sysdeps/unix/sysv/linux/i386/gettimeofday.c delete mode 100644
> sysdeps/unix/sysv/linux/i386/time.c delete mode 100644
> sysdeps/unix/sysv/linux/powerpc/gettimeofday.c delete mode 100644
> sysdeps/unix/sysv/linux/powerpc/time.c create mode 100644
> sysdeps/unix/sysv/linux/settimezone.c delete mode 100644
> sysdeps/unix/sysv/linux/sparc/sparc64/time.c delete mode 100644
> sysdeps/unix/sysv/linux/x86/gettimeofday.c delete mode 100644
> sysdeps/unix/sysv/linux/x86/time.c rename {rt =>
> time}/clock_getcpuclockid.c (100%) rename {rt => time}/clock_getres.c
> (100%) rename {rt => time}/clock_gettime.c (100%)
>  rename {rt => time}/clock_nanosleep.c (100%)
>  rename {rt => time}/clock_settime.c (96%)
>  rename sysdeps/unix/stime.c => time/settimezone.c (67%)
>  rename {rt => time}/tst-clock.c (100%)
>  rename {rt => time}/tst-clock2.c (100%)
>  rename {rt => time}/tst-clock_nanosleep.c (100%)
>  rename {rt => time}/tst-cpuclock1.c (100%)
> 



Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 03/12] Don’t use the argument to time.
  2019-08-20 18:08   ` [PATCH 03/12] Don’t use the argument to time Adhemerval Zanella
@ 2019-08-21 12:29     ` Zack Weinberg
  2019-08-22  9:37       ` Rafal Luzynski
  0 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-21 12:29 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Tue, Aug 20, 2019 at 2:08 PM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
> >       * misc/syslog.c (__vsyslog_internal)
> >       * time/getdate.c (__getdate_r)
> >       * time/tst_wcsftime.c (main):
> >       Use return value of time, not its argument.
> >
> >       * string/strfry.c (strfry)
> >       * sysdeps/mach/sleep.c (__sleep):
> >       Remove unnecessary casts of NULL.
>
> LGTM, thanks.
>
> Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

Committed, thanks.

I removed all of the non-ASCII characters from the commit message to
avoid tangling these changes up with an unrelated policy question.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 04/12] Use clock_settime to implement stime.
  2019-08-20 13:22 ` [PATCH 04/12] Use clock_settime to implement stime Zack Weinberg
@ 2019-08-21 15:10   ` Adhemerval Zanella
  2019-08-22 12:57     ` Zack Weinberg
  0 siblings, 1 reply; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-21 15:10 UTC (permalink / raw)
  To: libc-alpha



On 20/08/2019 10:21, Zack Weinberg wrote:
> Unconditionally, on all ports, use clock_settime to implement stime,
> not settimeofday or a direct syscall.
> 
> Note that the former stub implementation of stime would return -1 with
> errno set to EINVAL if passed a null pointer.  With this change, it
> instead unconditionally dereferences the pointer, so any hypothetical
> callers that passed NULL will now segfault.  I don’t think this will break
> any non-contrived programs.

I agree that using a null point does not make sense, so I would also recommend
to use __nonnull ((1)) on function prototype as well.

> 
> 	* time/stime.c (stime): No longer a stub implementation.
> 	Call __clock_settime.
> 
> 	* sysdeps/unix/stime.c: Delete file.
> 	* sysdeps/unix/sysv/linux/syscalls.list: Remove entry for stime.
> 
> 	* include/time.h: Add libc_hidden_proto for __clock_settime.
> 	* rt/clock_settime.c, sysdeps/unix/sysv/linux/clock_settime.c:
> 	Add libc_hidden_def for __clock_settime.

LGTM.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  include/time.h                          |  1 +
>  rt/clock_settime.c                      |  1 +
>  sysdeps/unix/stime.c                    | 39 -------------------------
>  sysdeps/unix/sysv/linux/clock_settime.c |  1 +
>  sysdeps/unix/sysv/linux/syscalls.list   |  1 -
>  time/stime.c                            | 15 +++-------
>  6 files changed, 7 insertions(+), 51 deletions(-)
>  delete mode 100644 sysdeps/unix/stime.c
> 
> diff --git a/include/time.h b/include/time.h
> index ac3163c2a5..c0421c7a28 100644
> --- a/include/time.h
> +++ b/include/time.h
> @@ -22,6 +22,7 @@ extern __typeof (clock_getres) __clock_getres;
>  extern __typeof (clock_gettime) __clock_gettime;
>  libc_hidden_proto (__clock_gettime)
>  extern __typeof (clock_settime) __clock_settime;
> +libc_hidden_proto (__clock_settime)
>  extern __typeof (clock_nanosleep) __clock_nanosleep;
>  extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
>  

Ok.

> diff --git a/rt/clock_settime.c b/rt/clock_settime.c
> index 891925ab2c..9c4f4fbc10 100644
> --- a/rt/clock_settime.c
> +++ b/rt/clock_settime.c
> @@ -26,5 +26,6 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
>    __set_errno (ENOSYS);
>    return -1;
>  }
> +libc_hidden_def (__clock_settime)
>  weak_alias (__clock_settime, clock_settime)
>  stub_warning (clock_settime)

Ok.

> diff --git a/sysdeps/unix/stime.c b/sysdeps/unix/stime.c
> deleted file mode 100644
> index b0809be400..0000000000
> --- a/sysdeps/unix/stime.c
> +++ /dev/null
> @@ -1,39 +0,0 @@
> -/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#include <errno.h>
> -#include <stddef.h>		/* For NULL.  */
> -#include <sys/time.h>
> -#include <time.h>
> -
> -/* Set the system clock to *WHEN.  */
> -
> -int
> -stime (const time_t *when)
> -{
> -  struct timeval tv;
> -
> -  if (when == NULL)
> -    {
> -      __set_errno (EINVAL);
> -      return -1;
> -    }
> -
> -  tv.tv_sec = *when;
> -  tv.tv_usec = 0;
> -  return __settimeofday (&tv, (struct timezone *) 0);
> -}

Ok.

> diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
> index d837e3019c..ef1512cc91 100644
> --- a/sysdeps/unix/sysv/linux/clock_settime.c
> +++ b/sysdeps/unix/sysv/linux/clock_settime.c
> @@ -34,4 +34,5 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
>  
>    return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
>  }
> +libc_hidden_def (__clock_settime)
>  weak_alias (__clock_settime, clock_settime)

Ok.

> diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
> index e374f97b5f..f6cb655e2c 100644
> --- a/sysdeps/unix/sysv/linux/syscalls.list
> +++ b/sysdeps/unix/sysv/linux/syscalls.list
> @@ -62,7 +62,6 @@ setfsgid	EXTRA	setfsgid	i:i	setfsgid
>  setfsuid	EXTRA	setfsuid	i:i	setfsuid
>  setpgid		-	setpgid		i:ii	__setpgid	setpgid
>  sigaltstack	-	sigaltstack	i:PP	__sigaltstack	sigaltstack
> -stime		-	stime		i:p	stime
>  sysinfo		EXTRA	sysinfo		i:p	__sysinfo	sysinfo
>  swapon		-	swapon		i:si	__swapon	swapon
>  swapoff		-	swapoff		i:s	__swapoff	swapoff

Ok.

> diff --git a/time/stime.c b/time/stime.c
> index de58c49562..b4d692ca32 100644
> --- a/time/stime.c
> +++ b/time/stime.c
> @@ -15,23 +15,16 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <errno.h>
>  #include <time.h>
> -#include <stddef.h>
>  
>  /* Set the system clock to *WHEN.  */
>  
>  int
>  stime (const time_t *when)
>  {
> -  if (when == NULL)
> -    {
> -      __set_errno (EINVAL);
> -      return -1;
> -    }
> +  struct timespec ts;
> +  ts.tv_sec = *when;
> +  ts.tv_nsec = 0;
>  
> -  __set_errno (ENOSYS);
> -  return -1;
> +  return __clock_settime (CLOCK_REALTIME, &ts);
>  }
> -
> -stub_warning (stime)
> 

Ok.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 07/12] Use clock_gettime to implement ftime.
  2019-08-20 13:37 ` [PATCH 07/12] Use clock_gettime to implement ftime Zack Weinberg
@ 2019-08-21 15:18   ` Adhemerval Zanella
  2019-08-22 12:59     ` Zack Weinberg
  0 siblings, 1 reply; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-21 15:18 UTC (permalink / raw)
  To: libc-alpha



On 20/08/2019 10:21, Zack Weinberg wrote:
> ftime is an obsolete variation on gettimeofday, offering only
> millisecond time resolution; it was probably a system call in ooold
> versions of BSD Unix.  For historic reasons, we had three
> implementations of it.  These are all consolidated into time/ftime.c.
> 
> Like gettimeofday, ftime tries to report the time zone, and using that
> information is always a bug.  This patch dummies out the reported
> timezone information; the ‘timezone’ and ‘dstflag’ fields of the
> returned ‘struct timeb’ will always be zero.
> 
> (There is an argument for turning this function into a compat symbol,
> and not installing sys/timeb.h anymore.  Thoughts?)

It was removed in POSIX.1-2008 and moving it to a compat symbol it one less
symbol we would need to adapt to y2038.  I think it is reasonable.

> 
> 	* time/ftime.c (ftime): Replace implementation with the code
> 	formerly in sysdeps/unix/bsd/ftime.c, then change that code to use
> 	__clock_gettime instead of __gettimeofday.  Always set the
> 	timezone and dstflag fields of the ‘timebuf’ argument to zero.
> 
> 	* sysdeps/unix/bsd/ftime.c
> 	* sysdeps/unix/sysv/linux/ftime.c: Delete file.

LGTM with a nit below regarding clock_gettime (CLOCK_REALTIME).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/unix/bsd/ftime.c        | 40 ---------------------------------
>  sysdeps/unix/sysv/linux/ftime.c |  3 ---
>  time/ftime.c                    | 26 ++++++++++-----------
>  3 files changed, 12 insertions(+), 57 deletions(-)
>  delete mode 100644 sysdeps/unix/bsd/ftime.c
>  delete mode 100644 sysdeps/unix/sysv/linux/ftime.c
> 
> diff --git a/sysdeps/unix/bsd/ftime.c b/sysdeps/unix/bsd/ftime.c
> deleted file mode 100644
> index 3a1c6e9b01..0000000000
> --- a/sysdeps/unix/bsd/ftime.c
> +++ /dev/null
> @@ -1,40 +0,0 @@
> -/* Copyright (C) 1994-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#include <sys/timeb.h>
> -#include <sys/time.h>
> -
> -int
> -ftime (struct timeb *timebuf)
> -{
> -  struct timeval tv;
> -  struct timezone tz;
> -
> -  if (__gettimeofday (&tv, &tz) < 0)
> -    return -1;
> -
> -  timebuf->time = tv.tv_sec;
> -  timebuf->millitm = (tv.tv_usec + 500) / 1000;
> -  if (timebuf->millitm == 1000)
> -    {
> -      ++timebuf->time;
> -      timebuf->millitm = 0;
> -    }
> -  timebuf->timezone = tz.tz_minuteswest;
> -  timebuf->dstflag = tz.tz_dsttime;
> -  return 0;
> -}

Ok.

> diff --git a/sysdeps/unix/sysv/linux/ftime.c b/sysdeps/unix/sysv/linux/ftime.c
> deleted file mode 100644
> index 5a5949f608..0000000000
> --- a/sysdeps/unix/sysv/linux/ftime.c
> +++ /dev/null
> @@ -1,3 +0,0 @@
> -/* Linux defines the ftime system call but doesn't actually implement
> -   it.  Use the BSD implementation.  */

Ok.

> -#include <sysdeps/unix/bsd/ftime.c>
> diff --git a/time/ftime.c b/time/ftime.c
> index 6c2a256048..de8d043893 100644
> --- a/time/ftime.c
> +++ b/time/ftime.c
> @@ -15,27 +15,25 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <errno.h>
> -#include <time.h>
>  #include <sys/timeb.h>
> +#include <time.h>
>  
>  int
>  ftime (struct timeb *timebuf)
>  {
> -  int save = errno;
> -  struct tm tp;
> +  struct timespec ts;
>  
> -  __set_errno (0);
> -  if (time (&timebuf->time) == (time_t) -1 && errno != 0)
> +  if (__clock_gettime (CLOCK_REALTIME, &ts) < 0)
>      return -1;

I think we can assume CLOCK_REALTIME is always supported and &ts is always
valid, so we can skip the test here.

> -  timebuf->millitm = 0;
> -
> -  if (__localtime_r (&timebuf->time, &tp) == NULL)
> -    return -1;
> -
> -  timebuf->timezone = tp.tm_gmtoff / 60;
> -  timebuf->dstflag = tp.tm_isdst;
>  
> -  __set_errno (save);
> +  timebuf->time = ts.tv_sec;
> +  timebuf->millitm = (ts.tv_nsec + 500000) / 1000000;

I think it is a fair assumption that kernel won't play foul here and give
us invalid tv_nsec.

> +  if (timebuf->millitm == 1000)
> +    {
> +      ++timebuf->time;
> +      timebuf->millitm = 0;
> +    }
> +  timebuf->timezone = 0;
> +  timebuf->dstflag = 0;
>    return 0;
>  }
> 

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument.
  2019-08-20 13:56 ` [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument Zack Weinberg
  2019-08-20 18:52   ` Paul Eggert
@ 2019-08-21 15:30   ` Adhemerval Zanella
  2019-08-21 16:03     ` Zack Weinberg
  1 sibling, 1 reply; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-21 15:30 UTC (permalink / raw)
  To: libc-alpha



On 20/08/2019 10:21, Zack Weinberg wrote:
> At this stage I don’t think we can issue warnings for settimeofday
> with a non-null tzp argument, nor for arbitrary use of struct
> timezone.  But we can warn about gettimeofday with non-null tzp.
> 
> This uses a macro instead of an inline (fortify-style) function
> because I got false positives with an inline, even with GCC 9.

Would be troublesome to add a check for the new warning? Also is the
false positive a GCC defect or something limited with the inline 
usage?

> 
> 	* time/sys/time.h (__timezone_ptr_t): Delete.
> 	(gettimeofday): Always declare second argument with type ‘void *’.
> 	When possible, wrap with a macro that detects non-null and
> 	non-constant second argument and issues a warning.
> 	Improve commentary.
> 	(settimeofday): Improve commentary.
> 
> 	* time/gettimeofday.c (gettimeofday):
> 	Declare second argument as type ‘void *’.
> ---
>  time/gettimeofday.c |  4 ++--
>  time/sys/time.h     | 36 +++++++++++++++++++++++++-----------
>  2 files changed, 27 insertions(+), 13 deletions(-)
> 
> diff --git a/time/gettimeofday.c b/time/gettimeofday.c
> index 22a996a220..bd1fc3cb5e 100644
> --- a/time/gettimeofday.c
> +++ b/time/gettimeofday.c
> @@ -23,10 +23,10 @@
>     If *TZ is not NULL, clear it.
>     Returns 0 on success, -1 on errors.  */
>  int
> -__gettimeofday (struct timeval *tv, struct timezone *tz)
> +__gettimeofday (struct timeval *restrict tv, void *restrict tz)
>  {
>    if (__glibc_unlikely (tz != 0))
> -    memset (tz, 0, sizeof *tz);
> +    memset (tz, 0, sizeof (struct timezone));
>  
>    struct timespec ts;
>    if (__clock_gettime (CLOCK_REALTIME, &ts))
> diff --git a/time/sys/time.h b/time/sys/time.h
> index 5dbc7fc627..1b6c112274 100644
> --- a/time/sys/time.h
> +++ b/time/sys/time.h
> @@ -54,23 +54,37 @@ struct timezone
>      int tz_minuteswest;		/* Minutes west of GMT.  */
>      int tz_dsttime;		/* Nonzero if DST is ever in effect.  */
>    };
> -
> -typedef struct timezone *__restrict __timezone_ptr_t;
> -#else
> -typedef void *__restrict __timezone_ptr_t;
>  #endif
>  
> -/* Get the current time of day and timezone information,
> -   putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
> -   Returns 0 on success, -1 on errors.
> -   NOTE: This form of timezone information is obsolete.
> -   Use the functions and variables declared in <time.h> instead.  */
> +/* Get the current time of day, putting it into *TV.
> +   If TZ is not null, *TZ must be a struct timezone, and both fields
> +   will be set to zero.
> +   Calling this function with a non-null TZ is obsolete;
> +   use localtime etc. instead.
> +   This function itself is semi-obsolete;
> +   most callers should use time or clock_gettime instead. */
>  extern int gettimeofday (struct timeval *__restrict __tv,
> -			 __timezone_ptr_t __tz) __THROW __nonnull ((1));
> +			 void *__restrict __tz) __THROW __nonnull ((1));
> +
> +#if __GNUC_PREREQ (4,3)
> +/* Issue a warning for use of gettimeofday with a non-null __tz argument.  */
> +__warndecl (__warn_gettimeofday_timezone,
> +            "gettimeofday with non-null or non-constant timezone parameter;"
> +            " this is obsolete and inaccurate, use localtime instead");
> +
> +#define gettimeofday(__tv, __tz)                        \
> +  (((!__builtin_constant_p (__tz) || (__tz) != 0)       \
> +    ? __warn_gettimeofday_timezone ()                   \
> +    : (void) 0),                                        \
> +   (gettimeofday) (__tv, __tz))
> +#endif
>  
>  #ifdef __USE_MISC
>  /* Set the current time of day and timezone information.
> -   This call is restricted to the super-user.  */
> +   This call is restricted to the super-user.
> +   Setting the timezone in this way is obsolete, but we don't yet
> +   warn about it because it still has some uses for which there is
> +   no alternative.  */
>  extern int settimeofday (const struct timeval *__tv,
>  			 const struct timezone *__tz)
>       __THROW;
> 

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument.
  2019-08-21 15:30   ` Adhemerval Zanella
@ 2019-08-21 16:03     ` Zack Weinberg
  2019-08-21 16:10       ` Florian Weimer
  0 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-21 16:03 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Wed, Aug 21, 2019 at 11:30 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
> On 20/08/2019 10:21, Zack Weinberg wrote:
> > At this stage I don’t think we can issue warnings for settimeofday
> > with a non-null tzp argument, nor for arbitrary use of struct
> > timezone.  But we can warn about gettimeofday with non-null tzp.
> >
> > This uses a macro instead of an inline (fortify-style) function
> > because I got false positives with an inline, even with GCC 9.
>
> Would be troublesome to add a check for the new warning?

Do we have any infrastructure for testing for warnings?  I don't know about any.

> Also is the
> false positive a GCC defect or something limited with the inline
> usage?

I didn't look into it in any detail, but the uses of __warndecl +
__builtin_constant_p in bits/string2.h inlines all follow the pattern

    __extern_always_inline T func (ptr)
    {
      if (__builtin_constant_p (ptr) && something_else_p (ptr))
__issue_warning ();
      ...
    }

that is, issue a warning if ptr is a compile-time constant with some
property.  What we want for gettimeofday is just the opposite,

    if (! (__builtin_constant_p (ptr) && ptr == NULL)) __issue_warning ();

that is, warn whenever ptr is _not_ a compile-time NULL.  I wouldn't
be surprised if GCC's earliest unreachable-code removal passes, the
ones that happen early enough to prevent __attribute__((warning))
diagnostics from triggering, were tuned precisely for what
bits/string2.h does, and don't handle this inverse case properly.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument.
  2019-08-21 16:03     ` Zack Weinberg
@ 2019-08-21 16:10       ` Florian Weimer
  2019-08-22 13:07         ` Zack Weinberg
  0 siblings, 1 reply; 74+ messages in thread
From: Florian Weimer @ 2019-08-21 16:10 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: Adhemerval Zanella, GNU C Library

* Zack Weinberg:

> I didn't look into it in any detail, but the uses of __warndecl +
> __builtin_constant_p in bits/string2.h inlines all follow the pattern
>
>     __extern_always_inline T func (ptr)
>     {
>       if (__builtin_constant_p (ptr) && something_else_p (ptr))
> __issue_warning ();
>       ...
>     }
>
> that is, issue a warning if ptr is a compile-time constant with some
> property.  What we want for gettimeofday is just the opposite,
>
>     if (! (__builtin_constant_p (ptr) && ptr == NULL)) __issue_warning ();
>
> that is, warn whenever ptr is _not_ a compile-time NULL.  I wouldn't
> be surprised if GCC's earliest unreachable-code removal passes, the
> ones that happen early enough to prevent __attribute__((warning))
> diagnostics from triggering, were tuned precisely for what
> bits/string2.h does, and don't handle this inverse case properly.

I don't think this will work.  You would have to use something like
this:

  __builtin_constant_p (ptr != NULL) && ptr != NULL

Otherwise you will produce a warning every time someone uses the
gettimeofday wrapper in a function for which optimization has been
disabled.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 11/12] Linux/Alpha: don’t use timeval32 system calls.
  2019-08-20 13:37 ` [PATCH 11/12] Linux/Alpha: don’t use timeval32 system calls Zack Weinberg
@ 2019-08-21 18:50   ` Adhemerval Zanella
  2019-08-22 13:36     ` Zack Weinberg
  0 siblings, 1 reply; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-21 18:50 UTC (permalink / raw)
  To: libc-alpha



On 20/08/2019 10:21, Zack Weinberg wrote:
> Linux/Alpha has two versions of several system call wrappers that take
> or return data of type ‘struct timeval’ (possibly nested inside a
> larger structure).  The GLIBC_2.0 version is a compat symbol that
> calls __NR_osf_foo or __NR_old_foo and uses a struct timeval with a
> 32-bit tv_sec field.  The GLIBC_2.1 version is used for current code,
> calls __NR_foo, and uses a struct timeval with a 64-bit tv_sec field.
> 
> This patch changes all of the remaining compat symbols of this type to
> be wrappers around their GLIBC_2.1 counterparts.  (gettimeofday
> already received this treatment in an earlier patch in this series.)
> The compat symbols that copy out a 32-bit struct timeval all check for
> overflow.  After the Y2038 deadline, they will fail with errno set to
> EOVERFLOW, but only after copying out as much as they can, and filling
> in the overflowed ‘struct timeval’(s) with tv_sec set to INT32_MAX and
> tv_nsec set to zero.
> 
> The new header file tv32-compat.h is currently Alpha-specific but I
> don’t know any reason why it couldn’t be reused to aid in writing
> wrappers for all affected architectures.
> 
> 	* sysdeps/unix/sysv/linux/alpha/tv32-compat.h: New file declaring
> 	types and helper functions for 32/64-bit time_t conversion.
> 
> 	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove entries for
> 	osf_getitimer, osf_setitimer, osf_utimes, osf_getrusage, and osf_wait4.
> 
> 	* sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
> 	* sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
> 	* sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
> 	* sysdeps/unix/sysv/linux/alpha/osf_utimes.c
> 	* sysdeps/unix/sysv/linux/alpha/osf_wait4.c:
> 	New files defining compatibility symbols formerly defined by
> 	alpha/syscalls.list.
> 
> 	* sysdeps/unix/sysv/linux/alpha/adjtime.c: Split the compat code to...
> 	* sysdeps/unix/sysv/linux/alpha/osf_adjtime.c: ...this new file.
> 
> 	* sysdeps/unix/sysv/linux/alpha/Makefile (sysdep_routines):
>         Add osf_adjtime.
> 
> 	* sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> 	* sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c:
> 	Use tv32-compat.h helpers.
> ---
>  sysdeps/unix/sysv/linux/alpha/Makefile        |   2 +-
>  sysdeps/unix/sysv/linux/alpha/adjtime.c       |  70 +-------
>  sysdeps/unix/sysv/linux/alpha/osf_adjtime.c   | 135 ++++++++++++++++
>  sysdeps/unix/sysv/linux/alpha/osf_getitimer.c |  48 ++++++
>  sysdeps/unix/sysv/linux/alpha/osf_getrusage.c |  44 +++++
>  .../unix/sysv/linux/alpha/osf_gettimeofday.c  |  27 +---
>  sysdeps/unix/sysv/linux/alpha/osf_setitimer.c |  55 +++++++
>  .../unix/sysv/linux/alpha/osf_settimeofday.c  |  12 +-
>  sysdeps/unix/sysv/linux/alpha/osf_utimes.c    |  36 +++++
>  sysdeps/unix/sysv/linux/alpha/osf_wait4.c     |  47 ++++++
>  sysdeps/unix/sysv/linux/alpha/syscalls.list   |   9 +-
>  sysdeps/unix/sysv/linux/alpha/tv32-compat.h   | 151 ++++++++++++++++++
>  12 files changed, 536 insertions(+), 100 deletions(-)
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_utimes.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_wait4.c
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/tv32-compat.h
> 
> diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile
> index fdd089af71..2e132e474b 100644
> --- a/sysdeps/unix/sysv/linux/alpha/Makefile
> +++ b/sysdeps/unix/sysv/linux/alpha/Makefile
> @@ -9,7 +9,7 @@ sysdep_routines += ieee_get_fp_control ieee_set_fp_control \
>  		   ioperm
>  
>  # Support old timeval32 entry points
> -sysdep_routines += osf_gettimeofday osf_settimeofday \
> +sysdep_routines += osf_adjtime osf_gettimeofday osf_settimeofday \
>  		   osf_getitimer osf_setitimer osf_utimes \
>  		   osf_getrusage osf_wait4
>  

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/adjtime.c b/sysdeps/unix/sysv/linux/alpha/adjtime.c
> index 65641e9c4d..f67f522300 100644
> --- a/sysdeps/unix/sysv/linux/alpha/adjtime.c
> +++ b/sysdeps/unix/sysv/linux/alpha/adjtime.c
> @@ -1,4 +1,5 @@
> -/* Copyright (C) 1998-2019 Free Software Foundation, Inc.
> +/* adjtime -- adjust the system clock.  Linux/Alpha/tv64 version.
> +   Copyright (C) 1998-2019 Free Software Foundation, Inc.
>     This file is part of the GNU C Library.
>  
>     The GNU C Library is free software; you can redistribute it and/or
> @@ -15,76 +16,19 @@
>     License along with the GNU C Library.  If not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <shlib-compat.h>
>  #include <sysdep.h>
>  #include <sys/time.h>
> +#include <shlib-compat.h>
>  
> -
> -#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
> -struct timeval32
> -{
> -    int tv_sec, tv_usec;
> -};
> -
> -struct timex32 {
> -	unsigned int modes;	/* mode selector */
> -	long offset;		/* time offset (usec) */
> -	long freq;		/* frequency offset (scaled ppm) */
> -	long maxerror;		/* maximum error (usec) */
> -	long esterror;		/* estimated error (usec) */
> -	int status;		/* clock command/status */
> -	long constant;		/* pll time constant */
> -	long precision;		/* clock precision (usec) (read only) */
> -	long tolerance;		/* clock frequency tolerance (ppm)
> -				 * (read only)
> -				 */
> -	struct timeval32 time;	/* (read only) */
> -	long tick;		/* (modified) usecs between clock ticks */
> -
> -	long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
> -	long jitter;            /* pps jitter (us) (ro) */
> -	int shift;              /* interval duration (s) (shift) (ro) */
> -	long stabil;            /* pps stability (scaled ppm) (ro) */
> -	long jitcnt;            /* jitter limit exceeded (ro) */
> -	long calcnt;            /* calibration intervals (ro) */
> -	long errcnt;            /* calibration errors (ro) */
> -	long stbcnt;            /* stability limit exceeded (ro) */
> -
> -	int  :32; int  :32; int  :32; int  :32;
> -	int  :32; int  :32; int  :32; int  :32;
> -	int  :32; int  :32; int  :32; int  :32;
> -};
> -
> -#define TIMEVAL		timeval32
> -#define TIMEX		timex32
> -#define ADJTIME		attribute_compat_text_section __adjtime_tv32
> -#define ADJTIMEX(x)	INLINE_SYSCALL (old_adjtimex, 1, x)
> -#define ADJTIMEX32(x)	INLINE_SYSCALL (old_adjtimex, 1, x)
> -
> -#include <sysdeps/unix/sysv/linux/adjtime.c>
> -
> -int attribute_compat_text_section
> -__adjtimex_tv32 (struct timex32 *tx) { return ADJTIMEX (tx); }
> -
> -strong_alias (__adjtimex_tv32, __adjtimex_tv32_1);
> -strong_alias (__adjtimex_tv32, __adjtimex_tv32_2);
> -compat_symbol (libc, __adjtimex_tv32_1, __adjtimex, GLIBC_2_0);
> -compat_symbol (libc, __adjtimex_tv32_2, adjtimex, GLIBC_2_0);
> -compat_symbol (libc, __adjtime_tv32, adjtime, GLIBC_2_0);
> -#endif /* SHLIB_COMPAT */
> -
> -#undef TIMEVAL
> -#undef TIMEX
> -#undef ADJTIME
> -#undef ADJTIMEX
> -#define TIMEVAL		timeval
> -#define TIMEX		timex
>  #define ADJTIMEX(x)	INLINE_SYSCALL (adjtimex, 1, x)
>  
>  #include <sysdeps/unix/sysv/linux/adjtime.c>
>  
>  int
> -__adjtimex_tv64 (struct timex *tx) { return ADJTIMEX (tx); }
> +__adjtimex_tv64 (struct timex *tx)
> +{
> +  return ADJTIMEX (tx);
> +}
>  
>  libc_hidden_ver (__adjtimex_tv64, __adjtimex)
>  strong_alias (__adjtimex_tv64, __adjtimex_tv64p);

I think you can just remove this file by adding

adjtimex       adjtime adjtimex        i:p     __adjtimex      __adjtimex@GLIBC_2.1 adjtimex@GLIBC_2.1

on sysdeps/unix/sysv/linux/alpha/syscalls.list.

> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
> new file mode 100644
> index 0000000000..57c77c3072
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
> @@ -0,0 +1,135 @@
> +/* adjtime -- adjust the system clock.  Linux/Alpha/tv32 version.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <sys/time.h>
> +#include <sys/timex.h>
> +#include <shlib-compat.h>
> +
> +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
> +
> +#include <errno.h>
> +#include <tv32-compat.h>
> +
> +struct timex32 {
> +	unsigned int modes;	/* mode selector */
> +	long offset;		/* time offset (usec) */
> +	long freq;		/* frequency offset (scaled ppm) */
> +	long maxerror;		/* maximum error (usec) */
> +	long esterror;		/* estimated error (usec) */
> +	int status;		/* clock command/status */
> +	long constant;		/* pll time constant */
> +	long precision;		/* clock precision (usec) (read only) */
> +	long tolerance;		/* clock frequency tolerance (ppm)
> +				 * (read only)
> +				 */
> +	struct timeval32 time;	/* (read only) */
> +	long tick;		/* (modified) usecs between clock ticks */
> +
> +	long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
> +	long jitter;            /* pps jitter (us) (ro) */
> +	int shift;              /* interval duration (s) (shift) (ro) */
> +	long stabil;            /* pps stability (scaled ppm) (ro) */
> +	long jitcnt;            /* jitter limit exceeded (ro) */
> +	long calcnt;            /* calibration intervals (ro) */
> +	long errcnt;            /* calibration errors (ro) */
> +	long stbcnt;            /* stability limit exceeded (ro) */
> +
> +	int  :32; int  :32; int  :32; int  :32;
> +	int  :32; int  :32; int  :32; int  :32;
> +	int  :32; int  :32; int  :32; int  :32;
> +};
> +
> +int attribute_compat_text_section
> +__adjtime_tv32 (const struct timeval32 *itv, struct timeval32 *otv)
> +{
> +  struct timeval itv64, otv64;
> +  TV32_TO_TV64 (&itv64, itv);
> +  if (__adjtime (&itv64, &otv64))
> +    return -1;

No implicit checks.

> +  if (TV64_TO_TV32 (otv, &itv64))

Ditto.

> +    {
> +      __set_errno (EOVERFLOW);
> +      return -1;
> +    }
> +  return 0;
> +}
> +
> +int attribute_compat_text_section
> +__adjtimex_tv32 (struct timex32 *tx)
> +{
> +  struct timex tx64;
> +  memset (&tx64, 0, sizeof tx64);

Maybe struct timex tx64 = { 0 } ?

> +  tx64.modes     = tx->modes;
> +  tx64.offset    = tx->offset;
> +  tx64.freq      = tx->freq;
> +  tx64.maxerror  = tx->maxerror;
> +  tx64.esterror  = tx->esterror;
> +  tx64.status    = tx->status;
> +  tx64.constant  = tx->constant;
> +  tx64.precision = tx->precision;
> +  tx64.tolerance = tx->tolerance;
> +  tx64.tick      = tx->tick;
> +  tx64.ppsfreq   = tx->ppsfreq;
> +  tx64.jitter    = tx->jitter;
> +  tx64.shift     = tx->shift;
> +  tx64.stabil    = tx->stabil;
> +  tx64.jitcnt    = tx->jitcnt;
> +  tx64.calcnt    = tx->calcnt;
> +  tx64.errcnt    = tx->errcnt;
> +  tx64.stbcnt    = tx->stbcnt;
> +  TV32_TO_TV64 (&tx64.time, &tx->time);
> +
> +  int status = __adjtimex (&tx64);
> +  if (status < 0)
> +    return status;
> +
> +  memset (tx, 0, sizeof *tx);
> +  tx->modes     = tx64.modes;
> +  tx->offset    = tx64.offset;
> +  tx->freq      = tx64.freq;
> +  tx->maxerror  = tx64.maxerror;
> +  tx->esterror  = tx64.esterror;
> +  tx->status    = tx64.status;
> +  tx->constant  = tx64.constant;
> +  tx->precision = tx64.precision;
> +  tx->tolerance = tx64.tolerance;
> +  tx->tick      = tx64.tick;
> +  tx->ppsfreq   = tx64.ppsfreq;
> +  tx->jitter    = tx64.jitter;
> +  tx->shift     = tx64.shift;
> +  tx->stabil    = tx64.stabil;
> +  tx->jitcnt    = tx64.jitcnt;
> +  tx->calcnt    = tx64.calcnt;
> +  tx->errcnt    = tx64.errcnt;
> +  tx->stbcnt    = tx64.stbcnt;
> +  if (TV64_TO_TV32 (&tx->time, &tx64.time))
> +    {
> +      __set_errno (EOVERFLOW);
> +      return -1;
> +    }

I am not sure it is correct to return EOVERFLOW for this pattern, because
the side-effects of time adjustment will be visible after the call. The
kernel (arch/alpha/kernel/osf_sys.c:1254) does not handle the overflow,
so I think we just need to mimic the kernel for this (the caller will see
the overflow in the returned value).

> +
> +  return status;
> +}
> +
> +strong_alias (__adjtimex_tv32, __adjtimex_tv32_1);
> +strong_alias (__adjtimex_tv32, __adjtimex_tv32_2);
> +compat_symbol (libc, __adjtimex_tv32_1, __adjtimex, GLIBC_2_0);
> +compat_symbol (libc, __adjtimex_tv32_2, adjtimex, GLIBC_2_0);
> +compat_symbol (libc, __adjtime_tv32, adjtime, GLIBC_2_0);
> +
> +#endif /* SHLIB_COMPAT */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
> new file mode 100644
> index 0000000000..d15d8f5be4
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
> @@ -0,0 +1,48 @@
> +/* getitimer -- Get the state of an interval timer.  Linux/Alpha/tv32 version.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <sys/time.h>
> +#include <shlib-compat.h>
> +
> +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
> +
> +#include <errno.h>
> +#include <tv32-compat.h>
> +
> +int
> +__getitimer_tv32 (int which, struct itimerval32 *curr_value)
> +{
> +  struct itimerval curr_value_64;
> +  if (__getitimer (which, &curr_value_64))

No implicit checks.

> +    return -1;
> +
> +  /* Make sure both fields of the output are filled in, even if one of them
> +     overflows.  */
> +  int e;
> +  e  = TV64_TO_TV32 (&curr_value->it_interval, &curr_value_64.it_interval);
> +  e |= TV64_TO_TV32 (&curr_value->it_value, &curr_value_64.it_value);
> +  if (e)
> +    {
> +      __set_errno (EOVERFLOW);
> +      return -1;
> +    }
> +  return 0;
> +}
> +
> +compat_symbol (libc, __getitimer_tv32, getitimer, GLIBC_2_0);
> +#endif

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
> new file mode 100644
> index 0000000000..ac094dddbf
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
> @@ -0,0 +1,44 @@
> +/* utimes -- change file timestamps.  Linux/Alpha/tv32 version.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <sys/time.h>
> +#include <sys/resource.h>
> +#include <shlib-compat.h>
> +
> +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
> +
> +#include <errno.h>
> +#include <tv32-compat.h>
> +
> +int
> +__getrusage_tv32 (int who, struct rusage32 *usage32)
> +{
> +  struct rusage usage64;
> +  if (__getrusage (who, &usage64))

No implicit checks.

> +    return -1;
> +
> +  if (RUSAGE64_TO_RUSAGE32 (usage32, &usage64))
> +    {
> +      __set_errno (EOVERFLOW);
> +      return -1;
> +    }
> +  return 0;
> +}
> +
> +compat_symbol (libc, __getrusage_tv32, getrusage, GLIBC_2_0);
> +#endif

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> index 9868dfd9c9..cc4c4eebdf 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> @@ -16,19 +16,15 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <errno.h>
> -#include <limits.h>
> -#include <string.h>
> -#include <time.h>
>  #include <sys/time.h>
>  #include <shlib-compat.h>

Ok.

>  
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
> -struct timeval32
> -{
> -    int tv_sec, tv_usec;
> -};
> +#include <time.h>
> +#include <errno.h>
> +#include <string.h>
> +#include <tv32-compat.h>
>  
>  /* Get the current time of day, putting it into *TV.
>     If *TZ is not NULL, clear it.
> @@ -36,29 +32,20 @@ struct timeval32
>  
>  int
>  attribute_compat_text_section
> -__gettimeofday_tv32 (struct timeval32 *tv32,
> -                     struct timezone *tz)
> +__gettimeofday_tv32 (struct timeval32 *restrict tv32, void *restrict tz)
>  {
>    if (__glibc_unlikely (tz != 0))
> -    memset (tz, 0, sizeof *tz);
> +    memset (tz, 0, sizeof (struct timezone));
>  
>    struct timespec ts;
>    if (__clock_gettime (CLOCK_REALTIME, &ts))
>      return -1;

I think it can be simplified to assume __clock_gettime (CLOCK_REALTIME) can't
fail.

>  
> -  if (__glibc_unlikely (ts.tv_sec > (time_t)INT_MAX))
> +  if (TS64_TO_TV32 (tv32, &ts))


No implicit checks.

>      {
> -      /* The clock has advanced past the time representable in a 32-bit
> -         time_t.  Fail, but write a saturated value to the output first,
> -         because callers don't typically expect gettimeofday to fail.  */
>        __set_errno (EOVERFLOW);
> -      tv32->tv_sec  = INT_MAX;
> -      tv32->tv_usec = 0;
>        return -1;
>      }
> -
> -  tv32->tv_sec = ts.tv_sec;
> -  tv32->tv_usec = ts.tv_nsec / 1000;
>    return 0;
>  }
>  

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
> new file mode 100644
> index 0000000000..48d5bbcd75
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
> @@ -0,0 +1,55 @@
> +/* getitimer -- Get the state of an interval timer.  Linux/Alpha/tv32 version.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <sys/time.h>
> +#include <shlib-compat.h>
> +
> +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
> +
> +#include <errno.h>
> +#include <tv32-compat.h>
> +
> +int
> +__setitimer_tv32 (int which, const struct itimerval32 *restrict new_value,
> +		  struct itimerval32 *restrict old_value)
> +{
> +  struct itimerval new_value_64;
> +  TV32_TO_TV64 (&new_value_64.it_interval, &new_value->it_interval);
> +  TV32_TO_TV64 (&new_value_64.it_value, &new_value->it_value);
> +
> +  if (!old_value)
> +    return __setitimer (which, &new_value_64, 0);

I think you code guidelines state we need to check against NULL.

> +
> +  struct itimerval old_value_64;
> +  if (__setitimer (which, &new_value_64, &old_value_64))
> +    return -1;

No implicit checks.

> +
> +  /* Write all fields of 'old_value' even on error.  */
> +  int e = 0;
> +  e |= TV64_TO_TV32 (&old_value->it_interval, &old_value_64.it_interval);
> +  e |= TV64_TO_TV32 (&old_value->it_value, &old_value_64.it_value);
> +  if (e)
> +    {
> +      __set_errno (EOVERFLOW);
> +      return -1;
> +    }
> +  return 0;
> +}

As for adjtimer, I am not sure it is correct to return EOVERFLOW for this 
pattern due the side-effects of time adjustment being visible after the
call.

> +
> +compat_symbol (libc, __setitimer_tv32, setitimer, GLIBC_2_0);
> +#endif> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
> index a61fcab482..d793b24dbf 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
> @@ -16,17 +16,14 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <errno.h>
> -#include <time.h>
>  #include <sys/time.h>
>  #include <shlib-compat.h>
>  
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
> -struct timeval32
> -{
> -    int tv_sec, tv_usec;
> -};
> +#include <errno.h>
> +#include <time.h>
> +#include <tv32-compat.h>
>  
>  /* Set the current time of day and timezone information.
>     This call is restricted to the super-user.  */
> @@ -46,8 +43,7 @@ __settimeofday_tv32 (const struct timeval32 *tv32,
>      }
>  
>    struct timespec ts;
> -  ts.tv_sec = tv32->tv_sec;
> -  ts.tv_nsec = tv32->tv_usec * 1000;
> +  TV32_TO_TS64 (&ts, tv32);
>    return __clock_settime (CLOCK_REALTIME, &ts);
>  }
>  

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
> new file mode 100644
> index 0000000000..7ed483ffb8
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
> @@ -0,0 +1,36 @@
> +/* utimes -- change file timestamps.  Linux/Alpha/tv32 version.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <sys/time.h>
> +#include <shlib-compat.h>
> +
> +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
> +
> +#include <tv32-compat.h>
> +
> +int
> +__utimes_tv32 (const char *filename, const struct timeval32 times32[2])
> +{
> +  struct timeval times[2];
> +  TV32_TO_TV64 (&times[0], &times32[0]);
> +  TV32_TO_TV64 (&times[1], &times32[1]);
> +  return __utimes (filename, times);
> +}
> +
> +compat_symbol (libc, __utimes_tv32, utimes, GLIBC_2_0);
> +#endif

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_wait4.c b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
> new file mode 100644
> index 0000000000..6ad3f1d510
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
> @@ -0,0 +1,47 @@
> +/* wait4 -- wait for process to change state.  Linux/Alpha/tv32 version.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <sys/time.h>
> +#include <sys/resource.h>
> +#include <sys/wait.h>
> +#include <shlib-compat.h>
> +
> +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
> +
> +#include <errno.h>
> +#include <string.h>
> +#include <tv32-compat.h>
> +
> +pid_t
> +__wait4_tv32 (pid_t pid, int *status, int options, struct rusage32 *usage32)
> +{
> +  struct rusage usage64;
> +  pid_t child = __wait4 (pid, status, options, &usage64);
> +  if (child < 0)
> +    return child;
> +
> +  if (RUSAGE64_TO_RUSAGE32 (usage32, &usage64))

No implicit checks.

> +    {
> +      __set_errno (EOVERFLOW);
> +      return -1;
> +    }

I am not sure it is correct to return EOVERFLOW for this pattern, because
wait return value expects that an -1 error either the input in invalid or
the child was not reaped.  With this pattern, the child will be terminated
correctly, but it won't indicate the correct value.

I think since it is a compat symbol to just convert to rusage32 and return
the value to caller.

> +  return child;
> +}
> +
> +compat_symbol (libc, __wait4_tv32, wait4, GLIBC_2_0);
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
> index 9ceed78c8d..0e472b4542 100644
> --- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
> +++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
> @@ -22,14 +22,7 @@ pciconfig_read	EXTRA	pciconfig_read	5	pciconfig_read
>  pciconfig_write	EXTRA	pciconfig_write	5	pciconfig_write
>  pciconfig_iobase EXTRA	pciconfig_iobase 3	__pciconfig_iobase pciconfig_iobase
>  
> -# support old timeval32 entry points
> -osf_getitimer	-	osf_getitimer	2	__getitimer_tv32  getitimer@GLIBC_2.0
> -osf_setitimer	-	osf_setitimer	3	__setitimer_tv32  setitimer@GLIBC_2.0
> -osf_utimes	-	osf_utimes	2	__utimes_tv32  utimes@GLIBC_2.0
> -osf_getrusage	-	osf_getrusage	2	__getrusage_tv32  getrusage@GLIBC_2.0
> -osf_wait4	-	osf_wait4	4	__wait4_tv32  wait4@GLIBC_2.0
> -
> -# support new timeval64 entry points
> +# new timeval64 entry points (see osf_* for the GLIBC_2.0 versions)
>  getitimer	-	getitimer	2	__getitimer getitimer@@GLIBC_2.1
>  setitimer	-	setitimer	3	__setitimer setitimer@@GLIBC_2.1
>  utimes		-	utimes		2	__utimes utimes@@GLIBC_2.1

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h b/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
> new file mode 100644
> index 0000000000..926e8ce017
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
> @@ -0,0 +1,151 @@
> +/* Compatibility definitions for `struct timeval' with 32-bit time_t.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#ifndef _TV32_COMPAT_H
> +#define _TV32_COMPAT_H 1

I personally prefer to prefix arch-specific header with the architectures
initial to allow include-next (although this header specific does not
actually require it).

> +
> +#include <features.h>
> +
> +#include <bits/types.h>
> +#include <bits/types/time_t.h>
> +#include <bits/types/struct_timeval.h>
> +#include <bits/types/struct_timespec.h>
> +#include <bits/types/struct_rusage.h>
> +
> +#include <stdint.h> // for INT32_MAX
> +#include <string.h> // for memset
> +
> +/* A version of 'struct timeval' with 32-bit time_t.  */
> +struct timeval32
> +{
> +  int32_t tv_sec;
> +  int32_t tv_usec;
> +};
> +
> +/* Structures containing 'struct timeval' with 32-bit time_t.  */
> +struct itimerval32
> +{
> +  struct timeval32 it_interval;
> +  struct timeval32 it_value;
> +};
> +
> +struct rusage32
> +{
> +  struct timeval32 ru_utime;	/* user time used */
> +  struct timeval32 ru_stime;	/* system time used */
> +  long ru_maxrss;		/* maximum resident set size */
> +  long ru_ixrss;		/* integral shared memory size */
> +  long ru_idrss;		/* integral unshared data size */
> +  long ru_isrss;		/* integral unshared stack size */
> +  long ru_minflt;		/* page reclaims */
> +  long ru_majflt;		/* page faults */
> +  long ru_nswap;		/* swaps */
> +  long ru_inblock;		/* block input operations */
> +  long ru_oublock;		/* block output operations */
> +  long ru_msgsnd;		/* messages sent */
> +  long ru_msgrcv;		/* messages received */
> +  long ru_nsignals;		/* signals received */
> +  long ru_nvcsw;		/* voluntary context switches */
> +  long ru_nivcsw;		/* involuntary " */
> +};

s/long/long int/

> +
> +/* Conversion functions.  If the seconds field of a timeval32 would
> +   overflow, they write { INT32_MAX, 0 } to the output and return -1;
> +   otherwise they return 0.  */
> +
> +__extern_always_inline void
> +TV32_TO_TV64 (struct timeval *restrict tv64,
> +              const struct timeval32 *restrict tv32)
> +{
> +  tv64->tv_sec = tv32->tv_sec;
> +  tv64->tv_usec = tv32->tv_usec;
> +}

I think since it is an internal header and we explict build glibc with gnu11,
use static inline should be suffice instead of __extern_always_inline.  Also,
although it is not a rule, glibc uses capitalized names for macros definitions
and default names for static inline functions.  The implementation looks ok.

> +
> +__extern_always_inline void
> +TV32_TO_TS64 (struct timespec *restrict ts64,
> +              const struct timeval32 *restrict tv32)
> +{
> +  ts64->tv_sec = tv32->tv_sec;
> +  ts64->tv_nsec = tv32->tv_usec * 1000;
> +}
> +
> +__extern_always_inline int
> +TV64_TO_TV32 (struct timeval32 *restrict tv32,
> +              const struct timeval *restrict tv64)
> +{
> +  if (__glibc_unlikely (tv64->tv_sec > (time_t) INT32_MAX))
> +    {
> +      tv32->tv_sec = INT32_MAX;
> +      tv32->tv_usec = 0;
> +      return -1;
> +    }
> +  else
> +    {
> +      tv32->tv_sec = tv64->tv_sec;
> +      tv32->tv_usec = tv64->tv_usec;
> +      return 0;
> +    }
> +}

Use bool/_Bool so there is no need to use explicit check for the function
use.  Same for TS64_TO_TV32 and RUSAGE64_TO_RUSAGE32.

> +
> +__extern_always_inline int
> +TS64_TO_TV32 (struct timeval32 *restrict tv32,
> +              const struct timespec *restrict ts64)
> +{
> +  if (__glibc_unlikely (ts64->tv_sec > (time_t) INT32_MAX))
> +    {
> +      tv32->tv_sec = INT32_MAX;
> +      tv32->tv_usec = 0;
> +      return -1;
> +    }
> +  else
> +    {
> +      tv32->tv_sec = ts64->tv_sec;
> +      tv32->tv_usec = ts64->tv_nsec / 1000;
> +      return 0;
> +    }
> +}
> +
> +__extern_always_inline int
> +RUSAGE64_TO_RUSAGE32 (struct rusage32 *restrict r32,
> +                      const struct rusage *restrict r64)
> +{
> +  /* Fill out the entire structure even on failure.  */
> +  memset (r32, 0, sizeof *r32);
> +
> +  int e = 0;
> +  e |= TV64_TO_TV32 (&r32->ru_utime, &r64->ru_utime);
> +  e |= TV64_TO_TV32 (&r32->ru_stime, &r64->ru_stime);
> +  r32->ru_maxrss   = r64->ru_maxrss;
> +  r32->ru_ixrss    = r64->ru_ixrss;
> +  r32->ru_idrss    = r64->ru_idrss;
> +  r32->ru_isrss    = r64->ru_isrss;
> +  r32->ru_minflt   = r64->ru_minflt;
> +  r32->ru_majflt   = r64->ru_majflt;
> +  r32->ru_nswap    = r64->ru_nswap;
> +  r32->ru_inblock  = r64->ru_inblock;
> +  r32->ru_oublock  = r64->ru_oublock;
> +  r32->ru_msgsnd   = r64->ru_msgsnd;
> +  r32->ru_msgrcv   = r64->ru_msgrcv;
> +  r32->ru_nsignals = r64->ru_nsignals;
> +  r32->ru_nvcsw    = r64->ru_nvcsw;
> +  r32->ru_nivcsw   = r64->ru_nivcsw;
> +
> +  return e;
> +}
> +
> +#endif /* tv32-compat.h */
> 

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime.
  2019-08-20 20:56   ` Adhemerval Zanella
@ 2019-08-21 21:09     ` Zack Weinberg
  2019-08-23 18:39       ` Adhemerval Zanella
  0 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-21 21:09 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Tue, Aug 20, 2019 at 4:56 PM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
> On 20/08/2019 10:21, Zack Weinberg wrote:
> > Since gettimeofday will shortly be implemented in terms of
> > clock_gettime on all platforms, internal code should use clock_gettime
> > directly; in addition to removing a layer of indirection, this will
> > allow us to remove the PLT-bypass gunk for gettimeofday.  In many
> > cases, the changed code does fewer conversions.
...
> >    if (__clock_gettime (CLOCK_MONOTONIC, &result.current) != 0)
> > -    {
> > -      struct timeval current_tv;
> > -      if (__gettimeofday (&current_tv, NULL) == 0)
> > -        __libc_fatal ("Fatal error: gettimeofday system call failed\n");
> > -      result.current.tv_sec = current_tv.tv_sec;
> > -      result.current.tv_nsec = current_tv.tv_usec * 1000;
> > -    }
> > +    if (__clock_gettime (CLOCK_REALTIME, &result.current) != 0)
> > +      __libc_fatal ("Fatal error: clock_gettime failed\n");
> >    assert (result.current.tv_sec >= 0);
> >    return result;
> >  }
>
> I think it is a fair assumption that CLOCK_REALTIME is always supported, as it
> is also specific by POSIX.1-2017. It allows simplify it further and remove the
> libc_fatal fallback code.

OK, I will make that change (here and elsewhere).

...
> > -      __gettimeofday (&tv, NULL);
> > +      __clock_gettime (CLOCK_REALTIME, &rt);
> >
> >        /* Compute relative timeout.  */
> > -      rt.tv_sec = abstime->tv_sec - tv.tv_sec;
> > -      rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
> > +      rt.tv_sec = abstime->tv_sec - rt.tv_sec;
> > +      rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
> >        if (rt.tv_nsec < 0)
> >          {
> >            rt.tv_nsec += 1000000000;
>
> I think we can simplify it even more by adding a cancellable
> lll_futex_clock_wait_bitset variant

I would rather not do that in this patch set.

This patch in particular should be as mechanical a replacement of
(__)gettimeofday with __clock_gettime as possible, but also, this
patch *set* is supposed to be about groundwork for 64-bit time_t.
Adding a new lowlevellock function in order to tighten up code is too
much scope creep for my taste.

...
> >         /* Recompute the timeout time.  */
> > -       (void) __gettimeofday (&now, NULL);
> > -       timeout = end - (now.tv_sec * 1000 + (now.tv_usec + 500) / 1000);
> > +          __clock_gettime (CLOCK_REALTIME, &now);
> > +       timeout = end - ((now.tv_sec * 1000 +
> > +                            (now.tv_nsec + 500000) / 1000000));
> >       }
> >      }
> >
>
> Couldn't we use the support/timespec-* to operate with struct timespec
> along with a helper function to get get current time?

Similarly, although I think we probably _should_ add timespec_add,
timespec_sub, timespec_cmp functions to the public <time.h> API, as
well as using them internally, I do not want to do that in this patch set.

> static inline struct timespec
> timespec_now (void)
> {
>   struct timespec r;
>   __clock_gettime (CLOCK_REALTIME, &r);
>   return r;
> }

It is not obvious whether this function should use CLOCK_REALTIME or
CLOCK_MONOTONIC, so I do not think we should have it at all.

> >    /*
> >     * Figure out the "time", accounting for any time difference
> >     * with the server if necessary.
> >     */
> > -  __gettimeofday (&tval, (struct timezone *) NULL);
> > -  ad->ad_timestamp.tv_sec = tval.tv_sec + ad->ad_timediff.tv_sec;
> > -  ad->ad_timestamp.tv_usec = tval.tv_usec + ad->ad_timediff.tv_usec;
> > +  __clock_gettime (CLOCK_REALTIME, &now);
> > +  ad->ad_timestamp.tv_sec = now.tv_sec + ad->ad_timediff.tv_sec;
> > +  ad->ad_timestamp.tv_usec = (now.tv_nsec / 1000) + ad->ad_timediff.tv_usec;
> >    if (ad->ad_timestamp.tv_usec >= MILLION)
> >      {
> >        ad->ad_timestamp.tv_usec -= MILLION;
>
> Ok (I think we probably should handle overflow here).

I don't understand the parenthetical.  Are you saying that we already
do handle overflow and that's good, or that overflow handling needs to
be added?

> >      printf ("%s: %lld.%06d\n",
> > -            what, (long long int) tv.tv_sec, (int) tv.tv_usec);
> > +            what, (long long int) tv.tv_sec, (int) tv.tv_nsec / 1000);
> >    else
> >      printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n",
> >              what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
> > -            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec);
> > +            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_nsec / 1000);
...
> Same as Paul has said about printing timestamps.

OK, will change.

> > +# define GETTIME(low,high)                                              \
> > +  {                                                                     \
> > +    struct timespec now;                                                \
> > +    uint64_t usecs;                                                     \
> > +    __clock_gettime (CLOCK_REALTIME, &now);                             \
> > +    usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \
> > +    low = usecs & 0xffffffff;                                                   \
> > +    high = usecs >> 32;                                                         \
> >    }
> >  #endif
> >
>
> I think it should have a space after the cast type.

Then it wouldn't fit into 80 columns.

> > -  if (__gettimeofday (&elapsed, NULL) < 0)
> > +  if (__host_get_time (__mach_host_self (), (time_value_t *) &elapsed) < 0)
> >      return -1;
>
> Looks ok (I can't really check if Hurd change is fully correct though).

Oh, this is actually wrong, I need to change it to use an actual
time_value_t rather than type punning.  GCC 9 complains about it in
other places, dunno why not this one.

The construct

    __host_get_time (__mach_host_self (), &tvt)

seems to be Mach's equivalent of gettimeofday(), but I do not actually
know this any better than you do, I copied it out of the former
sysdeps/mach/gettimeofday.c.

> > -      if (__gettimeofday (&now, NULL) < 0)
> > +      if (__host_get_time (__mach_host_self (), (time_value_t *) &now) < 0)
> >       {
> >         __spin_unlock (&_hurd_itimer_lock);
> >         _hurd_critical_section_unlock (crit);
>
> Looks ok.

Similar issue with time_value_t vs struct timeval, will fix.

> > +# define timespec_sub(a, b, result)                                        \
> > +  do {                                                                             \
> > +    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                          \
> > +    (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec;                       \
> > +    if ((result)->tv_nsec < 0) {                                           \
> > +      --(result)->tv_sec;                                                  \
> > +      (result)->tv_nsec += 1000000000;                                             \
> > +    }                                                                              \
> > +  } while (0)
> > +
>
> As before, I would prefer to use the support/timerspec_* routines intead of
> reimplement them.

As before: would really rather not do that in this patch series.

> >  # define RANDOM_BITS(Var) \
> >      {                                                                         \
> > -      struct timeval tv;                                                      \
> > -      __gettimeofday (&tv, NULL);                                             \
> > -      (Var) = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;                      \
> > +      struct timespec ts;                                                     \
> > +      clock_gettime (CLOCK_REALTIME, &ts);                                    \
> > +      (Var) = ((uint64_t) tv.tv_nsec << 16) ^ tv.tv_sec;                      \
> >      }
> >  #endif
>
> It should be __clock_gettime.

Not here.  If you look at the whole file, this definition of
RANDOM_BITS is used only when _LIBC is *not* defined.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 03/12] Don’t use the argument to time.
  2019-08-21 12:29     ` Zack Weinberg
@ 2019-08-22  9:37       ` Rafal Luzynski
  0 siblings, 0 replies; 74+ messages in thread
From: Rafal Luzynski @ 2019-08-22  9:37 UTC (permalink / raw)
  To: Zack Weinberg, Adhemerval Zanella; +Cc: GNU C Library

21.08.2019 14:29 Zack Weinberg <zackw@panix.com> wrote:
> [...]
> I removed all of the non-ASCII characters from the commit message to
> avoid tangling these changes up with an unrelated policy question.

Thank you for this.

Regards,

Rafal

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 03/12] Don’t use the argument to time.
  2019-08-20 17:36     ` Joseph Myers
@ 2019-08-22  9:42       ` Rafal Luzynski
  2019-08-22  9:49         ` Florian Weimer
  0 siblings, 1 reply; 74+ messages in thread
From: Rafal Luzynski @ 2019-08-22  9:42 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Zack Weinberg, libc-alpha, Florian Weimer, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

20.08.2019 19:35 Joseph Myers <joseph@codesourcery.com> wrote:
> [...]
> Clearly such characters should be allowed in the names of committers, for 
> example.  We have the known and previously discussed bug in the commit 
> hooks that they mark glibc-cvs messages as text/plain; charset="us-ascii" 
> even when that's inaccurate, but I think that should be fixed in the 
> hooks.

I agree, I personally suffer from the same problem.  In fact, I have
3 non-ASCII characters in my name but long ago but I replace them with
ASCII characters even if computers nowadays are able to handle Unicode
(as we can see, that is not always true).  I would be happy if we could
allow all Unicode characters, at least extended Latin, my point is that
probably we have not yet achieved this ability.

Regards,

Rafal

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 03/12] Don’t use the argument to time.
  2019-08-22  9:42       ` Rafal Luzynski
@ 2019-08-22  9:49         ` Florian Weimer
  2019-08-23 20:26           ` Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time) Paul Eggert
  0 siblings, 1 reply; 74+ messages in thread
From: Florian Weimer @ 2019-08-22  9:49 UTC (permalink / raw)
  To: Rafal Luzynski
  Cc: Joseph Myers, Zack Weinberg, libc-alpha, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

* Rafal Luzynski:

> 20.08.2019 19:35 Joseph Myers <joseph@codesourcery.com> wrote:
>> [...]
>> Clearly such characters should be allowed in the names of committers, for 
>> example.  We have the known and previously discussed bug in the commit 
>> hooks that they mark glibc-cvs messages as text/plain; charset="us-ascii" 
>> even when that's inaccurate, but I think that should be fixed in the 
>> hooks.
>
> I agree, I personally suffer from the same problem.  In fact, I have
> 3 non-ASCII characters in my name but long ago but I replace them with
> ASCII characters even if computers nowadays are able to handle Unicode
> (as we can see, that is not always true).  I would be happy if we could
> allow all Unicode characters, at least extended Latin, my point is that
> probably we have not yet achieved this ability.

Many of us have committed patches with author names which contain
non-ASCII characters.  Using UTF-8 quotation marks in GCC error messages
in commit messages is common, too.  I think the issues we saw with
commit notifications are really minor.

So please feel free to spell your name in the way you want.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday.
  2019-08-20 18:06   ` Adhemerval Zanella
@ 2019-08-22 12:54     ` Zack Weinberg
  2019-08-23 17:49       ` Adhemerval Zanella
  0 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-22 12:54 UTC (permalink / raw)
  To: libc-alpha; +Cc: Adhemerval Zanella

On 8/20/19 2:06 PM, Adhemerval Zanella wrote:
> 
> 
> On 20/08/2019 10:21, Zack Weinberg wrote:
>> gettimeofday and settimeofday are obsolete in POSIX and will not be
>> provided by Linux for future new architectures.  The preferred
>> interfaces are clock_gettime and clock_settime.
>>
>> In preparation for implementing all the other time query/set
>> interfaces using clock_gettime and clock_settime, remove the
>> generic-Unix implementations of clock_gettime and clock_settime that
>> forwarded to gettimeofday and settimeofday.  Ports of glibc to
>> historic Unixes that provided these functions, but not clock_gettime
>> and clock_settime, are unlikely to be contributed anymore.
>>
>> The removed implementations *were* being used on the Hurd.
>> Deal with this by converting the Hurd gettimeofday and settimeofday
>> implementations into clock_gettime and clock_settime implementations,
>> respectively.  (They still only supply microsecond resolution.
>> I don’t know enough about Hurd/Mach to know whether nanosecond-
>> resolution clocks are even available.)  This means Hurd temporarily
>> has no implementation of gettimeofday or settimeofday; this will be
>> corrected in subsequent patches.  (glibc will not fail to build in the
>> i386-gnu configuration, but gettimeofday and settimeofday will be
>> ENOSYS stubs.)
> 
> I would prefer to avoid patch that might break the ABI, couldn't you
> attach this change with the one that fix it for Hurd as well?

The changes that fix this for Hurd are the "use clock_gettime to
implement gettimeofday" and "use clock_settime to implement
settimeofday" patches.  I think it will be easier to review the patch
series if I keep those separate, but I can reorganize it so that those
two patches happen immediately after this one, and squash them together
for final commit, does that plan work for you?

>>
>> 	* sysdeps/unix/clock_gettime.c, sysdeps/unix/clock_settime.c:
>>         Delete file.
>>         * sysdeps/mach/gettimeofday.c: Rename to .../clock_gettime.c
>>         and convert into an implementation of clock_gettime.
> 
> I would prefer to just use the full path (makes it more readable).
> 
>>         * sysdeps/mach/hurd/settimeofday.c: Rename to .../clock_settime.c
>>         and convert into an implementation of clock_settime.
> 
> Ditto.

Changed in my local copy.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime.
  2019-08-20 18:53   ` Paul Eggert
@ 2019-08-22 12:55     ` Zack Weinberg
  0 siblings, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-22 12:55 UTC (permalink / raw)
  To: Paul Eggert, libc-alpha
  Cc: Joseph Myers, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

On 8/20/19 2:53 PM, Paul Eggert wrote:
> Zack Weinberg wrote:
>> +      long int end = (now.tv_sec * 1000 + usectmo +
>> +                      (now.tv_nsec + 500000) / 1000000);
> 
> The usual GNU style is to put that trailing "+" at the start of the next
> line instead, here and elsewhere.

Thanks, will fix.  (I've been working a lot on code that uses the other
convention recently.)

>> -            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec);
>> +            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_nsec / 1000);
>>  }
> 
> Since the goal of this test code is to print the timestamp, the code
> should simply use %09d in the format and not divide by 1000.

Yeah, OK.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 04/12] Use clock_settime to implement stime.
  2019-08-21 15:10   ` Adhemerval Zanella
@ 2019-08-22 12:57     ` Zack Weinberg
  0 siblings, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-22 12:57 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha

On 8/21/19 11:10 AM, Adhemerval Zanella wrote:
> 
> 
> On 20/08/2019 10:21, Zack Weinberg wrote:
>> Unconditionally, on all ports, use clock_settime to implement stime,
>> not settimeofday or a direct syscall.
>>
>> Note that the former stub implementation of stime would return -1 with
>> errno set to EINVAL if passed a null pointer.  With this change, it
>> instead unconditionally dereferences the pointer, so any hypothetical
>> callers that passed NULL will now segfault.  I don’t think this will break
>> any non-contrived programs.
> 
> I agree that using a null point does not make sense, so I would also recommend
> to use __nonnull ((1)) on function prototype as well.

Good point, but I'm not going to make this change because instead I'm
going to add a patch to the series that demotes stime to a compatibility
symbol, so its public prototype will be removed.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 06/12] Use clock_gettime to implement time.
  2019-08-20 18:02   ` Adhemerval Zanella
@ 2019-08-22 12:58     ` Zack Weinberg
  0 siblings, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-22 12:58 UTC (permalink / raw)
  To: libc-alpha; +Cc: Adhemerval Zanella

On 8/20/19 2:02 PM, Adhemerval Zanella wrote:
>>  /* Return the time now, and store it in *TIMER if not NULL.  */
>>  time_t
>>  time (time_t *timer)
>>  {
>> -  __set_errno (ENOSYS);
>> +  struct timespec ts;
>> +  time_t res;
>>  
>> -  if (timer != NULL)
>> -    *timer = (time_t) -1;
>> -  return (time_t) -1;
>> +  if (__clock_gettime (CLOCK_REALTIME, &ts))
> 
> No implicit check. Also I think we can assume CLOCK_REALTIME support on
> all current architectures (including Hurd), so there is no actually need
> to check clock_gettime return value.

OK, will change.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 07/12] Use clock_gettime to implement ftime.
  2019-08-21 15:18   ` Adhemerval Zanella
@ 2019-08-22 12:59     ` Zack Weinberg
  0 siblings, 0 replies; 74+ messages in thread
From: Zack Weinberg @ 2019-08-22 12:59 UTC (permalink / raw)
  To: libc-alpha, Adhemerval Zanella

On 8/21/19 11:18 AM, Adhemerval Zanella wrote:
>> -  __set_errno (0);
>> -  if (time (&timebuf->time) == (time_t) -1 && errno != 0)
>> +  if (__clock_gettime (CLOCK_REALTIME, &ts) < 0)
>>      return -1;
> 
> I think we can assume CLOCK_REALTIME is always supported and &ts is always
> valid, so we can skip the test here.

Will change.

>> +  timebuf->time = ts.tv_sec;
>> +  timebuf->millitm = (ts.tv_nsec + 500000) / 1000000;
> 
> I think it is a fair assumption that kernel won't play foul here and give
> us invalid tv_nsec.

Yes, we already assume this in many other places.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 08/12] Use clock_gettime to implement gettimeofday.
  2019-08-20 15:24   ` Joseph Myers
@ 2019-08-22 13:01     ` Zack Weinberg
  2019-08-27 14:34       ` Arnd Bergmann
  0 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-22 13:01 UTC (permalink / raw)
  To: Joseph Myers
  Cc: libc-alpha, Florian Weimer, Lukasz Majewski, Alistair Francis,
	Stepan Golosunov, Arnd Bergmann

On 8/20/19 11:24 AM, Joseph Myers wrote:
> On Tue, 20 Aug 2019, Zack Weinberg wrote:
> 
>> __gettimeofday is no longer called by anyone, so remove its internal
>> prototype and its entries in Versions and .abilist files.  (It would
>> have been a GLIBC_PRIVATE symbol if the GLIBC_PRIVATE convention had
>> been invented back in the days of 2.0.)
> 
> That's not obviously safe. ... __gettimeofday is certainly the kind of symbol 
> that could have been used by a library with its own namespace concerns 
> (cf. past discussions of how we might enable libstdc++ to be 
> namespace-clean), although maybe more likely to have been used by an 
> application that should be using gettimeofday.

Ugh, OK, I'll put it back in the Versions file.

> Perhaps someone set up to do so could check large sets of current and past 
> distribution binaries for any reference to the __gettimeofday symbol in 
> executable / shared library dynamic symbol tables, as evidence for whether 
> such an ABI change is safe or not?

I don't think this is important enough to go to that much trouble.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument.
  2019-08-21 16:10       ` Florian Weimer
@ 2019-08-22 13:07         ` Zack Weinberg
  2019-08-23 13:05           ` Florian Weimer
  0 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-22 13:07 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Adhemerval Zanella, GNU C Library

On 8/21/19 12:10 PM, Florian Weimer wrote:
> * Zack Weinberg:
> 
>> I didn't look into it in any detail, but the uses of __warndecl +
>> __builtin_constant_p in bits/string2.h inlines all follow the pattern
>>
>>     __extern_always_inline T func (ptr)
>>     {
>>       if (__builtin_constant_p (ptr) && something_else_p (ptr))
>> __issue_warning ();
>>       ...
>>     }
>>
>> that is, issue a warning if ptr is a compile-time constant with some
>> property.  What we want for gettimeofday is just the opposite,
>>
>>     if (! (__builtin_constant_p (ptr) && ptr == NULL)) __issue_warning ();
>>
>> that is, warn whenever ptr is _not_ a compile-time NULL.  I wouldn't
>> be surprised if GCC's earliest unreachable-code removal passes, the
>> ones that happen early enough to prevent __attribute__((warning))
>> diagnostics from triggering, were tuned precisely for what
>> bits/string2.h does, and don't handle this inverse case properly.
> 
> I don't think this will work.  You would have to use something like
> this:
> 
>   __builtin_constant_p (ptr != NULL) && ptr != NULL
> 
> Otherwise you will produce a warning every time someone uses the
> gettimeofday wrapper in a function for which optimization has been
> disabled.

That is the behavior I was seeing when the wrapper was an extern inline,
but not when it is a macro.  I'm going to do more thorough testing.

Also, `__builtin_constant_p (ptr != NULL) && ptr != NULL` would warn
only for compile-time non-NULL, if I'm reading it right.  But in this
case we also want to issue a warning for any argument that isn't a
compile-time constant.  In other words, we want to warn for everything
_except_ compile-time NULL.  Hence `! (__builtin_constant_p (ptr) && ptr
== NULL)`.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 11/12] Linux/Alpha: don’t use timeval32 system calls.
  2019-08-21 18:50   ` Adhemerval Zanella
@ 2019-08-22 13:36     ` Zack Weinberg
  2019-08-23 18:48       ` Adhemerval Zanella
  0 siblings, 1 reply; 74+ messages in thread
From: Zack Weinberg @ 2019-08-22 13:36 UTC (permalink / raw)
  To: libc-alpha, Adhemerval Zanella

On 8/21/19 2:49 PM, Adhemerval Zanella wrote:

>> +__adjtimex_tv64 (struct timex *tx)
>> +{
>> +  return ADJTIMEX (tx);
>> +}
>>  
>>  libc_hidden_ver (__adjtimex_tv64, __adjtimex)
>>  strong_alias (__adjtimex_tv64, __adjtimex_tv64p);
> 
> I think you can just remove this file by adding
> 
> adjtimex       adjtime adjtimex        i:p     __adjtimex      __adjtimex@GLIBC_2.1 adjtimex@GLIBC_2.1
> 
> on sysdeps/unix/sysv/linux/alpha/syscalls.list.

Thanks for the suggestion.  I'll try it.

>> +  if (__adjtime (&itv64, &otv64))
>> +    return -1;
> 
> No implicit checks.

*sigh* Will change.

>> +int attribute_compat_text_section
>> +__adjtimex_tv32 (struct timex32 *tx)
>> +{
>> +  struct timex tx64;
>> +  memset (&tx64, 0, sizeof tx64);
> 
> Maybe struct timex tx64 = { 0 } ?

I would prefer to keep parallel structure with the treatment of `tx`
below; we cannot use an initializer for that.

>> +  if (TV64_TO_TV32 (&tx->time, &tx64.time))
>> +    {
>> +      __set_errno (EOVERFLOW);
>> +      return -1;
>> +    }
> 
> I am not sure it is correct to return EOVERFLOW for this pattern, because
> the side-effects of time adjustment will be visible after the call. The
> kernel (arch/alpha/kernel/osf_sys.c:1254) does not handle the overflow,
> so I think we just need to mimic the kernel for this (the caller will see
> the overflow in the returned value).

This (and other comments along these lines) make me realize we need to
have a design discussion about this patch's proposed semantics for Y2038
overflow, separate from the line-by-line review.

To facilitate this, I am going to split this patch from the larger
series and resubmit it separately, after making some changes to the
semantics, not necessarily the ones you asked for.

(Unfortunately, because gettimeofday is one of the affected symbols, the
larger patch series depends on this patch.  So we're going to have to
have the discussion now.)

>> +#ifndef _TV32_COMPAT_H
>> +#define _TV32_COMPAT_H 1
> 
> I personally prefer to prefix arch-specific header with the architectures
> initial to allow include-next (although this header specific does not
> actually require it).

I didn't do that in this case because I am expecting that this header
will be moved up to sysdeps/unix/sysv/linux or maybe even all the way to
sysdeps/posix as part of the larger Y2038 project.  We want to have
consistent overflow behavior on all architectures, after all.  The only
reason not to make it arch-generic right now is I haven't checked that
other 32-bit architectures' structure layouts match the ones used for
Linux/Alpha.

>> +struct rusage32
>> +{
>> +  struct timeval32 ru_utime;	/* user time used */
>> +  struct timeval32 ru_stime;	/* system time used */
>> +  long ru_maxrss;		/* maximum resident set size */
>> +  long ru_ixrss;		/* integral shared memory size */
>> +  long ru_idrss;		/* integral unshared data size */
>> +  long ru_isrss;		/* integral unshared stack size */
>> +  long ru_minflt;		/* page reclaims */
>> +  long ru_majflt;		/* page faults */
>> +  long ru_nswap;		/* swaps */
>> +  long ru_inblock;		/* block input operations */
>> +  long ru_oublock;		/* block output operations */
>> +  long ru_msgsnd;		/* messages sent */
>> +  long ru_msgrcv;		/* messages received */
>> +  long ru_nsignals;		/* signals received */
>> +  long ru_nvcsw;		/* voluntary context switches */
>> +  long ru_nivcsw;		/* involuntary " */
>> +};
> 
> s/long/long int/

Must we?  That will make it harder for people in the future to check
whether the structure matches the kernel headers' version.

>> +/* Conversion functions.  If the seconds field of a timeval32 would
>> +   overflow, they write { INT32_MAX, 0 } to the output and return -1;
>> +   otherwise they return 0.  */
>> +
>> +__extern_always_inline void
>> +TV32_TO_TV64 (struct timeval *restrict tv64,
>> +              const struct timeval32 *restrict tv32)
>> +{
>> +  tv64->tv_sec = tv32->tv_sec;
>> +  tv64->tv_usec = tv32->tv_usec;
>> +}
> 
> I think since it is an internal header and we explict build glibc with gnu11,
> use static inline should be suffice instead of __extern_always_inline.  Also,
> although it is not a rule, glibc uses capitalized names for macros definitions
> and default names for static inline functions.  The implementation looks ok.

I'm using capitalized names to match the convention established by
<sys/time.h>'s TIMEVAL_TO_TIMESPEC and friends.

I will switch to static inline.

> Use bool/_Bool so there is no need to use explicit check for the function
> use.  Same for TS64_TO_TV32 and RUSAGE64_TO_RUSAGE32.

I will also make this change.

zw

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument.
  2019-08-22 13:07         ` Zack Weinberg
@ 2019-08-23 13:05           ` Florian Weimer
  0 siblings, 0 replies; 74+ messages in thread
From: Florian Weimer @ 2019-08-23 13:05 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: Adhemerval Zanella, GNU C Library

* Zack Weinberg:

> On 8/21/19 12:10 PM, Florian Weimer wrote:
>> * Zack Weinberg:
>> 
>>> I didn't look into it in any detail, but the uses of __warndecl +
>>> __builtin_constant_p in bits/string2.h inlines all follow the pattern
>>>
>>>     __extern_always_inline T func (ptr)
>>>     {
>>>       if (__builtin_constant_p (ptr) && something_else_p (ptr))
>>> __issue_warning ();
>>>       ...
>>>     }
>>>
>>> that is, issue a warning if ptr is a compile-time constant with some
>>> property.  What we want for gettimeofday is just the opposite,
>>>
>>>     if (! (__builtin_constant_p (ptr) && ptr == NULL)) __issue_warning ();
>>>
>>> that is, warn whenever ptr is _not_ a compile-time NULL.  I wouldn't
>>> be surprised if GCC's earliest unreachable-code removal passes, the
>>> ones that happen early enough to prevent __attribute__((warning))
>>> diagnostics from triggering, were tuned precisely for what
>>> bits/string2.h does, and don't handle this inverse case properly.
>> 
>> I don't think this will work.  You would have to use something like
>> this:
>> 
>>   __builtin_constant_p (ptr != NULL) && ptr != NULL
>> 
>> Otherwise you will produce a warning every time someone uses the
>> gettimeofday wrapper in a function for which optimization has been
>> disabled.
>
> That is the behavior I was seeing when the wrapper was an extern inline,
> but not when it is a macro.  I'm going to do more thorough testing.

I don't think we should turn gettimeofday into a macro.  It's likely to
cause problems with some C++ wrapper libraries.

> Also, `__builtin_constant_p (ptr != NULL) && ptr != NULL` would warn
> only for compile-time non-NULL, if I'm reading it right.

Correct.

> But in this case we also want to issue a warning for any argument that
> isn't a compile-time constant.  In other words, we want to warn for
> everything _except_ compile-time NULL.  Hence `! (__builtin_constant_p
> (ptr) && ptr == NULL)`.

I think this is simply not possible because it will cause unpredictable
false positives.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday.
  2019-08-22 12:54     ` Zack Weinberg
@ 2019-08-23 17:49       ` Adhemerval Zanella
  0 siblings, 0 replies; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-23 17:49 UTC (permalink / raw)
  To: Zack Weinberg, libc-alpha



On 22/08/2019 09:54, Zack Weinberg wrote:
> On 8/20/19 2:06 PM, Adhemerval Zanella wrote:
>>
>>
>> On 20/08/2019 10:21, Zack Weinberg wrote:
>>> gettimeofday and settimeofday are obsolete in POSIX and will not be
>>> provided by Linux for future new architectures.  The preferred
>>> interfaces are clock_gettime and clock_settime.
>>>
>>> In preparation for implementing all the other time query/set
>>> interfaces using clock_gettime and clock_settime, remove the
>>> generic-Unix implementations of clock_gettime and clock_settime that
>>> forwarded to gettimeofday and settimeofday.  Ports of glibc to
>>> historic Unixes that provided these functions, but not clock_gettime
>>> and clock_settime, are unlikely to be contributed anymore.
>>>
>>> The removed implementations *were* being used on the Hurd.
>>> Deal with this by converting the Hurd gettimeofday and settimeofday
>>> implementations into clock_gettime and clock_settime implementations,
>>> respectively.  (They still only supply microsecond resolution.
>>> I don’t know enough about Hurd/Mach to know whether nanosecond-
>>> resolution clocks are even available.)  This means Hurd temporarily
>>> has no implementation of gettimeofday or settimeofday; this will be
>>> corrected in subsequent patches.  (glibc will not fail to build in the
>>> i386-gnu configuration, but gettimeofday and settimeofday will be
>>> ENOSYS stubs.)
>>
>> I would prefer to avoid patch that might break the ABI, couldn't you
>> attach this change with the one that fix it for Hurd as well?
> 
> The changes that fix this for Hurd are the "use clock_gettime to
> implement gettimeofday" and "use clock_settime to implement
> settimeofday" patches.  I think it will be easier to review the patch
> series if I keep those separate, but I can reorganize it so that those
> two patches happen immediately after this one, and squash them together
> for final commit, does that plan work for you?

I think it would better, thanks.

> 
>>>
>>> 	* sysdeps/unix/clock_gettime.c, sysdeps/unix/clock_settime.c:
>>>         Delete file.
>>>         * sysdeps/mach/gettimeofday.c: Rename to .../clock_gettime.c
>>>         and convert into an implementation of clock_gettime.
>>
>> I would prefer to just use the full path (makes it more readable).
>>
>>>         * sysdeps/mach/hurd/settimeofday.c: Rename to .../clock_settime.c
>>>         and convert into an implementation of clock_settime.
>>
>> Ditto.
> 
> Changed in my local copy.
> 
> zw
> 

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime.
  2019-08-21 21:09     ` Zack Weinberg
@ 2019-08-23 18:39       ` Adhemerval Zanella
  0 siblings, 0 replies; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-23 18:39 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: GNU C Library



On 21/08/2019 18:09, Zack Weinberg wrote:
> On Tue, Aug 20, 2019 at 4:56 PM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>> On 20/08/2019 10:21, Zack Weinberg wrote:
>>> Since gettimeofday will shortly be implemented in terms of
>>> clock_gettime on all platforms, internal code should use clock_gettime
>>> directly; in addition to removing a layer of indirection, this will
>>> allow us to remove the PLT-bypass gunk for gettimeofday.  In many
>>> cases, the changed code does fewer conversions.
> ...
>>>    if (__clock_gettime (CLOCK_MONOTONIC, &result.current) != 0)
>>> -    {
>>> -      struct timeval current_tv;
>>> -      if (__gettimeofday (&current_tv, NULL) == 0)
>>> -        __libc_fatal ("Fatal error: gettimeofday system call failed\n");
>>> -      result.current.tv_sec = current_tv.tv_sec;
>>> -      result.current.tv_nsec = current_tv.tv_usec * 1000;
>>> -    }
>>> +    if (__clock_gettime (CLOCK_REALTIME, &result.current) != 0)
>>> +      __libc_fatal ("Fatal error: clock_gettime failed\n");
>>>    assert (result.current.tv_sec >= 0);
>>>    return result;
>>>  }
>>
>> I think it is a fair assumption that CLOCK_REALTIME is always supported, as it
>> is also specific by POSIX.1-2017. It allows simplify it further and remove the
>> libc_fatal fallback code.
> 
> OK, I will make that change (here and elsewhere).
> 
> ...
>>> -      __gettimeofday (&tv, NULL);
>>> +      __clock_gettime (CLOCK_REALTIME, &rt);
>>>
>>>        /* Compute relative timeout.  */
>>> -      rt.tv_sec = abstime->tv_sec - tv.tv_sec;
>>> -      rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
>>> +      rt.tv_sec = abstime->tv_sec - rt.tv_sec;
>>> +      rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
>>>        if (rt.tv_nsec < 0)
>>>          {
>>>            rt.tv_nsec += 1000000000;
>>
>> I think we can simplify it even more by adding a cancellable
>> lll_futex_clock_wait_bitset variant
> 
> I would rather not do that in this patch set.
> 
> This patch in particular should be as mechanical a replacement of
> (__)gettimeofday with __clock_gettime as possible, but also, this
> patch *set* is supposed to be about groundwork for 64-bit time_t.
> Adding a new lowlevellock function in order to tighten up code is too
> much scope creep for my taste.

Alright, I think I will send it as a subsequent cleanup after this patch
has landed.


> 
> ...
>>>         /* Recompute the timeout time.  */
>>> -       (void) __gettimeofday (&now, NULL);
>>> -       timeout = end - (now.tv_sec * 1000 + (now.tv_usec + 500) / 1000);
>>> +          __clock_gettime (CLOCK_REALTIME, &now);
>>> +       timeout = end - ((now.tv_sec * 1000 +
>>> +                            (now.tv_nsec + 500000) / 1000000));
>>>       }
>>>      }
>>>
>>
>> Couldn't we use the support/timespec-* to operate with struct timespec
>> along with a helper function to get get current time?
> 
> Similarly, although I think we probably _should_ add timespec_add,
> timespec_sub, timespec_cmp functions to the public <time.h> API, as
> well as using them internally, I do not want to do that in this patch set.

In fact we are using them just for libsupport, my suggestion would be to
include them on libc internally to help on the clock_gettime usage. The
public inclusion on <time.h> should be in another discussion/patch.

> 
>> static inline struct timespec
>> timespec_now (void)
>> {
>>   struct timespec r;
>>   __clock_gettime (CLOCK_REALTIME, &r);
>>   return r;
>> }
> 
> It is not obvious whether this function should use CLOCK_REALTIME or
> CLOCK_MONOTONIC, so I do not think we should have it at all.

Alright, although I think we can still add the helper functions with a
different prototype:

static inline struct timespec
timespec_now_clockid (clockid_t clk_id)
{
  _Static_assert (clk_id == CLOCK_REALTIME);
  struct timespec r;
  __clock_gettime (clk_id, &r);
  return r;
}

static inline struct timespec
timespec_now_realtime (void)
{
  /* CLOCK_REALTIME is always support.  */
  return timespec_now_clockid (CLOCK_REALTIME);
}

This allows rule out usage with invalid clocks and simplify its usage
on most common cases.

> 
>>>    /*
>>>     * Figure out the "time", accounting for any time difference
>>>     * with the server if necessary.
>>>     */
>>> -  __gettimeofday (&tval, (struct timezone *) NULL);
>>> -  ad->ad_timestamp.tv_sec = tval.tv_sec + ad->ad_timediff.tv_sec;
>>> -  ad->ad_timestamp.tv_usec = tval.tv_usec + ad->ad_timediff.tv_usec;
>>> +  __clock_gettime (CLOCK_REALTIME, &now);
>>> +  ad->ad_timestamp.tv_sec = now.tv_sec + ad->ad_timediff.tv_sec;
>>> +  ad->ad_timestamp.tv_usec = (now.tv_nsec / 1000) + ad->ad_timediff.tv_usec;
>>>    if (ad->ad_timestamp.tv_usec >= MILLION)
>>>      {
>>>        ad->ad_timestamp.tv_usec -= MILLION;
>>
>> Ok (I think we probably should handle overflow here).
> 
> I don't understand the parenthetical.  Are you saying that we already
> do handle overflow and that's good, or that overflow handling needs to
> be added?

I tend to frown upon these kind of operations that blindly adjust values
without some sort of sanitization, but it might be the case where overflow
values can't happen or are not really an issue.   The 'ad_timediff' seems 
to be adjusted only at this place (other places seems to zero it), and
below there an explicit comment that y2038 might trigger an issue.  But
for a mechanical patch to replace gettimeoday I think the patch looks ok.

> 
>>>      printf ("%s: %lld.%06d\n",
>>> -            what, (long long int) tv.tv_sec, (int) tv.tv_usec);
>>> +            what, (long long int) tv.tv_sec, (int) tv.tv_nsec / 1000);
>>>    else
>>>      printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n",
>>>              what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
>>> -            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec);
>>> +            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_nsec / 1000);
> ...
>> Same as Paul has said about printing timestamps.
> 
> OK, will change.
> 
>>> +# define GETTIME(low,high)                                              \
>>> +  {                                                                     \
>>> +    struct timespec now;                                                \
>>> +    uint64_t usecs;                                                     \
>>> +    __clock_gettime (CLOCK_REALTIME, &now);                             \
>>> +    usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \
>>> +    low = usecs & 0xffffffff;                                                   \
>>> +    high = usecs >> 32;                                                         \
>>>    }
>>>  #endif
>>>
>>
>> I think it should have a space after the cast type.
> 
> Then it wouldn't fit into 80 columns.
> 
>>> -  if (__gettimeofday (&elapsed, NULL) < 0)
>>> +  if (__host_get_time (__mach_host_self (), (time_value_t *) &elapsed) < 0)
>>>      return -1;
>>
>> Looks ok (I can't really check if Hurd change is fully correct though).
> 
> Oh, this is actually wrong, I need to change it to use an actual
> time_value_t rather than type punning.  GCC 9 complains about it in
> other places, dunno why not this one.
> 
> The construct
> 
>     __host_get_time (__mach_host_self (), &tvt)
> 
> seems to be Mach's equivalent of gettimeofday(), but I do not actually
> know this any better than you do, I copied it out of the former
> sysdeps/mach/gettimeofday.c.

The information I could get is __host_get_time accessed an mmap area (similar
to vDSO) that contains the system time. And yeah, even though Hurd time_value_t
is a struct with similar layout of struct timeval, it is not really valid to
cast is on __host_get_time (struct timeval also defines as a tv_usec, which
is __suseconds_t/long int).

> 
>>> -      if (__gettimeofday (&now, NULL) < 0)
>>> +      if (__host_get_time (__mach_host_self (), (time_value_t *) &now) < 0)
>>>       {
>>>         __spin_unlock (&_hurd_itimer_lock);
>>>         _hurd_critical_section_unlock (crit);
>>
>> Looks ok.
> 
> Similar issue with time_value_t vs struct timeval, will fix.
> 
>>> +# define timespec_sub(a, b, result)                                        \
>>> +  do {                                                                             \
>>> +    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                          \
>>> +    (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec;                       \
>>> +    if ((result)->tv_nsec < 0) {                                           \
>>> +      --(result)->tv_sec;                                                  \
>>> +      (result)->tv_nsec += 1000000000;                                             \
>>> +    }                                                                              \
>>> +  } while (0)
>>> +
>>
>> As before, I would prefer to use the support/timerspec_* routines intead of
>> reimplement them.
> 
> As before: would really rather not do that in this patch series.

I understand you want the patch to mechanically as possible, however I also see
counterproductive to replicate a routine that we already have a better implemented
one in the same code base.  These additions tend to linger until someone actively
refactors it.

> 
>>>  # define RANDOM_BITS(Var) \
>>>      {                                                                         \
>>> -      struct timeval tv;                                                      \
>>> -      __gettimeofday (&tv, NULL);                                             \
>>> -      (Var) = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;                      \
>>> +      struct timespec ts;                                                     \
>>> +      clock_gettime (CLOCK_REALTIME, &ts);                                    \
>>> +      (Var) = ((uint64_t) tv.tv_nsec << 16) ^ tv.tv_sec;                      \
>>>      }
>>>  #endif
>>
>> It should be __clock_gettime.
> 
> Not here.  If you look at the whole file, this definition of
> RANDOM_BITS is used only when _LIBC is *not* defined.

Right, I think we should follow Wilco suggestion and just clean this file up
with onyl glibc definitions.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 11/12] Linux/Alpha: don’t use timeval32 system calls.
  2019-08-22 13:36     ` Zack Weinberg
@ 2019-08-23 18:48       ` Adhemerval Zanella
  0 siblings, 0 replies; 74+ messages in thread
From: Adhemerval Zanella @ 2019-08-23 18:48 UTC (permalink / raw)
  To: Zack Weinberg, libc-alpha, Florian Weimer



On 22/08/2019 10:36, Zack Weinberg wrote:
> On 8/21/19 2:49 PM, Adhemerval Zanella wrote:
> 
>>> +__adjtimex_tv64 (struct timex *tx)
>>> +{
>>> +  return ADJTIMEX (tx);
>>> +}
>>>  
>>>  libc_hidden_ver (__adjtimex_tv64, __adjtimex)
>>>  strong_alias (__adjtimex_tv64, __adjtimex_tv64p);
>>
>> I think you can just remove this file by adding
>>
>> adjtimex       adjtime adjtimex        i:p     __adjtimex      __adjtimex@GLIBC_2.1 adjtimex@GLIBC_2.1
>>
>> on sysdeps/unix/sysv/linux/alpha/syscalls.list.
> 
> Thanks for the suggestion.  I'll try it.
> 
>>> +  if (__adjtime (&itv64, &otv64))
>>> +    return -1;
>>
>> No implicit checks.
> 
> *sigh* Will change.
> 
>>> +int attribute_compat_text_section
>>> +__adjtimex_tv32 (struct timex32 *tx)
>>> +{
>>> +  struct timex tx64;
>>> +  memset (&tx64, 0, sizeof tx64);
>>
>> Maybe struct timex tx64 = { 0 } ?
> 
> I would prefer to keep parallel structure with the treatment of `tx`
> below; we cannot use an initializer for that.

Fair enough.

> 
>>> +  if (TV64_TO_TV32 (&tx->time, &tx64.time))
>>> +    {
>>> +      __set_errno (EOVERFLOW);
>>> +      return -1;
>>> +    }
>>
>> I am not sure it is correct to return EOVERFLOW for this pattern, because
>> the side-effects of time adjustment will be visible after the call. The
>> kernel (arch/alpha/kernel/osf_sys.c:1254) does not handle the overflow,
>> so I think we just need to mimic the kernel for this (the caller will see
>> the overflow in the returned value).
> 
> This (and other comments along these lines) make me realize we need to
> have a design discussion about this patch's proposed semantics for Y2038
> overflow, separate from the line-by-line review.
> 
> To facilitate this, I am going to split this patch from the larger
> series and resubmit it separately, after making some changes to the
> semantics, not necessarily the ones you asked for.
> 
> (Unfortunately, because gettimeofday is one of the affected symbols, the
> larger patch series depends on this patch.  So we're going to have to
> have the discussion now.)

Alright.

> 
>>> +#ifndef _TV32_COMPAT_H
>>> +#define _TV32_COMPAT_H 1
>>
>> I personally prefer to prefix arch-specific header with the architectures
>> initial to allow include-next (although this header specific does not
>> actually require it).
> 
> I didn't do that in this case because I am expecting that this header
> will be moved up to sysdeps/unix/sysv/linux or maybe even all the way to
> sysdeps/posix as part of the larger Y2038 project.  We want to have
> consistent overflow behavior on all architectures, after all.  The only
> reason not to make it arch-generic right now is I haven't checked that
> other 32-bit architectures' structure layouts match the ones used for
> Linux/Alpha.

Alright.

> 
>>> +struct rusage32
>>> +{
>>> +  struct timeval32 ru_utime;	/* user time used */
>>> +  struct timeval32 ru_stime;	/* system time used */
>>> +  long ru_maxrss;		/* maximum resident set size */
>>> +  long ru_ixrss;		/* integral shared memory size */
>>> +  long ru_idrss;		/* integral unshared data size */
>>> +  long ru_isrss;		/* integral unshared stack size */
>>> +  long ru_minflt;		/* page reclaims */
>>> +  long ru_majflt;		/* page faults */
>>> +  long ru_nswap;		/* swaps */
>>> +  long ru_inblock;		/* block input operations */
>>> +  long ru_oublock;		/* block output operations */
>>> +  long ru_msgsnd;		/* messages sent */
>>> +  long ru_msgrcv;		/* messages received */
>>> +  long ru_nsignals;		/* signals received */
>>> +  long ru_nvcsw;		/* voluntary context switches */
>>> +  long ru_nivcsw;		/* involuntary " */
>>> +};
>>
>> s/long/long int/
> 
> Must we?  That will make it harder for people in the future to check
> whether the structure matches the kernel headers' version.

This is the feedback I got from Florian on my 'Refactor sigcontextinfo.h'
patch where I also copied some struct definition from kernel. I think 
we should follow GNU code convention even for such cases.

> 
>>> +/* Conversion functions.  If the seconds field of a timeval32 would
>>> +   overflow, they write { INT32_MAX, 0 } to the output and return -1;
>>> +   otherwise they return 0.  */
>>> +
>>> +__extern_always_inline void
>>> +TV32_TO_TV64 (struct timeval *restrict tv64,
>>> +              const struct timeval32 *restrict tv32)
>>> +{
>>> +  tv64->tv_sec = tv32->tv_sec;
>>> +  tv64->tv_usec = tv32->tv_usec;
>>> +}
>>
>> I think since it is an internal header and we explict build glibc with gnu11,
>> use static inline should be suffice instead of __extern_always_inline.  Also,
>> although it is not a rule, glibc uses capitalized names for macros definitions
>> and default names for static inline functions.  The implementation looks ok.
> 
> I'm using capitalized names to match the convention established by
> <sys/time.h>'s TIMEVAL_TO_TIMESPEC and friends.
> 
> I will switch to static inline.
> 
>> Use bool/_Bool so there is no need to use explicit check for the function
>> use.  Same for TS64_TO_TV32 and RUSAGE64_TO_RUSAGE32.
> 
> I will also make this change.
> 
> zw
> 

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time)
  2019-08-22  9:49         ` Florian Weimer
@ 2019-08-23 20:26           ` Paul Eggert
  2019-08-23 20:49             ` Joseph Myers
                               ` (2 more replies)
  0 siblings, 3 replies; 74+ messages in thread
From: Paul Eggert @ 2019-08-23 20:26 UTC (permalink / raw)
  To: Florian Weimer, Rafal Luzynski
  Cc: Joseph Myers, Zack Weinberg, libc-alpha, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

[-- Attachment #1: Type: text/plain, Size: 999 bytes --]

On 8/22/19 2:49 AM, Florian Weimer wrote:
> please feel free to spell your name in the way you want.

Yes, I went through Emacs ChangeLog files a while ago and fixed many spellings 
of names that had been ASCIIfied under the assumption that it was problematic to 
put non-UTF8 characters in text files. It's only polite for us to spell our 
contributors' names correctly, so I installed the attached patch to try to do a 
better job with glibc contributor names too. Because the patch has mixed 
encodings I compressed it; you may need special settings to read it, but it 
works fine with Git.

A few of our recent contributors (Rafael Ávila de Espíndola, Uroš Bizjak, 
Alexandra Hájková, István Kurucsai, Rafał Łużyński) use their natively-spelled 
names sometimes and their ASCIIfied names at other times, and it's conceivable 
that they prefer their names to be ASCIIfied when used in English text so I'll 
ask them before adjusting their names in the glibc commentary.

[-- Attachment #2: 0001-Fix-spellings-of-contributor-names-in-comments-and-d.patch.gz --]
[-- Type: application/gzip, Size: 15103 bytes --]

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time)
  2019-08-23 20:26           ` Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time) Paul Eggert
@ 2019-08-23 20:49             ` Joseph Myers
  2019-08-23 20:51               ` Joseph Myers
  2019-08-23 22:07             ` Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time) Rafal Luzynski
  2019-08-26 14:42             ` Spelling of contributor names Stefan Liebler
  2 siblings, 1 reply; 74+ messages in thread
From: Joseph Myers @ 2019-08-23 20:49 UTC (permalink / raw)
  To: Paul Eggert
  Cc: Florian Weimer, Rafal Luzynski, Zack Weinberg, libc-alpha,
	Lukasz Majewski, Alistair Francis, Stepan Golosunov,
	Arnd Bergmann

On Fri, 23 Aug 2019, Paul Eggert wrote:

> Yes, I went through Emacs ChangeLog files a while ago and fixed many spellings
> of names that had been ASCIIfied under the assumption that it was problematic
> to put non-UTF8 characters in text files. It's only polite for us to spell our
> contributors' names correctly, so I installed the attached patch to try to do
> a better job with glibc contributor names too. Because the patch has mixed
> encodings I compressed it; you may need special settings to read it, but it
> works fine with Git.

This patch changes several *installed* MIPS headers.  As per 
<https://sourceware.org/ml/libc-alpha/2019-03/msg00293.html> and thread, 
we need to limit installed headers to pure ASCII so they work for 
compilations with any -finput-charset= setting.  So please revert the 
changes to sysdeps/mips/fpu_control.h, sysdeps/mips/regdef.h, 
sysdeps/mips/sgidefs.h, sysdeps/mips/sys/asm.h, sysdeps/mips/sys/regdef.h 
and sysdeps/unix/sysv/linux/mips/sys/user.h, or add the contributors in 
question to contrib.texi and remove the Contributed by lines from the 
headers.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time)
  2019-08-23 20:49             ` Joseph Myers
@ 2019-08-23 20:51               ` Joseph Myers
  2019-08-23 21:28                 ` Paul Eggert
  0 siblings, 1 reply; 74+ messages in thread
From: Joseph Myers @ 2019-08-23 20:51 UTC (permalink / raw)
  To: Paul Eggert
  Cc: Florian Weimer, Rafal Luzynski, Zack Weinberg, libc-alpha,
	Lukasz Majewski, Alistair Francis, Stepan Golosunov,
	Arnd Bergmann

On Fri, 23 Aug 2019, Joseph Myers wrote:

> and sysdeps/unix/sysv/linux/mips/sys/user.h, or add the contributors in 
> question to contrib.texi and remove the Contributed by lines from the 
> headers.

(While we want to move away from Contributed by lines and put those 
credits in contrib.texi instead, removal isn't an option when the name 
appears in a copyright notice rather than a Contributed by line, which 
applies in at least one case.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time)
  2019-08-23 20:51               ` Joseph Myers
@ 2019-08-23 21:28                 ` Paul Eggert
  2019-08-24  5:58                   ` Spelling of contributor names Florian Weimer
  0 siblings, 1 reply; 74+ messages in thread
From: Paul Eggert @ 2019-08-23 21:28 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Florian Weimer, Rafal Luzynski, Zack Weinberg, libc-alpha,
	Lukasz Majewski, Alistair Francis, Stepan Golosunov,
	Arnd Bergmann

[-- Attachment #1: Type: text/plain, Size: 789 bytes --]

Joseph Myers wrote:
> (While we want to move away from Contributed by lines and put those
> credits in contrib.texi instead, removal isn't an option when the name
> appears in a copyright notice rather than a Contributed by line, which
> applies in at least one case.)

Yes, thanks for mentioning these glitches. I installed the attached to fix them.

I'm afraid we're stuck with the ASCIIfied spellings in the old copyright notice 
in sysdeps/unix/sysv/linux/mips/sys/user.h, as 
<https://sourceware.org/ml/libc-alpha/2019-03/msg00293.html> says the file must 
be ASCII, and the file's copyright notice requires that we keep the 
contributors' names. This is merely an annoyance of course, and I assume any 
future contributors in this situation won't mind ASCIIfying their names either.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Don-t-put-non-ASCII-into-installed-headers.patch --]
[-- Type: text/x-patch; name="0001-Don-t-put-non-ASCII-into-installed-headers.patch", Size: 5125 bytes --]

From 1bced8cadc82077f0201801239e89eb24b68e9aa Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 23 Aug 2019 14:14:29 -0700
Subject: [PATCH] Don't put non-ASCII into installed headers

Move non-ASCII contributor names from installed headers
into contrib.texi when possible, and when it's not (the
copyright notice in sysdeps/unix/sysv/linux/mips/sys/user.h)
go back to ASCIIfied names.  Problem reported by Joseph Myers in:
https://www.sourceware.org/ml/libc-alpha/2019-08/msg00646.html
---
 manual/contrib.texi                     | 9 +++++++++
 sysdeps/mips/fpu_control.h              | 1 -
 sysdeps/mips/regdef.h                   | 1 -
 sysdeps/mips/sgidefs.h                  | 1 -
 sysdeps/mips/sys/asm.h                  | 1 -
 sysdeps/mips/sys/regdef.h               | 1 -
 sysdeps/unix/sysv/linux/mips/sys/user.h | 4 ++--
 7 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/manual/contrib.texi b/manual/contrib.texi
index 47fdd59ffe..b04724b7b5 100644
--- a/manual/contrib.texi
+++ b/manual/contrib.texi
@@ -29,6 +29,11 @@ as FSF Project Steward for @theglibc{}.
 Miles Bader for writing the @code{argp} argument-parsing package, and the
 @code{argz}/@code{envz} interfaces.
 
+@item
+Ralf B@"achle for contributing @file{fpu_control.h},
+@file{regdef.h}, @file{sgidefs.h}, @file{sys/asm.h}, and @file{sys/regdef.h}
+under the @file{sysdeps/mips} directory.
+
 @item
 Jeff Bailey for his maintainership of the HPPA architecture.
 
@@ -131,6 +136,10 @@ Tulio Magno Quites Machado Filho for adding a new class of installed
 headers for low-level platform-specific functionality and one such for
 PowerPC and various fixes.
 
+@item
+Olaf Flebbe and Ralf B@"achle for contributing
+@file{sysdeps/mips/fpu_control.h}.
+
 @item
 Mike Frysinger for his maintaining of the IA64 architecture and for
 testing and bug fixing.
diff --git a/sysdeps/mips/fpu_control.h b/sysdeps/mips/fpu_control.h
index 6a68f92830..f8c834a0a7 100644
--- a/sysdeps/mips/fpu_control.h
+++ b/sysdeps/mips/fpu_control.h
@@ -1,7 +1,6 @@
 /* FPU control word bits.  Mips version.
    Copyright (C) 1996-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Olaf Flebbe and Ralf Bächle.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
diff --git a/sysdeps/mips/regdef.h b/sysdeps/mips/regdef.h
index 6d55f8a18d..62652864fc 100644
--- a/sysdeps/mips/regdef.h
+++ b/sysdeps/mips/regdef.h
@@ -1,6 +1,5 @@
 /* Copyright (C) 1994-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ralf Bächle <ralf@gnu.org>.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
diff --git a/sysdeps/mips/sgidefs.h b/sysdeps/mips/sgidefs.h
index 656a7f07f7..ad45dceb19 100644
--- a/sysdeps/mips/sgidefs.h
+++ b/sysdeps/mips/sgidefs.h
@@ -1,6 +1,5 @@
 /* Copyright (C) 1996-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ralf Bächle <ralf@gnu.org>.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
diff --git a/sysdeps/mips/sys/asm.h b/sysdeps/mips/sys/asm.h
index 8161495595..3a04974a76 100644
--- a/sysdeps/mips/sys/asm.h
+++ b/sysdeps/mips/sys/asm.h
@@ -1,6 +1,5 @@
 /* Copyright (C) 1997-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ralf Bächle <ralf@gnu.org>.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
diff --git a/sysdeps/mips/sys/regdef.h b/sysdeps/mips/sys/regdef.h
index 1c6be23ba3..2b53e6dbb9 100644
--- a/sysdeps/mips/sys/regdef.h
+++ b/sysdeps/mips/sys/regdef.h
@@ -1,6 +1,5 @@
 /* Copyright (C) 1997-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ralf Bächle <ralf@gnu.org>.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
diff --git a/sysdeps/unix/sysv/linux/mips/sys/user.h b/sysdeps/unix/sysv/linux/mips/sys/user.h
index ef1077da52..29a6c36785 100644
--- a/sysdeps/unix/sysv/linux/mips/sys/user.h
+++ b/sysdeps/unix/sysv/linux/mips/sys/user.h
@@ -41,7 +41,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 1995, 1999 by Ralf Bächle
+ * Copyright (C) 1995, 1999 by Ralf Baechle
  */
 #ifndef __ASM_MIPS_REG_H
 #define __ASM_MIPS_REG_H
@@ -110,7 +110,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 1995, 1999 Ralf Bächle
+ * Copyright (C) 1995, 1999 Ralf Baechle
  * Copyright (C) 1995, 1999 Silicon Graphics
  */
 #ifndef _ASM_REG_H
-- 
2.17.1


^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time)
  2019-08-23 20:26           ` Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time) Paul Eggert
  2019-08-23 20:49             ` Joseph Myers
@ 2019-08-23 22:07             ` Rafal Luzynski
  2019-08-23 22:31               ` Paul Eggert
  2019-08-26 14:42             ` Spelling of contributor names Stefan Liebler
  2 siblings, 1 reply; 74+ messages in thread
From: Rafal Luzynski @ 2019-08-23 22:07 UTC (permalink / raw)
  To: Paul Eggert, Florian Weimer
  Cc: Joseph Myers, Zack Weinberg, libc-alpha, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

23.08.2019 22:26 Paul Eggert <eggert@cs.ucla.edu> wrote:
> [...]
> A few of our recent contributors (Rafael Ávila de Espíndola, Uroš Bizjak, 
> Alexandra Hájková, István Kurucsai, Rafał Łużyński) use their
> natively-spelled 
> names sometimes and their ASCIIfied names at other times, and it's
> conceivable 
> that they prefer their names to be ASCIIfied when used in English text so
> I'll 
> ask them before adjusting their names in the glibc commentary.

I have already replied off-list but now I think it should be said in public:
my name is misspelled here so please don't take it as a correct example.

Now one more issue: do I assume correctly that this idea is limited only to
Latin alphabets?  What about Cyrillic or Greek?  What about Asian alphabets?

Regards,

Rafał

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time)
  2019-08-23 22:07             ` Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time) Rafal Luzynski
@ 2019-08-23 22:31               ` Paul Eggert
  0 siblings, 0 replies; 74+ messages in thread
From: Paul Eggert @ 2019-08-23 22:31 UTC (permalink / raw)
  To: Rafal Luzynski, Florian Weimer
  Cc: Joseph Myers, Zack Weinberg, libc-alpha, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov, Arnd Bergmann

Rafal Luzynski wrote:
> my name is misspelled here so please don't take it as a correct example.

Yes, sorry about that; as I mentioned privately, I got the wrong spelling by 
mistakenly lifting it from a web page about someone else who I thought was you 
but who spells their name with different accents.

> Now one more issue: do I assume correctly that this idea is limited only to
> Latin alphabets?

Yes, the glibc source code is in English so its text should use spelling 
preferred for an English-language audience. Although the audience can't grok 
names written in Cyrillic, Greek, Kanji, etc., it can grok Latin letters with 
accents.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: Spelling of contributor names
  2019-08-23 21:28                 ` Paul Eggert
@ 2019-08-24  5:58                   ` Florian Weimer
  2019-08-25  0:56                     ` Paul Eggert
  0 siblings, 1 reply; 74+ messages in thread
From: Florian Weimer @ 2019-08-24  5:58 UTC (permalink / raw)
  To: Paul Eggert
  Cc: Joseph Myers, Rafal Luzynski, Zack Weinberg, libc-alpha,
	Lukasz Majewski, Alistair Francis, Stepan Golosunov,
	Arnd Bergmann

* Paul Eggert:

> Joseph Myers wrote:
>> (While we want to move away from Contributed by lines and put those
>> credits in contrib.texi instead, removal isn't an option when the name
>> appears in a copyright notice rather than a Contributed by line, which
>> applies in at least one case.)
>
> Yes, thanks for mentioning these glitches. I installed the attached
> to fix them.
>
> I'm afraid we're stuck with the ASCIIfied spellings in the old
> copyright notice in sysdeps/unix/sysv/linux/mips/sys/user.h, as
> <https://sourceware.org/ml/libc-alpha/2019-03/msg00293.html> says
> the file must be ASCII, and the file's copyright notice requires
> that we keep the contributors' names. This is merely an annoyance of
> course, and I assume any future contributors in this situation won't
> mind ASCIIfying their names either.

Please restore the Contributed By lines as well.  We should not
discriminate against authors based on the preferred spelling of their
names.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: Spelling of contributor names
  2019-08-24  5:58                   ` Spelling of contributor names Florian Weimer
@ 2019-08-25  0:56                     ` Paul Eggert
  2019-08-27 15:58                       ` Joseph Myers
  0 siblings, 1 reply; 74+ messages in thread
From: Paul Eggert @ 2019-08-25  0:56 UTC (permalink / raw)
  To: Florian Weimer
  Cc: Joseph Myers, Rafal Luzynski, Zack Weinberg, libc-alpha,
	Lukasz Majewski, Alistair Francis, Stepan Golosunov,
	Arnd Bergmann

Florian Weimer wrote:
> Please restore the Contributed By lines as well.  We should not
> discriminate against authors based on the preferred spelling of their
> names.

I don't see that discrimination, as the policy (as I understand it) is that 
"Contributed by" is obsolete and it's fine to move the information involved to 
contrib.texi whenever convenient. If I'm understanding the policy incorrectly, 
please let me know.

It wouldn't be hard to move all the "Contributed by" info to contrib.texi. Would 
that suffice to allay any concerns about discrimination?

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: Spelling of contributor names
  2019-08-23 20:26           ` Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time) Paul Eggert
  2019-08-23 20:49             ` Joseph Myers
  2019-08-23 22:07             ` Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time) Rafal Luzynski
@ 2019-08-26 14:42             ` Stefan Liebler
  2 siblings, 0 replies; 74+ messages in thread
From: Stefan Liebler @ 2019-08-26 14:42 UTC (permalink / raw)
  To: libc-alpha

On 8/23/19 10:26 PM, Paul Eggert wrote:
> On 8/22/19 2:49 AM, Florian Weimer wrote:
>> please feel free to spell your name in the way you want.
> 
> Yes, I went through Emacs ChangeLog files a while ago and fixed many 
> spellings of names that had been ASCIIfied under the assumption that it 
> was problematic to put non-UTF8 characters in text files. It's only 
> polite for us to spell our contributors' names correctly, so I installed 
> the attached patch to try to do a better job with glibc contributor 
> names too. Because the patch has mixed encodings I compressed it; you 
> may need special settings to read it, but it works fine with Git.
> 
> A few of our recent contributors (Rafael Ávila de Espíndola, Uroš 
> Bizjak, Alexandra Hájková, István Kurucsai, Rafał Łużyński) use their 
> natively-spelled names sometimes and their ASCIIfied names at other 
> times, and it's conceivable that they prefer their names to be ASCIIfied 
> when used in English text so I'll ask them before adjusting their names 
> in the glibc commentary.

Hi,

after this change, the testcase posix/tst-regex is failing!
Please have a look at my proposed patch "[PATCH] Fix posix/tst-regex by 
using ISO-8859 encoding for ChangeLog.8." 
(https://www.sourceware.org/ml/libc-alpha/2019-08/msg00658.html)

Bye
Stefan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: [PATCH 08/12] Use clock_gettime to implement gettimeofday.
  2019-08-22 13:01     ` Zack Weinberg
@ 2019-08-27 14:34       ` Arnd Bergmann
  0 siblings, 0 replies; 74+ messages in thread
From: Arnd Bergmann @ 2019-08-27 14:34 UTC (permalink / raw)
  To: Zack Weinberg
  Cc: Joseph Myers, GNU C Library, Florian Weimer, Lukasz Majewski,
	Alistair Francis, Stepan Golosunov

On Thu, Aug 22, 2019 at 3:01 PM Zack Weinberg <zackw@panix.com> wrote:
>
> On 8/20/19 11:24 AM, Joseph Myers wrote:
> > On Tue, 20 Aug 2019, Zack Weinberg wrote:
> >
> >> __gettimeofday is no longer called by anyone, so remove its internal
> >> prototype and its entries in Versions and .abilist files.  (It would
> >> have been a GLIBC_PRIVATE symbol if the GLIBC_PRIVATE convention had
> >> been invented back in the days of 2.0.)
> >
> > That's not obviously safe. ... __gettimeofday is certainly the kind of symbol
> > that could have been used by a library with its own namespace concerns
> > (cf. past discussions of how we might enable libstdc++ to be
> > namespace-clean), although maybe more likely to have been used by an
> > application that should be using gettimeofday.
>
> Ugh, OK, I'll put it back in the Versions file.
>
> > Perhaps someone set up to do so could check large sets of current and past
> > distribution binaries for any reference to the __gettimeofday symbol in
> > executable / shared library dynamic symbol tables, as evidence for whether
> > such an ABI change is safe or not?
>
> I don't think this is important enough to go to that much trouble.

I had a quick look at debian code search and found a few hundred
copies of the glibc tempname.c:
https://codesearch.debian.net/show?file=parted_3.2-25%2Flib%2Ftempname.c&line=67

Then there are a few other references like faketime that try to
override gettimeofday in some form:
https://codesearch.debian.net/show?file=faketime_0.9.7-3%2Fsrc%2Flibfaketime.c&line=1679
https://codesearch.debian.net/show?file=datefudge_1.23%2Fdatefudge.c&line=69
https://codesearch.debian.net/show?file=cyrus-imapd_3.0.11-1%2Fcunit%2Ftimeofday.c&line=195

       Arnd

^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: Spelling of contributor names
  2019-08-25  0:56                     ` Paul Eggert
@ 2019-08-27 15:58                       ` Joseph Myers
  0 siblings, 0 replies; 74+ messages in thread
From: Joseph Myers @ 2019-08-27 15:58 UTC (permalink / raw)
  To: Paul Eggert
  Cc: Florian Weimer, Rafal Luzynski, Zack Weinberg, libc-alpha,
	Lukasz Majewski, Alistair Francis, Stepan Golosunov,
	Arnd Bergmann

On Sat, 24 Aug 2019, Paul Eggert wrote:

> It wouldn't be hard to move all the "Contributed by" info to contrib.texi.
> Would that suffice to allay any concerns about discrimination?

I think it should all go in the manual.  (Where people already have 
entries in contrib.texi, those may or may not sufficiently cover all the 
areas in which they have contributed.)

*But* the information in the manual should generally describe the logical 
areas in which someone contributed, not the names of particular files.  
("contributions to the MIPS port", for example, would seem a better 
description in the case currently under discussion.)  The details at the 
per-file level are covered by the ChangeLog files.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 74+ messages in thread

end of thread, other threads:[~2019-08-27 15:58 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-20 13:22 [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Zack Weinberg
2019-08-20 13:21 ` [PATCH 03/12] Don’t use the argument to time Zack Weinberg
2019-08-20 17:09   ` Rafal Luzynski
2019-08-20 17:21     ` Zack Weinberg
2019-08-20 17:36     ` Joseph Myers
2019-08-22  9:42       ` Rafal Luzynski
2019-08-22  9:49         ` Florian Weimer
2019-08-23 20:26           ` Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time) Paul Eggert
2019-08-23 20:49             ` Joseph Myers
2019-08-23 20:51               ` Joseph Myers
2019-08-23 21:28                 ` Paul Eggert
2019-08-24  5:58                   ` Spelling of contributor names Florian Weimer
2019-08-25  0:56                     ` Paul Eggert
2019-08-27 15:58                       ` Joseph Myers
2019-08-23 22:07             ` Spelling of contributor names (was: [PATCH 03/12] Don’t use the argument to time) Rafal Luzynski
2019-08-23 22:31               ` Paul Eggert
2019-08-26 14:42             ` Spelling of contributor names Stefan Liebler
2019-08-20 18:08   ` [PATCH 03/12] Don’t use the argument to time Adhemerval Zanella
2019-08-21 12:29     ` Zack Weinberg
2019-08-22  9:37       ` Rafal Luzynski
2019-08-20 13:22 ` [PATCH 04/12] Use clock_settime to implement stime Zack Weinberg
2019-08-21 15:10   ` Adhemerval Zanella
2019-08-22 12:57     ` Zack Weinberg
2019-08-20 13:22 ` [PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime Zack Weinberg
2019-08-20 18:53   ` Paul Eggert
2019-08-22 12:55     ` Zack Weinberg
2019-08-20 20:56   ` Adhemerval Zanella
2019-08-21 21:09     ` Zack Weinberg
2019-08-23 18:39       ` Adhemerval Zanella
2019-08-20 13:22 ` [PATCH 12/12] Revise the documentation of ‘simple calendar time’ Zack Weinberg
2019-08-20 18:50   ` Paul Eggert
2019-08-20 19:38     ` Joseph Myers
2019-08-20 19:55       ` Zack Weinberg
2019-08-20 20:19     ` Zack Weinberg
2019-08-20 20:23       ` Zack Weinberg
2019-08-20 13:22 ` [PATCH 01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday Zack Weinberg
2019-08-20 18:06   ` Adhemerval Zanella
2019-08-22 12:54     ` Zack Weinberg
2019-08-23 17:49       ` Adhemerval Zanella
2019-08-20 13:22 ` [PATCH 05/12] Use clock_settime to implement settimeofday Zack Weinberg
2019-08-20 13:22 ` [PATCH 09/12] Finish move of clock_* functions to libc Zack Weinberg
2019-08-20 15:13   ` Joseph Myers
2019-08-20 15:19     ` Zack Weinberg
2019-08-20 15:21     ` Florian Weimer
2019-08-20 15:25       ` Zack Weinberg
2019-08-20 13:37 ` [PATCH 11/12] Linux/Alpha: don’t use timeval32 system calls Zack Weinberg
2019-08-21 18:50   ` Adhemerval Zanella
2019-08-22 13:36     ` Zack Weinberg
2019-08-23 18:48       ` Adhemerval Zanella
2019-08-20 13:37 ` [PATCH 06/12] Use clock_gettime to implement time Zack Weinberg
2019-08-20 18:02   ` Adhemerval Zanella
2019-08-22 12:58     ` Zack Weinberg
2019-08-20 13:37 ` [PATCH 08/12] Use clock_gettime to implement gettimeofday Zack Weinberg
2019-08-20 15:24   ` Joseph Myers
2019-08-22 13:01     ` Zack Weinberg
2019-08-27 14:34       ` Arnd Bergmann
2019-08-20 17:51   ` Adhemerval Zanella
2019-08-20 13:37 ` [PATCH 07/12] Use clock_gettime to implement ftime Zack Weinberg
2019-08-21 15:18   ` Adhemerval Zanella
2019-08-22 12:59     ` Zack Weinberg
2019-08-20 13:56 ` [PATCH 10/12] Warn when gettimeofday is called with non-null tzp argument Zack Weinberg
2019-08-20 18:52   ` Paul Eggert
2019-08-20 19:03     ` Zack Weinberg
2019-08-20 19:06       ` Paul Eggert
2019-08-21 15:30   ` Adhemerval Zanella
2019-08-21 16:03     ` Zack Weinberg
2019-08-21 16:10       ` Florian Weimer
2019-08-22 13:07         ` Zack Weinberg
2019-08-23 13:05           ` Florian Weimer
2019-08-20 15:10 ` [PATCH 00/12] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions Joseph Myers
2019-08-20 15:21   ` Zack Weinberg
2019-08-20 18:47 ` Alistair Francis
2019-08-20 18:55 ` Paul Eggert
2019-08-21  8:00 ` Lukasz Majewski

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).