cpuinfo icon indicating copy to clipboard operation
cpuinfo copied to clipboard

For Apple silicon, use machdep.cpu.brand_string in preference to decoding hw.machine

Open dlenski opened this issue 1 year ago • 1 comments

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

dlenski avatar May 22 '24 18:05 dlenski

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!

facebook-github-bot avatar May 22 '24 18:05 facebook-github-bot

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? 😃

dlenski avatar Nov 27 '24 16:11 dlenski

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? 😅

dlenski avatar Dec 04 '24 23:12 dlenski

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 :)

F0bes avatar Mar 12 '25 21:03 F0bes

Thanks. LGTM. Sorry for the delay.

digantdesai avatar Mar 21 '25 07:03 digantdesai