Better method to get hwloc version.

This commit is contained in:
XMRig 2019-07-23 14:19:41 +07:00
parent 73558a0eaa
commit a6a0995d54
11 changed files with 35 additions and 29 deletions

View file

@ -24,11 +24,12 @@
#include <algorithm>
#include <assert.h>
#include <libcpuid.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "3rdparty/libcpuid/libcpuid.h"
#include "backend/cpu/platform/AdvancedCpuInfo.h"
@ -66,6 +67,7 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() :
cpu_identify(&raw, &data);
cpu_brand_string(m_brand, data.brand_str);
snprintf(m_backend, sizeof m_backend, "libcpuid/%s", cpuid_lib_version());
m_threads = static_cast<size_t>(data.total_logical_cpus);
m_packages = std::max<size_t>(threads() / static_cast<size_t>(data.num_logical_cpus), 1);

View file

@ -43,6 +43,7 @@ protected:
inline Assembly::Id assembly() const override { return m_assembly; }
inline bool hasAES() const override { return m_aes; }
inline bool hasAVX2() const override { return m_avx2; }
inline const char *backend() const override { return m_backend; }
inline const char *brand() const override { return m_brand; }
inline size_t cores() const override { return m_cores; }
inline size_t L2() const override { return m_L2; }
@ -56,7 +57,8 @@ private:
bool m_aes = false;
bool m_avx2 = false;
bool m_L2_exclusive = false;
char m_brand[64];
char m_backend[32];
char m_brand[64 + 5];
size_t m_cores = 0;
size_t m_L2 = 0;
size_t m_L3 = 0;

View file

@ -174,6 +174,12 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
}
const char *xmrig::BasicCpuInfo::backend() const
{
return "basic";
}
xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm) const
{
if (threads() == 1) {

View file

@ -38,6 +38,7 @@ public:
BasicCpuInfo();
protected:
const char *backend() const override;
CpuThreads threads(const Algorithm &algorithm) const override;
inline Assembly::Id assembly() const override { return m_assembly; }

View file

@ -57,7 +57,13 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
}
xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm) const
const char *xmrig::BasicCpuInfo::backend() const
{
return "basic_arm";
}
xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &) const
{
return CpuThreads(threads());
}

View file

@ -71,6 +71,7 @@ inline size_t countByType(hwloc_topology_t topology, hwloc_obj_type_t type)
xmrig::HwlocCpuInfo::HwlocCpuInfo() : BasicCpuInfo(),
m_backend(),
m_cache()
{
m_threads = 0;
@ -79,7 +80,14 @@ xmrig::HwlocCpuInfo::HwlocCpuInfo() : BasicCpuInfo(),
hwloc_topology_init(&topology);
hwloc_topology_load(topology);
findCache(hwloc_get_root_obj(topology), [this](hwloc_obj_t found) { this->m_cache[found->attr->cache.depth] += found->attr->cache.size; });
hwloc_obj_t root = hwloc_get_root_obj(topology);
snprintf(m_backend, sizeof m_backend, "hwloc/%s", hwloc_obj_get_info_by_name(root, "hwlocVersion"));
findCache(root, [this](hwloc_obj_t found) {
const unsigned depth = found->attr->cache.depth;
this->m_cache[depth] += found->attr->cache.size;
});
m_threads = countByType(topology, HWLOC_OBJ_PU);
m_cores = countByType(topology, HWLOC_OBJ_CORE);

View file

@ -38,6 +38,7 @@ public:
HwlocCpuInfo();
protected:
inline const char *backend() const override { return m_backend; }
inline size_t cores() const override { return m_cores; }
inline size_t L2() const override { return m_cache[2]; }
inline size_t L3() const override { return m_cache[3]; }
@ -45,6 +46,7 @@ protected:
inline size_t packages() const override { return m_packages; }
private:
char m_backend[20];
size_t m_cache[5];
size_t m_cores = 0;
size_t m_nodes = 0;