Skip to content

Commit

Permalink
[release/5.0] Fix reading cpu cache size for Alpine(musl) (#41547)
Browse files Browse the repository at this point in the history
* Fix reading cpu cache size for Alpine(musl)

* limiting the fallback to Linux only

* exclude ARM

* fixing copy-paste error

Co-authored-by: Manish Godse <[email protected]>
  • Loading branch information
github-actions[bot] and mangod9 authored Aug 31, 2020
1 parent 4328059 commit af1a3dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/coreclr/src/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/coreclr/src/pal/src/misc/sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
//
Expand Down

0 comments on commit af1a3dc

Please sign in to comment.