This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Common cpuid wrappers, use SYS_cpuid when available
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Piotr Henryk Dabrowski <ultr at ultr dot pl>
- Cc: <libc-alpha at sourceware dot org>
- Date: Wed, 9 Mar 2016 17:28:10 +0000
- Subject: Re: [PATCH] Common cpuid wrappers, use SYS_cpuid when available
- Authentication-results: sourceware.org; auth=none
- References: <20160309022443 dot 3e3530f6 at ultra dot tux-net> <20160309025455 dot 786115eb at ultra dot tux-net>
On Wed, 9 Mar 2016, Piotr Henryk Dabrowski wrote:
> Sorry for the malformed patch in the first post.
> Here is a working one.
>
> * config.h.in: Check for SYS_cpuid and define HAVE_SYS_CPUID
> * configure: Check for SYS_cpuid and define HAVE_SYS_CPUID
> * configure.ac: Check for SYS_cpuid and define HAVE_SYS_CPUID
> * misc/cpuid.h: Common cpuid wrappers, use SYS_cpuid when available
Non-sysdeps files should not have anything architecture-specific.
Now, *if* you need a configure test, you can't avoid changing the
architecture-independent config.h.in (we don't yet have a way to split
that by architecture). But the rest can be avoided by using sysdeps
configure fragments and headers. And you don't need a configure test
anyway - the code can use #ifdef __NR_cpuid to test if the syscall is
available at compile time, and __ASSUME_CPUID to test if the syscall can
be presumed to work (if the runtime kernel is known to be recent enough,
since the kernel headers used to build glibc may be more recent than the
kernel used by glibc at runtime). Finally, misc/cpuid.h should go under a
sysdeps directory, suitably named not to conflict with the compiler's
<cpuid.h>.
There's a complication: sysdeps/x86 shouldn't contain anything
Linux-specific either. So what that suggests is that you have e.g.
sysdeps/x86/x86-cpuid.h that uses just the cpuid instruction but that can
be overridden by an OS-specific header that supports the syscall - and
then have such an OS-specific version in sysdeps/unix/sysv/linux/x86 (you
can also do more complicated schemes to avoid duplicating the code to use
the instruction).
--
Joseph S. Myers
joseph@codesourcery.com