For Apple silicon, use machdep.cpu.brand_string in preference to decoding hw.machine
This functionality was implemented in #65 ("Updated package.name to also query machdep.cpu.brand_string if decode of hw.machine fails"), but then it was omitted from the subsequent #100, probably inadvertently.
Adding that functionality back here, so that the package/device name can be shown correctly on recent devices and macOS/iOS versions. I have reversed the order so that machdep.cpu.brand_string is checked before attempting
to decode hw.machine, since the former appears to be more future-proof.
Before this change, on a recent MacBook Pro:
$ cpu-info
...
Debug (cpuinfo): hw.machine: arm64
Warning in cpuinfo: parsing "hw.machine" failed: Undefined error: 0
...
Packages:
0:
After this change:
$ cpu-info
...
Debug (cpuinfo): machdep.cpu.brand_string: Apple M2 Pro
...
Packages:
0: Apple M2 Pro
Hi @dlenski!
Thank you for your pull request and welcome to our community.
Action Required
In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.
Process
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at [email protected]. Thanks!
This PR does exactly what it says it does, but it has not received any review or comments for ~6 months.
I see that @gonnet has recently merged a PR for Apple/Mach (https://github.com/pytorch/cpuinfo/commit/973ec72753f8cfabcd50db5a881ea06b92498ae0). Perhaps he could review this one as well? 😃
I fixed the clang-format violation from d8d9389 in 04efc5e (diff):
diff --git a/src/arm/mach/init.c b/src/arm/mach/init.c
index b37b6bb..c4e6521 100644
--- a/src/arm/mach/init.c
+++ b/src/arm/mach/init.c
@@ -109,7 +109,7 @@ static int read_package_name_from_brand_string(char* package_name) {
return false;
}
- char *brand_string = alloca(size);
+ char* brand_string = alloca(size);
if (sysctlbyname("machdep.cpu.brand_string", brand_string, &size, NULL, 0) != 0)
goto sysctlfail;
cpuinfo_log_debug("machdep.cpu.brand_string: %s", brand_string);
@malfet, @gonnet, could whoever trigger the PR workflows please retrigger it? 😅
Hi there. I come from @PCSX2 and we depend on this library. In hopes that this gets some attention, and so we can avoid manually patching the dependency, I just wanted to say that I've applied this patch locally and it works as expected. I'm using an Apple Mac Mini M4 Pro. Thanks :)
Thanks. LGTM. Sorry for the delay.