Fixed build without hwloc.

This commit is contained in:
XMRig 2019-12-08 10:20:23 +07:00
parent e9e747f0d1
commit 8ef3e2ec14
No known key found for this signature in database
GPG key ID: 446A53638BE94409
3 changed files with 46 additions and 10 deletions

View file

@ -22,6 +22,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "backend/cpu/platform/AdvancedCpuInfo.h"
#include "3rdparty/libcpuid/libcpuid.h"
#ifdef _MSC_VER
# include <intrin.h>
#else
# include <cpuid.h>
#endif
#include <algorithm>
#include <cassert>
#include <cmath>
@ -29,10 +40,6 @@
#include <cstring>
#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<int>(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<size_t>(data.num_cores) * m_packages;
m_L3 = data.l3_cache > 0 ? static_cast<size_t>(data.l3_cache) * m_packages : 0;
const size_t l2 = static_cast<size_t>(data.l2_cache);
const auto l2 = static_cast<size_t>(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) {

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 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;

View file

@ -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();