[06/12] Use clock_gettime to implement time.

Message ID 20190820132152.24100-7-zackw@panix.com
State Superseded
Headers

Commit Message

Zack Weinberg Aug. 20, 2019, 1:21 p.m. UTC
  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
  

Comments

Adhemerval Zanella Aug. 20, 2019, 6:02 p.m. UTC | #1
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)
>
  
Zack Weinberg Aug. 22, 2019, 12:58 p.m. UTC | #2
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
  

Patch

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)