From ecda2083d4866e97524165f4be7575b46fd5cb34 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Tue, 8 Feb 2022 13:40:49 -0300 Subject: [PATCH] Detect the number of performance cores in the M1 macs via the new macos12 API (#44072) * Use the new macos12 api to query perf cores --- src/sys.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/sys.c b/src/sys.c index 94ba43ae9b4b6..2538eaf62163c 100644 --- a/src/sys.c +++ b/src/sys.c @@ -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