From 6b3b1c3fc412981e51892bafd62b3dc4c1f87e7d Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 29 Jul 2019 19:24:53 +0700 Subject: [PATCH] #1082 Fixed hwloc autoconfig with AMD FX CPUs. --- src/backend/cpu/platform/HwlocCpuInfo.cpp | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/backend/cpu/platform/HwlocCpuInfo.cpp b/src/backend/cpu/platform/HwlocCpuInfo.cpp index eee59a3a..48a17f23 100644 --- a/src/backend/cpu/platform/HwlocCpuInfo.cpp +++ b/src/backend/cpu/platform/HwlocCpuInfo.cpp @@ -84,6 +84,15 @@ static inline void findByType(hwloc_obj_t obj, hwloc_obj_type_t type, func lambd } +static inline std::vector findByType(hwloc_obj_t obj, hwloc_obj_type_t type) +{ + std::vector out; + findByType(obj, type, [&out](hwloc_obj_t found) { out.emplace_back(found); }); + + return out; +} + + static inline size_t countByType(hwloc_topology_t topology, hwloc_obj_type_t type) { const int count = hwloc_get_nbobjs_by_type(topology, type); @@ -132,8 +141,7 @@ xmrig::HwlocCpuInfo::HwlocCpuInfo() : BasicCpuInfo(), } # endif - std::vector packages; - findByType(hwloc_get_root_obj(m_topology), HWLOC_OBJ_PACKAGE, [&packages](hwloc_obj_t found) { packages.emplace_back(found); }); + const std::vector packages = findByType(hwloc_get_root_obj(m_topology), HWLOC_OBJ_PACKAGE); if (packages.size()) { const char *value = hwloc_obj_get_info_by_name(packages[0], "CPUModel"); if (value) { @@ -249,14 +257,9 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith if (cacheHashes >= PUs) { for (hwloc_obj_t core : cores) { - if (core->arity == 0) { - continue; - } - - for (unsigned i = 0; i < core->arity; ++i) { - if (core->children[i]->type == HWLOC_OBJ_PU) { - threads.push_back(CpuThread(1, core->children[i]->os_index)); - } + const std::vector units = findByType(core, HWLOC_OBJ_PU); + for (hwloc_obj_t pu : units) { + threads.push_back(CpuThread(1, pu->os_index)); } } @@ -268,7 +271,8 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith bool allocated_pu = false; for (hwloc_obj_t core : cores) { - if (core->arity <= pu_id || core->children[pu_id]->type != HWLOC_OBJ_PU) { + const std::vector units = findByType(core, HWLOC_OBJ_PU); + if (units.size() <= pu_id) { continue; } @@ -276,7 +280,7 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith PUs--; allocated_pu = true; - threads.push_back(CpuThread(1, core->children[pu_id]->os_index)); + threads.push_back(CpuThread(1, units[pu_id]->os_index)); if (cacheHashes == 0) { break;