tt_result_t __thread_bind_numa(IN HANDLE hThread, IN USHORT Node) { GROUP_AFFINITY ProcessorMask; // how to handle the arch in which a numa node includes more than // 64 cpus?? if (!GetNumaNodeProcessorMaskEx(Node, &ProcessorMask)) { TT_ERROR("fail to get numa node processor mask"); return TT_FAIL; } if (!SetThreadGroupAffinity(hThread, &ProcessorMask, NULL)) { TT_ERROR("fail to bind thread to numa node[%d]", Node); return TT_FAIL; } return TT_SUCCESS; }
/* static */ void ThreadPool::setThreadNodeAffinity(int numaNode) { #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7 GROUP_AFFINITY groupAffinity; if (GetNumaNodeProcessorMaskEx((USHORT)numaNode, &groupAffinity)) { if (SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR)groupAffinity.Mask)) return; } x265_log(NULL, X265_LOG_ERROR, "unable to set thread affinity to NUMA node %d\n", numaNode); #elif HAVE_LIBNUMA if (numa_available() >= 0) { numa_run_on_node(numaNode); numa_set_preferred(numaNode); numa_set_localalloc(); return; } x265_log(NULL, X265_LOG_ERROR, "unable to set thread affinity to NUMA node %d\n", numaNode); #else (void)numaNode; #endif }