From: Lukasz Majewski <lukma@denx.de>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: Joseph Myers <joseph@codesourcery.com>,
Alistair Francis <alistair23@gmail.com>,
Alistair Francis <alistair.francis@wdc.com>,
GNU C Library <libc-alpha@sourceware.org>,
Florian Weimer <fweimer@redhat.com>,
Andreas Schwab <schwab@suse.de>
Subject: Re: [PATCH v2 5/5] y2038: Replace __clock_gettime with __clock_gettime64
Date: Fri, 1 May 2020 13:56:35 +0200 [thread overview]
Message-ID: <20200501135635.5178fd29@jawa> (raw)
In-Reply-To: <bf9f3ac8-8eea-9daf-b438-64d1514596de@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 9205 bytes --]
Hi Adhemerval,
> On 26/03/2020 05:06, Lukasz Majewski wrote:
> > The __clock_gettime internal function is not supporting 64 bit time
> > on architectures with __WORDSIZE == 32 and __TIMESIZE != 64 (like
> > e.g. ARM 32 bit).
> >
> > The __clock_gettime64 shall be used instead in the glibc itself as
> > it supports 64 bit time on those systems.
> > This change does not bring any change to systems with __WORDSIZE ==
> > 64 as for them the __clock_gettime64 is aliased to __clock_gettime
> > (in ./include/time.h).
> >
> > ---
> > Changes for v2:
> > - Use only TIMESPEC_TO_TIMEVAL instead of
> > valid_timespec64_to_timeval in logout.c and logwtmp.c as it is
> > generic enough to also support struct __timespec64 conversion to
> > struct timeval ---
> > benchtests/bench-timing.h | 2 +-
> > include/random-bits.h | 4 ++--
> > login/logout.c | 4 ++--
> > login/logwtmp.c | 5 +++--
> > nis/nis_call.c | 6 +++---
> > sysdeps/generic/hp-timing.h | 4 ++--
> > sysdeps/generic/memusage.h | 4 ++--
> > sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c | 4 ++--
> > sysdeps/unix/sysv/linux/clock.c | 7 ++-----
> > 9 files changed, 19 insertions(+), 21 deletions(-)
> >
> > diff --git a/benchtests/bench-timing.h b/benchtests/bench-timing.h
> > index 5b9a8384bb..a0d6f82465 100644
> > --- a/benchtests/bench-timing.h
> > +++ b/benchtests/bench-timing.h
> > @@ -18,7 +18,7 @@
> >
> > #undef attribute_hidden
> > #define attribute_hidden
> > -#define __clock_gettime clock_gettime
> > +#define __clock_gettime __clock_gettime64
> > #include <hp-timing.h>
> > #include <stdint.h>
> >
>
> Ok, although we might revise it later and build the benchmarks
> with __TIMESIZE==64.
>
> > diff --git a/include/random-bits.h b/include/random-bits.h
> > index fd3fa01f9b..7561e55ca6 100644
> > --- a/include/random-bits.h
> > +++ b/include/random-bits.h
> > @@ -30,8 +30,8 @@
> > static inline uint32_t
> > random_bits (void)
> > {
> > - struct timespec tv;
> > - __clock_gettime (CLOCK_MONOTONIC, &tv);
> > + struct __timespec64 tv;
> > + __clock_gettime64 (CLOCK_MONOTONIC, &tv);
> > /* Shuffle the lower bits to minimize the clock bias. */
> > uint32_t ret = tv.tv_nsec ^ tv.tv_sec;
> > ret ^= (ret << 24) | (ret >> 8);
>
> Ok.
>
> > diff --git a/login/logout.c b/login/logout.c
> > index 7653fe8886..091312eb1d 100644
> > --- a/login/logout.c
> > +++ b/login/logout.c
> > @@ -47,8 +47,8 @@ logout (const char *line)
> > memset (ut->ut_name, '\0', sizeof ut->ut_name);
> > memset (ut->ut_host, '\0', sizeof ut->ut_host);
> >
> > - struct timespec ts;
> > - __clock_gettime (CLOCK_REALTIME, &ts);
> > + struct __timespec64 ts;
> > + __clock_gettime64 (CLOCK_REALTIME, &ts);
> > TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
> > ut->ut_type = DEAD_PROCESS;
> >
>
> Ok.
>
> > diff --git a/login/logwtmp.c b/login/logwtmp.c
> > index 90406acc3d..050219c153 100644
> > --- a/login/logwtmp.c
> > +++ b/login/logwtmp.c
> > @@ -21,6 +21,7 @@
> > #include <time.h>
> > #include <unistd.h>
> > #include <utmp.h>
> > +#include <struct___timespec64.h>
> >
> >
> > void
> > @@ -36,8 +37,8 @@ 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 timespec ts;
> > - __clock_gettime (CLOCK_REALTIME, &ts);
> > + struct __timespec64 ts;
> > + __clock_gettime64 (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 92c70e97aa..9c6f62a753 100644
> > --- a/nis/nis_call.c
> > +++ b/nis/nis_call.c
> > @@ -709,7 +709,7 @@ __nisfind_server (const_nis_name name, int
> > search_parent, nis_error status;
> > directory_obj *obj;
> > struct timeval now;
> > - struct timespec ts;
> > + struct __timespec64 ts;
> > unsigned int server_used = ~0;
> > unsigned int current_ep = ~0;
> >
> > @@ -719,8 +719,8 @@ __nisfind_server (const_nis_name name, int
> > search_parent, if (*dir != NULL)
> > return NIS_SUCCESS;
> >
> > - __clock_gettime (CLOCK_REALTIME, &ts);
> > - TIMESPEC_TO_TIMEVAL (&now, &ts);
> > + __clock_gettime64 (CLOCK_REALTIME, &ts);
> > + now = valid_timespec64_to_timeval (ts);
> >
> > if ((flags & NO_CACHE) == 0)
> > *dir = nis_server_cache_search (name, search_parent,
> > &server_used,
>
> I think it would be simpler to just remove the timeval argument on
> nis_server_cache_search and move the __clock_gettime64 call on the
> function start.
Have I understood you correctly that you recommend removing the "now"
struct timeval argument and then call explicitly __clock_gettime64 on
the beginning of nis_server_cache_search function?
>
> Also, it would require to change nis_server_cache to use a
> __time64_t for 'expires', otherwise this change won't help in
> case of a time_t overflow.
>
Ok. I will update this. Thanks for pointing this out.
>
> > diff --git a/sysdeps/generic/hp-timing.h
> > b/sysdeps/generic/hp-timing.h index e2d7447212..af9d92f7f7 100644
> > --- a/sysdeps/generic/hp-timing.h
> > +++ b/sysdeps/generic/hp-timing.h
> > @@ -34,8 +34,8 @@ typedef uint64_t hp_timing_t;
> > vDSO symbol. */
> > #define HP_TIMING_NOW(var) \
> > ({ \
> > - struct timespec tv;
> > \
> > - __clock_gettime (CLOCK_MONOTONIC, &tv); \
> > + struct __timespec64 tv;
> > \
> > + __clock_gettime64 (CLOCK_MONOTONIC, &tv);
> > \ (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec); \
> > })
> >
>
> Ok.
>
> > diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h
> > index a111864b0b..91e56d24de 100644
> > --- a/sysdeps/generic/memusage.h
> > +++ b/sysdeps/generic/memusage.h
> > @@ -28,9 +28,9 @@
> > #ifndef GETTIME
> > # define GETTIME(low,high)
> > \ {
> > \
> > - struct timespec now;
> > \
> > + struct __timespec64 now;
> > \ uint64_t usecs;
> > \
> > - clock_gettime (CLOCK_REALTIME, &now);
> > \
> > + __clock_gettime64 (CLOCK_REALTIME, &now);
> > \ usecs = (uint64_t)now.tv_nsec / 1000 +
> > (uint64_t)now.tv_sec * 1000000; \ low = usecs & 0xffffffff;
> > \ high = usecs >>
> > 32; \
>
> Is is the requirement to export __clock_gettime64 as a GLIBC_PRIVATE
> symbol?
>
The __clock_gettime is already exported as GLIBC_PRIVATE at
./time/Versions, so I'm following this pattern.
Moreover, the glibc will not build when __clock_gettime64 is not
exported.
> In any case, I think we should try to avoid use internal symbols even
> for distributed glibc libraries, so I think this change should go
> once we start to export the clock_gettime64 as default symbol.
Am I correct that this is a preprocessor macro, which is in the
exported header?
>
> > diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> > b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c index
> > 8cf5d303f9..5075ae0444 100644 ---
> > a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c +++
> > b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c @@ -35,8 +35,8
> > @@ __gettimeofday_tv32 (struct __timeval32 *restrict tv32, void
> > *restrict tz) if (__glibc_unlikely (tz != 0)) memset (tz, 0, sizeof
> > (struct timezone));
> > - struct timespec ts;
> > - __clock_gettime (CLOCK_REALTIME, &ts);
> > + struct __timespec64 ts;
> > + __clock_gettime64 (CLOCK_REALTIME, &ts);
> >
> > *tv32 = valid_timespec_to_timeval32 (ts);
> > return 0;
>
> Ok.
>
> > diff --git a/sysdeps/unix/sysv/linux/clock.c
> > b/sysdeps/unix/sysv/linux/clock.c index 24a8df0cf5..157ae8eb3f
> > 100644 --- a/sysdeps/unix/sysv/linux/clock.c
> > +++ b/sysdeps/unix/sysv/linux/clock.c
> > @@ -23,15 +23,12 @@
> > clock_t
> > clock (void)
> > {
> > - struct timespec ts;
> > + struct __timespec64 ts;
> >
> > _Static_assert (CLOCKS_PER_SEC == 1000000,
> > "CLOCKS_PER_SEC should be 1000000");
> >
> > - /* clock_gettime shouldn't fail here since
> > CLOCK_PROCESS_CPUTIME_ID is
> > - supported since 2.6.12. Check the return value anyway in
> > case the kernel
> > - barfs on us for some reason. */
> > - if (__glibc_unlikely (__clock_gettime (CLOCK_PROCESS_CPUTIME_ID,
> > &ts) != 0))
> > + if (__glibc_unlikely (__clock_gettime64
> > (CLOCK_PROCESS_CPUTIME_ID, &ts) != 0)) return (clock_t) -1;
> >
> > return (ts.tv_sec * CLOCKS_PER_SEC
> >
>
> Ok.
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 --]
next prev parent reply other threads:[~2020-05-01 11:56 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-26 8:06 [PATCH v2 0/5] " Lukasz Majewski
2020-03-26 8:06 ` [PATCH v2 1/5] y2038: Export __clock_gettime64 to be usable in other libraries Lukasz Majewski
2020-03-26 8:06 ` [PATCH v2 2/5] y2038: hurd: Provide __clock_gettime64 function Lukasz Majewski
2020-03-26 8:06 ` [PATCH v2 3/5] y2038: inet: Convert inet deadline to support 64 bit time Lukasz Majewski
2020-04-30 20:51 ` Adhemerval Zanella
2020-03-26 8:06 ` [PATCH v2 4/5] y2038: nscd: Modify nscd_helper to use __clock_gettime64 Lukasz Majewski
2020-04-30 20:54 ` Adhemerval Zanella
2020-05-01 11:30 ` Lukasz Majewski
2020-05-04 12:27 ` Adhemerval Zanella
2020-05-04 15:26 ` Lukasz Majewski
2020-05-04 16:36 ` Adhemerval Zanella
2020-03-26 8:06 ` [PATCH v2 5/5] y2038: Replace __clock_gettime with __clock_gettime64 Lukasz Majewski
2020-04-06 16:07 ` Florian Weimer
2020-04-06 21:03 ` Lukasz Majewski
2020-04-14 12:14 ` Lukasz Majewski
2020-04-21 13:48 ` Lukasz Majewski
2020-04-29 21:48 ` Lukasz Majewski
2020-04-30 21:03 ` Adhemerval Zanella
2020-05-01 11:56 ` Lukasz Majewski [this message]
2020-05-04 14:04 ` Adhemerval Zanella
2020-05-04 15:32 ` Lukasz Majewski
2020-05-04 16:37 ` Adhemerval Zanella
2020-05-05 18:31 ` Lukasz Majewski
2020-04-06 15:16 ` [PATCH v2 0/5] " Lukasz Majewski
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=20200501135635.5178fd29@jawa \
--to=lukma@denx.de \
--cc=adhemerval.zanella@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=alistair23@gmail.com \
--cc=fweimer@redhat.com \
--cc=joseph@codesourcery.com \
--cc=libc-alpha@sourceware.org \
--cc=schwab@suse.de \
/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).