* [PATCH] util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD
@ 2024-07-28 3:58 Brad Smith
2024-07-28 4:46 ` Richard Henderson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Brad Smith @ 2024-07-28 3:58 UTC (permalink / raw)
To: Richard Henderson, Paolo Bonzini; +Cc: qemu-devel
util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD
Signed-off-by: Brad Smith <brad@comstyle.com>
---
meson.build | 8 ++++++++
util/cpuinfo-aarch64.c | 9 ++++++---
util/cpuinfo-ppc.c | 5 +++--
util/getauxval.c | 2 +-
4 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/meson.build b/meson.build
index 5613b62a4f..97f63aa86c 100644
--- a/meson.build
+++ b/meson.build
@@ -2835,6 +2835,14 @@ config_host_data.set('CONFIG_GETAUXVAL', cc.links(gnu_source_prefix + '''
return getauxval(AT_HWCAP) == 0;
}'''))
+config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(gnu_source_prefix + '''
+ #include <sys/auxv.h>
+ int main(void) {
+ unsigned long hwcap = 0;
+ elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
+ return hwcap;
+ }'''))
+
config_host_data.set('CONFIG_USBFS', have_linux_user and cc.compiles('''
#include <linux/usbdevice_fs.h>
diff --git a/util/cpuinfo-aarch64.c b/util/cpuinfo-aarch64.c
index 8ca775a14b..57468890c3 100644
--- a/util/cpuinfo-aarch64.c
+++ b/util/cpuinfo-aarch64.c
@@ -17,10 +17,13 @@
# define HWCAP2_BTI 0 /* added in glibc 2.32 */
# endif
#endif
+#ifdef CONFIG_ELF_AUX_INFO
+#include <sys/auxv.h>
+#endif
#ifdef CONFIG_DARWIN
# include <sys/sysctl.h>
#endif
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO)
# include <machine/armreg.h>
# include <machine/cpu.h>
# include <sys/types.h>
@@ -61,7 +64,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
info = CPUINFO_ALWAYS;
-#ifdef CONFIG_LINUX
+#if defined(CONFIG_LINUX) || defined(CONFIG_ELF_AUX_INFO)
unsigned long hwcap = qemu_getauxval(AT_HWCAP);
info |= (hwcap & HWCAP_ATOMICS ? CPUINFO_LSE : 0);
info |= (hwcap & HWCAP_USCAT ? CPUINFO_LSE2 : 0);
@@ -78,7 +81,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
info |= sysctl_for_bool("hw.optional.arm.FEAT_PMULL") * CPUINFO_PMULL;
info |= sysctl_for_bool("hw.optional.arm.FEAT_BTI") * CPUINFO_BTI;
#endif
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO)
int mib[2];
uint64_t isar0;
uint64_t pfr1;
diff --git a/util/cpuinfo-ppc.c b/util/cpuinfo-ppc.c
index 1304f9aa80..ccfcaa0754 100644
--- a/util/cpuinfo-ppc.c
+++ b/util/cpuinfo-ppc.c
@@ -14,7 +14,8 @@
# include "elf.h"
# endif
#endif
-#ifdef __FreeBSD__
+#if defined(CONFIG_ELF_AUX_INFO)
+# include <sys/auxv.h>
# include <machine/cpu.h>
# ifndef PPC_FEATURE2_ARCH_3_1
# define PPC_FEATURE2_ARCH_3_1 0
@@ -35,7 +36,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
info = CPUINFO_ALWAYS;
-#if defined(CONFIG_LINUX) || defined(__FreeBSD__)
+#if defined(CONFIG_LINUX) || deinfed(CONFIG_ELF_AUX_INFO)
unsigned long hwcap = qemu_getauxval(AT_HWCAP);
unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2);
diff --git a/util/getauxval.c b/util/getauxval.c
index b124107d61..5bdbb04f8f 100644
--- a/util/getauxval.c
+++ b/util/getauxval.c
@@ -98,7 +98,7 @@ unsigned long qemu_getauxval(unsigned long type)
return 0;
}
-#elif defined(__FreeBSD__)
+#elif deinfed(CONFIG_ELF_AUX_INFO)
#include <sys/auxv.h>
unsigned long qemu_getauxval(unsigned long type)
--
2.45.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD
2024-07-28 3:58 [PATCH] util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD Brad Smith
@ 2024-07-28 4:46 ` Richard Henderson
2024-07-29 0:28 ` Richard Henderson
2024-07-29 9:37 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2024-07-28 4:46 UTC (permalink / raw)
To: Brad Smith, Paolo Bonzini; +Cc: qemu-devel
On 7/28/24 13:58, Brad Smith wrote:
> util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD
>
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
> meson.build | 8 ++++++++
> util/cpuinfo-aarch64.c | 9 ++++++---
> util/cpuinfo-ppc.c | 5 +++--
> util/getauxval.c | 2 +-
> 4 files changed, 18 insertions(+), 6 deletions(-)
Is this specifically better than sysctl for cpuinfo-aarch64.c?
Otherwise, I'm happy with the getauxval.c and cpuinfo-ppc.c changes.
r~
>
> diff --git a/meson.build b/meson.build
> index 5613b62a4f..97f63aa86c 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2835,6 +2835,14 @@ config_host_data.set('CONFIG_GETAUXVAL', cc.links(gnu_source_prefix + '''
> return getauxval(AT_HWCAP) == 0;
> }'''))
>
> +config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(gnu_source_prefix + '''
> + #include <sys/auxv.h>
> + int main(void) {
> + unsigned long hwcap = 0;
> + elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
> + return hwcap;
> + }'''))
> +
> config_host_data.set('CONFIG_USBFS', have_linux_user and cc.compiles('''
> #include <linux/usbdevice_fs.h>
>
> diff --git a/util/cpuinfo-aarch64.c b/util/cpuinfo-aarch64.c
> index 8ca775a14b..57468890c3 100644
> --- a/util/cpuinfo-aarch64.c
> +++ b/util/cpuinfo-aarch64.c
> @@ -17,10 +17,13 @@
> # define HWCAP2_BTI 0 /* added in glibc 2.32 */
> # endif
> #endif
> +#ifdef CONFIG_ELF_AUX_INFO
> +#include <sys/auxv.h>
> +#endif
> #ifdef CONFIG_DARWIN
> # include <sys/sysctl.h>
> #endif
> -#ifdef __OpenBSD__
> +#if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO)
> # include <machine/armreg.h>
> # include <machine/cpu.h>
> # include <sys/types.h>
> @@ -61,7 +64,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
>
> info = CPUINFO_ALWAYS;
>
> -#ifdef CONFIG_LINUX
> +#if defined(CONFIG_LINUX) || defined(CONFIG_ELF_AUX_INFO)
> unsigned long hwcap = qemu_getauxval(AT_HWCAP);
> info |= (hwcap & HWCAP_ATOMICS ? CPUINFO_LSE : 0);
> info |= (hwcap & HWCAP_USCAT ? CPUINFO_LSE2 : 0);
> @@ -78,7 +81,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
> info |= sysctl_for_bool("hw.optional.arm.FEAT_PMULL") * CPUINFO_PMULL;
> info |= sysctl_for_bool("hw.optional.arm.FEAT_BTI") * CPUINFO_BTI;
> #endif
> -#ifdef __OpenBSD__
> +#if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO)
> int mib[2];
> uint64_t isar0;
> uint64_t pfr1;
> diff --git a/util/cpuinfo-ppc.c b/util/cpuinfo-ppc.c
> index 1304f9aa80..ccfcaa0754 100644
> --- a/util/cpuinfo-ppc.c
> +++ b/util/cpuinfo-ppc.c
> @@ -14,7 +14,8 @@
> # include "elf.h"
> # endif
> #endif
> -#ifdef __FreeBSD__
> +#if defined(CONFIG_ELF_AUX_INFO)
> +# include <sys/auxv.h>
> # include <machine/cpu.h>
> # ifndef PPC_FEATURE2_ARCH_3_1
> # define PPC_FEATURE2_ARCH_3_1 0
> @@ -35,7 +36,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
>
> info = CPUINFO_ALWAYS;
>
> -#if defined(CONFIG_LINUX) || defined(__FreeBSD__)
> +#if defined(CONFIG_LINUX) || deinfed(CONFIG_ELF_AUX_INFO)
> unsigned long hwcap = qemu_getauxval(AT_HWCAP);
> unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2);
>
> diff --git a/util/getauxval.c b/util/getauxval.c
> index b124107d61..5bdbb04f8f 100644
> --- a/util/getauxval.c
> +++ b/util/getauxval.c
> @@ -98,7 +98,7 @@ unsigned long qemu_getauxval(unsigned long type)
> return 0;
> }
>
> -#elif defined(__FreeBSD__)
> +#elif deinfed(CONFIG_ELF_AUX_INFO)
> #include <sys/auxv.h>
>
> unsigned long qemu_getauxval(unsigned long type)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD
2024-07-28 3:58 [PATCH] util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD Brad Smith
2024-07-28 4:46 ` Richard Henderson
@ 2024-07-29 0:28 ` Richard Henderson
2024-07-29 9:37 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2024-07-29 0:28 UTC (permalink / raw)
To: Brad Smith, Paolo Bonzini; +Cc: qemu-devel
On 7/28/24 13:58, Brad Smith wrote:
> util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD
>
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
> meson.build | 8 ++++++++
> util/cpuinfo-aarch64.c | 9 ++++++---
> util/cpuinfo-ppc.c | 5 +++--
> util/getauxval.c | 2 +-
> 4 files changed, 18 insertions(+), 6 deletions(-)
Queued.
r~
>
> diff --git a/meson.build b/meson.build
> index 5613b62a4f..97f63aa86c 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2835,6 +2835,14 @@ config_host_data.set('CONFIG_GETAUXVAL', cc.links(gnu_source_prefix + '''
> return getauxval(AT_HWCAP) == 0;
> }'''))
>
> +config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(gnu_source_prefix + '''
> + #include <sys/auxv.h>
> + int main(void) {
> + unsigned long hwcap = 0;
> + elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
> + return hwcap;
> + }'''))
> +
> config_host_data.set('CONFIG_USBFS', have_linux_user and cc.compiles('''
> #include <linux/usbdevice_fs.h>
>
> diff --git a/util/cpuinfo-aarch64.c b/util/cpuinfo-aarch64.c
> index 8ca775a14b..57468890c3 100644
> --- a/util/cpuinfo-aarch64.c
> +++ b/util/cpuinfo-aarch64.c
> @@ -17,10 +17,13 @@
> # define HWCAP2_BTI 0 /* added in glibc 2.32 */
> # endif
> #endif
> +#ifdef CONFIG_ELF_AUX_INFO
> +#include <sys/auxv.h>
> +#endif
> #ifdef CONFIG_DARWIN
> # include <sys/sysctl.h>
> #endif
> -#ifdef __OpenBSD__
> +#if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO)
> # include <machine/armreg.h>
> # include <machine/cpu.h>
> # include <sys/types.h>
> @@ -61,7 +64,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
>
> info = CPUINFO_ALWAYS;
>
> -#ifdef CONFIG_LINUX
> +#if defined(CONFIG_LINUX) || defined(CONFIG_ELF_AUX_INFO)
> unsigned long hwcap = qemu_getauxval(AT_HWCAP);
> info |= (hwcap & HWCAP_ATOMICS ? CPUINFO_LSE : 0);
> info |= (hwcap & HWCAP_USCAT ? CPUINFO_LSE2 : 0);
> @@ -78,7 +81,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
> info |= sysctl_for_bool("hw.optional.arm.FEAT_PMULL") * CPUINFO_PMULL;
> info |= sysctl_for_bool("hw.optional.arm.FEAT_BTI") * CPUINFO_BTI;
> #endif
> -#ifdef __OpenBSD__
> +#if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO)
> int mib[2];
> uint64_t isar0;
> uint64_t pfr1;
> diff --git a/util/cpuinfo-ppc.c b/util/cpuinfo-ppc.c
> index 1304f9aa80..ccfcaa0754 100644
> --- a/util/cpuinfo-ppc.c
> +++ b/util/cpuinfo-ppc.c
> @@ -14,7 +14,8 @@
> # include "elf.h"
> # endif
> #endif
> -#ifdef __FreeBSD__
> +#if defined(CONFIG_ELF_AUX_INFO)
> +# include <sys/auxv.h>
> # include <machine/cpu.h>
> # ifndef PPC_FEATURE2_ARCH_3_1
> # define PPC_FEATURE2_ARCH_3_1 0
> @@ -35,7 +36,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
>
> info = CPUINFO_ALWAYS;
>
> -#if defined(CONFIG_LINUX) || defined(__FreeBSD__)
> +#if defined(CONFIG_LINUX) || deinfed(CONFIG_ELF_AUX_INFO)
> unsigned long hwcap = qemu_getauxval(AT_HWCAP);
> unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2);
>
> diff --git a/util/getauxval.c b/util/getauxval.c
> index b124107d61..5bdbb04f8f 100644
> --- a/util/getauxval.c
> +++ b/util/getauxval.c
> @@ -98,7 +98,7 @@ unsigned long qemu_getauxval(unsigned long type)
> return 0;
> }
>
> -#elif defined(__FreeBSD__)
> +#elif deinfed(CONFIG_ELF_AUX_INFO)
> #include <sys/auxv.h>
>
> unsigned long qemu_getauxval(unsigned long type)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD
2024-07-28 3:58 [PATCH] util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD Brad Smith
2024-07-28 4:46 ` Richard Henderson
2024-07-29 0:28 ` Richard Henderson
@ 2024-07-29 9:37 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-29 9:37 UTC (permalink / raw)
To: Brad Smith, Richard Henderson, Paolo Bonzini; +Cc: qemu-devel
Hi Brad,
On 28/7/24 05:58, Brad Smith wrote:
> util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD
>
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
> meson.build | 8 ++++++++
> util/cpuinfo-aarch64.c | 9 ++++++---
> util/cpuinfo-ppc.c | 5 +++--
> util/getauxval.c | 2 +-
> 4 files changed, 18 insertions(+), 6 deletions(-)
> diff --git a/util/cpuinfo-ppc.c b/util/cpuinfo-ppc.c
> index 1304f9aa80..ccfcaa0754 100644
> --- a/util/cpuinfo-ppc.c
> +++ b/util/cpuinfo-ppc.c
> @@ -14,7 +14,8 @@
> # include "elf.h"
> # endif
> #endif
> -#ifdef __FreeBSD__
> +#if defined(CONFIG_ELF_AUX_INFO)
> +# include <sys/auxv.h>
> # include <machine/cpu.h>
> # ifndef PPC_FEATURE2_ARCH_3_1
> # define PPC_FEATURE2_ARCH_3_1 0
> @@ -35,7 +36,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
>
> info = CPUINFO_ALWAYS;
>
> -#if defined(CONFIG_LINUX) || defined(__FreeBSD__)
> +#if defined(CONFIG_LINUX) || deinfed(CONFIG_ELF_AUX_INFO)
Typo!
> unsigned long hwcap = qemu_getauxval(AT_HWCAP);
> unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2);
>
> diff --git a/util/getauxval.c b/util/getauxval.c
> index b124107d61..5bdbb04f8f 100644
> --- a/util/getauxval.c
> +++ b/util/getauxval.c
> @@ -98,7 +98,7 @@ unsigned long qemu_getauxval(unsigned long type)
> return 0;
> }
>
> -#elif defined(__FreeBSD__)
> +#elif deinfed(CONFIG_ELF_AUX_INFO)
Same typo, has this patch been tested?
> #include <sys/auxv.h>
>
> unsigned long qemu_getauxval(unsigned long type)
Except typos, code LGTM, so:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-29 9:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-28 3:58 [PATCH] util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD Brad Smith
2024-07-28 4:46 ` Richard Henderson
2024-07-29 0:28 ` Richard Henderson
2024-07-29 9:37 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).