Skip to content

Commit 69b9000

Browse files
authored
Fix LLC cache issue on Apple M1 (#64576)
1 parent 464d4bf commit 69b9000

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/coreclr/gc/unix/gcenv.unix.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,12 @@ static size_t GetLogicalProcessorCacheSizeFromOS()
946946
{
947947
int64_t cacheSizeFromSysctl = 0;
948948
size_t sz = sizeof(cacheSizeFromSysctl);
949-
const bool success = sysctlbyname("hw.l3cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0
949+
const bool success = false
950+
// macOS-arm64: Since macOS 12.0, Apple added ".perflevelX." to determinate cache sizes for efficiency
951+
// and performance cores separetely. "perflevel0" stands for "performance"
952+
|| sysctlbyname("hw.perflevel0.l2cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0
953+
// macOS-arm64: these report cache sizes for efficiency cores only:
954+
|| sysctlbyname("hw.l3cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0
950955
|| sysctlbyname("hw.l2cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0
951956
|| sysctlbyname("hw.l1dcachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0;
952957
if (success)

src/coreclr/pal/src/misc/sysinfo.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,15 @@ PAL_GetLogicalProcessorCacheSizeFromOS()
613613
{
614614
int64_t cacheSizeFromSysctl = 0;
615615
size_t sz = sizeof(cacheSizeFromSysctl);
616-
const bool success = sysctlbyname("hw.l3cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0
616+
const bool success = false
617+
// macOS-arm64: Since macOS 12.0, Apple added ".perflevelX." to determinate cache sizes for efficiency
618+
// and performance cores separetely. "perflevel0" stands for "performance"
619+
|| sysctlbyname("hw.perflevel0.l2cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0
620+
// macOS-arm64: these report cache sizes for efficiency cores only:
621+
|| sysctlbyname("hw.l3cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0
617622
|| sysctlbyname("hw.l2cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0
618623
|| sysctlbyname("hw.l1dcachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0;
624+
619625
if (success)
620626
{
621627
_ASSERTE(cacheSizeFromSysctl > 0);

0 commit comments

Comments
 (0)