Message ID | 20231213211142.1543025-1-evan@rivosinc.com |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25ADA385E038 for <patchwork@sourceware.org>; Wed, 13 Dec 2023 21:12:07 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by sourceware.org (Postfix) with ESMTPS id C07C9385841F for <libc-alpha@sourceware.org>; Wed, 13 Dec 2023 21:11:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C07C9385841F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C07C9385841F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702501915; cv=none; b=lxQ8/q0AcfrWyuqVhXeKjfoeA7+h7IaaqIReY0CNy+AlXUk+1Zr/qE2/evBBbPNdsMFxQ2CAajrCoDAr5HX/Q47kgAvPDWlmZ0mGxWLZTWraUFKAvLrP/cvwCo+4VXJrzWROGwnMs/w3sQ1QgKo9RoYDp1mQ9gzFcOk49sp4ZRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702501915; c=relaxed/simple; bh=I4opS9Be+INtkC2hA9gWrJz7Gocigk1ne0Vev3kF9No=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=BU5MPH5RSHiNAopp/55adQOpn2ho2CtuBJjmG7TQGAcWL9rHgvHJlPjzJxY+IdJrzk8UVr0A1xyafqwOvtgvCw3NoYfKWs463Q0wq4DWxItcw84KukAFVGEEhITHTsxA8v7zu52CXxq1qEwF6/M0TOXxQsw3oC18peAjkz3WlXk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-591553d3835so661792eaf.3 for <libc-alpha@sourceware.org>; Wed, 13 Dec 2023 13:11:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702501911; x=1703106711; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IKe6RkJc42cwV29ZWu3fQ433DqdAfgYOqUS4IYSdMrs=; b=RCPvHYnKlJAfiHKVOfKKckqL3lIumRqaES5d6YpXoCEmXcY8EzQ4XiMrOMZzoe8iyP jASS8/oMLyxjFnOt3EEAJWAM8BJEKUYcoDhZn6B1FHaPGR1zy7iq3bpdH9WY4uPYYmM/ H1+qt6yoJ/Wd+7miKErGo1VS1NZadWWs5+QbM7YaVSuyJZjJh9mB+kPbdpDEMhQzdV7n nRavxW6mp+b47zi3o9rko4AyIah+0NC5Hh0IfOof7/+i6l2a4XwQ0NTcVdPuynzBNZwe 62bHFhs7XhrdORYcLClisnoP2NJyrtLJnN6crEiMlPMmzikEIr7xnbFAHypU9kCXEWKk YydA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702501911; x=1703106711; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IKe6RkJc42cwV29ZWu3fQ433DqdAfgYOqUS4IYSdMrs=; b=e6k6wIj8bXMGfQAEekvhgJwDFDCVR/RCHOvoE9j6TuVAW2HpXWud/ln73cqNwQBFpS wKqLH8z3LdCqmDP3VS4MuRdYTGd1qs2aSI3bDLuouDJr/qLwNSL3FbP0w3qYFiss99sG 9Mw84l5rBtk3Aw/LtMz+mnv6pr13hai8ZDDptjgVvGfdGAFlHJrbQ0kzauvlG3/WHf2z UNRqMeOg+CYAj95dIs+LCl3wkZwgeOdjYeiwKjucMp5BzSod8UhQvMHz2vtZFQ09AkJB C0rnyZ/PaJZdI/VHszBvo+c8uFe774xyFvCQ+eYyEwswaTMXOIALRHtniPxkk5HG+Vqj 1yZA== X-Gm-Message-State: AOJu0Yziq7k6IOcTdNlF7517vszhySpJ7j05ZJJEdxpnvhtnJRrWlTxw zaQZgTMWw6KHGSa3uHCncbskVJVaJEAb7jHiASo= X-Google-Smtp-Source: AGHT+IGBZPr6eTXAWyTavk1cVpZ2He8BBfuhIgDR6Hi+dDdyt7MGVZM3pEB8PI4KJJMuVRKLPBRBPw== X-Received: by 2002:a4a:af44:0:b0:590:87ea:16d1 with SMTP id x4-20020a4aaf44000000b0059087ea16d1mr5096358oon.11.1702501911123; Wed, 13 Dec 2023 13:11:51 -0800 (PST) Received: from evan.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id c15-20020a4a380f000000b0058d1de21893sm3223109ooa.24.2023.12.13.13.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 13:11:50 -0800 (PST) From: Evan Green <evan@rivosinc.com> To: libc-alpha@sourceware.org Cc: vineetg@rivosinc.com, slewis@rivosinc.com, palmer@rivosinc.com, Florian Weimer <fweimer@redhat.com>, Evan Green <evan@rivosinc.com> Subject: [PATCH v10 0/7] RISC-V: ifunced memcpy using new kernel hwprobe interface Date: Wed, 13 Dec 2023 13:11:35 -0800 Message-Id: <20231213211142.1543025-1-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org |
Series |
RISC-V: ifunced memcpy using new kernel hwprobe interface
|
|
Message
Evan Green
Dec. 13, 2023, 9:11 p.m. UTC
This series illustrates the use of a recently accepted Linux syscall that enumerates architectural information about the RISC-V cores the system is running on. In this series we expose a small wrapper function around the syscall. An ifunc selector for memcpy queries it to see if unaligned access is "fast" on this hardware. If it is, it selects a newly provided implementation of memcpy that doesn't work hard at aligning the src and destination buffers. For applications and libraries outside of glibc that want to use __riscv_hwprobe() in ifunc selectors, this series also sends a pointer to the riscv_hwprobe() function in as the second argument to ifunc selectors. A new inline convenience function can help application and library callers to check for validity and quickly probe a single key. The memcpy implementation is independent enough from the rest of the series that it can be omitted safely if desired. Performance numbers were compared using a small test program [1], run on a D1 Nezha board, which supports fast unaligned access. "Fast" here means copying unaligned words is faster than copying byte-wise, but still slower than copying aligned words. Here's the speed of various memcpy()s with the generic implementation. The numbers before are using v4's memcpy implementation, with the "copy last byte via overlapping misaligned word" fix this should get slightly better. memcpy size 1 count 1000000 offset 0 took 109564 us memcpy size 3 count 1000000 offset 0 took 138425 us memcpy size 4 count 1000000 offset 0 took 148374 us memcpy size 7 count 1000000 offset 0 took 178433 us memcpy size 8 count 1000000 offset 0 took 188430 us memcpy size f count 1000000 offset 0 took 266118 us memcpy size f count 1000000 offset 1 took 265940 us memcpy size f count 1000000 offset 3 took 265934 us memcpy size f count 1000000 offset 7 took 266215 us memcpy size f count 1000000 offset 8 took 265954 us memcpy size f count 1000000 offset 9 took 265886 us memcpy size 10 count 1000000 offset 0 took 195308 us memcpy size 11 count 1000000 offset 0 took 205161 us memcpy size 17 count 1000000 offset 0 took 274376 us memcpy size 18 count 1000000 offset 0 took 199188 us memcpy size 19 count 1000000 offset 0 took 209258 us memcpy size 1f count 1000000 offset 0 took 278263 us memcpy size 20 count 1000000 offset 0 took 207364 us memcpy size 21 count 1000000 offset 0 took 217143 us memcpy size 3f count 1000000 offset 0 took 300023 us memcpy size 40 count 1000000 offset 0 took 231063 us memcpy size 41 count 1000000 offset 0 took 241259 us memcpy size 7c count 100000 offset 0 took 32807 us memcpy size 7f count 100000 offset 0 took 36274 us memcpy size ff count 100000 offset 0 took 47818 us memcpy size ff count 100000 offset 0 took 47932 us memcpy size 100 count 100000 offset 0 took 40468 us memcpy size 200 count 100000 offset 0 took 64245 us memcpy size 27f count 100000 offset 0 took 82549 us memcpy size 400 count 100000 offset 0 took 111254 us memcpy size 407 count 100000 offset 0 took 119364 us memcpy size 800 count 100000 offset 0 took 203899 us memcpy size 87f count 100000 offset 0 took 222465 us memcpy size 87f count 100000 offset 3 took 222289 us memcpy size 1000 count 100000 offset 0 took 388846 us memcpy size 1000 count 100000 offset 1 took 468827 us memcpy size 1000 count 100000 offset 3 took 397098 us memcpy size 1000 count 100000 offset 4 took 397379 us memcpy size 1000 count 100000 offset 5 took 397368 us memcpy size 1000 count 100000 offset 7 took 396867 us memcpy size 1000 count 100000 offset 8 took 389227 us memcpy size 1000 count 100000 offset 9 took 395949 us memcpy size 3000 count 50000 offset 0 took 674837 us memcpy size 3000 count 50000 offset 1 took 676944 us memcpy size 3000 count 50000 offset 3 took 679709 us memcpy size 3000 count 50000 offset 4 took 680829 us memcpy size 3000 count 50000 offset 5 took 678024 us memcpy size 3000 count 50000 offset 7 took 681097 us memcpy size 3000 count 50000 offset 8 took 670004 us memcpy size 3000 count 50000 offset 9 took 674553 us Here is that same test run with the assembly memcpy() in this series: memcpy size 1 count 1000000 offset 0 took 92703 us memcpy size 3 count 1000000 offset 0 took 112527 us memcpy size 4 count 1000000 offset 0 took 120481 us memcpy size 7 count 1000000 offset 0 took 149558 us memcpy size 8 count 1000000 offset 0 took 90617 us memcpy size f count 1000000 offset 0 took 174373 us memcpy size f count 1000000 offset 1 took 178615 us memcpy size f count 1000000 offset 3 took 178845 us memcpy size f count 1000000 offset 7 took 178636 us memcpy size f count 1000000 offset 8 took 174442 us memcpy size f count 1000000 offset 9 took 178660 us memcpy size 10 count 1000000 offset 0 took 99845 us memcpy size 11 count 1000000 offset 0 took 112522 us memcpy size 17 count 1000000 offset 0 took 179735 us memcpy size 18 count 1000000 offset 0 took 110870 us memcpy size 19 count 1000000 offset 0 took 121472 us memcpy size 1f count 1000000 offset 0 took 188231 us memcpy size 20 count 1000000 offset 0 took 119571 us memcpy size 21 count 1000000 offset 0 took 132429 us memcpy size 3f count 1000000 offset 0 took 227021 us memcpy size 40 count 1000000 offset 0 took 166416 us memcpy size 41 count 1000000 offset 0 took 180206 us memcpy size 7c count 100000 offset 0 took 28602 us memcpy size 7f count 100000 offset 0 took 31676 us memcpy size ff count 100000 offset 0 took 39257 us memcpy size ff count 100000 offset 0 took 39176 us memcpy size 100 count 100000 offset 0 took 21928 us memcpy size 200 count 100000 offset 0 took 35814 us memcpy size 27f count 100000 offset 0 took 60315 us memcpy size 400 count 100000 offset 0 took 63652 us memcpy size 407 count 100000 offset 0 took 73160 us memcpy size 800 count 100000 offset 0 took 121532 us memcpy size 87f count 100000 offset 0 took 147269 us memcpy size 87f count 100000 offset 3 took 144744 us memcpy size 1000 count 100000 offset 0 took 232057 us memcpy size 1000 count 100000 offset 1 took 254319 us memcpy size 1000 count 100000 offset 3 took 256973 us memcpy size 1000 count 100000 offset 4 took 257655 us memcpy size 1000 count 100000 offset 5 took 259456 us memcpy size 1000 count 100000 offset 7 took 260849 us memcpy size 1000 count 100000 offset 8 took 232347 us memcpy size 1000 count 100000 offset 9 took 254330 us memcpy size 3000 count 50000 offset 0 took 382376 us memcpy size 3000 count 50000 offset 1 took 389872 us memcpy size 3000 count 50000 offset 3 took 385310 us memcpy size 3000 count 50000 offset 4 took 389748 us memcpy size 3000 count 50000 offset 5 took 391707 us memcpy size 3000 count 50000 offset 7 took 386778 us memcpy size 3000 count 50000 offset 8 took 385691 us memcpy size 3000 count 50000 offset 9 took 392030 us The assembly routine is measurably better. [1] https://pastebin.com/DRyECNQW Changes in v10: - Remove spurious 5 from syscall patch (Adhemerval) - Use one item per line in Makefile (Adhemerval) - Remove double underscores from __riscv_hwprobe definition (Adhemerval) - Use only spaces in macro definitions of hwprobe.h (Adhemerval) - Introduced INTERNAL_VSYSCALL patch - Remove leading underscores in definition (Adhemerval) - Remove spurious 5 from INTERNAL_SYSCALL_CALL (Adhemerval) - Use new INTERNAL_VSYSCALL macro instead (Adhemerval) - Hand in pointer to __riscv_hwprobe(), not vDSO function - Avoid implicit comparisons (Adhemerval) - One line per function in Makefile for memcpy (Adhemerval) - Space before argument-like things (Adhemerval) Changes in v9: - Alphabetize new entries in libc.abilist (to pass checks) - Fix a couple of typos causing powerpc not to build (build-many-glibcs) - Use __inline rather than inline so c89 compiles (build-many-glibcs) Changes in v8: - Fix missed 2.39 in abilists (Joseph) - Just return -r (Florian) Changes in v7: - Bumped Versions up to 2.39 (Joseph) - Used INTERNAL_SYSCALL_CALL, and return positive errno to match pthreads API (Florian). - Remove __THROW since it creates a warning in combination with the fortified access decorators. - Use INTERNAL_VSYSCALL_CALL (Florian) - Remove __THROW from function pointer type, as it creates warnings together with __fortified_attr_access. - Introduced static inline helper (Richard) - Use new helper function in memcpy ifunc selector (Richard) Changes in v6: - Prefixed __riscv_hwprobe() parameters names with __ to avoid user macro namespace pollution (Joseph) - Introduced riscv-ifunc.h for multi-arg ifunc selectors. - Fix a couple regressions in the assembly from v5 :/ - Use passed hwprobe pointer in memcpy ifunc selector. Changes in v5: - Do unaligned word access for final trailing bytes (Richard) Changes in v4: - Remove __USE_GNU (Florian) - __nonnull, __wur, __THROW, and __fortified_attr_access decorations (Florian) - change long to long int (Florian) - Fix comment formatting (Florian) - Update backup kernel header content copy. - Fix function declaration formatting (Florian) - Changed export versions to 2.38 - Fixed comment style (Florian) Changes in v3: - Update argument types to match v4 kernel interface - Add the "return" to the vsyscall - Fix up vdso arg types to match kernel v4 version - Remove ifdef around INLINE_VSYSCALL (Adhemerval) - Word align dest for large memcpy()s. - Add tags - Remove spurious blank line from sysdeps/riscv/memcpy.c Changes in v2: - hwprobe.h: Use __has_include and duplicate Linux content to make compilation work when Linux headers are absent (Adhemerval) - hwprobe.h: Put declaration under __USE_GNU (Adhemerval) - Use INLINE_SYSCALL_CALL (Adhemerval) - Update versions - Update UNALIGNED_MASK to match kernel v3 series. - Add vDSO interface - Used _MASK instead of _FAST value itself. Evan Green (7): riscv: Add Linux hwprobe syscall support linux: Introduce INTERNAL_VSYSCALL riscv: Add hwprobe vdso call support riscv: Add __riscv_hwprobe pointer to ifunc calls riscv: Enable multi-arg ifunc resolvers riscv: Add ifunc helper method to hwprobe.h riscv: Add and use alignment-ignorant memcpy include/libc-symbols.h | 28 ++-- sysdeps/riscv/dl-irel.h | 9 +- sysdeps/riscv/memcopy.h | 26 ++++ sysdeps/riscv/memcpy.c | 63 ++++++++ sysdeps/riscv/memcpy_noalignment.S | 138 ++++++++++++++++++ sysdeps/riscv/riscv-ifunc.h | 27 ++++ sysdeps/unix/sysv/linux/dl-vdso-setup.c | 10 ++ sysdeps/unix/sysv/linux/dl-vdso-setup.h | 3 + sysdeps/unix/sysv/linux/riscv/Makefile | 21 ++- sysdeps/unix/sysv/linux/riscv/Versions | 3 + sysdeps/unix/sysv/linux/riscv/hwprobe.c | 36 +++++ .../unix/sysv/linux/riscv/memcpy-generic.c | 24 +++ .../unix/sysv/linux/riscv/rv32/libc.abilist | 1 + .../unix/sysv/linux/riscv/rv64/libc.abilist | 1 + sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 109 ++++++++++++++ sysdeps/unix/sysv/linux/riscv/sysdep.h | 1 + sysdeps/unix/sysv/linux/sysdep-vdso.h | 19 +++ 17 files changed, 502 insertions(+), 17 deletions(-) create mode 100644 sysdeps/riscv/memcopy.h create mode 100644 sysdeps/riscv/memcpy.c create mode 100644 sysdeps/riscv/memcpy_noalignment.S create mode 100644 sysdeps/riscv/riscv-ifunc.h create mode 100644 sysdeps/unix/sysv/linux/riscv/hwprobe.c create mode 100644 sysdeps/unix/sysv/linux/riscv/memcpy-generic.c create mode 100644 sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
Comments
Any last thoughts on this series? I think the plan is to land it shortly.
On Mon, 08 Jan 2024 09:06:10 PST (-0800), Evan Green wrote: > Any last thoughts on this series? I think the plan is to land it shortly. Sorry for benig slow here. It's good on my end, so as long as nobody has lurking issues I'm happy to take it. Acked-by: Palmer Dabbelt <palmer@rivosinc.com> in case someone else wants to pick it up, otherwise let's give it a day and see? There's no branch date listed on the wiki, but I'd like to get this in sooner rather than later so we can get the distro folks testing it and such.
On Mon, Jan 8, 2024, at 12:06 PM, Evan Green wrote:
> Any last thoughts on this series? I think the plan is to land it shortly.
I am still wondering what the intended ABI is for the second parameter on
non-Linux ELF systems which do not provide riscv_hwprobe as a system call.
Should it be passed as a null (or 1/-1) pointer in that case, or are dynamic
linkers expected to provide some emulation of riscv_hwprobe of some variable
fidelity? In the latter case, what features of riscv_hwprobe must be emulated
for the dynamic linker to claim ABI conformance?
-s
On Tue, Jan 9, 2024 at 4:06 AM Stefan O'Rear <sorear@fastmail.com> wrote: > > On Mon, Jan 8, 2024, at 12:06 PM, Evan Green wrote: > > Any last thoughts on this series? I think the plan is to land it shortly. > > I am still wondering what the intended ABI is for the second parameter on > non-Linux ELF systems which do not provide riscv_hwprobe as a system call. > Should it be passed as a null (or 1/-1) pointer in that case, or are dynamic > linkers expected to provide some emulation of riscv_hwprobe of some variable > fidelity? In the latter case, what features of riscv_hwprobe must be emulated > for the dynamic linker to claim ABI conformance? NULL would make the most sense IMO. Hwprobe is a Linuxism for sure, so code that uses hwprobe (either inside or outside an ifunc selector) won't by default be portable across OSes. If Linux is consistently good at defining the hwprobe bits and not breaking our own ABI, other OSes could in theory emulate the interface by exposing the same keys/values. Though at least from our perspective that's not a goal. -Evan > > -s
On Tue, Jan 9, 2024, at 12:10 PM, Evan Green wrote: > On Tue, Jan 9, 2024 at 4:06 AM Stefan O'Rear <sorear@fastmail.com> wrote: >> >> On Mon, Jan 8, 2024, at 12:06 PM, Evan Green wrote: >> > Any last thoughts on this series? I think the plan is to land it shortly. >> >> I am still wondering what the intended ABI is for the second parameter on >> non-Linux ELF systems which do not provide riscv_hwprobe as a system call. >> Should it be passed as a null (or 1/-1) pointer in that case, or are dynamic >> linkers expected to provide some emulation of riscv_hwprobe of some variable >> fidelity? In the latter case, what features of riscv_hwprobe must be emulated >> for the dynamic linker to claim ABI conformance? > > NULL would make the most sense IMO. Hwprobe is a Linuxism for sure, so > code that uses hwprobe (either inside or outside an ifunc selector) > won't by default be portable across OSes. If Linux is consistently > good at defining the hwprobe bits and not breaking our own ABI, other > OSes could in theory emulate the interface by exposing the same > keys/values. Though at least from our perspective that's not a goal. > > -Evan NULL was a mistake; we need to pass a non-NULL value in a1 to signal that a2 is defined, since the current implementations pass NULL in a1 and garbage in a2. If a dynamic linker does not provide a Linux-compatible riscv_hwprobe but does support features that are passed in a2..a7, would it be better to pass (long(*)())(-1) or a stub function that just returns 38 (+ENOSYS)? -s
On Tue, Jan 9, 2024 at 10:30 AM Stefan O'Rear <sorear@fastmail.com> wrote: > > On Tue, Jan 9, 2024, at 12:10 PM, Evan Green wrote: > > On Tue, Jan 9, 2024 at 4:06 AM Stefan O'Rear <sorear@fastmail.com> wrote: > >> > >> On Mon, Jan 8, 2024, at 12:06 PM, Evan Green wrote: > >> > Any last thoughts on this series? I think the plan is to land it shortly. > >> > >> I am still wondering what the intended ABI is for the second parameter on > >> non-Linux ELF systems which do not provide riscv_hwprobe as a system call. > >> Should it be passed as a null (or 1/-1) pointer in that case, or are dynamic > >> linkers expected to provide some emulation of riscv_hwprobe of some variable > >> fidelity? In the latter case, what features of riscv_hwprobe must be emulated > >> for the dynamic linker to claim ABI conformance? > > > > NULL would make the most sense IMO. Hwprobe is a Linuxism for sure, so > > code that uses hwprobe (either inside or outside an ifunc selector) > > won't by default be portable across OSes. If Linux is consistently > > good at defining the hwprobe bits and not breaking our own ABI, other > > OSes could in theory emulate the interface by exposing the same > > keys/values. Though at least from our perspective that's not a goal. > > > > -Evan > > NULL was a mistake; we need to pass a non-NULL value in a1 to signal that > a2 is defined, since the current implementations pass NULL in a1 and > garbage in a2. > > If a dynamic linker does not provide a Linux-compatible riscv_hwprobe but > does support features that are passed in a2..a7, would it be better to pass > (long(*)())(-1) or a stub function that just returns 38 (+ENOSYS)? Oh great point, I hadn't connected those dots. I'm fine with either. -1 would let them distinguish this case a little more explicitly, so maybe that's better? Is there a good spot to document this? Should I defend against that -1 value in my static helper function as well by checking for it? It seems like I shouldn't need to since it's in a Linux-specific header, but if there's a scenario for it then I'll add it. -Evan > > -s
On Tue, Jan 9, 2024, at 1:41 PM, Evan Green wrote: > On Tue, Jan 9, 2024 at 10:30 AM Stefan O'Rear <sorear@fastmail.com> wrote: >> >> On Tue, Jan 9, 2024, at 12:10 PM, Evan Green wrote: >> > On Tue, Jan 9, 2024 at 4:06 AM Stefan O'Rear <sorear@fastmail.com> wrote: >> >> >> >> On Mon, Jan 8, 2024, at 12:06 PM, Evan Green wrote: >> >> > Any last thoughts on this series? I think the plan is to land it shortly. >> >> >> >> I am still wondering what the intended ABI is for the second parameter on >> >> non-Linux ELF systems which do not provide riscv_hwprobe as a system call. >> >> Should it be passed as a null (or 1/-1) pointer in that case, or are dynamic >> >> linkers expected to provide some emulation of riscv_hwprobe of some variable >> >> fidelity? In the latter case, what features of riscv_hwprobe must be emulated >> >> for the dynamic linker to claim ABI conformance? >> > >> > NULL would make the most sense IMO. Hwprobe is a Linuxism for sure, so >> > code that uses hwprobe (either inside or outside an ifunc selector) >> > won't by default be portable across OSes. If Linux is consistently >> > good at defining the hwprobe bits and not breaking our own ABI, other >> > OSes could in theory emulate the interface by exposing the same >> > keys/values. Though at least from our perspective that's not a goal. >> > >> > -Evan >> >> NULL was a mistake; we need to pass a non-NULL value in a1 to signal that >> a2 is defined, since the current implementations pass NULL in a1 and >> garbage in a2. >> >> If a dynamic linker does not provide a Linux-compatible riscv_hwprobe but >> does support features that are passed in a2..a7, would it be better to pass >> (long(*)())(-1) or a stub function that just returns 38 (+ENOSYS)? > > Oh great point, I hadn't connected those dots. I'm fine with either. > -1 would let them distinguish this case a little more explicitly, so > maybe that's better? +1 might be a better choice (match SIG_IGN rather than MAP_FAILED, already a non-function in the uABI, and slightly fewer bytes for the branch). The stub function has a disadvantage of polluting the global ABI with Linux-specific error constants. No strong feelings here. > Is there a good spot to document this? The details of the IRELATIVE resolution process should probably go in riscv-elf-psabi-doc/riscv-elf.adoc . > Should I defend against that -1 value in my static helper function as > well by checking for it? It seems like I shouldn't need to since it's > in a Linux-specific header, but if there's a scenario for it then I'll > add it. > -Evan Do you mean select_memcpy_ifunc in patch 7? I'm inclined to say that it should be robust in case someone copies it into a library other than glibc and it can no longer depend on Linux and a specific version of the glibc dynamic linker. -s
On Tue, Jan 9, 2024, 11:10 Stefan O'Rear <sorear@fastmail.com> wrote: > On Tue, Jan 9, 2024, at 1:41 PM, Evan Green wrote: > > On Tue, Jan 9, 2024 at 10:30 AM Stefan O'Rear <sorear@fastmail.com> > wrote: > >> > >> On Tue, Jan 9, 2024, at 12:10 PM, Evan Green wrote: > >> > On Tue, Jan 9, 2024 at 4:06 AM Stefan O'Rear <sorear@fastmail.com> > wrote: > >> >> > >> >> On Mon, Jan 8, 2024, at 12:06 PM, Evan Green wrote: > >> >> > Any last thoughts on this series? I think the plan is to land it > shortly. > >> >> > >> >> I am still wondering what the intended ABI is for the second > parameter on > >> >> non-Linux ELF systems which do not provide riscv_hwprobe as a system > call. > >> >> Should it be passed as a null (or 1/-1) pointer in that case, or are > dynamic > >> >> linkers expected to provide some emulation of riscv_hwprobe of some > variable > >> >> fidelity? In the latter case, what features of riscv_hwprobe must > be emulated > >> >> for the dynamic linker to claim ABI conformance? > >> > > >> > NULL would make the most sense IMO. Hwprobe is a Linuxism for sure, so > >> > code that uses hwprobe (either inside or outside an ifunc selector) > >> > won't by default be portable across OSes. If Linux is consistently > >> > good at defining the hwprobe bits and not breaking our own ABI, other > >> > OSes could in theory emulate the interface by exposing the same > >> > keys/values. Though at least from our perspective that's not a goal. > >> > > >> > -Evan > >> > >> NULL was a mistake; we need to pass a non-NULL value in a1 to signal > that > >> a2 is defined, since the current implementations pass NULL in a1 and > >> garbage in a2. > >> > >> If a dynamic linker does not provide a Linux-compatible riscv_hwprobe > but > >> does support features that are passed in a2..a7, would it be better to > pass > >> (long(*)())(-1) or a stub function that just returns 38 (+ENOSYS)? > > > > Oh great point, I hadn't connected those dots. I'm fine with either. > > -1 would let them distinguish this case a little more explicitly, so > > maybe that's better? > > +1 might be a better choice (match SIG_IGN rather than MAP_FAILED, already > a non-function in the uABI, and slightly fewer bytes for the branch). > > The stub function has a disadvantage of polluting the global ABI with > Linux-specific error constants. > (and i'd still argue that no-one really needs it and, worse, folks who think they need it are probably pessimizing their code.) No strong feelings here. > > > Is there a good spot to document this? > > The details of the IRELATIVE resolution process should probably go in > riscv-elf-psabi-doc/riscv-elf.adoc . > > > Should I defend against that -1 value in my static helper function as > > well by checking for it? It seems like I shouldn't need to since it's > > in a Linux-specific header, but if there's a scenario for it then I'll > > add it. > > -Evan > > Do you mean select_memcpy_ifunc in patch 7? I'm inclined to say that it > should be robust in case someone copies it into a library other than glibc > and it can no longer depend on Linux and a specific version of the glibc > dynamic linker. > > -s >
On Tue, Jan 9, 2024 at 11:10 AM Stefan O'Rear <sorear@fastmail.com> wrote: > > On Tue, Jan 9, 2024, at 1:41 PM, Evan Green wrote: > > On Tue, Jan 9, 2024 at 10:30 AM Stefan O'Rear <sorear@fastmail.com> wrote: > >> > >> On Tue, Jan 9, 2024, at 12:10 PM, Evan Green wrote: > >> > On Tue, Jan 9, 2024 at 4:06 AM Stefan O'Rear <sorear@fastmail.com> wrote: > >> >> > >> >> On Mon, Jan 8, 2024, at 12:06 PM, Evan Green wrote: > >> >> > Any last thoughts on this series? I think the plan is to land it shortly. > >> >> > >> >> I am still wondering what the intended ABI is for the second parameter on > >> >> non-Linux ELF systems which do not provide riscv_hwprobe as a system call. > >> >> Should it be passed as a null (or 1/-1) pointer in that case, or are dynamic > >> >> linkers expected to provide some emulation of riscv_hwprobe of some variable > >> >> fidelity? In the latter case, what features of riscv_hwprobe must be emulated > >> >> for the dynamic linker to claim ABI conformance? > >> > > >> > NULL would make the most sense IMO. Hwprobe is a Linuxism for sure, so > >> > code that uses hwprobe (either inside or outside an ifunc selector) > >> > won't by default be portable across OSes. If Linux is consistently > >> > good at defining the hwprobe bits and not breaking our own ABI, other > >> > OSes could in theory emulate the interface by exposing the same > >> > keys/values. Though at least from our perspective that's not a goal. > >> > > >> > -Evan > >> > >> NULL was a mistake; we need to pass a non-NULL value in a1 to signal that > >> a2 is defined, since the current implementations pass NULL in a1 and > >> garbage in a2. > >> > >> If a dynamic linker does not provide a Linux-compatible riscv_hwprobe but > >> does support features that are passed in a2..a7, would it be better to pass > >> (long(*)())(-1) or a stub function that just returns 38 (+ENOSYS)? > > > > Oh great point, I hadn't connected those dots. I'm fine with either. > > -1 would let them distinguish this case a little more explicitly, so > > maybe that's better? > > +1 might be a better choice (match SIG_IGN rather than MAP_FAILED, already > a non-function in the uABI, and slightly fewer bytes for the branch). > > The stub function has a disadvantage of polluting the global ABI with > Linux-specific error constants. > > No strong feelings here. Sure, the arguments here make sense to me, so +1 seems fine. > > > Is there a good spot to document this? > > The details of the IRELATIVE resolution process should probably go in > riscv-elf-psabi-doc/riscv-elf.adoc . > > > Should I defend against that -1 value in my static helper function as > > well by checking for it? It seems like I shouldn't need to since it's > > in a Linux-specific header, but if there's a scenario for it then I'll > > add it. > > -Evan > > Do you mean select_memcpy_ifunc in patch 7? I'm inclined to say that it > should be robust in case someone copies it into a library other than glibc > and it can no longer depend on Linux and a specific version of the glibc > dynamic linker. Specifically I meant the __riscv_hwprobe_one() static inline helper in patch 6, which is what's used by patch 7. Yeah, as far as I can tell the only way to run into trouble is copying that function over to a substantially different world. Maybe a comment would be sufficient then? -Evan