Merge branch 'evo' into feature-per-pool-algo

This commit is contained in:
XMRig 2019-06-26 15:44:52 +07:00
commit 188338c493
19 changed files with 283 additions and 35 deletions

View file

@ -59,6 +59,14 @@ 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()
{
@ -183,6 +191,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;
@ -341,13 +353,90 @@ void Workers::start(IWorker *worker)
const double percent = (double) m_status.hugePages / m_status.pages * 100.0;
const size_t memory = m_status.ways * xmrig::CnAlgo<>::memory(m_status.algo) / 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,
(m_status.hugePages == m_status.pages ? GREEN_BOLD_S : (m_status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
m_status.hugePages, m_status.pages, percent, memory);
# ifdef XMRIG_ALGO_RANDOMX
if (m_status.algo.family() == xmrig::Algorithm::RANDOM_X) {
LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " memory " CYAN_BOLD("%zu KB") "",
m_status.threads, m_status.ways, memory);
} else
# endif
{
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,
(m_status.hugePages == m_status.pages ? GREEN_BOLD_S : (m_status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
m_status.hugePages, m_status.pages, percent, memory);
}
}
uv_mutex_unlock(&m_mutex);
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
if (memcmp(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash)) == 0)
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 (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