diff options
author | Andy Hanson <anhans@microsoft.com> | 2019-06-05 16:58:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-05 16:58:56 -0700 |
commit | 5d4ff2f11a87d7d434d05e72744946f48e017b11 (patch) | |
tree | 4b888de6cf6716f34e93fc40e0c0bcf352b94122 | |
parent | 10df20ed3ff0208b3f16f79d5062662a8827f579 (diff) | |
download | coreclr-5d4ff2f11a87d7d434d05e72744946f48e017b11.tar.gz coreclr-5d4ff2f11a87d7d434d05e72744946f48e017b11.tar.bz2 coreclr-5d4ff2f11a87d7d434d05e72744946f48e017b11.zip |
Fix PAL_GetLogicalProcessorCacheSizeFromOS on mac (#24777)
* Fix PAL_GetLogicalProcessorCacheSizeFromOS on mac
In a previous PR
(https://github.com/dotnet/coreclr/commit/ed52a006c01a582d4d34add40c318d6f324b99ba#diff-8447e54277bb962d167a77bb260760d7R1879),
GetCacheSizePerLogicalCpu was changed to no longer rely on cpuid on
amd64 systems; instead it uses GetLogicalProcessorCacheSizeFromOS().
Unfortunately that function consisted of a number of `#if`s, none of
which were active on macs, and we just returned 0. This caused us to
default to a gen0size of only 0.25MB, causing many GCs.
Fixed by adding a new case that uses `sysctlbyname`.
Fix #24658
* Fixes from code review
* Check for function sysctlbyname instead of header
-rw-r--r-- | src/pal/src/config.h.in | 1 | ||||
-rw-r--r-- | src/pal/src/configure.cmake | 1 | ||||
-rw-r--r-- | src/pal/src/misc/sysinfo.cpp | 16 |
3 files changed, 18 insertions, 0 deletions
diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in index 505b2ee208..6869455d09 100644 --- a/src/pal/src/config.h.in +++ b/src/pal/src/config.h.in @@ -45,6 +45,7 @@ #cmakedefine01 HAVE_FUTIMES #cmakedefine01 HAVE_UTIMES #cmakedefine01 HAVE_SYSCTL +#cmakedefine01 HAVE_SYSCTLBYNAME #cmakedefine01 HAVE_SYSCONF #cmakedefine01 HAVE_SYSINFO #cmakedefine01 HAVE_LOCALTIME_R diff --git a/src/pal/src/configure.cmake b/src/pal/src/configure.cmake index 7b6391f228..066bd52097 100644 --- a/src/pal/src/configure.cmake +++ b/src/pal/src/configure.cmake @@ -77,6 +77,7 @@ int main(int argc, char **argv) { set(CMAKE_REQUIRED_LIBRARIES) check_include_files(sys/sysctl.h HAVE_SYS_SYSCTL_H) +check_function_exists(sysctlbyname HAVE_SYSCTLBYNAME) check_include_files(gnu/lib-names.h HAVE_GNU_LIBNAMES_H) check_function_exists(kqueue HAVE_KQUEUE) diff --git a/src/pal/src/misc/sysinfo.cpp b/src/pal/src/misc/sysinfo.cpp index d0e8ca64dc..1e911023cf 100644 --- a/src/pal/src/misc/sysinfo.cpp +++ b/src/pal/src/misc/sysinfo.cpp @@ -529,5 +529,21 @@ PAL_GetLogicalProcessorCacheSizeFromOS() } #endif +#if HAVE_SYSCTLBYNAME + if (cacheSize == 0) + { + int64_t cacheSizeFromSysctl = 0; + size_t sz = sizeof(cacheSizeFromSysctl); + const bool success = sysctlbyname("hw.l3cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0 + || sysctlbyname("hw.l2cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0 + || sysctlbyname("hw.l1dcachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0; + if (success) + { + assert(cacheSizeFromSysctl > 0); + cacheSize = (size_t) cacheSizeFromSysctl; + } + } +#endif + return cacheSize; } |