From 2a6ca5c3eb8f5597be776aea85fb4086a53ac0ad Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Wed, 17 Apr 2019 05:11:35 +0200 Subject: [PATCH] Fix incorrect thread affinitization (#24045) 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 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/pal/src/thread/thread.cpp b/src/pal/src/thread/thread.cpp index ecbf725..21775f1 100644 --- a/src/pal/src/thread/thread.cpp +++ b/src/pal/src/thread/thread.cpp @@ -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 -- 2.7.4