From patchwork Mon Nov 11 21:47:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 1193158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-106905-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="SyCwqJ6V"; 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 47BkzG4GTlz9sPK for ; Tue, 12 Nov 2019 08:48:58 +1100 (AEDT) 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:mime-version:content-transfer-encoding; q=dns; s= default; b=KBva+guLOt93QZ8OLKp7LmiXRnGS57pd9uynrMzcMuILT8VKKF435 oMiSM5eC0uRe04hIEqOFbevfVQTLqTpSzvZw2dCfsQ2pEfnWE40qDeklwqtx6f7W m8OMB4fO3EXSXFQTzT1Y1qcFShOu5e5BM0GDV1E5rbamHVr1YCngjs= 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:mime-version:content-transfer-encoding; s=default; bh=/4dTyrQDm5J+9vd+tz6djBAVcGc=; b=SyCwqJ6V8Ba7WG1/HZn987kgEriG xnOx64k9t2iPLXK69UplgDkoDHxQ0H3B/8hNff373PqVs3LQ98M7GuHiCqPnBwk9 2XTC3+ujUCJzjv8djfZzYGC2+F9dMT47cjzkqEKRQ8ZSWdgovQ90IbZzxJDpG58v JzK6fhGQn1WeXbo= Received: (qmail 77817 invoked by alias); 11 Nov 2019 21:48:35 -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 77567 invoked by uid 89); 11 Nov 2019 21:48:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=contemporary, matrix, internally, observed X-HELO: mail-out.m-online.net From: Lukasz Majewski To: Joseph Myers , Paul Eggert Cc: Alistair Francis , Alistair Francis , GNU C Library , Adhemerval Zanella , Florian Weimer , Florian Weimer , Zack Weinberg , Carlos O'Donell , Lukasz Majewski Subject: [PATCH 4/5] y2038: linux: Provide __timer_gettime64 implementation Date: Mon, 11 Nov 2019 22:47:57 +0100 Message-Id: <20191111214758.3677-5-lukma@denx.de> In-Reply-To: <20191111214758.3677-1-lukma@denx.de> References: <20191111214758.3677-1-lukma@denx.de> MIME-Version: 1.0 This patch provides new __timer_gettime64 explicit 64 bit function for reading status of specified timer. To be more precise - the remaining time and interval set with timer_settime. Moreover, a 32 bit version - __timer_gettime has been refactored to internally use __timer_gettime64. The __timer_gettime is now supposed to be used on systems still supporting 32 bit time (__TIMESIZE != 64) - hence the necessary conversion from 64 bit struct __timespec64 to struct timespec. The new __timer_gettime64 syscall available from Linux 5.1+ has been used, when applicable. Build tests: - The code has been tested on x86_64/x86 (native compilation): make PARALLELMFLAGS="-j8" && make check PARALLELMFLAGS="-j8" && \\ make xcheck PARALLELMFLAGS="-j8" - The glibc has been build tested (make PARALLELMFLAGS="-j8") for x86 (i386), x86_64-x32, and armv7 Run-time tests: - Run specific tests on ARM/x86 32bit systems (qemu): https://github.com/lmajewski/meta-y2038 and run tests: https://github.com/lmajewski/y2038-tests/commits/master - Use of cross-test-ssh.sh for ARM (armv7): make PARALLELMFLAGS="-j8" test-wrapper='./cross-test-ssh.sh root@192.168.7.2' xcheck Linux kernel, headers and minimal kernel version for glibc build test matrix: - Linux v5.1 (with timer_gettime64) and glibc build with v5.1 as minimal kernel version (--enable-kernel="5.1.0") The __ASSUME_TIME64_SYSCALLS flag defined. - Linux v5.1 and default minimal kernel version The __ASSUME_TIME64_SYSCALLS not defined, but kernel supports timer_gettime64 syscall. - Linux v4.19 (no timer_gettime64 support) with default minimal kernel version for contemporary glibc (3.2.0) This kernel doesn't support timer_gettime64 syscall, so the fallback to timer_gettime is tested. Above tests were performed with Y2038 redirection applied as well as without (so the __TIMESIZE != 64 execution path is checked as well). No regressions were observed. Reviewed-by: Adhemerval Zanella --- include/time.h | 7 ++++ sysdeps/unix/sysv/linux/timer_gettime.c | 44 ++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/include/time.h b/include/time.h index 52ee213669..8b9a4b7a60 100644 --- a/include/time.h +++ b/include/time.h @@ -179,6 +179,13 @@ extern int __futimens64 (int fd, const struct __timespec64 tsp[2]); libc_hidden_proto (__futimens64); #endif +#if __TIMESIZE == 64 +# define __timer_gettime64 __timer_gettime +#else +extern int __timer_gettime64 (timer_t timerid, struct __itimerspec64 *value); +libc_hidden_proto (__timer_gettime64); +#endif + /* Compute the `struct tm' representation of T, offset OFFSET seconds east of UTC, and store year, yday, mon, mday, wday, hour, min, sec into *TP. diff --git a/sysdeps/unix/sysv/linux/timer_gettime.c b/sysdeps/unix/sysv/linux/timer_gettime.c index 8d9bef9196..31bf5ce25b 100644 --- a/sysdeps/unix/sysv/linux/timer_gettime.c +++ b/sysdeps/unix/sysv/linux/timer_gettime.c @@ -20,15 +20,51 @@ #include #include #include +#include #include "kernel-posix-timers.h" int -timer_gettime (timer_t timerid, struct itimerspec *value) +__timer_gettime64 (timer_t timerid, struct __itimerspec64 *value) { struct timer *kt = (struct timer *) timerid; - /* Delete the kernel timer object. */ - int res = INLINE_SYSCALL (timer_gettime, 2, kt->ktimerid, value); +#ifdef __ASSUME_TIME64_SYSCALLS +# ifndef __NR_timer_gettime64 +# define __NR_timer_gettime64 __NR_timer_gettime +# endif + return INLINE_SYSCALL (timer_gettime64, 2, kt->ktimerid, value); +#else +# ifdef __NR_timer_gettime64 + int ret = INLINE_SYSCALL (timer_gettime64, 2, kt->ktimerid, value); + if (ret == 0 || errno != ENOSYS) + return ret; +# endif + struct itimerspec its32; + int retval = INLINE_SYSCALL (timer_gettime, 2, kt->ktimerid, &its32); + if (! retval) + { + value->it_interval = valid_timespec_to_timespec64 (its32.it_interval); + value->it_value = valid_timespec_to_timespec64 (its32.it_value); + } - return res; + return retval; +#endif } + +#if __TIMESIZE != 64 +int +__timer_gettime (timer_t timerid, struct itimerspec *value) +{ + struct __itimerspec64 its64; + int retval = __timer_gettime64 (timerid, &its64); + if (! retval) + { + value->it_interval = valid_timespec64_to_timespec (its64.it_interval); + value->it_value = valid_timespec64_to_timespec (its64.it_value); + } + + return retval; +} +#endif +weak_alias (__timer_gettime, timer_gettime) +libc_hidden_def (timer_gettime)