This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC v3 02/23] sysdeps/gettimeofday: Use clock_gettime64 if avaliable
- From: Alistair Francis <alistair23 at gmail dot com>
- To: Lukasz Majewski <lukma at denx dot de>
- Cc: Alistair Francis <alistair dot francis at wdc dot com>, GNU C Library <libc-alpha at sourceware dot org>, Arnd Bergmann <arnd at arndb dot de>, Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, Palmer Dabbelt <palmer at sifive dot com>, macro at wdc dot com, Zong Li <zongbox at gmail dot com>, Wolfgang Denk <wd at denx dot de>, Joseph Myers <joseph at codesourcery dot com>, Florian Weimer <fweimer at redhat dot com>
- Date: Fri, 19 Jul 2019 15:26:09 -0700
- Subject: Re: [RFC v3 02/23] sysdeps/gettimeofday: Use clock_gettime64 if avaliable
- References: <cover.1563321715.git.alistair.francis@wdc.com> <d570d35acb1d9027cf7558ba47bf0fb3f5272860.1563321715.git.alistair.francis@wdc.com> <20190717144305.3eda6678@jawa>
On Wed, Jul 17, 2019 at 5:43 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> Hi Alistair,
>
> > Not all architectures support the obsolete gettimeofday so use the
> > newer clock_gettime64 syscall if it is avaliable. This fixes RV32
> > build issues.
> >
> > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > ---
> > ChangeLog | 1 +
> > sysdeps/unix/sysv/linux/gettimeofday.c | 28
> > ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+)
> >
> > diff --git a/ChangeLog b/ChangeLog
> > index 477b9b49b3..9ca390a9c3 100644
> > --- a/ChangeLog
> > +++ b/ChangeLog
> > @@ -1028,6 +1028,7 @@
> > * nptl/thrd_sleep.c: Use clock_nanosleep_time64 instead of
> > nanosleep.
> > * sysdeps/unix/sysv/linux/nanosleep.c: Likewise.
> > * sysdeps/unix/sysv/linux/nanosleep_nocancel.c: Likewise.
> > + * sysdeps/unix/sysv/linux/gettimeofday.c: Use
> > clock_gettime64 syscall for gettimeofday.
> > 2019-06-20 Dmitry V. Levin <ldv@altlinux.org>
> > Florian Weimer <fweimer@redhat.com>
> > diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c
> > b/sysdeps/unix/sysv/linux/gettimeofday.c index a74f03825a..151b1e606c
> > 100644 --- a/sysdeps/unix/sysv/linux/gettimeofday.c
> > +++ b/sysdeps/unix/sysv/linux/gettimeofday.c
> > @@ -32,7 +32,35 @@
> > int
> > __gettimeofday (struct timeval *tv, struct timezone *tz)
> > {
> > +#ifdef __ASSUME_TIME64_SYSCALLS
>
> I'm not the glibc expert but according to [1], the
> __ASSUME_TIME64_SYSCALLS will be defined also for __WORDSIZE = 64 archs.
>
> This means that this code will be executed on x86_64 and return with an
> ENOTSUPP error as those archs shall not define clock_gettime64 and
> will just use the clock_settime.
>
> Please consider re-using pattern from clock_settime conversion [2].
Yep, good point. I have updated this to better match what is being
discussed on the list and your patches.
Alistair
>
> > + int ret;
> > + struct __timespec64 now;
> > +
> > + ret = INLINE_VSYSCALL (clock_gettime64, 2, CLOCK_REALTIME,
> > + &now);
> > +
> > + /* Convert from timespec to timeval */
> > + tv->tv_sec = now.tv_sec;
> > + tv->tv_usec = now.tv_nsec / 1000;
> > +
> > + return ret;
> > +#else
> > +# ifdef __NR_clock_gettime64
> > + long int ret;
> > + struct __timespec64 now;
> > +
> > + ret = INLINE_VSYSCALL (clock_gettime64, 2, CLOCK_REALTIME,
> > + &now);
> > +
> > + /* Convert from timespec to timeval */
> > + tv->tv_sec = now.tv_sec;
> > + tv->tv_usec = now.tv_nsec / 1000;
> > +
> > + if (ret == 0 || errno != ENOSYS)
> > + return ret;
> > +# endif
> > return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
> > +#endif
> > }
> > libc_hidden_def (__gettimeofday)
> > weak_alias (__gettimeofday, gettimeofday)
>
> Note:
>
> [1] -
> https://github.com/lmajewski/y2038_glibc/commit/1fdbc6002101a78a8a6a076bbb642b3082c2225d
>
> [2] -
> https://github.com/lmajewski/y2038_glibc/commit/69f842a8519ca13ed11fab0ff1bcc6fa1a524192
>
> 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