From patchwork Fri Mar 24 07:27:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1760656 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=X9IQVKwS; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PjYkT3Vw0z1yXr for ; Fri, 24 Mar 2023 18:29:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D44D385AC29 for ; Fri, 24 Mar 2023 07:29:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D44D385AC29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679642971; bh=lu+jMejhLaz7GGnAXNyv8zx1R0ybGTmq5svli3qQrVc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=X9IQVKwSE7GGx0i19byKPlQhCKf9sBtHpwxMvCoKHqYZlFK8PaTZf3HMNIiPUieZz 3ZggWYfWmBPtYN9x4Z1xPWfKVOWeIIiiY+Z2JZ7khtgdvZm/YbPqQ90YUrDp8k+dqS kWBubWaXjOl5IgzQBB/gRRWU3E3ugwHhMU55oxys= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 9ADAB3858D28 for ; Fri, 24 Mar 2023 07:29:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9ADAB3858D28 Received: from stargazer.. (unknown [IPv6:240e:358:118d:1500:dc73:854d:832e:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 6260466120; Fri, 24 Mar 2023 03:28:57 -0400 (EDT) To: libc-alpha@sourceware.org Cc: caiyinyu , Wang Xuerui , Adhemerval Zanella Netto , Andreas Schwab , Xi Ruoyao Subject: [PATCH] linux: Allow avoiding va_list for generic syscall and use it for LoongArch Date: Fri, 24 Mar 2023 15:27:45 +0800 Message-Id: <20230324072745.4138-1-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_FROM, SPF_HELO_PASS, 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Currently GCC generates highly sub-optimal code on architectures where the calling convention prefers registers for arugment passing. This is GCC PR100955. While it's technically a missed-optimization in GCC, it seems not trivial to fix (I've not seen any compiler which can optimize this properly yet). As the generic Linux syscall actually uses a fixed number of arguments, we can avoid va_list if possible and make the compiler do right thing. Add a macro __ASSUME_SYSCALL_NAMED_WORKS which should be defined if: * The generic Linux syscall implementation will be used. * The calling convention has at least 7 GARs. * The kernel ABI uses registers for syscall numbers and arguments. LoongArch is benefited from this (saving about 430 CPU cycles per syscall, though I won't call it a significant improvement because syscall is "slow" in nature). And in the future we may switch more ports to use the generic syscall without a performance regression, reducing the number of target-specific syscall.{c,S} files we need to maintain. --- .../sysv/linux/loongarch/kernel-features.h | 25 +++++++++++++ sysdeps/unix/sysv/linux/syscall.c | 35 ++++++++++++++----- 2 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/loongarch/kernel-features.h diff --git a/sysdeps/unix/sysv/linux/loongarch/kernel-features.h b/sysdeps/unix/sysv/linux/loongarch/kernel-features.h new file mode 100644 index 0000000000..4a1c115831 --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/kernel-features.h @@ -0,0 +1,25 @@ +/* Set flags signalling availability of kernel features based on given + kernel version number. + 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_next + +/* Define this if the calling convention for passing 7 named arguments is + same as passing one named argument and 6 variable arguments, and the + kernel ABI uses registers for syscall number and arguments. */ +#define __ASSUME_SYSCALL_NAMED_WORKS 1 diff --git a/sysdeps/unix/sysv/linux/syscall.c b/sysdeps/unix/sysv/linux/syscall.c index a5a2843b73..ed5ad5afd5 100644 --- a/sysdeps/unix/sysv/linux/syscall.c +++ b/sysdeps/unix/sysv/linux/syscall.c @@ -16,9 +16,33 @@ License along with the GNU C Library. If not, see . */ -#include #include +#ifndef __ASSUME_SYSCALL_NAMED_WORKS +#include +#endif + +static inline long int +__syscall (long int number, long int a0, long int a1, long int a2, long int a3, + long int a4, long int a5) +{ + long int r = INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a3, a4, a5); + if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r))) + { + __set_errno (-r); + return -1; + } + return r; +} + +#ifdef __ASSUME_SYSCALL_NAMED_WORKS +long int +syscall (long int number, long int a0, long int a1, long int a2, long int a3, + long int a4, long int a5) +{ + return __syscall (number, a0, a1, a2, a3, a4, a5); +} +#else long int syscall (long int number, ...) { @@ -33,11 +57,6 @@ syscall (long int number, ...) long int a5 = va_arg (args, long int); va_end (args); - long int r = INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a3, a4, a5); - if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r))) - { - __set_errno (-r); - return -1; - } - return r; + return __syscall (number, a0, a1, a2, a3, a4, a5); } +#endif