From a3515ba0964729c55a5b2bf5c0ae8d2c39eb14be Mon Sep 17 00:00:00 2001 From: Manish Godse <61718172+mangod9@users.noreply.github.com> Date: Fri, 28 Aug 2020 22:17:01 -0700 Subject: [PATCH] Fix reading cpu cache size for Alpine(musl) (#41532) * Fix reading cpu cache size for Alpine(musl) * limiting the fallback to Linux only * exclude ARM * fixing copy-paste error --- src/coreclr/src/gc/unix/gcenv.unix.cpp | 9 ++++++++- src/coreclr/src/pal/src/misc/sysinfo.cpp | 13 ++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/gc/unix/gcenv.unix.cpp b/src/coreclr/src/gc/unix/gcenv.unix.cpp index 8bcc98a..fcba545 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 4592aa2..6b23c17 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 // -- 2.7.4