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

@ -42,18 +42,6 @@
static xmrig::ICpuInfo *cpuInfo = nullptr; static xmrig::ICpuInfo *cpuInfo = nullptr;
const char *xmrig::Cpu::backend()
{
# if defined(XMRIG_FEATURE_HWLOC)
return "hwloc";
# elif defined(XMRIG_FEATURE_LIBCPUID)
return "libcpuid";
# else
return "basic";
# endif
}
xmrig::ICpuInfo *xmrig::Cpu::info() xmrig::ICpuInfo *xmrig::Cpu::info()
{ {
assert(cpuInfo != nullptr); assert(cpuInfo != nullptr);
@ -82,7 +70,7 @@ rapidjson::Value xmrig::Cpu::toJSON(rapidjson::Document &doc)
cpu.AddMember("threads", static_cast<uint64_t>(i->threads()), allocator); cpu.AddMember("threads", static_cast<uint64_t>(i->threads()), allocator);
cpu.AddMember("packages", static_cast<uint64_t>(i->packages()), allocator); cpu.AddMember("packages", static_cast<uint64_t>(i->packages()), allocator);
cpu.AddMember("nodes", static_cast<uint64_t>(i->nodes()), allocator); cpu.AddMember("nodes", static_cast<uint64_t>(i->nodes()), allocator);
cpu.AddMember("backend", StringRef(backend()), allocator); cpu.AddMember("backend", StringRef(i->backend()), allocator);
return cpu; return cpu;
} }

View file

@ -35,7 +35,6 @@ namespace xmrig {
class Cpu class Cpu
{ {
public: public:
static const char *backend();
static ICpuInfo *info(); static ICpuInfo *info();
static rapidjson::Value toJSON(rapidjson::Document &doc); static rapidjson::Value toJSON(rapidjson::Document &doc);
static void init(); static void init();

View file

@ -48,6 +48,7 @@ public:
virtual Assembly::Id assembly() const = 0; virtual Assembly::Id assembly() const = 0;
virtual bool hasAES() const = 0; virtual bool hasAES() const = 0;
virtual bool hasAVX2() const = 0; virtual bool hasAVX2() const = 0;
virtual const char *backend() const = 0;
virtual const char *brand() const = 0; virtual const char *brand() const = 0;
virtual CpuThreads threads(const Algorithm &algorithm) const = 0; virtual CpuThreads threads(const Algorithm &algorithm) const = 0;
virtual size_t cores() const = 0; virtual size_t cores() const = 0;

View file

@ -24,11 +24,12 @@
#include <algorithm> #include <algorithm>
#include <assert.h> #include <assert.h>
#include <libcpuid.h>
#include <math.h> #include <math.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include "3rdparty/libcpuid/libcpuid.h"
#include "backend/cpu/platform/AdvancedCpuInfo.h" #include "backend/cpu/platform/AdvancedCpuInfo.h"
@ -66,6 +67,7 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() :
cpu_identify(&raw, &data); cpu_identify(&raw, &data);
cpu_brand_string(m_brand, data.brand_str); 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_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); 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 Assembly::Id assembly() const override { return m_assembly; }
inline bool hasAES() const override { return m_aes; } inline bool hasAES() const override { return m_aes; }
inline bool hasAVX2() const override { return m_avx2; } 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 const char *brand() const override { return m_brand; }
inline size_t cores() const override { return m_cores; } inline size_t cores() const override { return m_cores; }
inline size_t L2() const override { return m_L2; } inline size_t L2() const override { return m_L2; }
@ -56,7 +57,8 @@ private:
bool m_aes = false; bool m_aes = false;
bool m_avx2 = false; bool m_avx2 = false;
bool m_L2_exclusive = 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_cores = 0;
size_t m_L2 = 0; size_t m_L2 = 0;
size_t m_L3 = 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 xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm) const
{ {
if (threads() == 1) { if (threads() == 1) {

View file

@ -38,6 +38,7 @@ public:
BasicCpuInfo(); BasicCpuInfo();
protected: protected:
const char *backend() const override;
CpuThreads threads(const Algorithm &algorithm) const override; CpuThreads threads(const Algorithm &algorithm) const override;
inline Assembly::Id assembly() const override { return m_assembly; } 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()); 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(), xmrig::HwlocCpuInfo::HwlocCpuInfo() : BasicCpuInfo(),
m_backend(),
m_cache() m_cache()
{ {
m_threads = 0; m_threads = 0;
@ -79,7 +80,14 @@ xmrig::HwlocCpuInfo::HwlocCpuInfo() : BasicCpuInfo(),
hwloc_topology_init(&topology); hwloc_topology_init(&topology);
hwloc_topology_load(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_threads = countByType(topology, HWLOC_OBJ_PU);
m_cores = countByType(topology, HWLOC_OBJ_CORE); m_cores = countByType(topology, HWLOC_OBJ_CORE);

View file

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

View file

@ -35,7 +35,7 @@
#endif #endif
#ifdef XMRIG_FEATURE_HWLOC #ifdef XMRIG_FEATURE_HWLOC
# include <hwloc.h> # include "backend/cpu/Cpu.h"
#endif #endif
#ifdef XMRIG_AMD_PROJECT #ifdef XMRIG_AMD_PROJECT
@ -110,17 +110,8 @@ void xmrig::BaseConfig::printVersions()
} }
# endif # endif
# if defined(XMRIG_FEATURE_HWLOC) # if defined(XMRIG_FEATURE_HWLOC)
# if defined(HWLOC_VERSION) libs += Cpu::info()->backend();
snprintf(buf, sizeof buf, "hwloc/%s ", HWLOC_VERSION);
# elif HWLOC_API_VERSION >= 0x20000
snprintf(buf, sizeof buf, "hwloc/2 ");
# else
snprintf(buf, sizeof buf, "hwloc/1 ");
# endif
libs += buf;
# endif # endif
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str()); Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str());