Re: Detection of hadware feature => please do not use signal
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>, Bastien Roucariès <rouca@debian.org>, pgsql-bugs@lists.postgresql.org
Date: 2024-11-23T22:02:34Z
Lists: pgsql-bugs
Attachments
- v2-netbsd-arm-crc-detection.patch (text/x-diff) patch v2
I wrote: > But that developer.arm.com page seems pretty definitive. Tomorrow > I'll have a go at spinning up a 32-bit NetBSD installation and test > it. Thanks for the research! Conclusions: 1. Unsurprisingly, a 64-bit kernel exposes machdep.cpuN.cpu_id but not machdep.id_isar; a 32-bit kernel the reverse. 2. 32-bit userland does not provide <aarch64/armreg.h>. (So I did not try to use the ID_AA64ISAR0_EL1_CRC32 macro: we'd have had to hard-code the field position anyway for 32-bit.) 3. It doesn't look to me like NetBSD really supports 32-bit userland under a 64-bit kernel. Maybe it'd kind of work, but utilities like cpuctl seem to be built for only one of the kernel APIs. So I end up proposing the attached. If we do somehow find ourselves running 32-bit with a 64-bit kernel, this will report "no CRC" because the sysctl call will fail. I don't think it's worth sweating over that case. BTW, I found out that by default we'll build a software-CRC-only implementation on 32-bit ARM NetBSD, at least in the "generic" eabihf build: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=... no checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc... no checking which CRC-32C implementation to use... slicing-by-8 It turns out that -march=armv8-a+crc would work, except: configure:17624: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc configure:17648: ccache gcc -o conftest -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -O2 -march=armv8-a+crc -Wl,-z,now -Wl,-z,relro conftest.c -lz -ledit -lcurses -lpthread -lexecinfo -lrt -lm >&5 cc1: error: '-mfloat-abi=hard': selected processor lacks an FPU If you force it with a compatible -mfpu switch (I used -mfpu=neon) then you get a build with runtime CRC check, and all seems to work. I did not try very hard to determine what the default -mfpu is here or why -march=armv8-a+crc overrides whatever the default is. This probably means that no end user is going to see any benefit from this exercise, because they are not likely to try adding -mfpu by itself. If they add "-march=armv8-a+crc -mfpu=whatever" to CFLAGS manually then configure will deem that a runtime check is not required, so this code still doesn't get exercised. tl;dr: a lot of time spent on a probably-useless exercise. Still, now that we've got the code we may as well commit it. The configure issue was there all along. regards, tom lane
Commits
-
Update configure probes for CFLAGS needed for ARM CRC instructions.
- e266a0ed67d2 17.3 landed
- 851c6ff18fd3 15.11 landed
- 5980f1884fc9 18.0 landed
- 32057a0f791e 13.19 landed
- 2fc0199a5015 14.16 landed
- 1f4aadec41b8 16.7 landed
-
Support runtime CRC feature probing on NetBSD/ARM using sysctl().
- 4570b22666dd 18.0 landed
-
Use auxv to check for CRC32 instructions on ARM.
- aac831cafa6f 18.0 landed
-
Improve our method for probing the availability of ARM CRC instructions.
- 1c72ec6f4989 11.0 cited