Fix reading cpu cache size for Alpine(musl) (#41532)
authorManish Godse <61718172+mangod9@users.noreply.github.com>
Sat, 29 Aug 2020 05:17:01 +0000 (22:17 -0700)
committerGitHub <noreply@github.com>
Sat, 29 Aug 2020 05:17:01 +0000 (22:17 -0700)
* 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
src/coreclr/src/pal/src/misc/sysinfo.cpp

index 8bcc98a..fcba545 100644 (file)
@@ -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
index 4592aa2..6b23c17 100644 (file)
@@ -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
         //