mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 10:01:06 +00:00
hwloc used for CPU information.
This commit is contained in:
parent
42460b8805
commit
b27fc6fd5d
4 changed files with 94 additions and 10 deletions
|
@ -67,17 +67,30 @@ static void print_memory(xmrig::Config *) {
|
|||
static void print_cpu(xmrig::Config *)
|
||||
{
|
||||
using namespace xmrig;
|
||||
const ICpuInfo *info = Cpu::info();
|
||||
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%d)") " %sx64 %sAES %sAVX2",
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%zu/%zu)") " %sx64 %sAES %sAVX2",
|
||||
"CPU",
|
||||
Cpu::info()->brand(),
|
||||
Cpu::info()->packages(),
|
||||
Cpu::info()->isX64() ? GREEN_BOLD_S : RED_BOLD_S "-",
|
||||
Cpu::info()->hasAES() ? GREEN_BOLD_S : RED_BOLD_S "-",
|
||||
Cpu::info()->hasAVX2() ? GREEN_BOLD_S : RED_BOLD_S "-"
|
||||
info->brand(),
|
||||
info->packages(),
|
||||
info->nodes(),
|
||||
info->isX64() ? GREEN_BOLD_S : RED_BOLD_S "-",
|
||||
info->hasAES() ? GREEN_BOLD_S : RED_BOLD_S "-",
|
||||
info->hasAVX2() ? GREEN_BOLD_S : RED_BOLD_S "-"
|
||||
);
|
||||
# if defined(XMRIG_FEATURE_LIBCPUID) || defined (XMRIG_FEATURE_HWLOC)
|
||||
Log::print(WHITE_BOLD(" %-13s") BLACK_BOLD("L2:") WHITE_BOLD("%.1f MB") BLACK_BOLD(" L3:") WHITE_BOLD("%.1f MB") BLACK_BOLD(" cores:") CYAN_BOLD("%zu") BLACK_BOLD(" threads:") CYAN_BOLD("%zu"),
|
||||
"",
|
||||
info->L2() / 1048576.0,
|
||||
info->L3() / 1048576.0,
|
||||
info->cores(),
|
||||
info->threads()
|
||||
);
|
||||
# else
|
||||
Log::print(WHITE_BOLD(" %-13s") BLACK_BOLD("threads:") CYAN_BOLD("%zu"),
|
||||
"",
|
||||
info->threads()
|
||||
);
|
||||
# ifdef XMRIG_FEATURE_LIBCPUID
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%.1f MB/%.1f MB"), "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,9 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() :
|
|||
m_L2 = data.l2_cache > 0 ? l2 * cores() * m_packages : 0;
|
||||
}
|
||||
|
||||
m_L2 *= 1024;
|
||||
m_L3 *= 1024;
|
||||
|
||||
if (data.flags[CPU_FEATURE_AES]) {
|
||||
m_aes = true;
|
||||
|
||||
|
@ -127,7 +130,6 @@ xmrig::CpuThreads xmrig::AdvancedCpuInfo::threads(const Algorithm &algorithm) co
|
|||
}
|
||||
|
||||
if (cache) {
|
||||
cache *= 1024;
|
||||
const size_t memory = algorithm.memory();
|
||||
assert(memory > 0);
|
||||
|
||||
|
|
|
@ -29,6 +29,62 @@
|
|||
#include "backend/cpu/platform/HwlocCpuInfo.h"
|
||||
|
||||
|
||||
xmrig::HwlocCpuInfo::HwlocCpuInfo() : BasicCpuInfo()
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
inline bool isCacheObject(hwloc_obj_t obj)
|
||||
{
|
||||
# if HWLOC_API_VERSION >= 0x20000
|
||||
return hwloc_obj_type_is_cache(obj->type);
|
||||
# else
|
||||
return obj->type == HWLOC_OBJ_CACHE;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
template <typename func>
|
||||
inline void findCache(hwloc_obj_t obj, func lambda)
|
||||
{
|
||||
for (size_t i = 0; i < obj->arity; i++) {
|
||||
if (isCacheObject(obj->children[i])) {
|
||||
if (obj->children[i]->attr->cache.depth < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lambda(obj->children[i]);
|
||||
}
|
||||
|
||||
findCache(obj->children[i], lambda);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline size_t countByType(hwloc_topology_t topology, hwloc_obj_type_t type)
|
||||
{
|
||||
const int count = hwloc_get_nbobjs_by_type(topology, type);
|
||||
|
||||
return count > 0 ? static_cast<size_t>(count) : 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::HwlocCpuInfo::HwlocCpuInfo() : BasicCpuInfo(),
|
||||
m_cache()
|
||||
{
|
||||
m_threads = 0;
|
||||
|
||||
hwloc_topology_t topology;
|
||||
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; });
|
||||
|
||||
m_threads = countByType(topology, HWLOC_OBJ_PU);
|
||||
m_cores = countByType(topology, HWLOC_OBJ_CORE);
|
||||
m_nodes = countByType(topology, HWLOC_OBJ_NUMANODE);
|
||||
m_packages = countByType(topology, HWLOC_OBJ_PACKAGE);
|
||||
|
||||
hwloc_topology_destroy(topology);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,19 @@ class HwlocCpuInfo : public BasicCpuInfo
|
|||
{
|
||||
public:
|
||||
HwlocCpuInfo();
|
||||
|
||||
protected:
|
||||
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]; }
|
||||
inline size_t nodes() const override { return m_nodes; }
|
||||
inline size_t packages() const override { return m_packages; }
|
||||
|
||||
private:
|
||||
size_t m_cache[5];
|
||||
size_t m_cores = 0;
|
||||
size_t m_nodes = 0;
|
||||
size_t m_packages = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue