diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f515b1ae..697f3da5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ option(WITH_CN_LITE "CryptoNight-Lite support" ON) option(WITH_CN_HEAVY "CryptoNight-Heavy support" ON) option(WITH_CN_PICO "CryptoNight-Pico support" ON) option(WITH_CN_GPU "CryptoNight-GPU support" ON) +option(WITH_RANDOMX "RandomX support" ON) option(WITH_HTTP "HTTP protocol support (client/server)" ON) option(WITH_DEBUG_LOG "Enable debug log output" OFF) option(WITH_TLS "Enable OpenSSL support" ON) @@ -158,7 +159,17 @@ add_definitions(/DUNICODE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") find_package(UV REQUIRED) -find_package(RandomX REQUIRED) + +if (WITH_RANDOMX) + find_package(RandomX REQUIRED) + include_directories(${RANDOMX_INCLUDE_DIR}) + + add_definitions(/DXMRIG_ALGO_RANDOMX) +else() + set(RANDOMX_LIBRARIES "") + + remove_definitions(/DXMRIG_ALGO_RANDOMX) +endif() include(cmake/flags.cmake) @@ -220,7 +231,6 @@ endif() include_directories(src) include_directories(src/3rdparty) include_directories(${UV_INCLUDE_DIR}) -include_directories(${RANDOMX_INCLUDE_DIR}) if (BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS " -static") diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index 6d8d9a65a..6f53f6a84 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -69,7 +69,10 @@ static AlgoData const algorithms[] = { { "cryptonight/rwz", "cn/rwz", xmrig::CRYPTONIGHT, xmrig::VARIANT_RWZ }, { "cryptonight/zls", "cn/zls", xmrig::CRYPTONIGHT, xmrig::VARIANT_ZLS }, { "cryptonight/double", "cn/double", xmrig::CRYPTONIGHT, xmrig::VARIANT_DOUBLE }, + +# ifdef XMRIG_ALGO_RANDOMX { "randomx/wow", "rx/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_RX_WOW }, +# endif # ifdef XMRIG_ALGO_CN_LITE { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index d5a5af27f..e8a406691 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -39,11 +39,13 @@ MultiWorker::MultiWorker(ThreadHandle *handle) { m_memory = Mem::create(m_ctx, m_thread->algorithm(), N); +# ifdef XMRIG_ALGO_RANDOMX const int flags = RANDOMX_FLAG_LARGE_PAGES | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT; m_rx_vm = randomx_create_vm(static_cast(flags), nullptr, Workers::getDataset()); if (!m_rx_vm) { m_rx_vm = randomx_create_vm(static_cast(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, Workers::getDataset()); } +# endif } @@ -51,7 +53,10 @@ template MultiWorker::~MultiWorker() { Mem::release(m_ctx, N, m_memory); + +# ifdef XMRIG_ALGO_RANDOMX randomx_destroy_vm(m_rx_vm); +# endif } @@ -134,11 +139,15 @@ void MultiWorker::start() } const xmrig::Variant v = m_state.job.algorithm().variant(); + +# ifdef XMRIG_ALGO_RANDOMX if (v == xmrig::VARIANT_RX_WOW) { Workers::updateDataset(m_state.job.seed_hash(), m_totalWays); randomx_calculate_hash(m_rx_vm, m_state.blob, m_state.job.size(), m_hash); } - else { + else +# endif + { m_thread->fn(v)(m_state.blob, m_state.job.size(), m_hash, m_ctx, m_state.job.height()); } diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index 874949937..63dd78964 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -27,7 +27,9 @@ #define XMRIG_MULTIWORKER_H -#include +#ifdef XMRIG_ALGO_RANDOMX +# include +#endif #include "base/net/stratum/Job.h" @@ -74,7 +76,9 @@ private: State m_state; uint8_t m_hash[N * 32]; - randomx_vm* m_rx_vm; +# ifdef XMRIG_ALGO_RANDOMX + randomx_vm *m_rx_vm = nullptr; +# endif }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 5a23f6be3..18210b677 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -59,11 +59,14 @@ uv_mutex_t Workers::m_mutex; uv_rwlock_t Workers::m_rwlock; uv_timer_t *Workers::m_timer = nullptr; xmrig::Controller *Workers::m_controller = nullptr; + +#ifdef XMRIG_ALGO_RANDOMX uv_rwlock_t Workers::m_rx_dataset_lock; randomx_cache *Workers::m_rx_cache = nullptr; randomx_dataset *Workers::m_rx_dataset = nullptr; uint8_t Workers::m_rx_seed_hash[32] = {}; std::atomic Workers::m_rx_dataset_init_thread_counter = {}; +#endif xmrig::Job Workers::job() @@ -192,7 +195,10 @@ void Workers::start(xmrig::Controller *controller) uv_mutex_init(&m_mutex); uv_rwlock_init(&m_rwlock); + +# ifdef XMRIG_ALGO_RANDOMX uv_rwlock_init(&m_rx_dataset_lock); +# endif m_sequence = 1; m_paused = 1; @@ -363,6 +369,8 @@ void Workers::start(IWorker *worker) worker->start(); } + +#ifdef XMRIG_ALGO_RANDOMX void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads) { // Check if we need to update cache and dataset @@ -370,7 +378,7 @@ void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads return; const uint32_t thread_id = m_rx_dataset_init_thread_counter++; - LOG_NOTICE("Thread %u started updating RandomX dataset", thread_id); + LOG_DEBUG("Thread %u started updating RandomX dataset", thread_id); // Wait for all threads to get here do { @@ -390,7 +398,7 @@ void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads const uint32_t b = (randomx_dataset_item_count() * (thread_id + 1)) / num_threads; randomx_init_dataset(m_rx_dataset, m_rx_cache, a, b - a); - LOG_NOTICE("Thread %u finished updating RandomX dataset", thread_id); + LOG_DEBUG("Thread %u finished updating RandomX dataset", thread_id); // Wait for all threads to complete --m_rx_dataset_init_thread_counter; @@ -420,3 +428,4 @@ randomx_dataset* Workers::getDataset() return m_rx_dataset; } +#endif diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 3fa1d8181..39f3d5f66 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -30,7 +30,10 @@ #include #include #include -#include + +#ifdef XMRIG_ALGO_RANDOMX +# include +#endif #include "base/net/stratum/Job.h" #include "net/JobResult.h" @@ -73,8 +76,10 @@ public: static void threadsSummary(rapidjson::Document &doc); # endif +# ifdef XMRIG_ALGO_RANDOMX static void updateDataset(const uint8_t* seed_hash, uint32_t num_threads); static randomx_dataset* getDataset(); +# endif private: static void onReady(void *arg); @@ -119,11 +124,13 @@ private: static uv_timer_t *m_timer; static xmrig::Controller *m_controller; +# ifdef XMRIG_ALGO_RANDOMX static uv_rwlock_t m_rx_dataset_lock; static randomx_cache *m_rx_cache; static randomx_dataset *m_rx_dataset; static uint8_t m_rx_seed_hash[32]; static std::atomic m_rx_dataset_init_thread_counter; +# endif };