From 3489e56c875c6144c729b51063300c7d60b1ae31 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 28 May 2019 18:06:38 +0200 Subject: Fix initial thread affinity on Linux (#24801) * Fix initial thread affinity on Linux On Linux, a new thread inherits the affinity mask of the thread that created the new thread. This is a problem for background GC threads that are created by one of the server GC threads that are affinitized to single core. This change adds resetting each new thread affinity to match the current process affinity. In addition to that, I've also fixed the extraction of the CPU count that was using PID 0. While the doc says that 0 represents current process, it in fact means current thread. And as a small bonus, I've added caching of the value returned by the PAL_GetLogicalCpuCountFromOS, since it cannot change during runtime. --- src/gc/unix/gcenv.unix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gc') diff --git a/src/gc/unix/gcenv.unix.cpp b/src/gc/unix/gcenv.unix.cpp index 2828c949c4..3d7442ada9 100644 --- a/src/gc/unix/gcenv.unix.cpp +++ b/src/gc/unix/gcenv.unix.cpp @@ -289,7 +289,7 @@ bool GCToOSInterface::Initialize() g_currentProcessCpuCount = 0; cpu_set_t cpuSet; - int st = sched_getaffinity(0, sizeof(cpu_set_t), &cpuSet); + int st = sched_getaffinity(getpid(), sizeof(cpu_set_t), &cpuSet); if (st == 0) { -- cgit v1.2.3