Simplified VirtualMemory::bindToNUMANode.

This commit is contained in:
XMRig 2019-10-04 19:52:15 +07:00
parent 207dae418d
commit ad6dc876b3

View file

@ -28,57 +28,34 @@
#ifdef XMRIG_FEATURE_HWLOC #ifdef XMRIG_FEATURE_HWLOC
# include <hwloc.h> # include <hwloc.h>
# include "backend/cpu/platform/HwlocCpuInfo.h" # include "backend/cpu/platform/HwlocCpuInfo.h"
#
# if HWLOC_API_VERSION < 0x00010b00
# define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE
# endif
#endif #endif
#include "base/io/log/Log.h"
#include "crypto/common/VirtualMemory.h" #include "crypto/common/VirtualMemory.h"
#include "backend/cpu/Cpu.h"
#include "base/io/log/Log.h"
#include <cinttypes>
uint32_t xmrig::VirtualMemory::bindToNUMANode(int64_t affinity) uint32_t xmrig::VirtualMemory::bindToNUMANode(int64_t affinity)
{ {
# ifdef XMRIG_FEATURE_HWLOC # ifdef XMRIG_FEATURE_HWLOC
if (affinity < 0 || !HwlocCpuInfo::has(HwlocCpuInfo::SET_THISTHREAD_MEMBIND)) { if (affinity < 0 || Cpu::info()->nodes() < 2) {
return 0; return 0;
} }
hwloc_topology_t topology; auto cpu = static_cast<HwlocCpuInfo *>(Cpu::info());
hwloc_topology_init(&topology); hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(cpu->topology(), static_cast<unsigned>(affinity));
hwloc_topology_load(topology);
const unsigned puId = static_cast<unsigned>(affinity); if (pu == nullptr || !cpu->membind(pu->nodeset)) {
LOG_WARN("CPU #%02" PRId64 " warning: \"can't bind memory\"", affinity);
hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(topology, puId); return 0;
# if HWLOC_API_VERSION >= 0x20000
if (pu == nullptr || hwloc_set_membind(topology, pu->nodeset, HWLOC_MEMBIND_BIND, HWLOC_MEMBIND_THREAD | HWLOC_MEMBIND_BYNODESET) < 0) {
# else
if (pu == nullptr || hwloc_set_membind_nodeset(topology, pu->nodeset, HWLOC_MEMBIND_BIND, HWLOC_MEMBIND_THREAD) < 0) {
# endif
LOG_WARN("CPU #%02u warning: \"can't bind memory\"", puId);
} }
uint32_t nodeId = 0; return hwloc_bitmap_first(pu->nodeset);
if (pu) {
hwloc_obj_t node = nullptr;
while ((node = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, node)) != nullptr) {
if (hwloc_bitmap_intersects(node->cpuset, pu->cpuset)) {
nodeId = node->os_index;
break;
}
}
}
hwloc_topology_destroy(topology);
return nodeId;
# else # else
return 0; return 0;
# endif # endif