summaryrefslogtreecommitdiff
path: root/src/pal
diff options
context:
space:
mode:
authorJan Vorlicek <janvorli@microsoft.com>2020-01-14 19:33:49 +0100
committerAnirudh Agnihotry <anirudhagnihotry098@gmail.com>2020-01-14 10:33:49 -0800
commit8c478a8ab700ceb9db632990aa53b304a5186c8e (patch)
tree10512937f68a6ca962af0c13e3e3f73eed72d30d /src/pal
parente5bbbe6330dfffc2d3948a9d7cbd451e1b5a6788 (diff)
downloadcoreclr-8c478a8ab700ceb9db632990aa53b304a5186c8e.tar.gz
coreclr-8c478a8ab700ceb9db632990aa53b304a5186c8e.tar.bz2
coreclr-8c478a8ab700ceb9db632990aa53b304a5186c8e.zip
Port to 3.1 - Fix getting affinity set on MUSL on Jetson TX2 (#27957)
Ports https://github.com/dotnet/runtime/pull/206 to release/3.1. The code in PAL_GetCurrentThreadAffinitySet relied on the fact that the number of processors reported as configured in the system is always larger than the maximum CPU index. However, it turns out that it is not true on some devices / distros. The Jetson TX2 reports CPUs 0, 3, 4 and 5 in the affinity mask and the 1 and 2 are never reported. GLIBC reports 6 as the number of configured CPUs, however MUSL reports just 4. The PAL_GetCurrentThreadAffinitySet was using the number of CPUs reported as configured as the upper bound for scanning affinity set, so on Jetson TX2, the affinity mask returned had just two bits set while there were 4 CPUs. That triggered an assert in the GCToOSInterface::Initialize. This change fixes that by reading the maximum CPU index from the /proc/cpuinfo. It falls back to using the number of processors configured when the /proc/cpuinfo is not available (on macOS, FreeBSD, ...) Fixes https://github.com/dotnet/runtime/issues/170
Diffstat (limited to 'src/pal')
-rw-r--r--src/pal/src/thread/thread.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/pal/src/thread/thread.cpp b/src/pal/src/thread/thread.cpp
index 42209a6028..1bc89944dd 100644
--- a/src/pal/src/thread/thread.cpp
+++ b/src/pal/src/thread/thread.cpp
@@ -3079,10 +3079,9 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data)
if (st == 0)
{
const SIZE_T BitsPerBitsetEntry = 8 * sizeof(UINT_PTR);
- int nrcpus = PAL_GetTotalCpuCount();
// Get info for as much processors as it is possible to fit into the resulting set
- SIZE_T remainingCount = std::min(size * BitsPerBitsetEntry, (SIZE_T)nrcpus);
+ SIZE_T remainingCount = std::min(size * BitsPerBitsetEntry, (SIZE_T)CPU_SETSIZE);
SIZE_T i = 0;
while (remainingCount != 0)
{