Move CPU information classes to new location.

This commit is contained in:
XMRig 2019-06-29 09:51:23 +07:00
parent dd875c7c37
commit 62edb2fc0a
21 changed files with 62 additions and 115 deletions

View file

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

View file

@ -6,7 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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"

View file

@ -28,9 +28,9 @@
#include <uv.h>
#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
}

View file

@ -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"

View file

@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <assert.h>
#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
}

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 {

View file

@ -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"

View file

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

View file

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

View file

@ -27,7 +27,7 @@
#include <string.h>
#include "core/cpu/AdvancedCpuInfo.h"
#include "backend/cpu/platform/AdvancedCpuInfo.h"
xmrig::AdvancedCpuInfo::AdvancedCpuInfo() :

View file

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

View file

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

View file

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

View file

@ -1,57 +0,0 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#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;
}

View file

@ -26,7 +26,7 @@
#include <assert.h>
#include "common/cpu/Cpu.h"
#include "backend/cpu/Cpu.h"
#include "common/Platform.h"
#include "core/Controller.h"
#include "net/Network.h"

View file

@ -28,9 +28,9 @@
#include <inttypes.h>
#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"

View file

@ -26,7 +26,7 @@
#include <stdio.h>
#include "common/cpu/Cpu.h"
#include "backend/cpu/Cpu.h"
#include "crypto/cn/CnHash.h"
#include "crypto/common/VirtualMemory.h"

View file

@ -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"

View file

@ -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"

View file

@ -24,7 +24,7 @@
#include <chrono>
#include "common/cpu/Cpu.h"
#include "backend/cpu/Cpu.h"
#include "common/Platform.h"
#include "workers/CpuThread.h"
#include "workers/ThreadHandle.h"