SWDEV-299893 - Set preferred node affinity

Set affinity to the closest node of the current GPU. This reduces
the latency to fetch kernel args since device would query the CPU cache
of core which did the dispatch. This behavior is controlled with
AMD_CPU_AFFINITY env var(disabled by default)

Change-Id: I65afba62cb818ea25a311b88d1c0dd5c51330292
This commit is contained in:
Saleel Kudchadker committed 2021-11-19 04:42:42 -05:00
1 parent 6cf5089f37
commit b192beea52
6 files changed
+31 -4

No files matched your search

+18 -2
View File
@@ -48,6 +48,10 @@
#define DT_GNU_HASH 0x6ffffef5
#endif // DT_GNU_HASH
#ifdef ROCCLR_SUPPORT_NUMA_POLICY
#include <numa.h>
#endif // ROCCLR_SUPPORT_NUMA_POLICY
#include <atomic>
#include <vector>
#include <string>
@@ -60,7 +64,6 @@
#include <algorithm>
#include <mutex>
namespace amd {
static struct sigaction oldSigAction;
@@ -121,7 +124,6 @@ static void divisionErrorHandler(int sig, siginfo_t* info, void* ptr) {
return;
}
std::cerr << "Unhandled signal in divisionErrorHandler()" << std::endl;
::abort();
}
@@ -306,6 +308,20 @@ void Os::currentStackInfo(address* base, size_t* size) {
void Os::setCurrentThreadName(const char* name) { ::prctl(PR_SET_NAME, name); }
void Os::setPreferredNumaNode(uint32_t node) {
if (AMD_CPU_AFFINITY) {
// Set preferred node affinity mask
int num_cpus = numa_num_configured_cpus();
bitmask* bm = numa_bitmask_alloc(num_cpus);
numa_node_to_cpus(node, bm);
if (numa_sched_setaffinity(0, bm) < 0) {
assert(0 && "failed to set affinity");
}
numa_free_cpumask(bm);
}
}
void* Thread::entry(Thread* thread) {
sigset_t set;