This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC v2 05/20] sysdeps/nanosleep: Use clock_nanosleep_time64 if avaliable
- From: Arnd Bergmann <arnd at arndb dot de>
- To: Alistair Francis <alistair dot francis at wdc dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>, Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, Florian Weimer <fweimer at redhat dot com>, Palmer Dabbelt <palmer at sifive dot com>, macro at wdc dot com, Zong Li <zongbox at gmail dot com>, Zong Li <zong at andestech dot com>, Alistair Francis <alistair23 at gmail dot com>
- Date: Tue, 25 Jun 2019 10:59:11 +0200
- Subject: Re: [RFC v2 05/20] sysdeps/nanosleep: Use clock_nanosleep_time64 if avaliable
- References: <cover.1561421042.git.alistair.francis@wdc.com> <d85f6611d45b6c7fea9e82ffcacde71e28625b49.1561421042.git.alistair.francis@wdc.com>
On Tue, Jun 25, 2019 at 2:11 AM Alistair Francis
<alistair.francis@wdc.com> wrote:
> index f14ae565af..c2d6e2f766 100644
> --- a/sysdeps/unix/sysv/linux/nanosleep.c
> +++ b/sysdeps/unix/sysv/linux/nanosleep.c
> @@ -25,7 +25,19 @@ int
> __nanosleep (const struct timespec *requested_time,
> struct timespec *remaining)
> {
> +
> +#ifdef __ASSUME_TIME64_SYSCALLS
> + return SYSCALL_CANCEL (clock_nanosleep_time64, CLOCK_REALTIME, 0,
> + requested_time, remaining);
> +#else
> +# ifdef __NR_clock_nanosleep_time64
> + long int ret = SYSCALL_CANCEL (clock_nanosleep_time64, CLOCK_REALTIME, 0,
> + requested_time, remaining);
> + if (ret == 0 || errno != ENOSYS)
> + return ret;
> +# endif
> return SYSCALL_CANCEL (nanosleep, requested_time, remaining);
> +#endif
> }
There has to be a type conversion in here somewhere: If timespec
uses 32-bit time_t (on all existing 32-bit architectures), you must not
pass it into __NR_clock_nanosleep_time64, while on builds with
a 64-bit timespec you must not call nanosleep() without conversion.
I suppose you need something like an internal __nanosleep64 (like
your function above, but with the conversion added to the fallback
path) and an internal __nanosleep32 (not calling clock_nanosleep_time64
or doing conversion). Architectures that have always had a 64-bit time_t
don't need the latter of course.
No idea how that fits into the rest of the glibc implementation.
Arnd