From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id ACC453858D33 for ; Tue, 7 Feb 2023 13:05:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACC453858D33 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-ot1-x32c.google.com with SMTP id j6-20020a9d7686000000b0068d4ba9d141so4152486otl.6 for ; Tue, 07 Feb 2023 05:05:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=LtJ4elRtK2dIY0SXxh5q4j3mXcdmAtlpKOxjxEYVBUA=; b=f2GNLR/lI6uRd+sFIpLWuMzoIjuBD7wjvAwfqZczJFCpm9Rot3NIgO/eSws7abIXUE c0PHBTiEV8Dhv1FUhqjXp55oHtO4boTfoLNr6tvjLNwDh1hII3eKVAUL9ayBv/ZZdpXE rXuupPnrRMSdZoNC0gWEIIlgnLuysalhlW7hLRRhjFqtVgbzcoA41KBV/kO1QN30YCEz 2YcmfprWoxE8Zpf3WTfZI5SEZo/YeAQeccXtK6sar7bsDhrivcb4sNUJQ3QNvFckU+XS eWFlfAzqKOxvp79m5VEznxyof2vM/cup+25Mp7Z8jrUVGNHho1E3A80zD5oEiy66ljN9 N4rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc: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=LtJ4elRtK2dIY0SXxh5q4j3mXcdmAtlpKOxjxEYVBUA=; b=dnolU8CYfD5T/w32OE6tXATp5Jse9Q5Nkb06W8zhW2nlY67KpGvm38wgjPkZ6/e/Jg Bg7eyBu10QljVwU2MClY/HhqkRYrTvhVV8SnITXGlVGx7qE8e6jikmuFyRlkWy9d0Czh glBuXGlbpU6qvie7ali7BeVTWi2x99KNDGIjYKb3KKVWM14WNUdklmuDtilb2NlBN3+i o5aQpWBZ7X6Wa9tpsFVTQO61OoLk88jQdlR/kWnMVGLtVxNGJqdOm0I9501TIwcDYNWJ BhxW4h1iYzG78wOPJS+udZIQMw6RwL5+dlvRGuob2sCha7syCPlBN8K1D0M701ffDvmI BYJA== X-Gm-Message-State: AO0yUKVUYc5CBoGRScOHXXVaJr/sc1GECgoC192So5vZo77qIerd+UZD 6IW153edpDtVomBoj9JB+c0nkg== X-Google-Smtp-Source: AK7set+m1qJKHpHJbH9YVDmeA/DyArqm6wlfAz1a+sz57nmtnUVw6UBP3mqcsGw9EFKs93XNXL/IjQ== X-Received: by 2002:a05:6830:1d49:b0:68b:caa0:e820 with SMTP id p9-20020a0568301d4900b0068bcaa0e820mr1832154oth.12.1675775117481; Tue, 07 Feb 2023 05:05:17 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c2:8ced:8458:e6b7:cf66:aa19? ([2804:1b3:a7c2:8ced:8458:e6b7:cf66:aa19]) by smtp.gmail.com with ESMTPSA id k5-20020a9d7dc5000000b0068bcb44e7f5sm6369159otn.68.2023.02.07.05.05.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Feb 2023 05:05:16 -0800 (PST) Message-ID: Date: Tue, 7 Feb 2023 10:05:14 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH 1/2] riscv: Add Linux hwprobe syscall support Content-Language: en-US To: Evan Green , libc-alpha@sourceware.org Cc: slewis@rivosinc.com, vineetg@rivosinc.com, palmer@rivosinc.com References: <20230206194819.1679472-1-evan@rivosinc.com> <20230206194819.1679472-2-evan@rivosinc.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230206194819.1679472-2-evan@rivosinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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,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 06/02/23 16:48, 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. Do you want to use this symbol on external projects, for instance to implement builtin_cpu_supports (as powerpc does)? If so, it has the drawback that such feature will only work on glibc. > > Signed-off-by: Evan Green > --- > > 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 | 34 +++++++++++++++++++ > sysdeps/unix/sysv/linux/syscall-names.list | 1 + > 9 files changed, 74 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..891ae05730 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.37 { > + __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..ef6dccb9db > --- /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 (riscv_hwprobe, 5, pairs, pair_count, > + cpu_count, cpus, flags); > +} Use INLINE_SYSCALL_CALL to avoid the need to specify the argument size. > 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 ff90d1bff2..f4c391d3be 100644 > --- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist > +++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist > @@ -2396,3 +2396,4 @@ GLIBC_2.36 pidfd_open F > GLIBC_2.36 pidfd_send_signal F > GLIBC_2.36 process_madvise F > GLIBC_2.36 process_mrelease F > +GLIBC_2.37 __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 f1017f6ec5..0f57bbe9e1 100644 > --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > @@ -2596,3 +2596,4 @@ GLIBC_2.36 pidfd_open F > GLIBC_2.36 pidfd_send_signal F > GLIBC_2.36 process_madvise F > GLIBC_2.36 process_mrelease F > +GLIBC_2.37 __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..da8cdc90bf > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h > @@ -0,0 +1,34 @@ > +/* 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 Do we really want to tie its usage to the supplied kernel headers? It means that if kernel headers is too old a program that includes sys/hwprobe.h will just fail to compile, which is not ideal. For user exported header the usual way is to use __has_include and redefine the required fields (check sysdeps/unix/sysv/linux/bits/unistd_ext.h or grep for __has_include). It has the drawnback of require duplicate and constant sync kernel definition to exported header. > + > +__BEGIN_DECLS > + > +int > +__riscv_hwprobe (struct riscv_hwprobe *pairs, long pair_count, > + long cpu_count, unsigned long *cpus, unsigned long flags); > + > +__END_DECLS > + > +#endif /* sys/hwprobe.h */ I think we should also only export it as a GNU extension (__USE_GNU). > 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