From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 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 dcvr.yhbt.net (Postfix) with ESMTPS id 81BD21F463 for ; Tue, 17 Dec 2019 21:48:35 +0000 (UTC) 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=MQQAnjzbmiqofbdjzlK/g7FGIHqJPv2 xIJbIRADKO0ktCqmjm6VbDI7pboCbW4rzWe1cpXGuRXQ8RQ4wR3dSQ0XasNb/E4p 39FjHqtRI4PvjaeY+LG1VS84n1pDbL6lX2Vgg2VlV38IPDVT1Hx023fmiDkKb/95 gHz4iiV+p5xQ= 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=uN/e0 NJy/BKrHEt0Pp+bsDAXUsUFndneggS4E/iCN7zd3nUXJ//Omc+T7/3hTMyklimbC C2Ij7G8hlq0xrr06QlNCR8zECnNzOoSP6zegM3i4cpq8WqxhBej4X2QqbykhR6Sv 3XD7HJvbwDjv3nzQHnDkDs0/OPMUEdlnPebDTo= 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 Received: (qmail 110382 invoked by uid 89); 17 Dec 2019 21:47:46 -0000 Authentication-Results: sourceware.org; auth=none 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== 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 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