public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org, Bruno Haible <bruno@clisp.org>,
	Florian Weimer <fweimer@redhat.com>
Subject: [PATCH] time: Use CLOCK_REALTIME for time (BZ #30200)
Date: Mon,  6 Mar 2023 13:03:21 -0300	[thread overview]
Message-ID: <20230306160321.2942372-1-adhemerval.zanella@linaro.org> (raw)

Different than gettimeofday and timespec_get, time uses
CLOCK_REALTIME_COARSE instead of CLOCK_REALTIME on Linux.  The
coarse time is used mostly as optimization, but it may show
divergence progression due the clock resolution.

For x86_64 and powerpc64, it should add slight more latency since
it would call now clock_gettime internally.

Checked on x86_64-linux-gnu.
---
 include/time.h                           |  5 ++-
 manual/time.texi                         |  4 +--
 sysdeps/generic/time-clockid.h           | 20 ------------
 sysdeps/mach/hurd/bits/errno.h           |  1 -
 sysdeps/unix/sysv/linux/dl-vdso-setup.c  |  3 --
 sysdeps/unix/sysv/linux/dl-vdso-setup.h  |  3 --
 sysdeps/unix/sysv/linux/i386/sysdep.h    |  1 -
 sysdeps/unix/sysv/linux/powerpc/sysdep.h |  1 -
 sysdeps/unix/sysv/linux/powerpc/time.c   | 22 -------------
 sysdeps/unix/sysv/linux/time-clockid.h   | 22 -------------
 sysdeps/unix/sysv/linux/time.c           | 41 +++---------------------
 sysdeps/unix/sysv/linux/x86/time.c       | 22 -------------
 sysdeps/unix/sysv/linux/x86_64/sysdep.h  |  1 -
 time/time.c                              |  3 +-
 14 files changed, 8 insertions(+), 141 deletions(-)
 delete mode 100644 sysdeps/generic/time-clockid.h
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/time-clockid.h
 delete mode 100644 sysdeps/unix/sysv/linux/x86/time.c

diff --git a/include/time.h b/include/time.h
index f599eeed4e..2b27dc87cf 100644
--- a/include/time.h
+++ b/include/time.h
@@ -9,7 +9,6 @@
 # include <stdbool.h>
 # include <time/mktime-internal.h>
 # include <sys/time.h>
-# include <time-clockid.h>
 # include <sys/time.h>
 # include <stdint.h>
 
@@ -524,7 +523,7 @@ static inline time_t
 time_now (void)
 {
   struct timespec ts;
-  __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+  __clock_gettime (CLOCK_REALTIME, &ts);
   return ts.tv_sec;
 }
 
@@ -532,7 +531,7 @@ static inline __time64_t
 time64_now (void)
 {
   struct __timespec64 ts;
-  __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+  __clock_gettime64 (CLOCK_REALTIME, &ts);
   return ts.tv_sec;
 }
 
diff --git a/manual/time.texi b/manual/time.texi
index 0c7a942b4c..e42198522b 100644
--- a/manual/time.texi
+++ b/manual/time.texi
@@ -442,9 +442,7 @@ calendar time, with different levels of resolution.
 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_COARSE)}},
-when the clock is available or @w{@samp{clock_gettime (CLOCK_REALTIME)}}
-otherwise.
+uses the same clock as @w{@samp{clock_gettime (CLOCK_REALTIME)}}.
 
 If the argument @var{result} is not a null pointer, the calendar time
 value is also stored in @code{*@var{result}}.
diff --git a/sysdeps/generic/time-clockid.h b/sysdeps/generic/time-clockid.h
deleted file mode 100644
index 21f1235a31..0000000000
--- a/sysdeps/generic/time-clockid.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* System specific time definitions.  Generic Version.
-   Copyright 2019-2023 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
-   <https://www.gnu.org/licenses/>.  */
-
-/* Timer used on clock_gettime for time implementation.  */
-#define TIME_CLOCK_GETTIME_CLOCKID CLOCK_REALTIME
diff --git a/sysdeps/mach/hurd/bits/errno.h b/sysdeps/mach/hurd/bits/errno.h
index 90c8897739..0d935e724a 100644
--- a/sysdeps/mach/hurd/bits/errno.h
+++ b/sysdeps/mach/hurd/bits/errno.h
@@ -9,7 +9,6 @@
      mach/boolean.h
      mach/i386/boolean.h
      mach/i386/vm_types.h
-     mach/i386/stdint.h
      mach/mig_errors.h
      device/device_types.h
      mach/std_types.h
