From 8ef3e2ec14a464c0905fa54b5b83f956da11e448 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 8 Dec 2019 10:20:23 +0700 Subject: [PATCH] Fixed build without hwloc. --- src/backend/cpu/platform/AdvancedCpuInfo.cpp | 46 +++++++++++++++++--- src/backend/cpu/platform/AdvancedCpuInfo.h | 6 ++- src/backend/cpu/platform/BasicCpuInfo.cpp | 4 +- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/backend/cpu/platform/AdvancedCpuInfo.cpp b/src/backend/cpu/platform/AdvancedCpuInfo.cpp index 5cae55e28..37a958dbc 100644 --- a/src/backend/cpu/platform/AdvancedCpuInfo.cpp +++ b/src/backend/cpu/platform/AdvancedCpuInfo.cpp @@ -22,6 +22,17 @@ * along with this program. If not, see . */ +#include "backend/cpu/platform/AdvancedCpuInfo.h" +#include "3rdparty/libcpuid/libcpuid.h" + + +#ifdef _MSC_VER +# include +#else +# include +#endif + + #include #include #include @@ -29,10 +40,6 @@ #include -#include "3rdparty/libcpuid/libcpuid.h" -#include "backend/cpu/platform/AdvancedCpuInfo.h" - - namespace xmrig { @@ -54,11 +61,38 @@ static inline void cpu_brand_string(char out[64], const char *in) { } +static inline void cpuid(uint32_t level, int32_t output[4]) +{ + memset(output, 0, sizeof(int32_t) * 4); + +# ifdef _MSC_VER + __cpuid(output, static_cast(level)); +# else + __cpuid_count(level, 0, output[0], output[1], output[2], output[3]); +# endif +} + + +static inline bool has_feature(uint32_t level, uint32_t reg, int32_t bit) +{ + int32_t cpu_info[4] = { 0 }; + cpuid(level, cpu_info); + + return (cpu_info[reg] & bit) != 0; +} + + +static inline bool has_pdpe1gb() +{ + return has_feature(0x80000001, 3, 1 << 26); +} + + } // namespace xmrig xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : - m_brand() + m_pdpe1gb(has_pdpe1gb()) { struct cpu_raw_data_t raw = {}; struct cpu_id_t data = {}; @@ -74,7 +108,7 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : m_cores = static_cast(data.num_cores) * m_packages; m_L3 = data.l3_cache > 0 ? static_cast(data.l3_cache) * m_packages : 0; - const size_t l2 = static_cast(data.l2_cache); + const auto l2 = static_cast(data.l2_cache); // Workaround for AMD CPUs https://github.com/anrieff/libcpuid/issues/97 if (data.vendor == VENDOR_AMD && data.ext_family >= 0x15 && data.ext_family < 0x17) { diff --git a/src/backend/cpu/platform/AdvancedCpuInfo.h b/src/backend/cpu/platform/AdvancedCpuInfo.h index e2909a91d..f590ccfb3 100644 --- a/src/backend/cpu/platform/AdvancedCpuInfo.h +++ b/src/backend/cpu/platform/AdvancedCpuInfo.h @@ -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 bool hasOneGbPages() const override { return m_pdpe1gb; } 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; } @@ -57,8 +58,9 @@ private: bool m_aes = false; bool m_avx2 = false; bool m_L2_exclusive = false; - char m_backend[32]; - char m_brand[64 + 5]; + char m_backend[32]{}; + char m_brand[64 + 5]{}; + const bool m_pdpe1gb = false; size_t m_cores = 0; size_t m_L2 = 0; size_t m_L3 = 0; diff --git a/src/backend/cpu/platform/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp index e6145278c..e2ad19eac 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -113,7 +113,7 @@ static void cpu_brand_string(char out[64 + 6]) { } -static bool has_feature(uint32_t level, uint32_t reg, int32_t bit) +static inline bool has_feature(uint32_t level, uint32_t reg, int32_t bit) { int32_t cpu_info[4] = { 0 }; cpuid(level, cpu_info); @@ -191,7 +191,7 @@ const char *xmrig::BasicCpuInfo::backend() const } -xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm, uint32_t limit) const +xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm, uint32_t) const { const size_t count = std::thread::hardware_concurrency();