hwloc used for CPU information.
This commit is contained in:
parent
42460b8805
commit
b27fc6fd5d
4 changed files with 94 additions and 10 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue