From 62edb2fc0ace1b078e821e13229f18ec94ec3c42 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 29 Jun 2019 09:51:23 +0700 Subject: [PATCH] Move CPU information classes to new location. --- CMakeLists.txt | 19 ------- src/App.cpp | 4 +- src/Summary.cpp | 4 +- src/api/v1/ApiRouter.cpp | 2 +- src/{core => backend}/cpu/Cpu.cpp | 17 ++++-- src/{common => backend}/cpu/Cpu.h | 5 +- src/backend/cpu/CpuConfig.cpp | 2 +- src/backend/cpu/cpu.cmake | 22 +++++++ .../cpu}/interfaces/ICpuInfo.h | 7 ++- .../cpu/platform}/AdvancedCpuInfo.cpp | 2 +- .../cpu/platform}/AdvancedCpuInfo.h | 8 +-- .../cpu/platform}/BasicCpuInfo.cpp | 9 +-- .../cpu/platform}/BasicCpuInfo.h | 8 +-- .../cpu/platform}/BasicCpuInfo_arm.cpp | 0 src/common/cpu/Cpu.cpp | 57 ------------------- src/core/Controller.cpp | 2 +- src/core/config/Config.cpp | 2 +- src/crypto/cn/CnHash.cpp | 2 +- src/crypto/cn/CryptoNight_x86.h | 2 +- src/workers/CpuThread.cpp | 1 - src/workers/Worker.cpp | 2 +- 21 files changed, 62 insertions(+), 115 deletions(-) rename src/{core => backend}/cpu/Cpu.cpp (73%) rename src/{common => backend}/cpu/Cpu.h (88%) rename src/{common => backend/cpu}/interfaces/ICpuInfo.h (91%) rename src/{core/cpu => backend/cpu/platform}/AdvancedCpuInfo.cpp (98%) rename src/{core/cpu => backend/cpu/platform}/AdvancedCpuInfo.h (91%) rename src/{common/cpu => backend/cpu/platform}/BasicCpuInfo.cpp (94%) rename src/{common/cpu => backend/cpu/platform}/BasicCpuInfo.h (89%) rename src/{common/cpu => backend/cpu/platform}/BasicCpuInfo_arm.cpp (100%) delete mode 100644 src/common/cpu/Cpu.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 832c95d7f..7320b63dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,6 @@ set(HEADERS "${HEADERS_CPU}" src/api/interfaces/IApiListener.h src/App.h - src/common/cpu/Cpu.h - src/common/interfaces/ICpuInfo.h src/common/Platform.h src/common/xmrig.h src/core/config/Config_default.h @@ -178,23 +176,6 @@ endif() include(cmake/flags.cmake) -if (WITH_LIBCPUID) - add_subdirectory(src/3rdparty/libcpuid) - - include_directories(src/3rdparty/libcpuid) - set(CPUID_LIB cpuid) - set(SOURCES_CPUID src/core/cpu/AdvancedCpuInfo.h src/core/cpu/AdvancedCpuInfo.cpp src/core/cpu/Cpu.cpp) -else() - add_definitions(/DXMRIG_NO_LIBCPUID) - set(SOURCES_CPUID src/common/cpu/BasicCpuInfo.h src/common/cpu/Cpu.cpp) - - if (XMRIG_ARM) - set(SOURCES_CPUID ${SOURCES_CPUID} src/common/cpu/BasicCpuInfo_arm.cpp) - else() - set(SOURCES_CPUID ${SOURCES_CPUID} src/common/cpu/BasicCpuInfo.cpp) - endif() -endif() - include(cmake/OpenSSL.cmake) include(cmake/asm.cmake) include(cmake/cn-gpu.cmake) diff --git a/src/App.cpp b/src/App.cpp index 082bbeef6..6e42ac300 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -6,7 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018 SChernykh + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -30,10 +30,10 @@ #include "api/Api.h" #include "App.h" +#include "backend/cpu/Cpu.h" #include "base/io/Console.h" #include "base/io/log/Log.h" #include "base/kernel/Signals.h" -#include "common/cpu/Cpu.h" #include "common/Platform.h" #include "core/config/Config.h" #include "core/Controller.h" diff --git a/src/Summary.cpp b/src/Summary.cpp index a51f8f597..59e540d4f 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -28,9 +28,9 @@ #include +#include "backend/cpu/Cpu.h" #include "base/io/log/Log.h" #include "base/net/stratum/Pool.h" -#include "common/cpu/Cpu.h" #include "core/config/Config.h" #include "core/Controller.h" #include "crypto/common/Assembly.h" @@ -76,7 +76,7 @@ static void print_cpu(xmrig::Config *) Cpu::info()->hasAES() ? GREEN_BOLD_S : RED_BOLD_S "-", Cpu::info()->hasAVX2() ? GREEN_BOLD_S : RED_BOLD_S "-" ); -# ifndef XMRIG_NO_LIBCPUID +# 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 } diff --git a/src/api/v1/ApiRouter.cpp b/src/api/v1/ApiRouter.cpp index d066b0b1e..0f754e179 100644 --- a/src/api/v1/ApiRouter.cpp +++ b/src/api/v1/ApiRouter.cpp @@ -29,8 +29,8 @@ #include "api/interfaces/IApiRequest.h" #include "api/v1/ApiRouter.h" +#include "backend/cpu/Cpu.h" #include "base/kernel/Base.h" -#include "common/cpu/Cpu.h" #include "common/Platform.h" #include "core/config/Config.h" #include "interfaces/IThread.h" diff --git a/src/core/cpu/Cpu.cpp b/src/backend/cpu/Cpu.cpp similarity index 73% rename from src/core/cpu/Cpu.cpp rename to src/backend/cpu/Cpu.cpp index 773255d27..fdcad5a85 100644 --- a/src/core/cpu/Cpu.cpp +++ b/src/backend/cpu/Cpu.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 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 @@ -25,11 +26,13 @@ #include -#include "common/cpu/Cpu.h" +#include "backend/cpu/Cpu.h" -#ifndef XMRIG_NO_LIBCPUID -# include "core/cpu/AdvancedCpuInfo.h" +#ifdef XMRIG_FEATURE_LIBCPUID +# include "backend/cpu/platform/AdvancedCpuInfo.h" +#else +# include "backend/cpu/platform/BasicCpuInfo.h" #endif @@ -48,7 +51,11 @@ void xmrig::Cpu::init() { assert(cpuInfo == nullptr); +# ifdef XMRIG_FEATURE_LIBCPUID cpuInfo = new AdvancedCpuInfo(); +# else + cpuInfo = new BasicCpuInfo(); +# endif } diff --git a/src/common/cpu/Cpu.h b/src/backend/cpu/Cpu.h similarity index 88% rename from src/common/cpu/Cpu.h rename to src/backend/cpu/Cpu.h index 1d5a9fb1d..9c8afcede 100644 --- a/src/common/cpu/Cpu.h +++ b/src/backend/cpu/Cpu.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -25,7 +26,7 @@ #define XMRIG_CPU_H -#include "common/interfaces/ICpuInfo.h" +#include "backend/cpu/interfaces/ICpuInfo.h" namespace xmrig { diff --git a/src/backend/cpu/CpuConfig.cpp b/src/backend/cpu/CpuConfig.cpp index b3d780f47..5284d6075 100644 --- a/src/backend/cpu/CpuConfig.cpp +++ b/src/backend/cpu/CpuConfig.cpp @@ -23,9 +23,9 @@ */ +#include "backend/cpu/Cpu.h" #include "backend/cpu/CpuConfig.h" #include "base/io/json/Json.h" -#include "common/cpu/Cpu.h" #include "rapidjson/document.h" diff --git a/src/backend/cpu/cpu.cmake b/src/backend/cpu/cpu.cmake index 881598934..03ca70752 100644 --- a/src/backend/cpu/cpu.cmake +++ b/src/backend/cpu/cpu.cmake @@ -1,7 +1,29 @@ set(HEADERS_CPU + src/backend/cpu/Cpu.h src/backend/cpu/CpuConfig.h + src/backend/cpu/interfaces/ICpuInfo.h ) set(SOURCES_CPU + src/backend/cpu/Cpu.cpp src/backend/cpu/CpuConfig.cpp ) + + +if (WITH_LIBCPUID) + add_subdirectory(src/3rdparty/libcpuid) + include_directories(src/3rdparty/libcpuid) + add_definitions(/DXMRIG_FEATURE_LIBCPUID) + + set(CPUID_LIB cpuid) + set(SOURCES_CPUID src/backend/cpu/platform/AdvancedCpuInfo.h src/backend/cpu/platform/AdvancedCpuInfo.cpp src/backend/cpu/Cpu.cpp) +else() + remove_definitions(/DXMRIG_FEATURE_LIBCPUID) + set(SOURCES_CPUID src/backend/cpu/platform/BasicCpuInfo.h src/backend/cpu/Cpu.cpp) + + if (XMRIG_ARM) + set(SOURCES_CPUID ${SOURCES_CPUID} src/backend/cpu/platform/BasicCpuInfo_arm.cpp) + else() + set(SOURCES_CPUID ${SOURCES_CPUID} src/backend/cpu/platform/BasicCpuInfo.cpp) + endif() +endif() diff --git a/src/common/interfaces/ICpuInfo.h b/src/backend/cpu/interfaces/ICpuInfo.h similarity index 91% rename from src/common/interfaces/ICpuInfo.h rename to src/backend/cpu/interfaces/ICpuInfo.h index 907f3f63a..9618f4890 100644 --- a/src/common/interfaces/ICpuInfo.h +++ b/src/backend/cpu/interfaces/ICpuInfo.h @@ -41,10 +41,15 @@ class ICpuInfo public: virtual ~ICpuInfo() = default; +# if defined(__x86_64__) || defined(_M_AMD64) || defined (__arm64__) || defined (__aarch64__) + inline constexpr bool isX64() const { return true; } +# else + inline constexpr bool isX64() const { return false; } +# endif + virtual bool hasAES() const = 0; virtual bool hasAVX2() const = 0; virtual bool isSupported() const = 0; - virtual bool isX64() const = 0; virtual const char *brand() const = 0; virtual int32_t cores() const = 0; virtual int32_t L2() const = 0; diff --git a/src/core/cpu/AdvancedCpuInfo.cpp b/src/backend/cpu/platform/AdvancedCpuInfo.cpp similarity index 98% rename from src/core/cpu/AdvancedCpuInfo.cpp rename to src/backend/cpu/platform/AdvancedCpuInfo.cpp index 922e83113..fc7f734db 100644 --- a/src/core/cpu/AdvancedCpuInfo.cpp +++ b/src/backend/cpu/platform/AdvancedCpuInfo.cpp @@ -27,7 +27,7 @@ #include -#include "core/cpu/AdvancedCpuInfo.h" +#include "backend/cpu/platform/AdvancedCpuInfo.h" xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : diff --git a/src/core/cpu/AdvancedCpuInfo.h b/src/backend/cpu/platform/AdvancedCpuInfo.h similarity index 91% rename from src/core/cpu/AdvancedCpuInfo.h rename to src/backend/cpu/platform/AdvancedCpuInfo.h index 90152640e..83c3d8e58 100644 --- a/src/core/cpu/AdvancedCpuInfo.h +++ b/src/backend/cpu/platform/AdvancedCpuInfo.h @@ -26,7 +26,7 @@ #define XMRIG_ADVANCEDCPUINFO_H -#include "common/interfaces/ICpuInfo.h" +#include "backend/cpu/interfaces/ICpuInfo.h" namespace xmrig { @@ -52,12 +52,6 @@ protected: inline int32_t sockets() const override { return m_sockets; } inline int32_t threads() const override { return m_threads; } -# if defined(__x86_64__) || defined(_M_AMD64) - inline bool isX64() const override { return true; } -# else - inline bool isX64() const override { return false; } -# endif - private: Assembly m_assembly; bool m_aes; diff --git a/src/common/cpu/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp similarity index 94% rename from src/common/cpu/BasicCpuInfo.cpp rename to src/backend/cpu/platform/BasicCpuInfo.cpp index c5b8ed0ae..04ff589b5 100644 --- a/src/common/cpu/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -45,7 +45,8 @@ #endif -#include "common/cpu/BasicCpuInfo.h" +#include "backend/cpu/platform/BasicCpuInfo.h" +#include "crypto/common/Assembly.h" #define VENDOR_ID (0) @@ -121,7 +122,7 @@ static inline bool has_ossave() xmrig::BasicCpuInfo::BasicCpuInfo() : - m_assembly(ASM_NONE), + m_assembly(Assembly::NONE), m_aes(has_aes_ni()), m_avx2(has_avx2() && has_ossave()), m_brand(), @@ -141,10 +142,10 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : memcpy(vendor + 8, &data[2], 4); if (memcmp(vendor, "GenuineIntel", 12) == 0) { - m_assembly = ASM_INTEL; + m_assembly = Assembly::INTEL; } else if (memcmp(vendor, "AuthenticAMD", 12) == 0) { - m_assembly = ASM_RYZEN; + m_assembly = Assembly::RYZEN; } } # endif diff --git a/src/common/cpu/BasicCpuInfo.h b/src/backend/cpu/platform/BasicCpuInfo.h similarity index 89% rename from src/common/cpu/BasicCpuInfo.h rename to src/backend/cpu/platform/BasicCpuInfo.h index f6daee544..4d4a51639 100644 --- a/src/common/cpu/BasicCpuInfo.h +++ b/src/backend/cpu/platform/BasicCpuInfo.h @@ -26,7 +26,7 @@ #define XMRIG_BASICCPUINFO_H -#include "common/interfaces/ICpuInfo.h" +#include "backend/cpu/interfaces/ICpuInfo.h" namespace xmrig { @@ -52,12 +52,6 @@ protected: inline int32_t sockets() const override { return 1; } inline int32_t threads() const override { return m_threads; } -# if defined(__x86_64__) || defined(_M_AMD64) || defined (__arm64__) || defined (__aarch64__) - inline bool isX64() const override { return true; } -# else - inline bool isX64() const override { return false; } -# endif - private: Assembly m_assembly; bool m_aes; diff --git a/src/common/cpu/BasicCpuInfo_arm.cpp b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp similarity index 100% rename from src/common/cpu/BasicCpuInfo_arm.cpp rename to src/backend/cpu/platform/BasicCpuInfo_arm.cpp diff --git a/src/common/cpu/Cpu.cpp b/src/common/cpu/Cpu.cpp deleted file mode 100644 index b1bb28ac7..000000000 --- a/src/common/cpu/Cpu.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2016-2017 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 "common/cpu/BasicCpuInfo.h" -#include "common/cpu/Cpu.h" - - -static xmrig::ICpuInfo *cpuInfo = nullptr; - - -xmrig::ICpuInfo *xmrig::Cpu::info() -{ - assert(cpuInfo != nullptr); - - return cpuInfo; -} - - -void xmrig::Cpu::init() -{ - assert(cpuInfo == nullptr); - - cpuInfo = new BasicCpuInfo(); -} - - -void xmrig::Cpu::release() -{ - assert(cpuInfo != nullptr); - - delete cpuInfo; - cpuInfo = nullptr; -} diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 493b3e11e..8e2e03a12 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -26,7 +26,7 @@ #include -#include "common/cpu/Cpu.h" +#include "backend/cpu/Cpu.h" #include "common/Platform.h" #include "core/Controller.h" #include "net/Network.h" diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index 5b445c0f0..33f4cc44f 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -28,9 +28,9 @@ #include +#include "backend/cpu/Cpu.h" #include "base/io/log/Log.h" #include "base/kernel/interfaces/IJsonReader.h" -#include "common/cpu/Cpu.h" #include "core/config/Config.h" #include "crypto/common/Assembly.h" #include "rapidjson/document.h" diff --git a/src/crypto/cn/CnHash.cpp b/src/crypto/cn/CnHash.cpp index d17a8e2d1..6582db102 100644 --- a/src/crypto/cn/CnHash.cpp +++ b/src/crypto/cn/CnHash.cpp @@ -26,7 +26,7 @@ #include -#include "common/cpu/Cpu.h" +#include "backend/cpu/Cpu.h" #include "crypto/cn/CnHash.h" #include "crypto/common/VirtualMemory.h" diff --git a/src/crypto/cn/CryptoNight_x86.h b/src/crypto/cn/CryptoNight_x86.h index b24dea577..ae51cd182 100644 --- a/src/crypto/cn/CryptoNight_x86.h +++ b/src/crypto/cn/CryptoNight_x86.h @@ -35,7 +35,7 @@ #endif -#include "common/cpu/Cpu.h" +#include "backend/cpu/Cpu.h" #include "crypto/cn/CnAlgo.h" #include "crypto/cn/CryptoNight_monero.h" #include "crypto/cn/CryptoNight.h" diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 9f20a35ab..7011da12a 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -26,7 +26,6 @@ #include "base/io/log/Log.h" -#include "common/cpu/Cpu.h" #include "crypto/cn/CnHash.h" #include "crypto/common/Assembly.h" #include "crypto/common/VirtualMemory.h" diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 234e7bfda..c6ea6d9ae 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -24,7 +24,7 @@ #include -#include "common/cpu/Cpu.h" +#include "backend/cpu/Cpu.h" #include "common/Platform.h" #include "workers/CpuThread.h" #include "workers/ThreadHandle.h"