From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 20F163858D3C for ; Wed, 29 Mar 2023 18:38:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20F163858D3C 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-oi1-x234.google.com with SMTP id b19so12322722oib.7 for ; Wed, 29 Mar 2023 11:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680115103; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ej26HlpjZ6TTBE88UwPPJn8ICos/ZdQ68tt5D0aUeBU=; b=kYiG7v4Y4SPmjH5qZiLNY2TBOe3zwh+y21x1PFrElgdD0n1kSQjY+igeymuLqcBCK2 h/dZVlHhAzqdg7yJVu3HGQ4vAk4tRQamjUpfI25pwqkvZCmzhVNrGSRBdgIbOC3x9t0W RI7bMAtP9Lbzo1YyQGJLOB+KERR8ijjMQROYONuAzHjAaLQYi7c3ohHShcnfgIsk8ejm hZ7SNjQK/VTfO7/m7lNMjcUTnXYacAI3gW97ATuxHtXi4rGxw/EGLmvEE05FuW7jJqZG 1ZiyL0dwKqu0uE6pjtwh50FgudxC5O/UCkMYHlGlDpZDBpaPjve+se5Jvo4/ftWeK8QA pAyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115103; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ej26HlpjZ6TTBE88UwPPJn8ICos/ZdQ68tt5D0aUeBU=; b=spno/ltIQmnH1MKI7KgM3LfQ/WeBBeSSBWWdzvnpZ/g+Vo+HbwAG1f6rsIxQ6WrYGP itisb8B8uzVkgQW6KN1PmLdjhBZss71xsMaiZSrnLSIcG66NKCFtdis9NdGmGo6z613W udYWHUg7F+1FZhiGBZEhd9YcUw/CmBjCL5bJyinEFwF1+37D2BgZtlSNY0vGxhvITN+p 6gEqmJZjY5wCvGuApCUH8By+qRj6edeMKg4f5NR5ihcJiRSZ/fPJBNdhoxme23eG9ea8 /dOw1cpuuW78GlCDpfvExFuSnQWWH7ivEllTDvzOarpMhT590oscKYkMBi3R2rYDNQsq 5hkA== X-Gm-Message-State: AAQBX9ddNsw8Gpw13bo4zmO7UXRP++hgLdbWCPLiZZhorH9+a5qswQRg 1VuIF/SGtK1GvOOIV2YO5ZDai05uIMu/swYSD7bxrg== X-Google-Smtp-Source: AKy350YSyD0zMHSx5fzJ0s/NL2Un6d0naRh6rsJYCP9WDP+9u+7sX2YTDHdnHAXP+4pDyDd+okiHwg== X-Received: by 2002:a54:4898:0:b0:389:4cf7:47ee with SMTP id r24-20020a544898000000b003894cf747eemr3964631oic.47.1680115102192; Wed, 29 Mar 2023 11:38:22 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:60f9:1426:1d2d:d6b:1761? ([2804:1b3:a7c1:60f9:1426:1d2d:d6b:1761]) by smtp.gmail.com with ESMTPSA id b186-20020aca34c3000000b00389295e8424sm3770950oia.45.2023.03.29.11.38.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Mar 2023 11:38:21 -0700 (PDT) Message-ID: <9804d26f-449d-9997-be7d-52ec4b616758@linaro.org> Date: Wed, 29 Mar 2023 15:38:19 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v2 1/3] riscv: Add Linux hwprobe syscall support Content-Language: en-US To: libc-alpha@sourceware.org References: <20230221191537.3159966-1-evan@rivosinc.com> <20230221191537.3159966-2-evan@rivosinc.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230221191537.3159966-2-evan@rivosinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,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 List-Id: On 21/02/23 16:15, 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. > > Signed-off-by: Evan Green > --- > > 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 | 67 +++++++++++++++++++ > sysdeps/unix/sysv/linux/syscall-names.list | 1 + > 9 files changed, 107 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..74f68889ca > --- /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, long pair_count, > + long cpu_count, unsigned long *cpus, unsigned long 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 29be561b60..83b7932db7 100644 > --- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist > +++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist > @@ -2416,3 +2416,4 @@ GLIBC_2.38 __isoc23_wcstoul_l F > GLIBC_2.38 __isoc23_wcstoull F > GLIBC_2.38 __isoc23_wcstoull_l F > GLIBC_2.38 __isoc23_wcstoumax 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 506a4e6a65..6ddbcfb131 100644 > --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > @@ -2616,3 +2616,4 @@ GLIBC_2.38 __isoc23_wcstoul_l F > GLIBC_2.38 __isoc23_wcstoull F > GLIBC_2.38 __isoc23_wcstoull_l F > GLIBC_2.38 __isoc23_wcstoumax 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..e619ea43b8 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h > @@ -0,0 +1,67 @@ > +/* 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 > +#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; > +}; Indentation seems ok here, I think curly brackets should be in the next line. > + > +#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) Indentation seems off here. > + > +#endif // RISCV_HWPROBE_KEY_MVENDORID No C99/C++ style comments in public headers. > + > +__BEGIN_DECLS > + Could you add some minimal comment on the how to use this interface, the exects parameters, etc? > +#ifdef __USE_GNU > +int > +__riscv_hwprobe (struct riscv_hwprobe *pairs, long pair_count, > + long cpu_count, unsigned long *cpus, unsigned long flags); Add 'extern' (for old -std= modes) and put the function on same line as return type. > +#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 822498d3e3..4f4a62e91c 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