Message ID | 20201015123429.5446-1-lukma@denx.de |
---|---|
State | Dropped |
Delegated to: | Lukasz Majewski |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6ECDF3947C38; Thu, 15 Oct 2020 12:35:33 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by sourceware.org (Postfix) with ESMTPS id F24B73857C62 for <libc-alpha@sourceware.org>; Thu, 15 Oct 2020 12:35:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F24B73857C62 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=lukma@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4CBpf65D1Bz1sKVw; Thu, 15 Oct 2020 14:35:26 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4CBpf63kf1z1qrgh; Thu, 15 Oct 2020 14:35:26 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id rbB4UoAwNbn5; Thu, 15 Oct 2020 14:35:24 +0200 (CEST) X-Auth-Info: 408XP3DSxYSbTGAP9gx8VKwPnRk5yFqnT7O9ZJWbEA8= Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 15 Oct 2020 14:35:24 +0200 (CEST) From: Lukasz Majewski <lukma@denx.de> To: Joseph Myers <joseph@codesourcery.com>, Paul Eggert <eggert@cs.ucla.edu>, Adhemerval Zanella <adhemerval.zanella@linaro.org> Subject: [PATCH] y2038: linux: Provide __time64 implementation Date: Thu, 15 Oct 2020 14:34:29 +0200 Message-Id: <20201015123429.5446-1-lukma@denx.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-16.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Cc: Florian Weimer <fweimer@redhat.com>, GNU C Library <libc-alpha@sourceware.org>, Andreas Schwab <schwab@suse.de>, Stepan Golosunov <stepan@golosunov.pp.ru>, Alistair Francis <alistair.francis@wdc.com> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
y2038: linux: Provide __time64 implementation
|
|
Commit Message
Lukasz Majewski
Oct. 15, 2020, 12:34 p.m. UTC
In the glibc the time function can use vDSO (on power and x86 the USE_IFUNC_TIME is defined), time syscall or 'default' time() from ./time/time.c (as a fallback). In this patch the last function (time) has been refactored and moved to ./sysdeps/unix/sysv/linux/time.c to be Linux specific. The new __time64 explicit 64 bit function for providing 64 bit value of seconds after epoch (by internally calling __clock_gettime64) has been introduced. Moreover, a 32 bit version - __time has been refactored to internally use __time64. The __time is now supposed to be used on systems still supporting 32 bit time (__TIMESIZE != 64) - hence the necessary check for time_t potential overflow. Build tests: ./src/scripts/build-many-glibcs.py glibcs Run-time tests: - Run specific tests on ARM/x86 32bit systems (qemu): https://github.com/lmajewski/meta-y2038 and run tests: https://github.com/lmajewski/y2038-tests/commits/master Above tests were performed with Y2038 redirection applied as well as without to test proper usage of both __time64 and __time. --- include/time.h | 7 ++++++ sysdeps/unix/sysv/linux/time.c | 39 +++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-)
Comments
On 15/10/2020 09:34, Lukasz Majewski wrote: > In the glibc the time function can use vDSO (on power and x86 the > USE_IFUNC_TIME is defined), time syscall or 'default' time() from > ./time/time.c (as a fallback). > > In this patch the last function (time) has been refactored and moved > to ./sysdeps/unix/sysv/linux/time.c to be Linux specific. > > The new __time64 explicit 64 bit function for providing 64 bit value of > seconds after epoch (by internally calling __clock_gettime64) has been > introduced. > > Moreover, a 32 bit version - __time has been refactored to internally > use __time64. > > The __time is now supposed to be used on systems still supporting 32 bit > time (__TIMESIZE != 64) - hence the necessary check for time_t potential > overflow. > > Build tests: > ./src/scripts/build-many-glibcs.py glibcs > > Run-time tests: > - Run specific tests on ARM/x86 32bit systems (qemu): > https://github.com/lmajewski/meta-y2038 and run tests: > https://github.com/lmajewski/y2038-tests/commits/master > > Above tests were performed with Y2038 redirection applied as well as without > to test proper usage of both __time64 and __time. Looks good in general, some comments below. > --- > include/time.h | 7 ++++++ > sysdeps/unix/sysv/linux/time.c | 39 +++++++++++++++++++++++++++++++++- > 2 files changed, 45 insertions(+), 1 deletion(-) > > diff --git a/include/time.h b/include/time.h > index edf6cdf829..caf2af5e74 100644 > --- a/include/time.h > +++ b/include/time.h > @@ -317,6 +317,13 @@ extern int __timespec_get64 (struct __timespec64 *ts, int base); > libc_hidden_proto (__timespec_get64) > #endif > > +#if __TIMESIZE == 64 > +# define __time64 __time > +#else > +extern __time64_t __time64 (__time64_t *timer); > +libc_hidden_proto (__time64) > +#endif > + > /* Use in the clock_* functions. Size of the field representing the > actual clock ID. */ > #define CLOCK_IDFIELD_SIZE 3 Ok. > diff --git a/sysdeps/unix/sysv/linux/time.c b/sysdeps/unix/sysv/linux/time.c > index 9d8e573c0a..1a9a7c0413 100644 > --- a/sysdeps/unix/sysv/linux/time.c > +++ b/sysdeps/unix/sysv/linux/time.c > @@ -47,5 +47,42 @@ time (time_t *t) > } > # endif /* !SHARED */ > #else /* USE_IFUNC_TIME */ You need to handle USE_IFUNC_TIME, which is still used for powerpc32 and i686. I don't think optimizing for vDSO access pay for the complexity in these cases, so disable it with: 20 #ifdef USE_IFUNC_TIME && __TIMESIZE == 64 21 # include <time.h> > -# include <time/time.c> > +/* Conversion of time function to support 64 bit time on archs > + with __WORDSIZE == 32 and __TIMESIZE == 32/64 */ I think this comment is kinda unnecessary, but if would still want to add it I would put close to '__time' implementation rather than the '__time64'. > +# include <time.h> > +# include <time-clockid.h> > +# include <errno.h> > +/* Return the time now, and store it in *TIMER if not NULL. */ Space after the include. > + > +__time64_t > +__time64 (__time64_t *timer) > +{ > + struct __timespec64 ts; > + __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts); > + > + if (timer) No implicit checks, use 'if (timer != NULL)'. > + *timer = ts.tv_sec; > + return ts.tv_sec; > +} > + > +# if __TIMESIZE != 64 > +libc_hidden_def (__time64) Ok. > + > +time_t > +__time (time_t *timer) > +{ > + __time64_t t = __time64 (NULL); > + > + if (! in_time_t_range (t)) > + { > + __set_errno (EOVERFLOW); > + return -1; > + } > + > + if (timer) No implicit checks, use 'if (timer != NULL)'. > + *timer = t; > + return t; > +} > +# endif > +weak_alias (__time, time) > #endif >
Hi Adhemerval, > On 15/10/2020 09:34, Lukasz Majewski wrote: > > In the glibc the time function can use vDSO (on power and x86 the > > USE_IFUNC_TIME is defined), time syscall or 'default' time() from > > ./time/time.c (as a fallback). > > > > In this patch the last function (time) has been refactored and moved > > to ./sysdeps/unix/sysv/linux/time.c to be Linux specific. > > > > The new __time64 explicit 64 bit function for providing 64 bit > > value of seconds after epoch (by internally calling > > __clock_gettime64) has been introduced. > > > > Moreover, a 32 bit version - __time has been refactored to > > internally use __time64. > > > > The __time is now supposed to be used on systems still supporting > > 32 bit time (__TIMESIZE != 64) - hence the necessary check for > > time_t potential overflow. > > > > Build tests: > > ./src/scripts/build-many-glibcs.py glibcs > > > > Run-time tests: > > - Run specific tests on ARM/x86 32bit systems (qemu): > > https://github.com/lmajewski/meta-y2038 and run tests: > > https://github.com/lmajewski/y2038-tests/commits/master > > > > Above tests were performed with Y2038 redirection applied as well > > as without to test proper usage of both __time64 and __time. > > Looks good in general, some comments below. I'm going to send v2 of this patch. > > > --- > > include/time.h | 7 ++++++ > > sysdeps/unix/sysv/linux/time.c | 39 > > +++++++++++++++++++++++++++++++++- 2 files changed, 45 > > insertions(+), 1 deletion(-) > > > > diff --git a/include/time.h b/include/time.h > > index edf6cdf829..caf2af5e74 100644 > > --- a/include/time.h > > +++ b/include/time.h > > @@ -317,6 +317,13 @@ extern int __timespec_get64 (struct > > __timespec64 *ts, int base); libc_hidden_proto (__timespec_get64) > > #endif > > > > +#if __TIMESIZE == 64 > > +# define __time64 __time > > +#else > > +extern __time64_t __time64 (__time64_t *timer); > > +libc_hidden_proto (__time64) > > +#endif > > + > > /* Use in the clock_* functions. Size of the field representing > > the actual clock ID. */ > > #define CLOCK_IDFIELD_SIZE 3 > > Ok. > > > diff --git a/sysdeps/unix/sysv/linux/time.c > > b/sysdeps/unix/sysv/linux/time.c index 9d8e573c0a..1a9a7c0413 100644 > > --- a/sysdeps/unix/sysv/linux/time.c > > +++ b/sysdeps/unix/sysv/linux/time.c > > @@ -47,5 +47,42 @@ time (time_t *t) > > } > > # endif /* !SHARED */ > > #else /* USE_IFUNC_TIME */ > > You need to handle USE_IFUNC_TIME, which is still used for powerpc32 > and i686. I don't think optimizing for vDSO access pay for the > complexity in these cases, so disable it with: > > 20 #ifdef USE_IFUNC_TIME && __TIMESIZE == 64 > 21 # include <time.h> > In the gettimeofday() conversion patch it was enough to use #ifdef __x86_64__ and #ifdef __powerpc64__ in arch specific time.c so (SHA1: 7455b700279ec8baccf8dd7b119648f8b3e34eec) > > > -# include <time/time.c> > > +/* Conversion of time function to support 64 bit time on archs > > + with __WORDSIZE == 32 and __TIMESIZE == 32/64 */ > > I think this comment is kinda unnecessary, but if would still want > to add it I would put close to '__time' implementation rather than > the '__time64'. Ok. I will remove it. > > > +# include <time.h> > > +# include <time-clockid.h> > > +# include <errno.h> > > +/* Return the time now, and store it in *TIMER if not NULL. */ > > Space after the include. Those #includes are following the #else /* USE_IFUNC_TIME */ and the same indentation is used in other places in this file. I've just followed it. > > > + > > +__time64_t > > +__time64 (__time64_t *timer) > > +{ > > + struct __timespec64 ts; > > + __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts); > > + > > + if (timer) > > No implicit checks, use 'if (timer != NULL)'. Ok. > > > + *timer = ts.tv_sec; > > + return ts.tv_sec; > > +} > > + > > +# if __TIMESIZE != 64 > > +libc_hidden_def (__time64) > > Ok. > > > + > > +time_t > > +__time (time_t *timer) > > +{ > > + __time64_t t = __time64 (NULL); > > + > > + if (! in_time_t_range (t)) > > + { > > + __set_errno (EOVERFLOW); > > + return -1; > > + } > > + > > + if (timer) > > No implicit checks, use 'if (timer != NULL)'. Ok. > > > + *timer = t; > > + return t; > > +} > > +# endif > > +weak_alias (__time, time) > > #endif > > 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
diff --git a/include/time.h b/include/time.h index edf6cdf829..caf2af5e74 100644 --- a/include/time.h +++ b/include/time.h @@ -317,6 +317,13 @@ extern int __timespec_get64 (struct __timespec64 *ts, int base); libc_hidden_proto (__timespec_get64) #endif +#if __TIMESIZE == 64 +# define __time64 __time +#else +extern __time64_t __time64 (__time64_t *timer); +libc_hidden_proto (__time64) +#endif + /* Use in the clock_* functions. Size of the field representing the actual clock ID. */ #define CLOCK_IDFIELD_SIZE 3 diff --git a/sysdeps/unix/sysv/linux/time.c b/sysdeps/unix/sysv/linux/time.c index 9d8e573c0a..1a9a7c0413 100644 --- a/sysdeps/unix/sysv/linux/time.c +++ b/sysdeps/unix/sysv/linux/time.c @@ -47,5 +47,42 @@ time (time_t *t) } # endif /* !SHARED */ #else /* USE_IFUNC_TIME */ -# include <time/time.c> +/* Conversion of time function to support 64 bit time on archs + with __WORDSIZE == 32 and __TIMESIZE == 32/64 */ +# include <time.h> +# include <time-clockid.h> +# include <errno.h> +/* Return the time now, and store it in *TIMER if not NULL. */ + +__time64_t +__time64 (__time64_t *timer) +{ + struct __timespec64 ts; + __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts); + + if (timer) + *timer = ts.tv_sec; + return ts.tv_sec; +} + +# if __TIMESIZE != 64 +libc_hidden_def (__time64) + +time_t +__time (time_t *timer) +{ + __time64_t t = __time64 (NULL); + + if (! in_time_t_range (t)) + { + __set_errno (EOVERFLOW); + return -1; + } + + if (timer) + *timer = t; + return t; +} +# endif +weak_alias (__time, time) #endif