From patchwork Tue Dec 17 21:47:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 181917 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp6350139ile; Tue, 17 Dec 2019 13:48:43 -0800 (PST) X-Google-Smtp-Source: APXvYqxzQMlQwHrcUhHOkPx6+zQM/1ELme9c8BL2/JTJDr9IcEmEJayDcxmFqSPQdFp5cFGjMkvJ X-Received: by 2002:a05:6830:1bf1:: with SMTP id k17mr39606319otb.101.1576619323165; Tue, 17 Dec 2019 13:48:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576619323; cv=none; d=google.com; s=arc-20160816; b=KbYkfj25dzWRtvNgwAMx3Bs3NgUrMkBWD2Bsv78weNpeolzQjzci/nLgsp9RfRrkI1 kp0wRQEIJJbH5fsm10m7ydCMhgIzAzTzm9ZHbxqZX5EGEB1nn8+CTCrw6j8fEd/uorGy rOlA0g3t/JZtufmGC4jPOt/fQQKdNzZmscaG2ZQMF46hcV6udv9igEExOE0HFtUfQcgE X/tUSZaosUr0reoeAIL40bH4Z8CicGoZhzZGa7lTlFfwpjmbGnmCES6U4YvJFQSNEeCI VLrXaOZF6jJM8E2IGlNZaqhtDHzjnsPA5yrM0SzJhrs4U4/e/wrFLmCj59NTnnfjgoZJ OKVA== 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: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=IIuAdZVF2aJgLYlG8U70B93H4H5XyR7ZjkbmnZah82w=; b=je83s/AjYw8eRRM8aiz2FL2AlC8cVBGjTVWW9ILhElvbfEDNo1VDNLWx349CEcBZRe 1KDv+77Gmjefl9G6IM4fl6w/jlHtjA3S3niBFGZtYAMcuubIJ4nY3yxSQlCExFQLjRc8 wvxZIJ+nshmalfheeibkaMbOy9f2zmNQl49+Hsil1zbmyv7jDq9qYxFf+zDOKxWsj35e 42ja/lGB0aWST3VjdlXo0yePDEZsWX1zR0yw+E+yFfbp1kXjy1JAGosQRrO/q49zUWFw gV5p4aTc7z8dnBNjn4J87o5gFA7ntBAf3G7eoayufntuSKZSYho3Yi7ExReqRF6goiBA ffiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=TSivZAkD; dkim=pass header.i=@linaro.org header.s=google header.b=CGGZos12; spf=pass (google.com: domain of libc-alpha-return-108168-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-108168-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 u30si14295617otj.268.2019.12.17.13.48.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2019 13:48:43 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-108168-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=TSivZAkD; dkim=pass header.i=@linaro.org header.s=google header.b=CGGZos12; spf=pass (google.com: domain of libc-alpha-return-108168-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-108168-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:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=Z8ZJznCuME2OyAjj7cIjC/16QPQ7Pi9 P2XO8tlO0wZtQRgNW65211jfnAyvQ9Jp5zLK0jgI8j2YeIICdcGgZo6RPB64CY8e t2JnxUZfbA1/4VLwnW1UX/Qu4xwaOmg8vmy8zJ+1fyk2rDXD67C1FGBG/d1dSwrt HUtExb6MBSKA= 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:subject:date:message-id:in-reply-to :references; s=default; bh=doqqrwj4k32e2QcT9kKA/au5FUs=; b=TSivZ AkDELaA4rGuadnA6k7wz4msOWfVHMNCJKIXQMJJQdJ5d+zD9mitxtbHgiXdbUfQM D8mrQkbzTlPBHKiOD+vkPxNs/Gb43FgqpT6InLe2wssymZXndK927+AHcZXKkeEi iJwswgHsCCo0e0GvLOXmSZjHG//xfQFIM9SlA8= Received: (qmail 110447 invoked by alias); 17 Dec 2019 21:47:47 -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 110382 invoked by uid 89); 17 Dec 2019 21:47:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.9 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=consolidate, Consolidate X-HELO: mail-pj1-f67.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=IIuAdZVF2aJgLYlG8U70B93H4H5XyR7ZjkbmnZah82w=; b=CGGZos12QW4k1XaRxPreMlHLdMrKL3LJQUTBdtnGKK34/dX0b/IhpzHcF9MGQDQZS/ Oim2Kg6LVBA51YMemOjys1AbPok7NpviuuMBvoZza4dnsWJRqsKFVmdYlTEFk2MRCL+L 2E9p0f8HSR7Z4GPu2mlcKNW60yawn7SlRulrr36JAe51rd3ywt4+xapPTdd2Mytu3i8R trVwnTbkTvjxqzNF4bfFBV9XCutyXF+KeOGkaX5pFtaLsY0yxPGxYVgoHUDfvJ7oV/cr oeEvHhklAFpC4wrrDejmE7vx4l+iBZdmtdVrUBYb+IgvwOwByvXvkEct9Tj39nLVAtm+ GHpw== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 06/16] linux: Consolidate Linux gettimeofday Date: Tue, 17 Dec 2019 18:47:18 -0300 Message-Id: <20191217214728.2886-6-adhemerval.zanella@linaro.org> In-Reply-To: <20191217214728.2886-1-adhemerval.zanella@linaro.org> References: <20191217214728.2886-1-adhemerval.zanella@linaro.org> The IFUNC bypass to vDSO is used when USE_IFUNC_GETTIMEOFDAY is set. Currently aarch64, powerpc*, and x86 defines it. Otherwise the generic implementation is used, which calls clock_gettime. Checked on aarch64-linux-gnu, powerpc64le-linux-gnu, powerpc64-linux-gnu, powerpc-linux-gnu-power4, x86_64-linux-gnu, and i686-linux-gnu. --- .../unix/sysv/linux/aarch64/gettimeofday.c | 38 +------------ sysdeps/unix/sysv/linux/gettimeofday.c | 57 +++++++++++++++++++ .../unix/sysv/linux/powerpc/gettimeofday.c | 35 +----------- sysdeps/unix/sysv/linux/x86/gettimeofday.c | 33 +---------- 4 files changed, 63 insertions(+), 100 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/gettimeofday.c -- 2.17.1 diff --git a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c index 143c5c1507..f28260c8e9 100644 --- a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c @@ -16,39 +16,5 @@ 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. */ - -#include -#include -#include - -/* Used as a fallback in the ifunc resolver if VDSO is not available - and for libc.so internal __gettimeofday calls. */ -static int -__gettimeofday_vsyscall (struct timeval *restrict tv, void *restrict tz) -{ - if (__glibc_unlikely (tz != 0)) - memset (tz, 0, sizeof *tz); - - return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); -} - -#ifdef SHARED -# include -# include - -# define INIT_ARCH() -libc_ifunc (__gettimeofday, - (get_vdso_symbol (HAVE_GETTIMEOFDAY_VSYSCALL) - ?: __gettimeofday_vsyscall)) - -#else -int -__gettimeofday (struct timeval *restrict tv, void *restrict tz) -{ - return __gettimeofday_vsyscall (tv, tz); -} -#endif -weak_alias (__gettimeofday, gettimeofday) +#define USE_IFUNC_GETTIMEOFDAY +#include diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c new file mode 100644 index 0000000000..600da6b468 --- /dev/null +++ b/sysdeps/unix/sysv/linux/gettimeofday.c @@ -0,0 +1,57 @@ +/* gettimeofday - set time. Linux version. + Copyright (C) 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 + . */ + +/* Some architecture might optimize the gettimeofday by setting the plt direct + to vDSO symbol by using a IFUNC. */ +#ifdef USE_IFUNC_GETTIMEOFDAY +# include +# include +# include + +# ifdef SHARED +# include + +static int +__gettimeofday_syscall (struct timeval *restrict tv, void *restrict tz) +{ + if (__glibc_unlikely (tz != 0)) + memset (tz, 0, sizeof *tz); + return INLINE_SYSCALL_CALL (gettimeofday, tv, tz); +} + +# undef INIT_ARCH +# define INIT_ARCH() \ + void *vdso_gettimeofday = get_vdso_symbol (HAVE_GETTIMEOFDAY_VSYSCALL) +libc_ifunc (__gettimeofday, + vdso_gettimeofday ? VDSO_IFUNC_RET (vdso_gettimeofday) + : (void *) __gettimeofday_syscall) + +# else +int +__gettimeofday (struct timeval *restrict tv, void *restrict tz) +{ + if (__glibc_unlikely (tz != 0)) + memset (tz, 0, sizeof *tz); + + return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); +} +# endif +weak_alias (__gettimeofday, gettimeofday) +#else /* USE_IFUNC_GETTIMEOFDAY */ +# include