Fix incorrect thread affinitization (#24045)
authorJan Vorlicek <janvorli@microsoft.com>
Wed, 17 Apr 2019 03:11:35 +0000 (05:11 +0200)
committerJan Kotas <jkotas@microsoft.com>
Wed, 17 Apr 2019 03:11:35 +0000 (20:11 -0700)
The PAL_SetCurrentThreadAffinity was incorrectly adding the specified processor
to the current thread affinity set instead of setting the affinity to only
the processor specified.
It was causing significant performance hit in aspnet benchmarks on machines with
many cores.
This change crept in when I was refactoring the related code while removing
CPU groups emulation.

src/pal/src/thread/thread.cpp

index ecbf725..21775f1 100644 (file)
@@ -2948,13 +2948,8 @@ PAL_SetCurrentThreadAffinity(WORD procNo)
     cpu_set_t cpuSet;
     CPU_ZERO(&cpuSet);
 
-    int st = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuSet);
-
-    if (st == 0)
-    {
-        CPU_SET(procNo, &cpuSet);
-        st = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuSet);
-    }
+    CPU_SET(procNo, &cpuSet);
+    int st = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuSet);
 
     return st == 0;
 #else  // HAVE_PTHREAD_GETAFFINITY_NP