diff --git a/src/coreclr/src/gc/unix/gcenv.unix.cpp b/src/coreclr/src/gc/unix/gcenv.unix.cpp index 8bcc98a3526aee..fcba54551a8ded 100644 --- a/src/coreclr/src/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/src/gc/unix/gcenv.unix.cpp @@ -834,9 +834,14 @@ static size_t GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, ( size_t) sysconf(_SC_LEVEL4_CACHE_SIZE)); #endif -#if defined(HOST_ARM64) +#if defined(TARGET_LINUX) && !defined(HOST_ARM) if (cacheSize == 0) { + // + // Fallback to retrieve cachesize via /sys/.. if sysconf was not available + // for the platform. Currently musl and arm64 should be only cases to use + // this method to determine cache size. + // size_t size; if (ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index0/size", &size)) @@ -850,7 +855,9 @@ static size_t GetLogicalProcessorCacheSizeFromOS() if (ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index4/size", &size)) cacheSize = std::max(cacheSize, size); } +#endif +#if defined(HOST_ARM64) if (cacheSize == 0) { // It is currently expected to be missing cache size info diff --git a/src/coreclr/src/pal/src/misc/sysinfo.cpp b/src/coreclr/src/pal/src/misc/sysinfo.cpp index 4592aa2a14342c..6b23c17ac14820 100644 --- a/src/coreclr/src/pal/src/misc/sysinfo.cpp +++ b/src/coreclr/src/pal/src/misc/sysinfo.cpp @@ -565,9 +565,14 @@ PAL_GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL4_CACHE_SIZE)); #endif -#if defined(HOST_ARM64) - if(cacheSize == 0) +#if defined(TARGET_LINUX) && !defined(HOST_ARM) + if (cacheSize == 0) { + // + // Fallback to retrieve cachesize via /sys/.. if sysconf was not available + // for the platform. Currently musl and arm64 should be only cases to use + // this method to determine cache size. + // size_t size; if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index0/size", &size)) @@ -581,8 +586,10 @@ PAL_GetLogicalProcessorCacheSizeFromOS() if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index4/size", &size)) cacheSize = std::max(cacheSize, size); } +#endif - if(cacheSize == 0) +#if defined(HOST_ARM64) + if (cacheSize == 0) { // It is currently expected to be missing cache size info //