From patchwork Mon Sep 11 13:25:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 721457 Delivered-To: patch@linaro.org Received: by 2002:adf:f64d:0:b0:31d:da82:a3b4 with SMTP id x13csp1098365wrp; Mon, 11 Sep 2023 06:26:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMQ9kNSu8WY/Z3HdubDS3S8r/bZzL05AbS11cTjTMIQfA06GkoMco7MsIB0lM/bP4Lzyrm X-Received: by 2002:a17:906:9e:b0:9a9:efdd:967a with SMTP id 30-20020a170906009e00b009a9efdd967amr9076557ejc.71.1694438763290; Mon, 11 Sep 2023 06:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694438763; cv=none; d=google.com; s=arc-20160816; b=ZCzt35Va5fPIZH0Gby2zTmjlu93QTHXmUx3VUmGDw9V6Q0cXE2koWpBtltcRqpJuBu 6LBH1BiAO7uZvITsreSbZnthXJXa0JRRS3do/6OSttcbIkJLI/W8c8z8y1NGc2/0jXpq /REv6FagdMt1WfgjQkKBjNWRkjVXSuWo8pktdKjndmiiLLRqo9m8W5YFhqAYM3PpWV3m 0u0FrpRG6LpOZasF68QlcFtBhYT7yYMaCVyQBvYvrQv4Iad02SHgLIg+JmRwzumcBzHy gezViiT3TgtPb6qAadEvud6MbdHfKNuk5ynSbn82Jtz1D3njPDo1RwS+hhoPi4oX9xlx sb9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=NrWLHGZ7b1AbkzDm3GntaD5bSoTxggCcEKadmK7gwx0=; fh=ypUQ2HUvNwsjXqW60k3fubcNnCzihljktRPFVH75lB0=; b=JokrD/6lqN7HhmA5tewZEKCG7feUsf52vc0Gi1HkAa74gKO+wLapRgEAAnTuigxsHH LKQkZxDyHXFMfZo4bW6IjwGiISe1h4itqKyr1aQkHqQOIgduu0AH+KWeC8ro3aG1YD4b RvyyP8pEjLD1dcWXQnnetqZp7ZnIkvF457XWRPaAUXxE9KMx/BgxZw4dszHdi+n7FgxF FMOcNx7rjnW/Z4AYKno9wGG/KQFZZ7I0uzVTU2iGpsn5yGjM3aGJp4EuJGjGFsatgAGF rywSyjjVQjHDWoXLFiPrV3jupE3vVSIa7/i8F6RpW5YcbCW9d0MTEdkqy1uA/zeCd1pN FVKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e1pe2+OT; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j8-20020a170906830800b00986560ae9a7si6089063ejx.307.2023.09.11.06.26.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 06:26:03 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e1pe2+OT; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 477DA3858C5E for ; Mon, 11 Sep 2023 13:26:02 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) by sourceware.org (Postfix) with ESMTPS id 504C73858D3C for ; Mon, 11 Sep 2023 13:25:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 504C73858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-5739965a482so2328728eaf.0 for ; Mon, 11 Sep 2023 06:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694438753; x=1695043553; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=NrWLHGZ7b1AbkzDm3GntaD5bSoTxggCcEKadmK7gwx0=; b=e1pe2+OTHK//NE0SLxVQX/gftcsX/INCB055Seo+ZX1HdafVHWSD4ilvsaY66PfgMM c3ePUxgYh55+gLiy5cdHE/2pKhGQvW6lXbYdiz2pTNLkie37FsbfwHf3i70KvlyjQ2jG L+pSsnfiMR5ojl9mDBQ6ZQTpwc5bnaNgx26nd+B6qZ+Wyf0HrOVBgArpX7q2vTFQFszU UU1OfOiDJOcPyFomMSXk49d03bvT8BUMm0Rdx4rcBl/+i1EpLJmGKqVhBVe8+jp2v+i5 e3njPp6jijLCIB7DodWxd8MxLghoaKaiLPzJQ/ZSk7+IlG4wRqZoUwcOhjNWzIXlgAfo iaQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694438753; x=1695043553; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NrWLHGZ7b1AbkzDm3GntaD5bSoTxggCcEKadmK7gwx0=; b=sSKgPc4moNHe1uCYIZyBuL5S2qold9pYDPE4gUE9lsA6aRgFz6wp/5d2TMLpIcaRmo Wcn7D/qXXyjQIk/GMWZq48Tu3xBOwDDzMZVbXotx5ndlIEADVQWgD1+jPTMieQpJNWg7 OpyY0gbUwCzgqVghTzLflK8wwMjXPkifhadIG7/+IfjZTEefFFgU6pSmlIpP3UwstrzF cNPvM+u0y1QMtbjjV3vxcOAmppTH3uTzzK/Vqd3mRjqTnpJmBMeqaW1+bWf1XjnFm4/Y HDCV9OJXxZ2pKHiL7roLRwgSkmaHovUnIzQ3sE6VHxVLaXhREX9e0mUmS8sCB4H61qYA OWJQ== X-Gm-Message-State: AOJu0YzhDmB1D6Sdg8jTcOfElnf5f07gUfhxVivXideOzcC3UawmsqHd 2ftUm5/QYL3gn1VJTK8ilIvIUol20odDK64xo+u+EA== X-Received: by 2002:a4a:2211:0:b0:571:1c44:c9c0 with SMTP id f17-20020a4a2211000000b005711c44c9c0mr4398760ooa.1.1694438753048; Mon, 11 Sep 2023 06:25:53 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:91cb:8dba:c245:9a76:bfb3]) by smtp.gmail.com with ESMTPSA id e190-20020a4a55c7000000b00573a3e283e1sm3345086oob.39.2023.09.11.06.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 06:25:52 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Mateusz Guzik , Linus Torvalds Subject: [PATCH v2] io: Do not implement fstat with fstatat Date: Mon, 11 Sep 2023 10:25:48 -0300 Message-Id: <20230911132548.1981093-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org AT_EMPTY_PATH is a requirement to implement fstat over fstatat, however it does not prevent the kernel to read the path argument. It is not an issue, but on x86-64 with SMAP-capable CPUs the kernel is forced to perform expensive user memory access. After that regular lookup is performed which adds even more overhead. Instead, issue the fstat syscall directly on LFS fstat implementation (32 bit architectures will still continue to use statx, which is required to have 64 bit time_t support). it should be even a small performance gain on non x86_64, since there is no need to handle the path argument. Checked on x86_64-linux-gnu. --- sysdeps/unix/sysv/linux/fstat64.c | 37 +++++++++++++++++++++++-- sysdeps/unix/sysv/linux/fstatat64.c | 12 ++------ sysdeps/unix/sysv/linux/internal-stat.h | 31 +++++++++++++++++++++ 3 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/internal-stat.h diff --git a/sysdeps/unix/sysv/linux/fstat64.c b/sysdeps/unix/sysv/linux/fstat64.c index 124384e57f..a291f0825b 100644 --- a/sysdeps/unix/sysv/linux/fstat64.c +++ b/sysdeps/unix/sysv/linux/fstat64.c @@ -19,20 +19,53 @@ #define __fstat __redirect___fstat #define fstat __redirect_fstat #include +#undef __fstat +#undef fstat #include -#include -#include +#include #include int __fstat64_time64 (int fd, struct __stat64_t64 *buf) { +#if !FSTATAT_USE_STATX +# if XSTAT_IS_XSTAT64 +# ifdef __NR_fstat + /* 64-bit kABI, e.g. aarch64, ia64, powerpc64*, s390x, riscv64, and + x86_64. */ + return INLINE_SYSCALL_CALL (fstat, fd, buf); +# elif defined __NR_fstat64 +# if STAT64_IS_KERNEL_STAT64 + /* 64-bit kABI outlier, e.g. alpha */ + return INLINE_SYSCALL_CALL (fstat64, fd, buf); +# else + /* 64-bit kABI outlier, e.g. sparc64. */ + struct kernel_stat64 kst64; + int r = INLINE_SYSCALL_CALL (fstat64, fd, &kst64); + if (r == 0) + __cp_stat64_kstat64 (buf, &kst64); + return r; +# endif /* STAT64_IS_KERNEL_STAT64 */ +# endif +# else /* XSTAT_IS_XSTAT64 */ + /* 64-bit kabi outlier, e.g. mips64 and mips64-n32. */ + struct kernel_stat kst; + int r = INLINE_SYSCALL_CALL (fstat, fd, &kst); + if (r == 0) + __cp_kstat_stat64_t64 (&kst, buf); + return r; +# endif +#else /* !FSTATAT_USE_STATX */ + /* All kABIs with non-LFS support and with old 32-bit time_t support + e.g. arm, csky, i386, hppa, m68k, microblaze, nios2, sh, powerpc32, + and sparc32. */ if (fd < 0) { __set_errno (EBADF); return -1; } return __fstatat64_time64 (fd, "", buf, AT_EMPTY_PATH); +#endif } #if __TIMESIZE != 64 hidden_def (__fstat64_time64) diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c index 3509d3ca6d..127c6ff601 100644 --- a/sysdeps/unix/sysv/linux/fstatat64.c +++ b/sysdeps/unix/sysv/linux/fstatat64.c @@ -21,12 +21,10 @@ #include #include #include -#include #include #include -#include -#include #include +#include #if __TIMESIZE == 64 \ && (__WORDSIZE == 32 \ @@ -40,11 +38,7 @@ _Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t), "__blkcnt_t and __blkcnt64_t must match"); #endif -#if (__WORDSIZE == 32 \ - && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) \ - || defined STAT_HAS_TIME32 \ - || (!defined __NR_newfstatat && !defined __NR_fstatat64) -# define FSTATAT_USE_STATX 1 +#if FSTATAT_USE_STATX static inline int fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf, @@ -79,8 +73,6 @@ fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf, return r; } -#else -# define FSTATAT_USE_STATX 0 #endif /* Only statx supports 64-bit timestamps for 32-bit architectures with diff --git a/sysdeps/unix/sysv/linux/internal-stat.h b/sysdeps/unix/sysv/linux/internal-stat.h new file mode 100644 index 0000000000..e3b0569853 --- /dev/null +++ b/sysdeps/unix/sysv/linux/internal-stat.h @@ -0,0 +1,31 @@ +/* Internal stat definitions. + Copyright (C) 2023 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 + +#if (__WORDSIZE == 32 \ + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) \ + || defined STAT_HAS_TIME32 \ + || (!defined __NR_newfstatat && !defined __NR_fstatat64) +# define FSTATAT_USE_STATX 1 +#else +# define FSTATAT_USE_STATX 0 +#endif