From 42460b8805ae7a4a4636075391881dfe0b7394ad Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 23 Jul 2019 01:18:55 +0700 Subject: [PATCH] Added hwloc stub. --- CMakeLists.txt | 5 +++ cmake/FindHWLOC.cmake | 25 +++++++++++++ src/backend/cpu/Cpu.cpp | 8 +++- src/backend/cpu/cpu.cmake | 33 +++++++++++++++-- src/backend/cpu/platform/HwlocCpuInfo.cpp | 34 +++++++++++++++++ src/backend/cpu/platform/HwlocCpuInfo.h | 45 +++++++++++++++++++++++ 6 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 cmake/FindHWLOC.cmake create mode 100644 src/backend/cpu/platform/HwlocCpuInfo.cpp create mode 100644 src/backend/cpu/platform/HwlocCpuInfo.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e0290778..8ae89502 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8) project(xmrig) option(WITH_LIBCPUID "Use Libcpuid" ON) +option(WITH_HWLOC "Use hwloc" OFF) option(WITH_CN_LITE "CryptoNight-Lite support" ON) option(WITH_CN_HEAVY "CryptoNight-Heavy support" ON) option(WITH_CN_PICO "CryptoNight-Pico support" ON) @@ -146,6 +147,10 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") find_package(UV REQUIRED) +if (WITH_HWLOC) + find_package(HWLOC REQUIRED) +endif() + if (WITH_RANDOMX) include_directories(src/crypto/randomx) add_definitions(/DXMRIG_ALGO_RANDOMX) diff --git a/cmake/FindHWLOC.cmake b/cmake/FindHWLOC.cmake new file mode 100644 index 00000000..55309d3e --- /dev/null +++ b/cmake/FindHWLOC.cmake @@ -0,0 +1,25 @@ +find_path( + HWLOC_INCLUDE_DIR + NAMES hwloc.h + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "include" + NO_DEFAULT_PATH +) + +find_path(HWLOC_INCLUDE_DIR NAMES hwloc.h) + +find_library( + HWLOC_LIBRARY + NAMES hwloc.a hwloc libhwloc + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "lib" + NO_DEFAULT_PATH +) + +find_library(HWLOC_LIBRARY NAMES hwloc.a hwloc libhwloc) + +set(HWLOC_LIBRARIES ${HWLOC_LIBRARY}) +set(HWLOC_INCLUDE_DIRS ${HWLOC_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(HWLOC DEFAULT_MSG HWLOC_LIBRARY HWLOC_INCLUDE_DIR) diff --git a/src/backend/cpu/Cpu.cpp b/src/backend/cpu/Cpu.cpp index fdcad5a8..603ce634 100644 --- a/src/backend/cpu/Cpu.cpp +++ b/src/backend/cpu/Cpu.cpp @@ -29,7 +29,9 @@ #include "backend/cpu/Cpu.h" -#ifdef XMRIG_FEATURE_LIBCPUID +#if defined(XMRIG_FEATURE_HWLOC) +# include "backend/cpu/platform/HwlocCpuInfo.h" +#elif defined(XMRIG_FEATURE_LIBCPUID) # include "backend/cpu/platform/AdvancedCpuInfo.h" #else # include "backend/cpu/platform/BasicCpuInfo.h" @@ -51,7 +53,9 @@ void xmrig::Cpu::init() { assert(cpuInfo == nullptr); -# ifdef XMRIG_FEATURE_LIBCPUID +# if defined(XMRIG_FEATURE_HWLOC) + cpuInfo = new HwlocCpuInfo(); +# elif defined(XMRIG_FEATURE_LIBCPUID) cpuInfo = new AdvancedCpuInfo(); # else cpuInfo = new BasicCpuInfo(); diff --git a/src/backend/cpu/cpu.cmake b/src/backend/cpu/cpu.cmake index 871debd3..a8bbd8e8 100644 --- a/src/backend/cpu/cpu.cmake +++ b/src/backend/cpu/cpu.cmake @@ -18,16 +18,43 @@ set(SOURCES_BACKEND_CPU ) -if (WITH_LIBCPUID) +if (WITH_HWLOC) + set(WITH_LIBCPUID OFF) + + include_directories(${HWLOC_INCLUDE_DIR}) + set(CPUID_LIB ${HWLOC_LIBRARY}) + + remove_definitions(/DXMRIG_FEATURE_LIBCPUID) + add_definitions(/DXMRIG_FEATURE_HWLOC) + + set(SOURCES_CPUID + src/backend/cpu/platform/BasicCpuInfo.cpp + src/backend/cpu/platform/BasicCpuInfo.h + src/backend/cpu/platform/HwlocCpuInfo.cpp + src/backend/cpu/platform/HwlocCpuInfo.h + ) +elseif (WITH_LIBCPUID) + set(WITH_HWLOC OFF) + add_subdirectory(src/3rdparty/libcpuid) include_directories(src/3rdparty/libcpuid) + add_definitions(/DXMRIG_FEATURE_LIBCPUID) + remove_definitions(/DXMRIG_FEATURE_HWLOC) set(CPUID_LIB cpuid) - set(SOURCES_CPUID src/backend/cpu/platform/AdvancedCpuInfo.h src/backend/cpu/platform/AdvancedCpuInfo.cpp src/backend/cpu/Cpu.cpp) + set(SOURCES_CPUID + src/backend/cpu/platform/AdvancedCpuInfo.cpp + src/backend/cpu/platform/AdvancedCpuInfo.h + ) else() remove_definitions(/DXMRIG_FEATURE_LIBCPUID) - set(SOURCES_CPUID src/backend/cpu/platform/BasicCpuInfo.h src/backend/cpu/Cpu.cpp) + remove_definitions(/DXMRIG_FEATURE_HWLOC) + + set(CPUID_LIB "") + set(SOURCES_CPUID + src/backend/cpu/platform/BasicCpuInfo.h + ) if (XMRIG_ARM) set(SOURCES_CPUID ${SOURCES_CPUID} src/backend/cpu/platform/BasicCpuInfo_arm.cpp) diff --git a/src/backend/cpu/platform/HwlocCpuInfo.cpp b/src/backend/cpu/platform/HwlocCpuInfo.cpp new file mode 100644 index 00000000..ef518b33 --- /dev/null +++ b/src/backend/cpu/platform/HwlocCpuInfo.cpp @@ -0,0 +1,34 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2019 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include + + +#include "backend/cpu/platform/HwlocCpuInfo.h" + + +xmrig::HwlocCpuInfo::HwlocCpuInfo() : BasicCpuInfo() +{ +} diff --git a/src/backend/cpu/platform/HwlocCpuInfo.h b/src/backend/cpu/platform/HwlocCpuInfo.h new file mode 100644 index 00000000..0b09bf88 --- /dev/null +++ b/src/backend/cpu/platform/HwlocCpuInfo.h @@ -0,0 +1,45 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2019 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_HWLOCCPUINFO_H +#define XMRIG_HWLOCCPUINFO_H + + +#include "backend/cpu/platform/BasicCpuInfo.h" + + +namespace xmrig { + + +class HwlocCpuInfo : public BasicCpuInfo +{ +public: + HwlocCpuInfo(); +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_HWLOCCPUINFO_H */