From patchwork Wed Aug 28 15:32:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 1154556 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104816-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=panix.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="s2UzDY14"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46JVBx37B4z9sBF for ; Thu, 29 Aug 2019 01:33:45 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; q=dns; s= default; b=d6b7PWyKGAJbVFgvnSYICbZMQmjYmnKTyT7Wnywa4NzCgzM6QgeNG Bkl6GiuKHHkdW5MHAImP63/kN5CYQj2g1rLqu7wKuikGlAqvepX2ibisMOMX/UKi KOr+WhhLhfeFE6p5v2hcATlvjMI/DHduhus7m/xK4peFQKyoAAr0mI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; s=default; bh=IvLDTpuC8NYacLIklQe2TKTlYPI=; b=s2UzDY14m00Kc195kof9PKi5D7w1 pOb6EJMRon12f+ZOnHeRDI2C7NAN/fsM8CE02XT1P1k20c2nw3LV+4cdEQwBBsUF dCWaze8fKYW3ULJVHGf8x9tRtDhWPmUb2C9JEeufUTzAi/pyP3r3+OBZyAUwIPlg uqYygN3u3L2FRDQ= Received: (qmail 14348 invoked by alias); 28 Aug 2019 15:32:50 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 14268 invoked by uid 89); 28 Aug 2019 15:32:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: l2mail1.panix.com From: Zack Weinberg To: libc-alpha@sourceware.org Cc: Joseph Myers , Florian Weimer , Lukasz Majewski , Alistair Francis , Stepan Golosunov , Arnd Bergmann , Adhemerval Zanella , Samuel Thibault Subject: [PATCH v2 05/10] Use clock_gettime to implement time. Date: Wed, 28 Aug 2019 11:32:31 -0400 Message-Id: <20190828153236.18229-6-zackw@panix.com> In-Reply-To: <20190828153236.18229-1-zackw@panix.com> References: <20190828153236.18229-1-zackw@panix.com> MIME-Version: 1.0 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 | 12 ++- 10 files changed, 5 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 - . */ - -#include /* For NULL. */ -#include -#include - - -/* 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 - . */ - -#ifdef SHARED -# define time __redirect_time -#endif - -#include - -#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 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 - . */ - -#ifdef SHARED -# ifndef __powerpc64__ -# define time __redirect_time -# else -# define __redirect_time time -# endif - -# include -# include -# include -# include -# include - -# 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 - -#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 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 - . */ - -#include -#include - -#include - -#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 - -#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 - . */ - -#include - -#ifdef SHARED - -#include -#include - -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 - -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..bae0fd14dd 100644 --- a/time/time.c +++ b/time/time.c @@ -15,19 +15,17 @@ License along with the GNU C Library; if not, see . */ -#include #include /* Return the time now, and store it in *TIMER if not NULL. */ time_t time (time_t *timer) { - __set_errno (ENOSYS); + struct timespec ts; + __clock_gettime (CLOCK_REALTIME, &ts); - if (timer != NULL) - *timer = (time_t) -1; - return (time_t) -1; + if (timer) + *timer = ts.tv_sec; + return ts.tv_sec; } libc_hidden_def (time) - -stub_warning (time)