Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/5.0] Fix reading cpu cache size for Alpine(musl) #41547

Merged
merged 4 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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