When compiled for armv6+ and getauxval() is present (glibc 2.16+), avoid slow and unreliable /proc/cpuinfo parsing.
E.g. /proc/cpuinfo contains junk with qemu-user and can be unavailable in some chroot environment.
"Yuriy M. Kaminskiy" yumkam@gmail.com writes:
When compiled for armv6+ and getauxval() is present (glibc 2.16+), avoid slow and unreliable /proc/cpuinfo parsing.
E.g. /proc/cpuinfo contains junk with qemu-user and can be unavailable in some chroot environment.
Do you know what's the preferred way to do this on android? Do we still need /proc/cpuinfo, or are there any library facilities?
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16) +#include <sys/auxv.h>
This part could be an AC_CHECK_HEADERS([sys/auxv.h]) in configure.ac.
+#if defined(AT_HWCAP) && defined(HWCAP_ARM_NEON) +#define HAVE_GETAUXVAL 1 +#endif +#endif
#include "nettle-types.h"
#include "aes-internal.h" @@ -87,6 +94,18 @@ get_arm_features (struct arm_features *features) } else { +#if defined(HAVE_GETAUXVAL) && __ARM_ARCH >= 6
Why the condition __ARM_ARCH >= 6? Is it because getauxval doesn't let us make the distinction between arch_version 5 and 6?
unsigned long hwcap = getauxval(AT_HWCAP);
features->arch_version = __ARM_ARCH;
Is it important to take the compile-time arch into account? The effect (when it makes a difference at all) will be to force use of certain features, even if runtime checks say we're running on an older arch.
Is the getauxval method missing a way to get cpu arch at runtime? In the docs (https://github.com/torvalds/linux/blob/master/arch/arm/include/uapi/asm/hwca...) I don't see anything corresponding to the "CPU arcitecture" line in /proc/cpuinfo.
I'd be happier about getauxval if we could find a way to also get the arch version without reading /proc/cpuinfo. But I don't think it's a blocker for this change.
Regards, /Niels
On 14.03.2019 08:41, Niels Möller wrote:
"Yuriy M. Kaminskiy" yumkam@gmail.com writes:
When compiled for armv6+ and getauxval() is present (glibc 2.16+), avoid slow and unreliable /proc/cpuinfo parsing.
E.g. /proc/cpuinfo contains junk with qemu-user and can be unavailable in some chroot environment.
Do you know what's the preferred way to do this on android? Do we still need /proc/cpuinfo, or are there any library facilities?
Google suggests https://developer.android.com/ndk/guides/cpu-features I have no experience with it.
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16) +#include <sys/auxv.h>
This part could be an AC_CHECK_HEADERS([sys/auxv.h]) in configure.ac.
Hmm... musl also provides it, I'll move detection to configure; then again, musl does not define HWCAP_*, and I'm reluctant to fallback to <asm/hwcap.h> or define HWCAP_* myself, so practically it still works on glibc only.
else { +#if defined(HAVE_GETAUXVAL) && __ARM_ARCH >= 6
Why the condition __ARM_ARCH >= 6? Is it because getauxval doesn't let us make the distinction between arch_version 5 and 6?
There are (const char *)getauxval(AT_PLATFORM); it is expected to be "v[45678][lb]"; probably, I should use it.
Things that should be checked: arm (32bit) userland with aarch64/arm64 kernel.
unsigned long hwcap = getauxval(AT_HWCAP);
features->arch_version = __ARM_ARCH;
Is it important to take the compile-time arch into account? The effect (when it makes a difference at all) will be to force use of certain features, even if runtime checks say we're running on an older arch.
I wanted to limit change to cases I'm sure will work (e.g. on debian/armhf __ARM_ARCH is 7, on raspbian - 6; both are sufficient for nettle to use most optimized code); and don't touch anything "unusual".
Is the getauxval method missing a way to get cpu arch at runtime? In the docs (https://github.com/torvalds/linux/blob/master/arch/arm/include/uapi/asm/hwca...) I don't see anything corresponding to the "CPU arcitecture" line in /proc/cpuinfo.
I'd be happier about getauxval if we could find a way to also get the arch version without reading /proc/cpuinfo. But I don't think it's a blocker for this change.
"Yuriy M. Kaminskiy" yumkam@gmail.com writes:
On 14.03.2019 08:41, Niels Möller wrote:
"Yuriy M. Kaminskiy" yumkam@gmail.com writes:
When compiled for armv6+ and getauxval() is present (glibc 2.16+), avoid slow and unreliable /proc/cpuinfo parsing.
E.g. /proc/cpuinfo contains junk with qemu-user and can be unavailable in some chroot environment.
Do you know what's the preferred way to do this on android? Do we still need /proc/cpuinfo, or are there any library facilities?
Google suggests https://developer.android.com/ndk/guides/cpu-features I have no experience with it.
That page says that getauxval is available on later versions ("API level 18" and later, whatever that means). So should hopefully work, with the same configure check.
Not sure if there's any easy way to test on android, without downloading either the ndk (with whatever license agreements required) or just the cross-compiler binaries. Is http://android-rebuilds.beuc.net/ the way to go? I also tried native compile under termux a while ago, but configure failed because there was no /bin/sh.
There are (const char *)getauxval(AT_PLATFORM); it is expected to be "v[45678][lb]"; probably, I should use it.
Things that should be checked: arm (32bit) userland with aarch64/arm64 kernel.
Any progress on this? I'd really like to have the arch version check also done via getauxval, if that's possible.
Regards, /Niels
nettle-bugs@lists.lysator.liu.se