From 34b94adc4b6dbbffd4a15fad7fdccfb65c4d1f45 Mon Sep 17 00:00:00 2001 From: Manish Godse <61718172+mangod9@users.noreply.github.com> Date: Fri, 28 Aug 2020 12:35:34 -0700 Subject: [PATCH 1/4] Fix reading cpu cache size for Alpine(musl) --- src/coreclr/src/gc/unix/gcenv.unix.cpp | 7 ++++++- src/coreclr/src/pal/src/misc/sysinfo.cpp | 11 ++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/gc/unix/gcenv.unix.cpp b/src/coreclr/src/gc/unix/gcenv.unix.cpp index 8bcc98a3526aee..049b328de5b9ef 100644 --- a/src/coreclr/src/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/src/gc/unix/gcenv.unix.cpp @@ -834,9 +834,13 @@ static size_t GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, ( size_t) sysconf(_SC_LEVEL4_CACHE_SIZE)); #endif -#if defined(HOST_ARM64) 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)) @@ -851,6 +855,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, size); } +#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..6e75b20a645ce2 100644 --- a/src/coreclr/src/pal/src/misc/sysinfo.cpp +++ b/src/coreclr/src/pal/src/misc/sysinfo.cpp @@ -565,9 +565,13 @@ PAL_GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL4_CACHE_SIZE)); #endif -#if defined(HOST_ARM64) - if(cacheSize == 0) + 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)) @@ -582,7 +586,8 @@ PAL_GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, size); } - if(cacheSize == 0) +#if defined(HOST_ARM64) + if (cacheSize == 0) { // It is currently expected to be missing cache size info // From 4371e43e4a57cfe31efb0bc4e532318f624de4ec Mon Sep 17 00:00:00 2001 From: Manish Godse <61718172+mangod9@users.noreply.github.com> Date: Fri, 28 Aug 2020 14:25:43 -0700 Subject: [PATCH 2/4] limiting the fallback to Linux only --- src/coreclr/src/gc/unix/gcenv.unix.cpp | 2 ++ src/coreclr/src/pal/src/misc/sysinfo.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/coreclr/src/gc/unix/gcenv.unix.cpp b/src/coreclr/src/gc/unix/gcenv.unix.cpp index 049b328de5b9ef..bb60ec6a501623 100644 --- a/src/coreclr/src/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/src/gc/unix/gcenv.unix.cpp @@ -834,6 +834,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, ( size_t) sysconf(_SC_LEVEL4_CACHE_SIZE)); #endif +#if defined(TARGET_LINUX) if (cacheSize == 0) { // @@ -854,6 +855,7 @@ 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) diff --git a/src/coreclr/src/pal/src/misc/sysinfo.cpp b/src/coreclr/src/pal/src/misc/sysinfo.cpp index 6e75b20a645ce2..d63c80ca82585b 100644 --- a/src/coreclr/src/pal/src/misc/sysinfo.cpp +++ b/src/coreclr/src/pal/src/misc/sysinfo.cpp @@ -565,6 +565,7 @@ PAL_GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL4_CACHE_SIZE)); #endif +#if defined(TARGET_LINUX) if (cacheSize == 0) { // @@ -585,6 +586,7 @@ PAL_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) From 3a5deed57116c4a365a87b315dfc434f6b6dc4d9 Mon Sep 17 00:00:00 2001 From: Manish Godse <61718172+mangod9@users.noreply.github.com> Date: Fri, 28 Aug 2020 16:03:22 -0700 Subject: [PATCH 3/4] exclude ARM --- src/coreclr/src/gc/unix/gcenv.unix.cpp | 2 +- src/coreclr/src/pal/src/misc/sysinfo.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/gc/unix/gcenv.unix.cpp b/src/coreclr/src/gc/unix/gcenv.unix.cpp index bb60ec6a501623..978c5b9e862946 100644 --- a/src/coreclr/src/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/src/gc/unix/gcenv.unix.cpp @@ -857,7 +857,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS() } #endif -#if defined(HOST_ARM64) +#if defined(TARGET_LINUX) && !defined(HOST_ARM) 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 d63c80ca82585b..6b23c17ac14820 100644 --- a/src/coreclr/src/pal/src/misc/sysinfo.cpp +++ b/src/coreclr/src/pal/src/misc/sysinfo.cpp @@ -565,7 +565,7 @@ PAL_GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL4_CACHE_SIZE)); #endif -#if defined(TARGET_LINUX) +#if defined(TARGET_LINUX) && !defined(HOST_ARM) if (cacheSize == 0) { // From d9da30eae0bca0c816a5b29c8e3ab25399a1ba5c Mon Sep 17 00:00:00 2001 From: Manish Godse <61718172+mangod9@users.noreply.github.com> Date: Fri, 28 Aug 2020 16:54:36 -0700 Subject: [PATCH 4/4] fixing copy-paste error --- src/coreclr/src/gc/unix/gcenv.unix.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/gc/unix/gcenv.unix.cpp b/src/coreclr/src/gc/unix/gcenv.unix.cpp index 978c5b9e862946..fcba54551a8ded 100644 --- a/src/coreclr/src/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/src/gc/unix/gcenv.unix.cpp @@ -834,7 +834,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS() cacheSize = std::max(cacheSize, ( size_t) sysconf(_SC_LEVEL4_CACHE_SIZE)); #endif -#if defined(TARGET_LINUX) +#if defined(TARGET_LINUX) && !defined(HOST_ARM) if (cacheSize == 0) { // @@ -857,7 +857,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS() } #endif -#if defined(TARGET_LINUX) && !defined(HOST_ARM) +#if defined(HOST_ARM64) if (cacheSize == 0) { // It is currently expected to be missing cache size info