From patchwork Tue May 15 23:07:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Steve Ellcey X-Patchwork-Id: 27277 Received: (qmail 48796 invoked by alias); 15 May 2018 23:07:59 -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 48787 invoked by uid 89); 15 May 2018 23:07:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=1, 68, Sleep, U*$, HX-ClientProxiedBy:10b6 X-HELO: NAM03-BY2-obe.outbound.protection.outlook.com Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Steve.Ellcey@cavium.com; Message-ID: <1526425669.8676.49.camel@cavium.com> Subject: Re: [Patch] Use VDSO interface for gettimeofday on aarch64 From: Steve Ellcey Reply-To: sellcey@cavium.com To: Szabolcs Nagy , libc-alpha Cc: nd@arm.com Date: Tue, 15 May 2018 16:07:49 -0700 In-Reply-To: <0b2d054c-d016-d825-780a-27e2b7c75c6a@arm.com> References: <1525975253.28825.227.camel@cavium.com> <0b2d054c-d016-d825-780a-27e2b7c75c6a@arm.com> Mime-Version: 1.0 X-ClientProxiedBy: CO2PR07CA0052.namprd07.prod.outlook.com (2603:10b6:100::20) To SN6PR07MB4573.namprd07.prod.outlook.com (2603:10b6:805:5f::16) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(49563074)(7193020); SRVR:SN6PR07MB4573; X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4573; 3:9aCVZ75+V8vf1NEMzJqnoOkPZEcbww/2Gq9WEcfR/S8xlbLMuDLTZUN5FFgmXfI/nC89RjrX4UEBq0C7FbP55iE4PWyZSfD0ahkUE+LXprZ8DgHZyjmBVuwCMS8vfhmZjkZHxuCaf+ng3IFoFHtjSRMLHVKmtkNGaGw/W+PXPpob+8fEDgpv7pM4jGx9RQsD/jvrImofnAExzizR3q0fE0ky7L1vCbJm0+N4ViuKPC5Cqsk6SshSe7sJfUd52wLk; 25:GwI371zopcJa3TMlCVCgL3LaJ3yo7TldQ9+N/ISf6QwXric0qqBXbhlCGQMxplhEg4QS1OVRESmVdN0ZVsg2f2jtDeHRs4bH81I47Qr4halO3tRs8o03txO8sblxkir/uk9/UVPuoZRPDyvpSPBHpUmj61KLk4+Tb7EAtjydyOVZvQdlUOQeNtlHipq92fj0yLsDHG/5JicNUtqrv+apHHr19uFPVvi1dED28E0rTs2zJBbS8Hk9Kf+90vv13HdM43G87rf/MjfSwU0D2W74Q68d74T/VxksSXSDfE3KeaN7ElK3/K24ch+m7kWDT+9wTf9WGTX9EAiWrbbB/cI75A==; 31:Qn5yVWnC2hUPaaKgQ10ejxCy+JlJ75sCUuwD/OmYOUnbCJDdwPks4Z3k9QUKUsbrAMN7tngVvcESKQz1+U/Dc2e2p0IekY1RmOutgMbUR8vM25cr/GO4y31uSMgDZbU6BYXyfIUjqiF9JpgXD0BRpN7/m2u01YdeJBZ9eYnU6L++h1T3ZsQV5tHtQhehjt91MsLK3ZaKJ8znTe5REdzMWRWzr+IsomdbZRZb7yGQOM0= X-MS-TrafficTypeDiagnostic: SN6PR07MB4573: X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4573; 20:+dptyHG31XX4D5i6dp7sL/MjKEm5h3vg1PTW8iA2GqR6QMjfNh1pLvDswnmYat+00C2T1cwf5WwBAxKDIrwwigPYzqeBJLMdObGJF6udl79oe2hy9/c6qgVmHdAeGVFGMoCR4VEVxQcEAvBhWMqiDaxSQ43TEaiN9oDrx28I9yp3SO+aTV2XpY0t5haTXC0uAHNeoZX0F7wHVx1Lx8NB1QUKzLryIlDdGP/PF/Ab80B5Cv1NptbqA8wUWV6I3WDR8E+mjIHwtVDJdGaIXpkMReglQdN3bnmWYVCGqaY2DJfZcpHL5tC5jcSAn7erAG2EmuttaGiuo3o25edQ6aF02teIs/8SZeCMtoMGF6OYBTkdkQjbDJMk6dslu2ysV/GKo9k7s//HXZiKNXYbvg0YuXI19CDpv0zsUQ5A1mbNUF+KRe0SeN2a12IU8r5/YdpSkkMTwfcdEqrKuSlPXihoHHsKEw4d1qRefCP6q1LT0rEObqoy51HKS4aP2YBjzPs8; 4:a13ou6j83CO641Ld5VdPTLg5R6PbOqEW7lVcVPBxPvh/vusK3U4k8lSJ/8YTOY5+MM9pa28przMgGF6swARSeirZTNJ34pP0QHmEMdGFOY4KHgF+wwH/GPp86X438jmPn+CCQOQi4jgJd+8PpptQ2MC7KfYpOboj4YbCfRgAYdz7wdU6ZZZDEAjD6wqhCyH1vvkNcht73p4ZO4jfQbN6HGS9ykphiXH4FxEarbPKa2CGsV1cv84XhW89AQBndYrzGy7u8SYwEp0TLMDAgJBhYw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(102415395)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231254)(944501410)(52105095)(149027)(150027)(6041310)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:SN6PR07MB4573; BCL:0; PCL:0; RULEID:; SRVR:SN6PR07MB4573; X-Forefront-PRVS: 0673F5BE31 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(39860400002)(39380400002)(396003)(346002)(376002)(377424004)(189003)(199004)(81156014)(81166006)(52116002)(6666003)(6512007)(50226002)(68736007)(5890100001)(4610100001)(8936002)(229853002)(5660300001)(2616005)(476003)(956004)(486006)(103116003)(53936002)(97736004)(6486002)(59450400001)(568964002)(106356001)(11346002)(53416004)(105586002)(26005)(2476003)(186003)(16526019)(386003)(6506007)(33964004)(69596002)(36756003)(8676002)(76176011)(446003)(305945005)(7736002)(2906002)(4326008)(6246003)(3450700001)(72206003)(25786009)(316002)(16586007)(110136005)(478600001)(43066004)(6116002)(3846002)(66066001)(84326002)(99106002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR07MB4573; H:sellcey-dt.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN6PR07MB4573; 23:yG05BHVy5SFumYaJl4aZ4BVicRUhHvdE+29J6fwR8?= =?us-ascii?Q?Sxe36noB20T5r1Ch69SSGuq/Ojod3QmMuiMu2ivrBFw2Eead6byTv4EkH1/+?= =?us-ascii?Q?wDANGskMlDritDOGXtB/++CtW8lYUckDkIFphTXe8nClUqgJBSUUoBCuGUyU?= =?us-ascii?Q?7DmraK+uuUVaXqh16H6Fob2aBJUu0ppFxfe7fmUprdjKb4ut7Z8tcho2v1bS?= =?us-ascii?Q?DD9GPWq7TPSLqGeKnFplL3pyNy11/sGuZae2v3cilYkXeWY1+senp0iQazAP?= =?us-ascii?Q?Oge7kx4ZTdLoJGM4cWYeeVy/Hca0KZMeoRlYosG+RqQF5X2Rd8EFqOjb56Ab?= =?us-ascii?Q?DMWRuSPO9IUy1e1zjRuGPWRXT8zIFyGIr+hpXfKHfVT4oM+kjA4/I/fX2LeW?= =?us-ascii?Q?Rws61HImt2aTIvy6BV7ge1tQHzHQkDe2TZpkvyQ3tPVM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Ef0EDEOEZRppno=; 24:CPE8BpJjBJ9yrwnu4yFPKILYwTpBO8MfIeWhCEaErwGADMWLgIJKNJf65hiGQzqwT8siv+jE0R2ir2lCI/bE8aPKkNvbKglhzhCMuxCymYQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4573; 7:YnO9TaOSBBkldowaMp0HDBCJoRkkQ2TefE8K7N3dBgkqKlF1YwY91H1xm02sMlf4WqVKBHEHSCnk+tuTi3e4tv0GHJxehMTZNxagGcYMVh534e1lA5pwCR7N+apBvi1aActfYixP+ZBrCGd2EnqlSBXNsK1yCCgLklcLFEBnBUn6dXNi01r5I4OT8Dpo35qpiGYa4CNIrikLd+t69S9R1AUSWgFQHqbi8KuY/JWqzOewHnVVy7EpK8FhOd5oDut0 X-MS-Office365-Filtering-Correlation-Id: 8928e9f1-798a-41d7-810b-08d5bab8afcd X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2018 23:07:52.5272 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8928e9f1-798a-41d7-810b-08d5bab8afcd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR07MB4573 Here is an updated version of the gettimeofday vdso patch.  I tried to address as many of the questions as I could.  I added two tests, tst-gettimeofday and tst-gettimeofday2.  tst-gettimeofday2 just  includes tst-gettimeofday but is tested with 'LD_BIND_NOW=1'. I think defining __gettimeofday to be __redirect___gettimeofday and including sys/time.h is the best way to handle things.  Even if we did a explicit definition of __redirect__gettimeofday we would need to include sys/time.h to get the timeval and timezone structures and if we didn't redefine __gettimeofday when doing that the definition of __gettimeofday in the header file would conflict with the one defined by libc_ifunc_hidden.  This is how x86 and powerpc handle it in their gettimeofday functions and also how aarch64 handles the definition/redefinition of memcpy in sysdeps/aarch64/multiarch/memcpy.c. I am not sure how to handle the static linked binary issue you raised, I have been copying what x86/powerpc did and if they or some other platform has solved this then I would be interested in how to do it.  Since PR 19767 is still open I assume it hasn't been fixed anywhere yet and I would rather not try to deal with it in this patch. I changed __gettimeofday_syscall to __gettimeofday_vsyscall and I got rid of the redefinition of libc_hidden_def by just calling __hidden_ver1 directly (in the shared case). There do seem to be places where libc calls gettimeofday (nis/nis_call.c, login/logwtmp.c, resolv/gai_suspend.c, others).  Most of them call __gettimeofday but some just call gettimeofday.  I am not sure what if anything needs to be done with these calls, they don't seem to have changed when x86 or powerpc made their gettimeofday/vdso changes.. Steve Ellcey sellcey@cavium.com This is what I would use for a commit message: aarch64: Use an ifunc/VDSO to implement gettimeofday in shared glibc. This patch uses an ifunc to implement gettimeofday in the shared libc. If the kernel supports the VDSO interface we use it, otherwise we use the old method of a vsyscall.  The static version of gettimeofday  continues to use a syscall. 2018-05-15  Steve Ellcey   * sysdeps/unix/sysv/linux/aarch64/gettimeofday.c: New file. * posix/tst-gettimeofday.c: New file. * posix/tst-gettimeofday2.c: New file. * posix/Makefile (tests): Add new tests to list. diff --git a/posix/Makefile b/posix/Makefile index e9730ee..2cd3a44 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -95,7 +95,8 @@ tests := test-errno tstgetopt testfnm runtests runptests \ tst-posix_spawn-fd tst-posix_spawn-setsid \ tst-posix_fadvise tst-posix_fadvise64 \ tst-sysconf-empty-chroot tst-glob_symlinks tst-fexecve \ - tst-glob-tilde test-ssize-max + tst-glob-tilde test-ssize-max \ + tst-gettimeofday tst-gettimeofday2 tests-internal := bug-regex5 bug-regex20 bug-regex33 \ tst-rfc3484 tst-rfc3484-2 tst-rfc3484-3 \ tst-glob_lstat_compat @@ -257,6 +258,8 @@ tst-boost-ARGS = BOOST.tests bug-glob1-ARGS = "$(objpfx)" tst-execvp3-ARGS = --test-dir=$(objpfx) +tst-gettimeofday2-ENV = LD_BIND_NOW=1 + testcases.h: TESTS TESTS2C.sed LC_ALL=C sed -f TESTS2C.sed < $< > $@T mv -f $@T $@ diff --git a/posix/tst-gettimeofday.c b/posix/tst-gettimeofday.c index e69de29..703c1ce 100644 --- a/posix/tst-gettimeofday.c +++ b/posix/tst-gettimeofday.c @@ -0,0 +1,55 @@ +/* Copyright (C) 2018 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 +#include +#include +#include +#include + + +/* Test that nanosleep() does sleep. */ +static int +do_test (void) +{ + /* Current time. */ + struct timeval tv1; + TEMP_FAILURE_RETRY (gettimeofday (&tv1, NULL)); + + /* Sleep for one second to make sure time changes. */ + TEMP_FAILURE_RETRY (sleep (1)); + + /* At least one second must have passed. */ + struct timeval tv2; + TEMP_FAILURE_RETRY (gettimeofday (&tv2, NULL)); + + tv2.tv_sec -= tv1.tv_sec; + tv2.tv_usec -= tv1.tv_usec; + if (tv2.tv_usec < 0) + --tv2.tv_sec; + + if (tv2.tv_sec < 1) + { + puts ("sleep didn't sleep long enough or gettimeofday is broken"); + return 1; + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/posix/tst-gettimeofday2.c b/posix/tst-gettimeofday2.c index e69de29..6c08761 100644 --- a/posix/tst-gettimeofday2.c +++ b/posix/tst-gettimeofday2.c @@ -0,0 +1 @@ +#include "tst-gettimeofday.c" diff --git a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c index e69de29..5b6ba70 100644 --- a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c @@ -0,0 +1,68 @@ +/* Copyright (C) 2018 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 + . */ + +/* Get the current time of day and timezone information, + putting it into *tv and *tz. If tz is null, *tz is not filled. + Returns 0 on success, -1 on errors. */ + +#ifdef SHARED + +# define __gettimeofday __redirect___gettimeofday +# include +# undef __gettimeofday +# define HAVE_VSYSCALL +# include +# include + +static int +__gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz) +{ + return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); +} + +/* PREPARE_VERSION will need an __LP64__ ifdef when ILP32 support + goes in. See _libc_vdso_platform_setup in + sysdeps/unix/sysv/linux/aarch64/init-first.c. */ + +# undef INIT_ARCH +# define INIT_ARCH() \ + PREPARE_VERSION (linux_version, "LINUX_2.6.39", 123718537); \ + void *vdso_gettimeofday = \ + _dl_vdso_vsym ("__kernel_gettimeofday", &linux_version); + +libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday, + vdso_gettimeofday ?: (void *) __gettimeofday_vsyscall) + +__hidden_ver1 (__gettimeofday_vsyscall, __GI___gettimeofday, + __gettimeofday_vsyscall); + +#else + +# include +# include +int +__gettimeofday (struct timeval *tv, struct timezone *tz) +{ + return INLINE_SYSCALL (gettimeofday, 2, tv, tz); +} +libc_hidden_def (__gettimeofday) + +#endif + +weak_alias (__gettimeofday, gettimeofday) +libc_hidden_weak (gettimeofday)