summaryrefslogtreecommitdiff
path: root/src/pal/src/misc
diff options
context:
space:
mode:
authorAndy Hanson <anhans@microsoft.com>2019-06-05 16:58:56 -0700
committerGitHub <noreply@github.com>2019-06-05 16:58:56 -0700
commit5d4ff2f11a87d7d434d05e72744946f48e017b11 (patch)
tree4b888de6cf6716f34e93fc40e0c0bcf352b94122 /src/pal/src/misc
parent10df20ed3ff0208b3f16f79d5062662a8827f579 (diff)
downloadcoreclr-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
Diffstat (limited to 'src/pal/src/misc')
-rw-r--r--src/pal/src/misc/sysinfo.cpp16
1 files changed, 16 insertions, 0 deletions
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;
}