mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 10:01:06 +00:00
Merge branch 'feature-randomx' into evo
This commit is contained in:
commit
e743301a79
4 changed files with 37 additions and 12 deletions
|
@ -38,14 +38,6 @@ MultiWorker<N>::MultiWorker(ThreadHandle *handle)
|
|||
: Worker(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
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,11 +47,28 @@ MultiWorker<N>::~MultiWorker()
|
|||
Mem::release(m_ctx, N, m_memory);
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_rx_vm) {
|
||||
randomx_destroy_vm(m_rx_vm);
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_ALGO_RANDOMX
|
||||
template<size_t N>
|
||||
void MultiWorker<N>::allocateRandomX_VM()
|
||||
{
|
||||
if (!m_rx_vm) {
|
||||
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
|
||||
|
||||
|
||||
template<size_t N>
|
||||
bool MultiWorker<N>::selfTest()
|
||||
{
|
||||
|
@ -142,6 +151,7 @@ void MultiWorker<N>::start()
|
|||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (v == xmrig::VARIANT_RX_WOW) {
|
||||
allocateRandomX_VM();
|
||||
Workers::updateDataset(m_state.job.seed_hash(), m_totalWays);
|
||||
randomx_calculate_hash(m_rx_vm, m_state.blob, m_state.job.size(), m_hash);
|
||||
}
|
||||
|
|
|
@ -53,6 +53,10 @@ protected:
|
|||
void start() override;
|
||||
|
||||
private:
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
void allocateRandomX_VM();
|
||||
# endif
|
||||
|
||||
bool resume(const xmrig::Job &job);
|
||||
bool verify(xmrig::Variant variant, const uint8_t *referenceValue);
|
||||
bool verify2(xmrig::Variant variant, const uint8_t *referenceValue);
|
||||
|
|
|
@ -185,6 +185,7 @@ void Workers::start(xmrig::Controller *controller)
|
|||
|
||||
const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
|
||||
m_status.algo = controller->config()->algorithm().algo();
|
||||
m_status.variant = controller->config()->algorithm().variant();
|
||||
m_status.threads = threads.size();
|
||||
|
||||
for (const xmrig::IThread *thread : threads) {
|
||||
|
@ -252,7 +253,7 @@ void Workers::threadsSummary(rapidjson::Document &doc)
|
|||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
const uint64_t pages[2] = { m_status.hugePages, m_status.pages };
|
||||
const uint64_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo);
|
||||
const uint64_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo, m_status.variant);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
@ -356,7 +357,7 @@ void Workers::start(IWorker *worker)
|
|||
|
||||
if (m_status.started == m_status.threads) {
|
||||
const double percent = (double) m_status.hugePages / m_status.pages * 100.0;
|
||||
const size_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo) / 1024;
|
||||
const size_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo, m_status.variant) / 1024;
|
||||
|
||||
LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") "",
|
||||
m_status.threads, m_status.ways,
|
||||
|
@ -382,6 +383,10 @@ void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads
|
|||
|
||||
// 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);
|
||||
|
||||
|
@ -403,6 +408,10 @@ void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads
|
|||
// 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);
|
||||
}
|
||||
|
|
|
@ -96,7 +96,8 @@ private:
|
|||
started(0),
|
||||
threads(0),
|
||||
ways(0),
|
||||
algo(xmrig::CRYPTONIGHT)
|
||||
algo(xmrig::CRYPTONIGHT),
|
||||
variant(xmrig::VARIANT_AUTO)
|
||||
{}
|
||||
|
||||
size_t hugePages;
|
||||
|
@ -105,6 +106,7 @@ private:
|
|||
size_t threads;
|
||||
size_t ways;
|
||||
xmrig::Algo algo;
|
||||
xmrig::Variant variant;
|
||||
};
|
||||
|
||||
static bool m_active;
|
||||
|
|
Loading…
Reference in a new issue