This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC v4 06/24] sysdeps/timespec_get: Use clock_gettime64 if avaliable
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Alistair Francis <alistair23 at gmail dot com>
- 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>, 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>
- Date: Thu, 15 Aug 2019 19:46:30 +0000
- Subject: Re: [RFC v4 06/24] sysdeps/timespec_get: Use clock_gettime64 if avaliable
- Ironport-sdr: LY+lcE5Podxo1/tztHpJOYOxnRygmzu6rs4TgjQw9suot4ws+Bu5BhoBeRI8LXwEIBo38AyjFv zWPjxCj9ayO9Tv8VmwkYEQjFqvJo9yUnS/haPq/uK3SIuWRH2FdAQCHRAIeGpOPb33A5KB/eRG 92GNUI0rdaX7UZJb3AyqnHrY2PY7PBWPMuUrS28jhWp1cUMxjHuvaOHW3HIa5kOe2Cm+yVuPjl V1Cswq93JhU+16um+k+5vTTCMpjNIodzHxrXjRo9U8uFb5mv/G9DvTmo4EgS1lBILmZe3Vn7Vo K7A=
- Ironport-sdr: x/eYBnidGi7dfItzdwobatK4rzZU/1+jZI8H8BcCaHhypQv8inkFW1Cty4Xl2PRRZAfLdzjdxg VyO66WaqRDdjvtZxXf2b7sy/6TEsL9V4A4ETbeSeDz0/mRZJ9asqsZvsZDTLroVtUJ6Gek7z+U WD9zo4RPI/pVUt2prR3binpiMGbZ0ggPMvpewlEASECgdSp3zQx8agnGSNQTzAbxLovssPjWl7 N/2wG+lR7wMGybQ0KahH2njg7AIWgX+xgfw7zXuohjVzsb6ZOi/MfA4/Z8+5Ik5bXgzVd+hjj0 mWM=
- References: <cover.1565398513.git.alistair.francis@wdc.com> <3ee6c1e52cbefe6f6dbd7aef423f13607ff50402.1565398513.git.alistair.francis@wdc.com> <alpine.DEB.2.21.1908121946160.18203@digraph.polyomino.org.uk> <CAKmqyKOm_j5_v45oLj+RXMZQP297QVZ54Obww9enzcp4maRHKA@mail.gmail.com>
On Thu, 15 Aug 2019, Alistair Francis wrote:
> Is this the type of layout you are looking for? (untested, just a general idea)
I'm not convinced making timespec_get into a wrapper round another
function is a good thing.
You need to end up, in the __TIMESIZE == 32 case, with two functions that
have the public timespec_get semantics - not two internal functions and a
single wrapper - in preparation for when we support _TIME_BITS == 64. So
I'd expect defining __timespec_get64 as a function with the public
semantics (not as an internal function that only calls the syscall), and
conditionally defining timespec_get as a thin wrapper in the case of
32-bit time_t, and having a #define of __timespec_get64 to timespec_get in
an internal header in the case of 64-bit time_t.
> int
> __timespec_get64 (struct __timespec64 *ts, int base)
> {
> #ifdef __ASSUME_TIME64_SYSCALLS
> return INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, ts);
> #else
You need
# ifndef __NR_clock_gettime64
# define __NR_clock_gettime64 __NR_clock_gettime
# endif
here, because 64-bit platforms define __ASSUME_TIME64_SYSCALLS but with
unsuffixed syscall names.
> long int ret;
> # ifdef __NR_clock_gettime64
> ret = INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, ts);
>
> if (ret == 0 || errno != ENOSYS)
> {
> return ret;
> }
You need to check INTERNAL_SYSCALL_ERRNO (...) not errno; errno isn't set
by INTERNAL_*, only by INLINE_*.
No braces when only a single statement is inside them.
> ret = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, &ts32);
>
> if ((ret == 0 || errno != ENOSYS) && ts)
No need to consider ENOSYS here. NULL ts isn't valid so no need to check
for it being non-NULL.
> /* Set TS to calendar time based in time base BASE. */
> int
> timespec_get (struct timespec *ts, int base)
> {
> switch (base)
> {
> int res;
> INTERNAL_SYSCALL_DECL (err);
> case TIME_UTC:
> res = __timespec_get (ts, base);
> if (INTERNAL_SYSCALL_ERROR_P (res, err))
> return 0;
This wrapper is using an uninitialized variable err.
--
Joseph S. Myers
joseph@codesourcery.com