From patchwork Thu Sep 7 22:41:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Albert ARIBAUD (3ADEV)" X-Patchwork-Id: 811203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-84327-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="VRdXg3I3"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xpFr252Y1z9sCZ for ; Fri, 8 Sep 2017 08:44:18 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=F4yqlzY+LfRVO6nJRerg1bfC9I2NO4I OPrcgBJSpNcstgr1OAWaqI45GUTzWYkFxY7mGEKuTZZ+4NwFqaB/IITyWgfszRm8 1K/QMgVuK9m+mmKzMXMWTWsrCe+HjJJlG27ZZi8iA5iXsoBDBOGMoWKIvjOCo9Fv TxrZCKDtiuL0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=J5sY312bQVEDA7c8AZUxofu8vnw=; b=VRdXg 3I3HcbF9Xu2fXDc5pKKY/s7P9yl4c7FH4sZOopwdcvTSnymbALFdQFljkwbvaf2e glqfTBAtI/S9bfTiIcj6uHDzxXNh6s6Ejhj/qKwH17alW1BsXu7USHa5O3jNpdJq fx3qaOBNzkmHCKYRABrtP9e4SaE8fnx5HzUOXw= Received: (qmail 66407 invoked by alias); 7 Sep 2017 22:43:08 -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 66339 invoked by uid 89); 7 Sep 2017 22:43:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: smtp6-g21.free.fr From: "Albert ARIBAUD (3ADEV)" To: libc-alpha@sourceware.org Cc: "Albert ARIBAUD (3ADEV)" Subject: [RFC PATCH 09/52] Y2038: add function __clock_getres64 Date: Fri, 8 Sep 2017 00:41:36 +0200 Message-Id: <20170907224219.12483-10-albert.aribaud@3adev.fr> In-Reply-To: <20170907224219.12483-9-albert.aribaud@3adev.fr> References: <20170907224219.12483-1-albert.aribaud@3adev.fr> <20170907224219.12483-2-albert.aribaud@3adev.fr> <20170907224219.12483-3-albert.aribaud@3adev.fr> <20170907224219.12483-4-albert.aribaud@3adev.fr> <20170907224219.12483-5-albert.aribaud@3adev.fr> <20170907224219.12483-6-albert.aribaud@3adev.fr> <20170907224219.12483-7-albert.aribaud@3adev.fr> <20170907224219.12483-8-albert.aribaud@3adev.fr> <20170907224219.12483-9-albert.aribaud@3adev.fr> Signed-off-by: Albert ARIBAUD (3ADEV) --- include/time.h | 2 + sysdeps/posix/clock_getres.c | 87 +++++++++++++++++++++++++++++++++- sysdeps/unix/sysv/linux/arm/Versions | 1 + sysdeps/unix/sysv/linux/clock_getres.c | 40 ++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) diff --git a/include/time.h b/include/time.h index 63237e23f4..00bdb2853a 100644 --- a/include/time.h +++ b/include/time.h @@ -52,6 +52,8 @@ extern int __clock_gettime64 (clockid_t __clock_id, struct __timespec64 *__tp) __THROW; extern int __clock_settime64 (clockid_t __clock_id, const struct __timespec64 *__tp) __THROW; +extern int __clock_getres64 (clockid_t __clock_id, + struct __timespec64 *__res) __THROW; /* Now define the internal interfaces. */ struct tm; diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c index b6248bef2c..3b74014d41 100644 --- a/sysdeps/posix/clock_getres.c +++ b/sysdeps/posix/clock_getres.c @@ -23,7 +23,6 @@ #include #include - #if HP_TIMING_AVAIL static long int nsec; /* Clock frequency of the processor. */ @@ -53,6 +52,33 @@ hp_timing_getres (struct timespec *res) return 0; } + +static int +hp_timing_getres64 (struct __timespec64 *res) +{ + if (__glibc_unlikely (nsec == 0)) + { + hp_timing_t freq; + + /* This can only happen if we haven't initialized the `nsec' + variable yet. Do this now. We don't have to protect this + code against multiple execution since all of them should + lead to the same result. */ + freq = __get_clockfreq (); + if (__glibc_unlikely (freq == 0)) + /* Something went wrong. */ + return -1; + + nsec = MAX (UINT64_C (1000000000) / freq, 1); + } + + /* Fill in the values. + The seconds are always zero (unless we have a 1Hz machine). */ + res->tv_sec = 0; + res->tv_nsec = nsec; + + return 0; +} #endif static inline int @@ -73,6 +99,24 @@ realtime_getres (struct timespec *res) return -1; } +static inline int +realtime_getres64 (struct __timespec64 *res) +{ + long int clk_tck = sysconf (_SC_CLK_TCK); + + if (__glibc_likely (clk_tck != -1)) + { + /* This implementation assumes that the realtime clock has a + resolution higher than 1 second. This is the case for any + reasonable implementation. */ + res->tv_sec = 0; + res->tv_nsec = 1000000000 / clk_tck; + return 0; + } + + return -1; +} + /* Get resolution of clock. */ int @@ -116,3 +160,44 @@ __clock_getres (clockid_t clock_id, struct timespec *res) return retval; } weak_alias (__clock_getres, clock_getres) + +int +__clock_getres64 (clockid_t clock_id, struct __timespec64 *res) +{ + int retval = -1; + + switch (clock_id) + { +#ifdef SYSDEP_GETRES64 + SYSDEP_GETRES64; +#endif + +#ifndef HANDLED_REALTIME64 + case CLOCK_REALTIME64: + retval = realtime_getres64 (res); + break; +#endif /* handled REALTIME */ + + default: +#ifdef SYSDEP_GETRES_CPU64 + SYSDEP_GETRES_CPU64; +#endif +#if HP_TIMING_AVAIL + if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1)) + == CLOCK_THREAD_CPUTIME_ID) + retval = hp_timing_getres64 (res); + else +#endif + __set_errno (EINVAL); + break; + +#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME + case CLOCK_PROCESS_CPUTIME_ID: + case CLOCK_THREAD_CPUTIME_ID: + retval = hp_timing_getres64 (res); + break; +#endif + } + + return retval; +} diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions index 553cdd7543..4b03cce526 100644 --- a/sysdeps/unix/sysv/linux/arm/Versions +++ b/sysdeps/unix/sysv/linux/arm/Versions @@ -31,5 +31,6 @@ libc { __vdso_clock_gettime64; __y2038_kernel_support; __clock_settime64; + __clock_getres64; } } diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c index 2b7bb65e55..095b284b23 100644 --- a/sysdeps/unix/sysv/linux/clock_getres.c +++ b/sysdeps/unix/sysv/linux/clock_getres.c @@ -48,4 +48,44 @@ #define SYSDEP_GETRES_CPU SYSCALL_GETRES #define SYSDEP_GETRES_CPUTIME /* Default catches them too. */ +/* The 64-bit version */ + +extern int __y2038_linux_support; + +#define SYSCALL_GETRES64 \ + if (__y2038_linux_support) \ + { \ + retval = INLINE_VSYSCALL (clock_getres64, 2, clock_id, res); \ + } \ + else \ + { \ + retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, &ts32); \ + if (retval==0) \ + { \ + res->tv_sec = ts32.tv_sec; \ + res->tv_nsec = ts32.tv_nsec; \ + res->tv_pad = 0; \ + } \ + } \ + break + +/* The REALTIME and MONOTONIC clock are definitely supported in the + kernel. */ +#define SYSDEP_GETRES64 \ + SYSDEP_GETRES_CPUTIME64 \ + case CLOCK_REALTIME: \ + case CLOCK_MONOTONIC: \ + case CLOCK_MONOTONIC_RAW: \ + case CLOCK_REALTIME_COARSE: \ + case CLOCK_MONOTONIC_COARSE: \ + SYSCALL_GETRES64 + +/* We handled the REALTIME clock here. */ +#define HANDLED_REALTIME64 1 +#define HANDLED_CPUTIME64 1 + +#define SYSDEP_GETRES_CPU64 SYSCALL_GETRES64 +#define SYSDEP_GETRES_CPUTIME64 \ + struct timespec ts32; + #include