From patchwork Sat Aug 10 00:59:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 34030 Received: (qmail 72077 invoked by alias); 10 Aug 2019 01:03:18 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 72007 invoked by uid 89); 10 Aug 2019 01:03:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=west X-HELO: esa5.hgst.iphmx.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1565398997; x=1596934997; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QToKvWvR/tacqoyiOoWvXrEKo1S5PlsffeKuk85aM0c=; b=AogCqiREiboCIR7qLeR/u+uzfaUtyaTbtYzeiudYK18C9i0yySt6jlkB O2pxALjcMrYrlft3SuMn2/YxPtzHmq5CJK/K3FImKDqssYaGM8/GoNJ4o mwLt8WkpeLRjaoqL/wYI1GcBTcFlKJ8Yd1mAsxQ+xn186HKYKy+lrJ+Jj 0ncyBoODGU2C+HIn2NdQicQ2HayRUmogwMyxDyb2iUbtx8P+UI9QgzzUo Xs0BY9+ajF1vW+lmWIhHr8+oF+Rz2xl6nLl0Yx7W6G8U0rWqewEnr5iNX YBwlnObrP3vyfFZ0nbXIY/COM24GwctazXyKMtb7YJBobo48fpAabSkmG g==; IronPort-SDR: NaBXTxolvAH6gqfkr+lhE71UxAV5jsnZRNIe9SHS2b8vzlljlrCUyp/UQvn3UnTRZuTLrU5+k6 eBddYRS56t1+xvih/87EN/gQzuTonB6Z0WJ+5kLW/riIh1RgFbW5Lzy/rZ5TWClRINQ6Z/Smqs RH2eFx7bZqr8KJNpF16stWHwNpACckG26zwncA+7pV4wD/tICqfWawkfah8EQfQOd3tzjgVcyu shB3fEREzhXmV5Z5cuquI57swD4VDz2u7YchP8eeTqvARbBDMYO5a9VJhN28XVY0KUA8J9zNYb swM= IronPort-SDR: b6QXPHP6ioLdU9PX1tN7+6ZU+OojgVVLXMJwVwmibZPO0BbF6VqWf8VuAondNiVuiiMwuYtFNj 9Yk39VwoLbB0n6HlH8lQSbWRS9tR1B6rNANDR45VxYmRIv61C1o3+5am9Nz2wrXQu/VK7EVx1g PqEpe1Fk5b2E42AMql7HB2G9LanCQnCX5CCF50x/+cYnAa3So0QIHJ9D+nBhwwzsGbQDA08MqQ KYhBcV7o2GN/iVqiQj4mPaBmNTO0ifWDc2nBCLYgqLdqpged4Uk5+dxSnQwrIbciuSuGwrrOpE GGa9GCsuV5HinET6cGac3E6g IronPort-SDR: FdvvgC9uevDH59ku6mfBvjDZCI2SkOtHv1UTIVsvAVAOcwUdXWzFpvOXAfsrhWImddxp9R/ie9 IkdbEV9eT9n8OWIsWv1ECENPN3+5mdGSldQjZvGpOsIw6RKRhJPbbShyIBaWjqEjurK/LWhLUW tqsLBJcW+phCwg0HEfQ/7kUCjV6K6DSSdBzRTpRG9gAk/OEAb+yWv6E0sq6aKC00LA45C/Vex5 oTVEBoDX2nc1POctGMIyO7FHLDzz3ABPzMwpv0aKSpvCrz7n0cx7jUy7fHE7JdFn2DWwPI9uYQ y4k= From: Alistair Francis To: libc-alpha@sourceware.org Cc: arnd@arndb.de, adhemerval.zanella@linaro.org, fweimer@redhat.com, palmer@sifive.com, macro@wdc.com, zongbox@gmail.com, alistair.francis@wdc.com, alistair23@gmail.com Subject: [RFC v4 03/24] sysdeps/gettimeofday: Use clock_gettime64 if avaliable Date: Fri, 9 Aug 2019 17:59:55 -0700 Message-Id: <1561c94daae983eb2380b9579d737146505f1a6f.1565398513.git.alistair.francis@wdc.com> In-Reply-To: References: MIME-Version: 1.0 Not all architectures support the obsolete gettimeofday so use the newer clock_gettime64 syscall if it is avaliable. This fixes RV32 build issues. This has the side effect of not setting the struct timezone *tz variable if __ASSUME_TIME64_SYSCALLS or __NR_clock_gettime64 is defined!!! The struct timezone *tz variable contaions information on the current timezone, in this structure: struct timezone { int tz_minuteswest; /* minutes west of Greenwich */ int tz_dsttime; /* type of DST correction */ }; On 32-bit systems with __ARCH_WANT_TIME32_SYSCALLS not defined there is no way way to get the struct timezone via a syscall. AFAIK there are no plans to add suppor to a future kernel. The Linux documentation says that "The use of the timezone structure is obsolete; the tz argument should normally be specified as NULL." Most callers of gettimeofday() don't use the timezone data, see example code from Debian below. If __ASSUME_TIME64_SYSCALLS and __NR_clock_gettime64 are not defined then struct timezone *tz will be set as usual. Example code from Debian: struct timeval my_gettime(void) { struct timezone tz_ignored; struct timeval tv; gettimeofday(&tv, &tz_ignored); return tv; } Signed-off-by: Alistair Francis --- ChangeLog | 1 + sysdeps/unix/sysv/linux/gettimeofday.c | 51 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/ChangeLog b/ChangeLog index aab4469b3d4..82a2cdc746d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1424,6 +1424,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 Florian Weimer diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c index a74f03825a5..bfbe7216198 100644 --- a/sysdeps/unix/sysv/linux/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/gettimeofday.c @@ -32,7 +32,58 @@ int __gettimeofday (struct timeval *tv, struct timezone *tz) { +#ifdef __ASSUME_TIME64_SYSCALLS + long int ret; + struct timespec now; + + ret = INLINE_VSYSCALL (clock_gettime64, 2, CLOCK_REALTIME, + &now); + + if (ret == 0 || errno != ENOSYS) + { + /* Convert from timespec to timeval */ + tv->tv_sec = now.tv_sec; + tv->tv_usec = now.tv_nsec / 1000; + } + return ret; +#else +# ifdef __NR_clock_nanosleep_time64 + long int ret; +# if __TIMESIZE == 64 + ret = INLINE_VSYSCALL (clock_gettime64, 2, CLOCK_REALTIME, + &now); + + if (ret == 0 || errno != ENOSYS) + { + /* Convert from timespec to timeval */ + tv->tv_sec = now.tv_sec; + tv->tv_usec = now.tv_nsec / 1000; + return ret; + } +# else + struct __timespec64 now; + + ret = INLINE_VSYSCALL (clock_gettime64, 2, CLOCK_REALTIME, + &now); + + if (ret == 0 || errno != ENOSYS) + { + /* Convert from timespec to timeval */ + tv->tv_sec = now.tv_sec; + tv->tv_usec = now.tv_nsec / 1000; + return ret; + } +# endif /* __TIMESIZE == 64 */ +# endif /* __NR_clock_nanosleep_time64 */ +# if __TIMESIZE == 64 + if (! in_time_t_range (tv->tv_sec)) + { + __set_errno (EOVERFLOW); + return -1; + } +# endif /* __TIMESIZE == 64 */ return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); +#endif } libc_hidden_def (__gettimeofday) weak_alias (__gettimeofday, gettimeofday)