Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect the number of performance cores in the M1 macs via the new macos12 API #44072

Merged
merged 3 commits into from
Feb 8, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,23 @@ JL_DLLEXPORT int jl_cpu_threads(void) JL_NOTSAFEPOINT
}

#if defined(__APPLE__) && defined(_CPU_AARCH64_)
// Manually subtract efficiency cores for Apple's big.LITTLE cores
int32_t family = 0;
len = 4;
sysctlbyname("hw.cpufamily", &family, &len, NULL, 0);
if (family >= 1 && count > 1) {
if (family == CPUFAMILY_ARM_FIRESTORM_ICESTORM) {
// We know the Apple M1 has 4 efficiency cores, so subtract them out.
count -= 4;
// MacOS 12 added a way to query performance cores,
gbaraldi marked this conversation as resolved.
Show resolved Hide resolved
char buf[7];
len = 7;
sysctlbyname("kern.osrelease", buf, &len, NULL, 0);
if (buf[0] > 1 && buf[1] > 0){
len = 4;
sysctlbyname("hw.perflevel0.physicalcpu", &count, &len, NULL, 0);
}
else {
int32_t family = 0;
len = 4;
sysctlbyname("hw.cpufamily", &family, &len, NULL, 0);
if (family >= 1 && count > 1) {
if (family == CPUFAMILY_ARM_FIRESTORM_ICESTORM) {
// We know the Apple M1 has 4 efficiency cores, so subtract them out.
count -= 4;
}
}
}
#endif
Expand Down