From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id B71E73858D32 for ; Wed, 28 Jun 2023 00:20:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B71E73858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6689430d803so3040660b3a.0 for ; Tue, 27 Jun 2023 17:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1687911627; x=1690503627; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=HD5SPhrX0tPm74lmfXlOkBJoaxtiXIFKWGoPd7hx3u4=; b=Q18dazZ4I2TMX/VQtCe5N9JpyRpSuWBTntHhEkTJMZjsE2zwbCAOZTjk/0DrPiy2+f JTY7DC2nHZslfDEaVd/RhVStmKI+MNIpDNWP7PmmtZSR9iYc86Gd/UhhmVAGBpsm1Qqr 9DSsMEa0LSCpPZSJgEjORO2LO9GP3gqzcCK1zd7pVCE6vEvzG5V345VgHITb8+4V3zHC vR5f2akl2Rh+qWPaYugK6nnlVibxhmKk04VYl3937RHLCS0ziNcIvCp0qK/o5qt5cq9b QV2OFfzazFOmtzmh2b1codq2Z18oXJeoOIqsOKvg784b/0prOfiAwtjXqYhn8hRhSpkl 9w5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687911627; x=1690503627; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HD5SPhrX0tPm74lmfXlOkBJoaxtiXIFKWGoPd7hx3u4=; b=cd3DkWz4dxxCHyk5npD9sVnSiUkaTYA5XbquxKjb7LhwLyuglaORyl3xONo+HlVL5o j5dWbCs37uyu8F86qrHZ6kETGEFUbuMIaTBI19Mx3qPs4Ur45FrQA6z3nmY8CjbyWKgj BYNex6WYzq7tYCMF1lW/JL2WhKZF82aDrYWBCJCu2Oqf7YYLTaRTgxaZkYDsDxjUVxZ6 ThOIMap0k3+dEU561Y/B8yz2mLJ7hfnefBgy6OX3YhBuQm5Vw5e2DbwVsU4q8IZAL35i q44367TKDSvckBW2RpsS2JMzynBUYr66H1diGMe0mqsgpMArv9PJm4/k//jeEKpjcM4C y3TA== X-Gm-Message-State: AC+VfDz+fPU54NOfMyY/dG83UtWrusMoLFW70PTDD4NqHdntXmYnlj8R iyGbYbbkKv0hR/3QsAaflhT232Cr9y04O7qmM9A= X-Google-Smtp-Source: ACHHUZ5rfggvp1Fboayej66QK4Hd+lypuPlXiawSGxLNj6EVRjRzeHp2a5ipAbSjbnypSVvZJb0Zcw== X-Received: by 2002:a05:6a20:12d6:b0:127:63a4:c585 with SMTP id v22-20020a056a2012d600b0012763a4c585mr6757487pzg.22.1687911627219; Tue, 27 Jun 2023 17:20:27 -0700 (PDT) Received: from localhost ([135.180.227.0]) by smtp.gmail.com with ESMTPSA id e5-20020a62ee05000000b0064f76992905sm5803393pfi.202.2023.06.27.17.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:20:24 -0700 (PDT) Date: Tue, 27 Jun 2023 17:20:24 -0700 (PDT) X-Google-Original-Date: Tue, 27 Jun 2023 17:20:23 PDT (-0700) Subject: Re: [PATCH v3 1/3] riscv: Add Linux hwprobe syscall support In-Reply-To: <20230407230711.2621614-2-evan@rivosinc.com> CC: libc-alpha@sourceware.org, Vineet Gupta , slewis@rivosinc.com, Evan Green From: Palmer Dabbelt To: Evan Green Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_SHORT,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 List-Id: On Fri, 07 Apr 2023 16:07:08 PDT (-0700), Evan Green wrote: > Add awareness and a thin wrapper function around a new Linux system call > that allows callers to get architecture and microarchitecture > information about the CPUs from the kernel. This can be used to > do things like dynamically choose a memcpy implementation. Linux 6.4, which has the syscall, was released earlier this week. IIRC that was the last procedural blocker for these, but not sure if anyone else had comments on the implementation -- no big rush on my end, but it'd be nice to aim for these in the next release so folks can start building stuff on it (as opposed to calling the syscall directly). > Signed-off-by: Evan Green > Reviewed-by: Palmer Dabbelt > --- > > Changes in v3: > - Update argument types to match v4 kernel interface > > 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. > > sysdeps/unix/sysv/linux/riscv/Makefile | 4 +- > sysdeps/unix/sysv/linux/riscv/Versions | 3 + > sysdeps/unix/sysv/linux/riscv/hwprobe.c | 30 ++++++++ > .../unix/sysv/linux/riscv/rv32/arch-syscall.h | 1 + > .../unix/sysv/linux/riscv/rv32/libc.abilist | 1 + > .../unix/sysv/linux/riscv/rv64/arch-syscall.h | 1 + > .../unix/sysv/linux/riscv/rv64/libc.abilist | 1 + > sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 68 +++++++++++++++++++ > sysdeps/unix/sysv/linux/syscall-names.list | 1 + > 9 files changed, 108 insertions(+), 2 deletions(-) > create mode 100644 sysdeps/unix/sysv/linux/riscv/hwprobe.c > create mode 100644 sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h > > diff --git a/sysdeps/unix/sysv/linux/riscv/Makefile b/sysdeps/unix/sysv/linux/riscv/Makefile > index 4b6eacb32f..45cc29e40d 100644 > --- a/sysdeps/unix/sysv/linux/riscv/Makefile > +++ b/sysdeps/unix/sysv/linux/riscv/Makefile > @@ -1,6 +1,6 @@ > ifeq ($(subdir),misc) > -sysdep_headers += sys/cachectl.h > -sysdep_routines += flush-icache > +sysdep_headers += sys/cachectl.h sys/hwprobe.h > +sysdep_routines += flush-icache hwprobe > endif > > ifeq ($(subdir),stdlib) > diff --git a/sysdeps/unix/sysv/linux/riscv/Versions b/sysdeps/unix/sysv/linux/riscv/Versions > index 5625d2a0b8..8717b62a4a 100644 > --- a/sysdeps/unix/sysv/linux/riscv/Versions > +++ b/sysdeps/unix/sysv/linux/riscv/Versions > @@ -8,4 +8,7 @@ libc { > GLIBC_2.27 { > __riscv_flush_icache; > } > + GLIBC_2.39 { > + __riscv_hwprobe; > + } > } > diff --git a/sysdeps/unix/sysv/linux/riscv/hwprobe.c b/sysdeps/unix/sysv/linux/riscv/hwprobe.c > new file mode 100644 > index 0000000000..e9023e2fba > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/riscv/hwprobe.c > @@ -0,0 +1,30 @@ > +/* RISC-V hardware feature probing support on Linux > + 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 > + > +int > +__riscv_hwprobe (struct riscv_hwprobe *pairs, size_t pair_count, > + size_t cpu_count, unsigned long *cpus, unsigned int flags) > +{ > + return INLINE_SYSCALL_CALL (riscv_hwprobe, pairs, pair_count, > + cpu_count, cpus, flags); > +} > diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/arch-syscall.h b/sysdeps/unix/sysv/linux/riscv/rv32/arch-syscall.h > index 202520ee25..2416e041c8 100644 > --- a/sysdeps/unix/sysv/linux/riscv/rv32/arch-syscall.h > +++ b/sysdeps/unix/sysv/linux/riscv/rv32/arch-syscall.h > @@ -198,6 +198,7 @@ > #define __NR_request_key 218 > #define __NR_restart_syscall 128 > #define __NR_riscv_flush_icache 259 > +#define __NR_riscv_hwprobe 258 > #define __NR_rseq 293 > #define __NR_rt_sigaction 134 > #define __NR_rt_sigpending 136 > diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist > index b716f5c763..1548587eb1 100644 > --- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist > +++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist > @@ -2428,3 +2428,4 @@ GLIBC_2.38 __isoc23_wcstoull F > GLIBC_2.38 __isoc23_wcstoull_l F > GLIBC_2.38 __isoc23_wcstoumax F > GLIBC_2.38 __isoc23_wscanf F > +GLIBC_2.39 __riscv_hwprobe F > diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/arch-syscall.h b/sysdeps/unix/sysv/linux/riscv/rv64/arch-syscall.h > index 4e65f337d4..a32bc82f60 100644 > --- a/sysdeps/unix/sysv/linux/riscv/rv64/arch-syscall.h > +++ b/sysdeps/unix/sysv/linux/riscv/rv64/arch-syscall.h > @@ -205,6 +205,7 @@ > #define __NR_request_key 218 > #define __NR_restart_syscall 128 > #define __NR_riscv_flush_icache 259 > +#define __NR_riscv_hwprobe 258 > #define __NR_rseq 293 > #define __NR_rt_sigaction 134 > #define __NR_rt_sigpending 136 > diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > index 774e777b65..49c0577b61 100644 > --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > @@ -2628,3 +2628,4 @@ GLIBC_2.38 __isoc23_wcstoull F > GLIBC_2.38 __isoc23_wcstoull_l F > GLIBC_2.38 __isoc23_wcstoumax F > GLIBC_2.38 __isoc23_wscanf F > +GLIBC_2.39 __riscv_hwprobe F > diff --git a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h > new file mode 100644 > index 0000000000..49e27ee855 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h > @@ -0,0 +1,68 @@ > +/* RISC-V architecture probe interface > + 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 > + . */ > + > +#ifndef _SYS_HWPROBE_H > +#define _SYS_HWPROBE_H 1 > + > +#include > +#include > +#ifdef __has_include > +# if __has_include () > +# include > +# endif > +#endif > + > +/* > + * Define a (probably stale) version of the interface if the Linux headers > + * aren't present. > + */ > +#ifndef RISCV_HWPROBE_KEY_MVENDORID > +struct riscv_hwprobe { > + signed long long key; > + unsigned long long value; > +}; > + > +#define RISCV_HWPROBE_KEY_MVENDORID 0 > +#define RISCV_HWPROBE_KEY_MARCHID 1 > +#define RISCV_HWPROBE_KEY_MIMPID 2 > +#define RISCV_HWPROBE_KEY_BASE_BEHAVIOR 3 > +#define RISCV_HWPROBE_BASE_BEHAVIOR_IMA (1 << 0) > +#define RISCV_HWPROBE_KEY_IMA_EXT_0 4 > +#define RISCV_HWPROBE_IMA_FD (1 << 0) > +#define RISCV_HWPROBE_IMA_C (1 << 1) > +#define RISCV_HWPROBE_KEY_CPUPERF_0 5 > +#define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) > +#define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) > +#define RISCV_HWPROBE_MISALIGNED_SLOW (2 << 0) > +#define RISCV_HWPROBE_MISALIGNED_FAST (3 << 0) > +#define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0) > + > +#endif // RISCV_HWPROBE_KEY_MVENDORID > + > +__BEGIN_DECLS > + > +#ifdef __USE_GNU > +int > +__riscv_hwprobe (struct riscv_hwprobe *pairs, size_t pair_count, > + size_t cpu_count, unsigned long *cpus, unsigned int flags); > +#endif > + > +__END_DECLS > + > +#endif /* sys/hwprobe.h */ > diff --git a/sysdeps/unix/sysv/linux/syscall-names.list b/sysdeps/unix/sysv/linux/syscall-names.list > index 5d27b5279c..bbc0e01d3a 100644 > --- a/sysdeps/unix/sysv/linux/syscall-names.list > +++ b/sysdeps/unix/sysv/linux/syscall-names.list > @@ -477,6 +477,7 @@ renameat2 > request_key > restart_syscall > riscv_flush_icache > +riscv_hwprobe > rmdir > rseq > rt_sigaction