Allow disable RandomX support.

This commit is contained in:
XMRig 2019-06-18 06:11:53 +07:00
parent 3d17ba6af6
commit 2a07cf391d
6 changed files with 50 additions and 8 deletions

View file

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

View file

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

View file

@ -39,11 +39,13 @@ MultiWorker<N>::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<randomx_flags>(flags), nullptr, Workers::getDataset());
if (!m_rx_vm) {
m_rx_vm = randomx_create_vm(static_cast<randomx_flags>(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, Workers::getDataset());
}
# endif
}
@ -51,7 +53,10 @@ template<size_t N>
MultiWorker<N>::~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<N>::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());
}

View file

@ -27,7 +27,9 @@
#define XMRIG_MULTIWORKER_H
#include <randomx.h>
#ifdef XMRIG_ALGO_RANDOMX
# include <randomx.h>
#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
};

View file

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

View file

@ -30,7 +30,10 @@
#include <list>
#include <uv.h>
#include <vector>
#include <randomx.h>
#ifdef XMRIG_ALGO_RANDOMX
# include <randomx.h>
#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<uint32_t> m_rx_dataset_init_thread_counter;
# endif
};