From 4e766cc4b2656bce0e821fa4e8d589ddc12089b2 Mon Sep 17 00:00:00 2001 From: Payam Date: Tue, 14 Jul 2020 01:22:56 -0400 Subject: [PATCH] Reset each thread's affinity to all avilable cpus reset happens at the start of the thread SWDEV-240685 Change-Id: I6c35473bab67d02f76a8013ab9394f293c6f2b07 [ROCm/clr commit: 55b5f5f06c991370afbdb0eef9b6b7c4711e583d] --- projects/clr/rocclr/os/os_posix.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/projects/clr/rocclr/os/os_posix.cpp b/projects/clr/rocclr/os/os_posix.cpp index c53b084ac0..8ccc037654 100755 --- a/projects/clr/rocclr/os/os_posix.cpp +++ b/projects/clr/rocclr/os/os_posix.cpp @@ -369,6 +369,16 @@ const void* Os::createOsThread(amd::Thread* thread) { // We never plan the use join, so free the resources now. ::pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_DETACHED); + cpu_set_t cpuset; + if (processorCount_ > 0) { + CPU_ZERO(&cpuset); + for (uint i = 0; i < processorCount_; i++) { + CPU_SET(i, &cpuset); + } + if (0 != pthread_attr_setaffinity_np(&threadAttr, sizeof(cpu_set_t), &cpuset)) { + fatal("pthread_attr_setaffinity_np failed to set affinity"); + } + } pthread_t handle = 0; if (0 != ::pthread_create(&handle, &threadAttr, (void* (*)(void*)) & Thread::entry, thread)) {