Added classes Rx, RxAlgo, RxCache, RxDataset.
This commit is contained in:
parent
ea1149a971
commit
f42adafee0
18 changed files with 704 additions and 144 deletions
|
@ -28,6 +28,8 @@
|
|||
|
||||
|
||||
#include "crypto/cn/CryptoNight_test.h"
|
||||
#include "crypto/rx/Rx.h"
|
||||
#include "crypto/rx/RxDataset.h"
|
||||
#include "net/JobResults.h"
|
||||
#include "workers/CpuThreadLegacy.h"
|
||||
#include "workers/MultiWorker.h"
|
||||
|
@ -67,9 +69,11 @@ void xmrig::MultiWorker<N>::allocateRandomX_VM()
|
|||
flags |= RANDOMX_FLAG_HARD_AES;
|
||||
}
|
||||
|
||||
m_rx_vm = randomx_create_vm(static_cast<randomx_flags>(flags), nullptr, Workers::getDataset());
|
||||
RxDataset *dataset = Rx::dataset(m_state.job.seedHash(), m_state.job.algorithm());
|
||||
|
||||
m_rx_vm = randomx_create_vm(static_cast<randomx_flags>(flags), nullptr, dataset->get());
|
||||
if (!m_rx_vm) {
|
||||
m_rx_vm = randomx_create_vm(static_cast<randomx_flags>(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, Workers::getDataset());
|
||||
m_rx_vm = randomx_create_vm(static_cast<randomx_flags>(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, dataset->get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +164,6 @@ void xmrig::MultiWorker<N>::start()
|
|||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_state.job.algorithm().family() == Algorithm::RANDOM_X) {
|
||||
allocateRandomX_VM();
|
||||
Workers::updateDataset(m_state.job.seedHash(), m_totalWays, m_state.job.algorithm());
|
||||
randomx_calculate_hash(m_rx_vm, m_state.blob, m_state.job.size(), m_hash);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -29,9 +29,13 @@
|
|||
|
||||
#include "api/Api.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "crypto/rx/RxAlgo.h"
|
||||
#include "crypto/rx/RxCache.h"
|
||||
#include "crypto/rx/RxDataset.h"
|
||||
#include "interfaces/IThread.h"
|
||||
#include "Mem.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
@ -55,15 +59,6 @@ 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] = {};
|
||||
xmrig::Algorithm Workers::m_rx_algo;
|
||||
std::atomic<uint32_t> Workers::m_rx_dataset_init_thread_counter = {};
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::Job Workers::job()
|
||||
{
|
||||
|
@ -176,7 +171,7 @@ void Workers::start(xmrig::Controller *controller)
|
|||
m_controller = controller;
|
||||
|
||||
const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
|
||||
m_status.algo = xmrig::Algorithm::CN_0; // FIXME algo
|
||||
m_status.algo = xmrig::Algorithm::RX_WOW; // FIXME algo
|
||||
m_status.threads = threads.size();
|
||||
|
||||
for (const xmrig::IThread *thread : threads) {
|
||||
|
@ -188,10 +183,6 @@ 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;
|
||||
|
||||
|
@ -335,92 +326,3 @@ void Workers::start(IWorker *worker)
|
|||
|
||||
worker->start();
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_ALGO_RANDOMX
|
||||
void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads, const xmrig::Algorithm &algorithm)
|
||||
{
|
||||
// Check if we need to update cache and dataset
|
||||
if ((memcmp(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash)) == 0) && (m_rx_algo == algorithm))
|
||||
return;
|
||||
|
||||
const uint32_t thread_id = m_rx_dataset_init_thread_counter++;
|
||||
LOG_DEBUG("Thread %u started updating RandomX dataset", thread_id);
|
||||
|
||||
// Wait for all threads to get here
|
||||
do {
|
||||
if (m_sequence.load(std::memory_order_relaxed) == 0) {
|
||||
// Exit immediately if workers were stopped
|
||||
return;
|
||||
}
|
||||
std::this_thread::yield();
|
||||
} while (m_rx_dataset_init_thread_counter.load() != num_threads);
|
||||
|
||||
// One of the threads updates cache
|
||||
uv_rwlock_wrlock(&m_rx_dataset_lock);
|
||||
|
||||
if (m_rx_algo != algorithm) {
|
||||
switch (algorithm) {
|
||||
case xmrig::Algorithm::RX_WOW:
|
||||
randomx_apply_config(RandomX_WowneroConfig);
|
||||
break;
|
||||
|
||||
case xmrig::Algorithm::RX_LOKI:
|
||||
randomx_apply_config(RandomX_LokiConfig);
|
||||
break;
|
||||
|
||||
default:
|
||||
randomx_apply_config(RandomX_MoneroConfig);
|
||||
break;
|
||||
}
|
||||
|
||||
m_rx_algo = algorithm;
|
||||
}
|
||||
|
||||
if (memcmp(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash)) != 0) {
|
||||
memcpy(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash));
|
||||
randomx_init_cache(m_rx_cache, m_rx_seed_hash, sizeof(m_rx_seed_hash));
|
||||
}
|
||||
|
||||
uv_rwlock_wrunlock(&m_rx_dataset_lock);
|
||||
|
||||
// All threads update dataset
|
||||
const uint32_t a = (randomx_dataset_item_count() * thread_id) / 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_DEBUG("Thread %u finished updating RandomX dataset", thread_id);
|
||||
|
||||
// Wait for all threads to complete
|
||||
--m_rx_dataset_init_thread_counter;
|
||||
do {
|
||||
if (m_sequence.load(std::memory_order_relaxed) == 0) {
|
||||
// Exit immediately if workers were stopped
|
||||
return;
|
||||
}
|
||||
std::this_thread::yield();
|
||||
} while (m_rx_dataset_init_thread_counter.load() != 0);
|
||||
}
|
||||
|
||||
randomx_dataset* Workers::getDataset()
|
||||
{
|
||||
if (m_rx_dataset)
|
||||
return m_rx_dataset;
|
||||
|
||||
uv_rwlock_wrlock(&m_rx_dataset_lock);
|
||||
if (!m_rx_dataset) {
|
||||
randomx_dataset* dataset = randomx_alloc_dataset(RANDOMX_FLAG_LARGE_PAGES);
|
||||
if (!dataset) {
|
||||
dataset = randomx_alloc_dataset(RANDOMX_FLAG_DEFAULT);
|
||||
}
|
||||
m_rx_cache = randomx_alloc_cache(static_cast<randomx_flags>(RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES));
|
||||
if (!m_rx_cache) {
|
||||
m_rx_cache = randomx_alloc_cache(RANDOMX_FLAG_JIT);
|
||||
}
|
||||
m_rx_dataset = dataset;
|
||||
}
|
||||
uv_rwlock_wrunlock(&m_rx_dataset_lock);
|
||||
|
||||
return m_rx_dataset;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -73,11 +73,6 @@ public:
|
|||
static void threadsSummary(rapidjson::Document &doc);
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
static void updateDataset(const uint8_t* seed_hash, uint32_t num_threads, const xmrig::Algorithm &algorithm);
|
||||
static randomx_dataset* getDataset();
|
||||
# endif
|
||||
|
||||
private:
|
||||
static void onReady(void *arg);
|
||||
static void onTick(uv_timer_t *handle);
|
||||
|
@ -115,15 +110,6 @@ private:
|
|||
static uv_rwlock_t m_rwlock;
|
||||
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 xmrig::Algorithm m_rx_algo;
|
||||
static std::atomic<uint32_t> m_rx_dataset_init_thread_counter;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue