google / cpu_features

A cross platform C99 library to get cpu features at runtime.
Apache License 2.0
2.44k stars 258 forks source link

FreeBSD Arm64 MIDR_EL1 detection info #344

Open toor1245 opened 11 months ago

toor1245 commented 11 months ago

This issue was created to make it easier for people experiencing the problem of MIDR_EL1 not receiving information on FreeBSD Arm64 to more easily determine the root cause.

We use elf_aux_info(3) to detect MIDR_EL1 info (implementer, variant, part, revision) for FreeBSD Arm64. To retrieve this information we check if HWCAP_CPUID is enabled to retrieve data from system registers EL1 in user mode. However, FreeBSD export the cpuid registers since 2018 but never set the HWCAP_CPUID flag to tell userspace, so it was fixed recently.

ref: https://cgit.freebsd.org/src/commit/?id=d61f9bfb0e5c119c97a559f187b1e9c73077307b

Below you can see results with build on current main FreeBSD branch before and after the fix:

mhohsadze@generic:~/cpu_features_toor1245_2 $ bazel run list_cpu_features
INFO: Analyzed target //:list_cpu_features (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:list_cpu_features up-to-date:
  bazel-bin/list_cpu_features
INFO: Elapsed time: 0.991s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/list_cpu_features
arch            : aarch64
implementer     :   0 (0x00)
variant         :   0 (0x00)
part            :   0 (0x00)
revision        :   0 (0x00)
flags           : asimd,crc32,fp
mhohsadze@generic:~/cpu_features_toor1245_2 $ bazel run list_cpu_features
Starting local Bazel server and connecting to it...
... still trying to connect to local Bazel server (1532) after 10 seconds ...
INFO: Analyzed target //:list_cpu_features (37 packages loaded, 192 targets configured).
INFO: Found 1 target...
Target //:list_cpu_features up-to-date:
  bazel-bin/list_cpu_features
INFO: Elapsed time: 61.431s, Critical Path: 4.52s
INFO: 8 processes: 1 internal, 7 processwrapper-sandbox.
INFO: Build completed successfully, 8 total actions
INFO: Running command line: bazel-bin/list_cpu_features
arch            : aarch64
implementer     :  65 (0x41)
variant         :   0 (0x00)
part            : 3336 (0xD08)
revision        :   3 (0x03)
flags           : asimd,cpuid,crc32,fp
mhohsadze@generic:~/cpu_features_toor1245_2 $ 

As you can see, a user of the stable version of FreeBSD will currently see empty MIDR information. The fix will probably work starting from versions 14.x+