diff --git a/sysdeps/unix/sysv/linux/dl-vdso-setup.c b/sysdeps/unix/sysv/linux/dl-vdso-setup.c
index 68fa8de641..895c24133e 100644
--- a/sysdeps/unix/sysv/linux/dl-vdso-setup.c
+++ b/sysdeps/unix/sysv/linux/dl-vdso-setup.c
@@ -52,9 +52,6 @@ PROCINFO_CLASS int (*_dl_vdso_clock_gettime64) (clockid_t,
 # ifdef HAVE_GETTIMEOFDAY_VSYSCALL
 PROCINFO_CLASS int (*_dl_vdso_gettimeofday) (struct timeval *, void *) RELRO;
 #endif
-# ifdef HAVE_TIME_VSYSCALL
-PROCINFO_CLASS time_t (*_dl_vdso_time) (time_t *) RELRO;
-# endif
 # ifdef HAVE_GETCPU_VSYSCALL
 PROCINFO_CLASS int (*_dl_vdso_getcpu) (unsigned *, unsigned *, void *) RELRO;
 # endif
diff --git a/sysdeps/unix/sysv/linux/dl-vdso-setup.h b/sysdeps/unix/sysv/linux/dl-vdso-setup.h
index 867072b897..1f29708e93 100644
--- a/sysdeps/unix/sysv/linux/dl-vdso-setup.h
+++ b/sysdeps/unix/sysv/linux/dl-vdso-setup.h
@@ -32,9 +32,6 @@ setup_vdso_pointers (void)
 #ifdef HAVE_GETTIMEOFDAY_VSYSCALL
   GLRO(dl_vdso_gettimeofday) = dl_vdso_vsym (HAVE_GETTIMEOFDAY_VSYSCALL);
 #endif
-#ifdef HAVE_TIME_VSYSCALL
-  GLRO(dl_vdso_time) = dl_vdso_vsym (HAVE_TIME_VSYSCALL);
-#endif
 #ifdef HAVE_GETCPU_VSYSCALL
   GLRO(dl_vdso_getcpu) = dl_vdso_vsym (HAVE_GETCPU_VSYSCALL);
 #endif
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
index 8538cd5342..77c37a33d3 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -256,7 +256,6 @@ struct libc_do_syscall_args
 # define HAVE_CLOCK_GETTIME_VSYSCALL    "__vdso_clock_gettime"
 # define HAVE_CLOCK_GETTIME64_VSYSCALL  "__vdso_clock_gettime64"
 # define HAVE_GETTIMEOFDAY_VSYSCALL     "__vdso_gettimeofday"
-# define HAVE_TIME_VSYSCALL             "__vdso_time"
 # define HAVE_CLOCK_GETRES_VSYSCALL     "__vdso_clock_getres"
 
 # define HAVE_CLONE3_WRAPPER		1
diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
index 96a0edc38f..59cda57639 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
@@ -220,7 +220,6 @@
 #define HAVE_CLOCK_GETTIME_VSYSCALL	"__kernel_clock_gettime"
 #endif
 #define HAVE_GETCPU_VSYSCALL		"__kernel_getcpu"
-#define HAVE_TIME_VSYSCALL		"__kernel_time"
 #define HAVE_GETTIMEOFDAY_VSYSCALL      "__kernel_gettimeofday"
 #define HAVE_GET_TBFREQ                 "__kernel_get_tbfreq"
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c
deleted file mode 100644
index 0318a7a93d..0000000000
--- a/sysdeps/unix/sysv/linux/powerpc/time.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* time system call for Linux/PowerPC.
-   Copyright (C) 2013-2023 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
-   <https://www.gnu.org/licenses/>.  */
-
-#ifdef __powerpc64__
-# define USE_IFUNC_TIME
-#endif
-#include <sysdeps/unix/sysv/linux/time.c>
diff --git a/sysdeps/unix/sysv/linux/time-clockid.h b/sysdeps/unix/sysv/linux/time-clockid.h
deleted file mode 100644
index b9ff418ecb..0000000000
--- a/sysdeps/unix/sysv/linux/time-clockid.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* System specific time definitions.  Generic Version.
-   Copyright 2019-2023 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
-   <https://www.gnu.org/licenses/>.  */
-
-/* Timer used on clock_gettime for time implementation.  For Linux
-   it uses the coarse version which returns the time at the last tick
-   and mimic what time as syscall should return.  */
-#define TIME_CLOCK_GETTIME_CLOCKID CLOCK_REALTIME_COARSE
diff --git a/sysdeps/unix/sysv/linux/time.c b/sysdeps/unix/sysv/linux/time.c
index a0e7fd7ac2..0480b5a782 100644
--- a/sysdeps/unix/sysv/linux/time.c
+++ b/sysdeps/unix/sysv/linux/time.c
@@ -16,40 +16,8 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-/* Optimize the function call by setting the PLT directly to vDSO symbol.  */
-#ifdef USE_IFUNC_TIME
-# include <time.h>
-# include <sysdep.h>
-# include <sysdep-vdso.h>
-
-#ifdef SHARED
-# include <dl-vdso.h>
-# include <libc-vdso.h>
-
-static time_t
-time_syscall (time_t *t)
-{
-  return INLINE_SYSCALL_CALL (time, t);
-}
-
-# undef INIT_ARCH
-# define INIT_ARCH() \
-  void *vdso_time = dl_vdso_vsym (HAVE_TIME_VSYSCALL);
-libc_ifunc (time,
-	    vdso_time ? VDSO_IFUNC_RET (vdso_time)
-		      : (void *) time_syscall);
-
-# else
-time_t
-time (time_t *t)
-{
-  return INLINE_VSYSCALL (time, 1, t);
-}
-# endif /* !SHARED */
-#else /* USE_IFUNC_TIME  */
-# include <time.h>
-# include <time-clockid.h>
-# include <errno.h>
+#include <time.h>
+#include <errno.h>
 
 /* Return the time now, and store it in *TIMER if not NULL.  */
 
@@ -57,7 +25,7 @@ __time64_t
 __time64 (__time64_t *timer)
 {
   struct __timespec64 ts;
-  __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+  __clock_gettime64 (CLOCK_REALTIME, &ts);
 
   if (timer != NULL)
     *timer = ts.tv_sec;
@@ -82,6 +50,5 @@ __time (time_t *timer)
     *timer = t;
   return t;
 }
-# endif
-weak_alias (__time, time)
 #endif
+weak_alias (__time, time)
diff --git a/sysdeps/unix/sysv/linux/x86/time.c b/sysdeps/unix/sysv/linux/x86/time.c
deleted file mode 100644
index aac2fbc4d1..0000000000
--- a/sysdeps/unix/sysv/linux/x86/time.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* time -- Get number of seconds since Epoch.  Linux/x86 version.
-   Copyright (C) 2015-2023 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
-   <https://www.gnu.org/licenses/>.  */
-
-#ifdef __x86_64__
-# define USE_IFUNC_TIME
-#endif
-#include <sysdeps/unix/sysv/linux/time.c>
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index cfb51be8c5..6a8d610238 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -373,7 +373,6 @@
 /* List of system calls which are supported as vsyscalls.  */
 # define HAVE_CLOCK_GETTIME64_VSYSCALL  "__vdso_clock_gettime"
 # define HAVE_GETTIMEOFDAY_VSYSCALL     "__vdso_gettimeofday"
-# define HAVE_TIME_VSYSCALL             "__vdso_time"
 # define HAVE_GETCPU_VSYSCALL		"__vdso_getcpu"
 # define HAVE_CLOCK_GETRES64_VSYSCALL   "__vdso_clock_getres"
 
diff --git a/time/time.c b/time/time.c
index 6713bbf452..a37fd2571b 100644
--- a/time/time.c
+++ b/time/time.c
@@ -16,14 +16,13 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <time.h>
-#include <time-clockid.h>
 
 /* Return the time now, and store it in *TIMER if not NULL.  */
 time_t
 time (time_t *timer)
 {
   struct timespec ts;
-  __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+  __clock_gettime (CLOCK_REALTIME, &ts);
 
   if (timer)
     *timer = ts.tv_sec;
-- 
2.34.1


             reply	other threads:[~2023-03-06 16:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-06 16:03 Adhemerval Zanella [this message]
2023-03-07 11:11 ` Florian Weimer
2023-03-07 11:45   ` Adhemerval Zanella Netto
2023-03-07 11:51     ` Florian Weimer
2023-03-07 11:57       ` Adhemerval Zanella Netto
2023-03-07 12:07         ` Florian Weimer
2023-03-08  5:51           ` Paul Eggert
2023-03-08  8:59             ` Florian Weimer
2023-03-08 23:08               ` Paul Eggert
2023-03-08 16:23             ` Bruno Haible
2023-03-08 16:57               ` Adhemerval Zanella Netto
2023-03-08 17:09                 ` Florian Weimer
2023-03-08 17:46                   ` Adhemerval Zanella Netto
2023-03-08 17:44                 ` Bruno Haible
2023-03-08 17:50                   ` Adhemerval Zanella Netto

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20230306160321.2942372-1-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=bruno@clisp.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

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

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