From patchwork Fri Oct 25 12:08:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 177738 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3603078ill; Fri, 25 Oct 2019 05:10:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5+YcmgnDBnDDlBI3RBczQsvolcjXr5yPDxkPxswKRUchXp1ZpwxkTjXDOkuAMYmlTjaoQ X-Received: by 2002:a17:906:5407:: with SMTP id q7mr3185958ejo.24.1572005412443; Fri, 25 Oct 2019 05:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572005412; cv=none; d=google.com; s=arc-20160816; b=OP3x9n4dsgPuRIQ2nnVZ6u17wUWZuV6ysdMMBeL7HyI+tURY8gBTI7U+ZJzu6oQ0gp LJmwfYmXPpvscU0J/3ftd5JojoedmhBuc9c9/Zaf+R/4IWya4lBvnFHDe5In+3da2NFZ DXWdLFmhnfZiEKRE28S4+sPQGVE40YnexD0BHXllNKqUkppw2cyLAm/hzOlt6Z5vENXY 0vTAsYs7ugRpCWxcK2G+V1FdkwVgqqwKc2xY9oilgZLF5lKkXt889WIf77PurTiz5Jxw rWoV807p05nvTPhziDNFBAftik1IogNFkUBOPYCr23m+HdxHOnZrdxpiDHrVr5AvpGPu Y9Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=kAg1ZrAuFcVfbI2HXMgUk1jLPF3FY21chvEnhK/Qjyo=; b=AaruLYHhqd25czIsREzq7ogE/xVKZRGOc1lztVnw8/jAD/hqUKG79rp/pEDcH6IFr9 WO3UBeA15wCf7dobbhIacG219USL50uFk3xQZn+DiLvNvSiy+ZW4dpZxXHSFWbmGu1U8 RxignVkUZDHfd7sJ17Y2EPEf0oaJHabC8lCY+VA4gU26t8cjnLX1ZwbuR1o3iSVvYqO2 ycwMtIiiAjsyHx8R4akPJZRl93ZdvmcuzTq/bFO1J6gW9JJDSL2N4+WqtMpgPqbbsIg4 JlZEwAbCbArtneHyNGERq2v3RUaTcQP5m1A1Wc6upzpARLMhukt9mGZPIW3j+zIilVur du/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=oY29tG+2; dkim=pass header.i=@linaro.org header.s=google header.b=OQuSbxzN; spf=pass (google.com: domain of libc-alpha-return-106288-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-106288-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id g12si1113652ejf.379.2019.10.25.05.10.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Oct 2019 05:10:12 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-106288-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=oY29tG+2; dkim=pass header.i=@linaro.org header.s=google header.b=OQuSbxzN; spf=pass (google.com: domain of libc-alpha-return-106288-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-106288-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=e60Cx2LEit8z5OzgBEK3GIrKtD6BK4E +ujgNwlY+1eJ1ZVR5sZ/mSklMZTuqxDwT1fa0taumbpDOAW/vSXMphR/df86lcFS HnS/xYwWkbJtRMla4EryDGLfrSFOkJTCIfYqnU/lMQgMm0FxkHPd+d7jcJImHYWR +5cyfFV2zddo= 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=vzzxRrCeY7UVWqAYjuR0OCbDuBs=; b=oY29t G+2F3qP3rAEyrwahCr7Nirh1GdqcPuihmPj+mMpI7DgzMUSKhKX58zu1szPIkNDp NgGbo5Lkh6RIlwYSPXUC/hNGz+/+0uWN1r78uEhSderP4qsBGxz75WI3zBgw3hmG +gwRClKLqUK15KLj6ztMA35RbG2n0AcHpirI3g= Received: (qmail 78554 invoked by alias); 25 Oct 2019 12:09:03 -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 78462 invoked by uid 89); 25 Oct 2019 12:09:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=coating X-HELO: mail-qk1-f193.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kAg1ZrAuFcVfbI2HXMgUk1jLPF3FY21chvEnhK/Qjyo=; b=OQuSbxzNSTob5kvcslzYEWdmmpod3o+Vp+3jbOuFF5R9XdG/jHUCA4+ufRXKhJBWu9 nF0kGDeVEDiJsO3cRxb29bSf9sznhELW9HxRjF/v8tHRZlsEQvVMshMH/cy2ToGpYHjF 2hoYc8D+7w/mJLO1nxqKO3FNCGM8ivy9VU9oDmhWKzRB1zlAabu1/M8IqdMrSXt+VPkp wadfFcgm+MgMv781woe/84fd+4AdmDtq7tthdJG9nYqBQpLA4UHJ0kOhy9to5tREaHdC Gud66mrn+WjT2frxG4GeG/O1f8qkhQI1ZLKVbAXie105Pv2INe+VBUUltlODiOxLZe/A 1FVw== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Lukasz Majewski , Zack Weinberg Subject: [PATCH v2 08/11] Use clock_gettime to implement timespec_get. Date: Fri, 25 Oct 2019 09:08:29 -0300 Message-Id: <20191025120832.27667-9-adhemerval.zanella@linaro.org> In-Reply-To: <20191025120832.27667-1-adhemerval.zanella@linaro.org> References: <20191025120832.27667-1-adhemerval.zanella@linaro.org> From: Zack Weinberg Use clock_gettime to implement timespec_get. Changes from previous version: - Change commit message remove the rationale to not promote it. -- timespec_get is the same function as clock_gettime, with an obnoxious coating of NIH painted on it by the ISO C committee. In addition to the rename, it takes its arguments in a different order, it returns 0 on *failure* or a positive number on *success*, and it requires that all of its TIME_* constants be positive. This last means we cannot directly reuse the existing CLOCK_* constants for it, because those have been allocated starting with CLOCK_REALTIME = 0 on all existing platforms. This patch simply promotes the sysdeps/posix implementation to universal, and removes the Linux-specific implementation, whose apparent reason for existing was to cut out one function call's worth of overhead. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu. --- sysdeps/posix/timespec_get.c | 32 ------------------ sysdeps/unix/sysv/linux/timespec_get.c | 46 -------------------------- time/timespec_get.c | 14 +++----- 3 files changed, 4 insertions(+), 88 deletions(-) delete mode 100644 sysdeps/posix/timespec_get.c delete mode 100644 sysdeps/unix/sysv/linux/timespec_get.c -- 2.17.1 Reviewed-by: Lukasz Majewski diff --git a/sysdeps/posix/timespec_get.c b/sysdeps/posix/timespec_get.c deleted file mode 100644 index e3146da2d3..0000000000 --- a/sysdeps/posix/timespec_get.c +++ /dev/null @@ -1,32 +0,0 @@ -/* timespec_get -- C11 interface to sample a clock. Generic POSIX.1 version. - Copyright (C) 2013-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - - -/* Set TS to calendar time based in time base BASE. */ -int -timespec_get (struct timespec *ts, int base) -{ - if (base == TIME_UTC) - { - __clock_gettime (CLOCK_REALTIME, ts); - return base; - } - return 0; -} diff --git a/sysdeps/unix/sysv/linux/timespec_get.c b/sysdeps/unix/sysv/linux/timespec_get.c deleted file mode 100644 index 629827d0f9..0000000000 --- a/sysdeps/unix/sysv/linux/timespec_get.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2011-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - -#ifdef HAVE_CLOCK_GETTIME_VSYSCALL -# define HAVE_VSYSCALL -#endif -#include - -/* 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 = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, ts); - if (INTERNAL_SYSCALL_ERROR_P (res, err)) - return 0; - break; - - default: - return 0; - } - - return base; -} diff --git a/time/timespec_get.c b/time/timespec_get.c index cef9a4263c..5124c747c2 100644 --- a/time/timespec_get.c +++ b/time/timespec_get.c @@ -22,16 +22,10 @@ int timespec_get (struct timespec *ts, int base) { - switch (base) + if (base == TIME_UTC) { - case TIME_UTC: - /* Not supported. */ - return 0; - - default: - return 0; + __clock_gettime (CLOCK_REALTIME, ts); + return base; } - - return base; + return 0; } -stub_warning (timespec_get)