Skip to content

Commit

Permalink
Detect the number of performance cores in the M1 macs via the new mac…
Browse files Browse the repository at this point in the history
…os12 API (JuliaLang#44072)

* Use the new macos12 api to query perf cores
  • Loading branch information
gbaraldi authored and LilithHafner committed Mar 8, 2022
1 parent 17bb9de commit ecda208
Showing 1 changed file with 17 additions and 8 deletions.
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
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

0 comments on commit ecda208

Please sign in to comment.