From c8ee6f7db81d29fdaa89f99702adcb3ada64e6aa Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 4 Dec 2020 09:23:40 +0700 Subject: [PATCH] Move Profiler and more cleanup. --- cmake/randomx.cmake | 7 ++++ src/backend/common/interfaces/IRxStorage.h | 17 ++++---- src/backend/cpu/platform/HwlocCpuInfo.cpp | 10 +---- src/backend/cpu/platform/HwlocCpuInfo.h | 10 +---- src/base/base.cmake | 7 ---- src/core/Miner.cpp | 4 +- src/crypto/common/Assembly.cpp | 15 ++----- src/crypto/common/Assembly.h | 11 ++---- src/crypto/randomx/aes_hash.cpp | 6 +-- src/crypto/randomx/jit_compiler_x86.cpp | 6 +-- src/crypto/randomx/randomx.cpp | 2 +- src/crypto/randomx/virtual_machine.cpp | 8 ++-- src/crypto/randomx/vm_compiled.cpp | 2 +- src/{base/tools => crypto/rx}/Profiler.cpp | 8 ++-- src/{base/tools => crypto/rx}/Profiler.h | 4 +- src/crypto/rx/Rx.cpp | 13 ++---- src/crypto/rx/Rx.h | 13 ++---- src/crypto/rx/RxAlgo.cpp | 13 ++---- src/crypto/rx/RxAlgo.h | 13 ++---- src/crypto/rx/RxBasicStorage.cpp | 14 ++----- src/crypto/rx/RxBasicStorage.h | 14 ++----- src/crypto/rx/RxConfig.cpp | 2 +- src/crypto/rx/RxDataset.cpp | 46 ++++++++++------------ src/crypto/rx/RxDataset.h | 23 +++-------- src/crypto/rx/RxNUMAStorage.cpp | 14 ++----- src/crypto/rx/RxNUMAStorage.h | 14 ++----- src/crypto/rx/RxVm.cpp | 23 ++++------- src/crypto/rx/RxVm.h | 24 +++-------- src/crypto/rx/Rx_linux.cpp | 17 +++----- src/crypto/rx/Rx_win.cpp | 19 +++------ 30 files changed, 123 insertions(+), 256 deletions(-) rename src/{base/tools => crypto/rx}/Profiler.cpp (93%) rename src/{base/tools => crypto/rx}/Profiler.h (94%) diff --git a/cmake/randomx.cmake b/cmake/randomx.cmake index 99de2632..9b6f76bc 100644 --- a/cmake/randomx.cmake +++ b/cmake/randomx.cmake @@ -108,6 +108,13 @@ if (WITH_RANDOMX) remove_definitions(/DXMRIG_FIX_RYZEN) message("-- WITH_MSR=OFF") endif() + + if (WITH_PROFILING) + add_definitions(/DXMRIG_FEATURE_PROFILING) + + list(APPEND HEADERS_CRYPTO src/crypto/rx/Profiler.h) + list(APPEND SOURCES_CRYPTO src/crypto/rx/Profiler.cpp) + endif() else() remove_definitions(/DXMRIG_ALGO_RANDOMX) endif() diff --git a/src/backend/common/interfaces/IRxStorage.h b/src/backend/common/interfaces/IRxStorage.h index ff447044..ab287a76 100644 --- a/src/backend/common/interfaces/IRxStorage.h +++ b/src/backend/common/interfaces/IRxStorage.h @@ -1,10 +1,7 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2016-2018 XMRig + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -24,8 +21,9 @@ #define XMRIG_IRXSTORAGE_H -#include "crypto/rx/RxConfig.h" +#include "base/tools/Object.h" #include "crypto/common/HugePagesInfo.h" +#include "crypto/rx/RxConfig.h" #include @@ -43,7 +41,10 @@ class RxSeed; class IRxStorage { public: - virtual ~IRxStorage() = default; + XMRIG_DISABLE_COPY_MOVE(IRxStorage) + + IRxStorage() = default; + virtual ~IRxStorage() = default; virtual bool isAllocated() const = 0; virtual HugePagesInfo hugePages() const = 0; diff --git a/src/backend/cpu/platform/HwlocCpuInfo.cpp b/src/backend/cpu/platform/HwlocCpuInfo.cpp index 0d587332..6f6cb4b7 100644 --- a/src/backend/cpu/platform/HwlocCpuInfo.cpp +++ b/src/backend/cpu/platform/HwlocCpuInfo.cpp @@ -1,12 +1,6 @@ /* 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-2020 SChernykh - * Copyright 2016-2020 XMRig + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 diff --git a/src/backend/cpu/platform/HwlocCpuInfo.h b/src/backend/cpu/platform/HwlocCpuInfo.h index eed3ae8b..1a24f425 100644 --- a/src/backend/cpu/platform/HwlocCpuInfo.h +++ b/src/backend/cpu/platform/HwlocCpuInfo.h @@ -1,12 +1,6 @@ /* 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-2020 SChernykh - * Copyright 2016-2020 XMRig + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 diff --git a/src/base/base.cmake b/src/base/base.cmake index 2273fdc1..cd6ee88b 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -232,13 +232,6 @@ if (WITH_KAWPOW) ) endif() -if (WITH_PROFILING) - add_definitions(/DXMRIG_FEATURE_PROFILING) - - list(APPEND HEADERS_BASE src/base/tools/Profiler.h) - list(APPEND SOURCES_BASE src/base/tools/Profiler.cpp) -endif() - if (WITH_RANDOMX AND WITH_BENCHMARK) add_definitions(/DXMRIG_FEATURE_BENCHMARK) diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 67a93488..63bbbb54 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -38,12 +38,10 @@ #include "base/kernel/Platform.h" #include "base/net/stratum/Job.h" #include "base/tools/Object.h" -#include "base/tools/Profiler.h" #include "base/tools/Timer.h" #include "core/config/Config.h" #include "core/Controller.h" #include "crypto/common/Nonce.h" -#include "crypto/rx/Rx.h" #include "version.h" @@ -64,6 +62,8 @@ #ifdef XMRIG_ALGO_RANDOMX +# include "crypto/rx/Profiler.h" +# include "crypto/rx/Rx.h" # include "crypto/rx/RxConfig.h" #endif diff --git a/src/crypto/common/Assembly.cpp b/src/crypto/common/Assembly.cpp index 5b7f8959..eb6b8537 100644 --- a/src/crypto/common/Assembly.cpp +++ b/src/crypto/common/Assembly.cpp @@ -1,13 +1,6 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 SChernykh - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -24,8 +17,8 @@ */ -#include -#include +#include +#include #ifdef _MSC_VER diff --git a/src/crypto/common/Assembly.h b/src/crypto/common/Assembly.h index 803ea716..8d7ba43c 100644 --- a/src/crypto/common/Assembly.h +++ b/src/crypto/common/Assembly.h @@ -1,12 +1,6 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -57,6 +51,7 @@ public: rapidjson::Value toJSON() const; inline bool isEqual(const Assembly &other) const { return m_id == other.m_id; } + inline Id id() const { return m_id; } inline bool operator!=(Assembly::Id id) const { return m_id != id; } inline bool operator!=(const Assembly &other) const { return !isEqual(other); } diff --git a/src/crypto/randomx/aes_hash.cpp b/src/crypto/randomx/aes_hash.cpp index 6697a4ed..4d0ee7a2 100644 --- a/src/crypto/randomx/aes_hash.cpp +++ b/src/crypto/randomx/aes_hash.cpp @@ -30,10 +30,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "crypto/randomx/aes_hash.hpp" -#include "crypto/randomx/soft_aes.h" -#include "crypto/randomx/randomx.h" #include "base/tools/Chrono.h" -#include "base/tools/Profiler.h" +#include "crypto/randomx/randomx.h" +#include "crypto/randomx/soft_aes.h" +#include "crypto/rx/Profiler.h" #define AES_HASH_1R_STATE0 0xd7983aad, 0xcc82db47, 0x9fa856de, 0x92b52c0d #define AES_HASH_1R_STATE1 0xace78057, 0xf59e125a, 0x15c7b798, 0x338d996e diff --git a/src/crypto/randomx/jit_compiler_x86.cpp b/src/crypto/randomx/jit_compiler_x86.cpp index 9753701e..4d5d0ee1 100644 --- a/src/crypto/randomx/jit_compiler_x86.cpp +++ b/src/crypto/randomx/jit_compiler_x86.cpp @@ -31,13 +31,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include "crypto/randomx/jit_compiler_x86.hpp" +#include "backend/cpu/Cpu.h" #include "crypto/randomx/jit_compiler_x86_static.hpp" -#include "crypto/randomx/superscalar.hpp" #include "crypto/randomx/program.hpp" #include "crypto/randomx/reciprocal.h" +#include "crypto/randomx/superscalar.hpp" #include "crypto/randomx/virtual_memory.hpp" -#include "base/tools/Profiler.h" -#include "backend/cpu/Cpu.h" +#include "crypto/rx/Profiler.h" #ifdef XMRIG_FIX_RYZEN # include "crypto/rx/Rx.h" diff --git a/src/crypto/randomx/randomx.cpp b/src/crypto/randomx/randomx.cpp index 9dd4aeee..28b9f39a 100644 --- a/src/crypto/randomx/randomx.cpp +++ b/src/crypto/randomx/randomx.cpp @@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include "base/tools/Profiler.h" +#include "crypto/rx/Profiler.h" RandomX_ConfigurationWownero::RandomX_ConfigurationWownero() { diff --git a/src/crypto/randomx/virtual_machine.cpp b/src/crypto/randomx/virtual_machine.cpp index 4a6990b2..43e19939 100644 --- a/src/crypto/randomx/virtual_machine.cpp +++ b/src/crypto/randomx/virtual_machine.cpp @@ -30,13 +30,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include "crypto/randomx/virtual_machine.hpp" -#include "crypto/randomx/common.hpp" #include "crypto/randomx/aes_hash.hpp" -#include "crypto/randomx/blake2/blake2.h" -#include "crypto/randomx/intrin_portable.h" #include "crypto/randomx/allocator.hpp" +#include "crypto/randomx/blake2/blake2.h" +#include "crypto/randomx/common.hpp" +#include "crypto/randomx/intrin_portable.h" #include "crypto/randomx/soft_aes.h" -#include "base/tools/Profiler.h" +#include "crypto/rx/Profiler.h" randomx_vm::~randomx_vm() { diff --git a/src/crypto/randomx/vm_compiled.cpp b/src/crypto/randomx/vm_compiled.cpp index c32034b3..c40247d9 100644 --- a/src/crypto/randomx/vm_compiled.cpp +++ b/src/crypto/randomx/vm_compiled.cpp @@ -28,7 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "crypto/randomx/vm_compiled.hpp" #include "crypto/randomx/common.hpp" -#include "base/tools/Profiler.h" +#include "crypto/rx/Profiler.h" namespace randomx { diff --git a/src/base/tools/Profiler.cpp b/src/crypto/rx/Profiler.cpp similarity index 93% rename from src/base/tools/Profiler.cpp rename to src/crypto/rx/Profiler.cpp index ac2a6d2c..9cfe72a0 100644 --- a/src/base/tools/Profiler.cpp +++ b/src/crypto/rx/Profiler.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -17,9 +17,11 @@ */ -#include "base/tools/Profiler.h" +#include "crypto/rx/Profiler.h" #include "base/io/log/Log.h" #include "base/io/log/Tags.h" + + #include #include #include diff --git a/src/base/tools/Profiler.h b/src/crypto/rx/Profiler.h similarity index 94% rename from src/base/tools/Profiler.h rename to src/crypto/rx/Profiler.h index ae3470f8..ca7d29db 100644 --- a/src/base/tools/Profiler.h +++ b/src/crypto/rx/Profiler.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 diff --git a/src/crypto/rx/Rx.cpp b/src/crypto/rx/Rx.cpp index 2fffb0e6..ea671d01 100644 --- a/src/crypto/rx/Rx.cpp +++ b/src/crypto/rx/Rx.cpp @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 diff --git a/src/crypto/rx/Rx.h b/src/crypto/rx/Rx.h index 1c452e8b..42bd0c15 100644 --- a/src/crypto/rx/Rx.h +++ b/src/crypto/rx/Rx.h @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 diff --git a/src/crypto/rx/RxAlgo.cpp b/src/crypto/rx/RxAlgo.cpp index 91d2c195..b7d2b083 100644 --- a/src/crypto/rx/RxAlgo.cpp +++ b/src/crypto/rx/RxAlgo.cpp @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 diff --git a/src/crypto/rx/RxAlgo.h b/src/crypto/rx/RxAlgo.h index 81c4687c..0cbbbd35 100644 --- a/src/crypto/rx/RxAlgo.h +++ b/src/crypto/rx/RxAlgo.h @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 diff --git a/src/crypto/rx/RxBasicStorage.cpp b/src/crypto/rx/RxBasicStorage.cpp index 7f389666..eacb6295 100644 --- a/src/crypto/rx/RxBasicStorage.cpp +++ b/src/crypto/rx/RxBasicStorage.cpp @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -30,7 +23,6 @@ #include "base/io/log/Log.h" #include "base/io/log/Tags.h" #include "base/tools/Chrono.h" -#include "base/tools/Object.h" #include "crypto/rx/RxAlgo.h" #include "crypto/rx/RxCache.h" #include "crypto/rx/RxDataset.h" diff --git a/src/crypto/rx/RxBasicStorage.h b/src/crypto/rx/RxBasicStorage.h index c689df83..463b479e 100644 --- a/src/crypto/rx/RxBasicStorage.h +++ b/src/crypto/rx/RxBasicStorage.h @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -29,7 +22,6 @@ #include "backend/common/interfaces/IRxStorage.h" -#include "base/tools/Object.h" namespace xmrig diff --git a/src/crypto/rx/RxConfig.cpp b/src/crypto/rx/RxConfig.cpp index c501e712..d9f05d4e 100644 --- a/src/crypto/rx/RxConfig.cpp +++ b/src/crypto/rx/RxConfig.cpp @@ -122,7 +122,7 @@ bool xmrig::RxConfig::read(const rapidjson::Value &value) } # endif - const uint32_t mode = static_cast(Json::getInt(value, kScratchpadPrefetchMode, static_cast(m_scratchpadPrefetchMode))); + const auto mode = static_cast(Json::getInt(value, kScratchpadPrefetchMode, static_cast(m_scratchpadPrefetchMode))); if (mode < ScratchpadPrefetchMax) { m_scratchpadPrefetchMode = static_cast(mode); } diff --git a/src/crypto/rx/RxDataset.cpp b/src/crypto/rx/RxDataset.cpp index c207d6f4..410a2f34 100644 --- a/src/crypto/rx/RxDataset.cpp +++ b/src/crypto/rx/RxDataset.cpp @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -30,6 +23,7 @@ #include "base/io/log/Tags.h" #include "base/kernel/Platform.h" #include "crypto/common/VirtualMemory.h" +#include "crypto/randomx/randomx.h" #include "crypto/rx/RxAlgo.h" #include "crypto/rx/RxCache.h" @@ -162,6 +156,22 @@ size_t xmrig::RxDataset::size(bool cache) const } +uint8_t *xmrig::RxDataset::tryAllocateScrathpad() +{ + auto p = reinterpret_cast(raw()); + if (!p) { + return nullptr; + } + + const size_t offset = m_scratchpadOffset.fetch_add(RANDOMX_SCRATCHPAD_L3_MAX_SIZE); + if (offset + RANDOMX_SCRATCHPAD_L3_MAX_SIZE > m_scratchpadLimit) { + return nullptr; + } + + return p + offset; +} + + void *xmrig::RxDataset::raw() const { return m_dataset ? randomx_get_dataset_memory(m_dataset) : nullptr; @@ -208,19 +218,3 @@ void xmrig::RxDataset::allocate(bool hugePages, bool oneGbPages) } # endif } - - -uint8_t* xmrig::RxDataset::tryAllocateScrathpad() -{ - uint8_t* p = reinterpret_cast(raw()); - if (!p) { - return nullptr; - } - - const size_t offset = m_scratchpadOffset.fetch_add(RANDOMX_SCRATCHPAD_L3_MAX_SIZE); - if (offset + RANDOMX_SCRATCHPAD_L3_MAX_SIZE > m_scratchpadLimit) { - return nullptr; - } - - return p + offset; -} diff --git a/src/crypto/rx/RxDataset.h b/src/crypto/rx/RxDataset.h index 798ec996..1621cae1 100644 --- a/src/crypto/rx/RxDataset.h +++ b/src/crypto/rx/RxDataset.h @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -28,12 +21,10 @@ #define XMRIG_RX_DATASET_H -#include "base/crypto/Algorithm.h" #include "base/tools/Buffer.h" #include "base/tools/Object.h" #include "crypto/common/HugePagesInfo.h" #include "crypto/randomx/configuration.h" -#include "crypto/randomx/randomx.h" #include "crypto/rx/RxConfig.h" #include @@ -68,11 +59,10 @@ public: bool isOneGbPages() const; HugePagesInfo hugePages(bool cache = true) const; size_t size(bool cache = true) const; + uint8_t *tryAllocateScrathpad(); void *raw() const; void setRaw(const void *raw); - uint8_t *tryAllocateScrathpad(); - static inline constexpr size_t maxSize() { return RANDOMX_DATASET_MAX_SIZE; } private: @@ -82,10 +72,9 @@ private: const uint32_t m_node; randomx_dataset *m_dataset = nullptr; RxCache *m_cache = nullptr; - VirtualMemory *m_memory = nullptr; - - std::atomic m_scratchpadOffset; size_t m_scratchpadLimit = 0; + std::atomic m_scratchpadOffset{}; + VirtualMemory *m_memory = nullptr; }; diff --git a/src/crypto/rx/RxNUMAStorage.cpp b/src/crypto/rx/RxNUMAStorage.cpp index 4b4ab4d6..6bd5627f 100644 --- a/src/crypto/rx/RxNUMAStorage.cpp +++ b/src/crypto/rx/RxNUMAStorage.cpp @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -32,7 +25,6 @@ #include "base/io/log/Tags.h" #include "base/kernel/Platform.h" #include "base/tools/Chrono.h" -#include "base/tools/Object.h" #include "crypto/rx/RxAlgo.h" #include "crypto/rx/RxCache.h" #include "crypto/rx/RxDataset.h" diff --git a/src/crypto/rx/RxNUMAStorage.h b/src/crypto/rx/RxNUMAStorage.h index ef0d6431..29ec5fb0 100644 --- a/src/crypto/rx/RxNUMAStorage.h +++ b/src/crypto/rx/RxNUMAStorage.h @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -29,7 +22,6 @@ #include "backend/common/interfaces/IRxStorage.h" -#include "base/tools/Object.h" #include diff --git a/src/crypto/rx/RxVm.cpp b/src/crypto/rx/RxVm.cpp index aa2217fc..f4b37375 100644 --- a/src/crypto/rx/RxVm.cpp +++ b/src/crypto/rx/RxVm.cpp @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -26,6 +19,7 @@ #include "crypto/randomx/randomx.h" +#include "backend/cpu/Cpu.h" #include "crypto/rx/RxCache.h" #include "crypto/rx/RxDataset.h" #include "crypto/rx/RxVm.h" @@ -36,7 +30,7 @@ extern "C" uint32_t rx_blake2b_use_sse41; #endif -randomx_vm* xmrig::RxVm::create(RxDataset *dataset, uint8_t *scratchpad, bool softAes, xmrig::Assembly assembly, uint32_t node) +randomx_vm *xmrig::RxVm::create(RxDataset *dataset, uint8_t *scratchpad, bool softAes, const Assembly &assembly, uint32_t node) { int flags = 0; @@ -52,11 +46,8 @@ randomx_vm* xmrig::RxVm::create(RxDataset *dataset, uint8_t *scratchpad, bool so flags |= RANDOMX_FLAG_JIT; } - if (assembly == Assembly::AUTO) { - assembly = Cpu::info()->assembly(); - } - - if ((assembly == Assembly::RYZEN) || (assembly == Assembly::BULLDOZER)) { + const auto asmId = assembly == Assembly::AUTO ? Cpu::info()->assembly() : assembly.id(); + if ((asmId == Assembly::RYZEN) || (asmId == Assembly::BULLDOZER)) { flags |= RANDOMX_FLAG_AMD; } diff --git a/src/crypto/rx/RxVm.h b/src/crypto/rx/RxVm.h index 6397d726..424da209 100644 --- a/src/crypto/rx/RxVm.h +++ b/src/crypto/rx/RxVm.h @@ -1,14 +1,7 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 @@ -28,10 +21,6 @@ #define XMRIG_RX_VM_H -#include "base/tools/Object.h" -#include "backend/cpu/Cpu.h" - - #include @@ -42,16 +31,15 @@ namespace xmrig { +class Assembly; class RxDataset; class RxVm { public: - XMRIG_DISABLE_COPY_MOVE_DEFAULT(RxVm); - - static randomx_vm* create(RxDataset *dataset, uint8_t *scratchpad, bool softAes, xmrig::Assembly assembly, uint32_t node); - static void destroy(randomx_vm* vm); + static randomx_vm *create(RxDataset *dataset, uint8_t *scratchpad, bool softAes, const Assembly &assembly, uint32_t node); + static void destroy(randomx_vm *vm); }; diff --git a/src/crypto/rx/Rx_linux.cpp b/src/crypto/rx/Rx_linux.cpp index 62ce936a..1525f99d 100644 --- a/src/crypto/rx/Rx_linux.cpp +++ b/src/crypto/rx/Rx_linux.cpp @@ -1,16 +1,9 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2000 Transmeta Corporation - * Copyright 2004-2008 H. Peter Anvin - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2000 Transmeta Corporation + * Copyright (c) 2004-2008 H. Peter Anvin + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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 diff --git a/src/crypto/rx/Rx_win.cpp b/src/crypto/rx/Rx_win.cpp index b32c3dae..77e7c9b4 100644 --- a/src/crypto/rx/Rx_win.cpp +++ b/src/crypto/rx/Rx_win.cpp @@ -1,17 +1,10 @@ /* 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 Lee Clagett - * Copyright 2018-2019 tevador - * Copyright 2000 Transmeta Corporation - * Copyright 2004-2008 H. Peter Anvin - * Copyright 2007-2009 hiyohiyo , - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2000 Transmeta Corporation + * Copyright (c) 2004-2008 H. Peter Anvin + * Copyright (c) 2007-2009 hiyohiyo , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 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