Start mining threads only after RandomX dataset initialization.
This commit is contained in:
parent
4a5e185973
commit
2a5110aa04
6 changed files with 165 additions and 74 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <map>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HWLOC
|
||||
|
@ -36,12 +37,14 @@
|
|||
#endif
|
||||
|
||||
|
||||
#include "backend/common/interfaces/IRxListener.h"
|
||||
#include "backend/cpu/Cpu.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "crypto/rx/Rx.h"
|
||||
#include "crypto/rx/RxAlgo.h"
|
||||
#include "crypto/rx/RxCache.h"
|
||||
|
@ -56,6 +59,7 @@ class RxPrivate;
|
|||
|
||||
static const char *tag = BLUE_BG(WHITE_BOLD_S " rx ") " ";
|
||||
static RxPrivate *d_ptr = nullptr;
|
||||
static std::mutex mutex;
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HWLOC
|
||||
|
@ -91,6 +95,11 @@ public:
|
|||
inline RxPrivate() :
|
||||
m_seed()
|
||||
{
|
||||
m_async = new uv_async_t;
|
||||
m_async->data = this;
|
||||
|
||||
uv_async_init(uv_default_loop(), m_async, RxPrivate::onReady);
|
||||
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
if (Cpu::info()->nodes() > 1) {
|
||||
for (uint32_t nodeId : HwlocCpuInfo::nodeIndexes()) {
|
||||
|
@ -107,6 +116,8 @@ public:
|
|||
|
||||
inline ~RxPrivate()
|
||||
{
|
||||
Handle::close(m_async);
|
||||
|
||||
for (auto const &item : datasets) {
|
||||
delete item.second;
|
||||
}
|
||||
|
@ -119,6 +130,7 @@ public:
|
|||
inline const Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const uint8_t *seed() const { return m_seed; }
|
||||
inline size_t count() const { return isNUMA() ? datasets.size() : 1; }
|
||||
inline void asyncSend() { m_ready++; if (m_ready == count()) { uv_async_send(m_async); } }
|
||||
|
||||
|
||||
static void allocate(uint32_t nodeId)
|
||||
|
@ -163,12 +175,12 @@ public:
|
|||
|
||||
static void initDataset(uint32_t nodeId, uint32_t threads)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(d_ptr->mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
const uint64_t ts = Chrono::steadyMSecs();
|
||||
|
||||
d_ptr->getOrAllocate(nodeId)->init(d_ptr->seed(), threads);
|
||||
d_ptr->m_ready++;
|
||||
d_ptr->asyncSend();
|
||||
|
||||
LOG_INFO("%s" CYAN_BOLD("#%u") GREEN(" init done") BLACK_BOLD(" (%" PRIu64 " ms)"), tag, nodeId, Chrono::steadyMSecs() - ts);
|
||||
}
|
||||
|
@ -196,7 +208,7 @@ public:
|
|||
}
|
||||
|
||||
|
||||
inline void setState(const Job &job, bool hugePages, bool numa)
|
||||
inline void setState(const Job &job, bool hugePages, bool numa, IRxListener *listener)
|
||||
{
|
||||
if (m_algorithm != job.algorithm()) {
|
||||
m_algorithm = RxAlgo::apply(job.algorithm());
|
||||
|
@ -205,6 +217,7 @@ public:
|
|||
m_ready = 0;
|
||||
m_numa = numa && Cpu::info()->nodes() > 1;
|
||||
m_hugePages = hugePages;
|
||||
m_listener = listener;
|
||||
|
||||
memcpy(m_seed, job.seedHash(), sizeof(m_seed));
|
||||
}
|
||||
|
@ -217,23 +230,73 @@ public:
|
|||
|
||||
|
||||
std::map<uint32_t, RxDataset *> datasets;
|
||||
std::mutex mutex;
|
||||
|
||||
private:
|
||||
bool m_hugePages = true;
|
||||
bool m_numa = true;
|
||||
static void onReady(uv_async_t *)
|
||||
{
|
||||
if (d_ptr->m_listener) {
|
||||
d_ptr->m_listener->onDatasetReady();
|
||||
}
|
||||
}
|
||||
|
||||
Algorithm m_algorithm;
|
||||
size_t m_ready = 0;
|
||||
bool m_hugePages = true;
|
||||
bool m_numa = true;
|
||||
IRxListener *m_listener = nullptr;
|
||||
size_t m_ready = 0;
|
||||
uint8_t m_seed[32];
|
||||
uv_async_t *m_async;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
bool xmrig::Rx::init(const Job &job, int initThreads, bool hugePages, bool numa, IRxListener *listener)
|
||||
{
|
||||
if (job.algorithm().family() != Algorithm::RANDOM_X) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
if (d_ptr->isReady(job)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
d_ptr->setState(job, hugePages, numa, listener);
|
||||
const uint32_t threads = initThreads < 1 ? static_cast<uint32_t>(Cpu::info()->threads()) : static_cast<uint32_t>(initThreads);
|
||||
const String buf = Buffer::toHex(job.seedHash(), 8);
|
||||
|
||||
LOG_INFO("%s" MAGENTA_BOLD("init dataset%s") " algo " WHITE_BOLD("%s (") CYAN_BOLD("%u") WHITE_BOLD(" threads)") BLACK_BOLD(" seed %s..."),
|
||||
tag,
|
||||
d_ptr->count() > 1 ? "s" : "",
|
||||
job.algorithm().shortName(),
|
||||
threads,
|
||||
buf.data()
|
||||
);
|
||||
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
if (d_ptr->isNUMA()) {
|
||||
for (auto const &item : d_ptr->datasets) {
|
||||
std::thread thread(RxPrivate::initDataset, item.first, threads);
|
||||
thread.detach();
|
||||
}
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
std::thread thread(RxPrivate::initDataset, 0, threads);
|
||||
thread.detach();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Rx::isReady(const Job &job)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(d_ptr->mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
return d_ptr->isReady(job);
|
||||
}
|
||||
|
@ -241,7 +304,7 @@ bool xmrig::Rx::isReady(const Job &job)
|
|||
|
||||
xmrig::RxDataset *xmrig::Rx::dataset(const Job &job, uint32_t nodeId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(d_ptr->mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
if (!d_ptr->isReady(job)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -253,7 +316,7 @@ xmrig::RxDataset *xmrig::Rx::dataset(const Job &job, uint32_t nodeId)
|
|||
std::pair<unsigned, unsigned> xmrig::Rx::hugePages()
|
||||
{
|
||||
std::pair<unsigned, unsigned> pages(0, 0);
|
||||
std::lock_guard<std::mutex> lock(d_ptr->mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
for (auto const &item : d_ptr->datasets) {
|
||||
if (!item.second) {
|
||||
|
@ -281,43 +344,3 @@ void xmrig::Rx::init()
|
|||
{
|
||||
d_ptr = new RxPrivate();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Rx::init(const Job &job, int initThreads, bool hugePages, bool numa)
|
||||
{
|
||||
if (job.algorithm().family() != Algorithm::RANDOM_X) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(d_ptr->mutex);
|
||||
|
||||
if (d_ptr->isReady(job)) {
|
||||
return;
|
||||
}
|
||||
|
||||
d_ptr->setState(job, hugePages, numa);
|
||||
const uint32_t threads = initThreads < 1 ? static_cast<uint32_t>(Cpu::info()->threads()) : static_cast<uint32_t>(initThreads);
|
||||
const String buf = Buffer::toHex(job.seedHash(), 8);
|
||||
|
||||
LOG_INFO("%s" MAGENTA_BOLD("init dataset%s") " algo " WHITE_BOLD("%s (") CYAN_BOLD("%u") WHITE_BOLD(" threads)") BLACK_BOLD(" seed %s..."),
|
||||
tag,
|
||||
d_ptr->count() > 1 ? "s" : "",
|
||||
job.algorithm().shortName(),
|
||||
threads,
|
||||
buf.data()
|
||||
);
|
||||
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
if (d_ptr->isNUMA()) {
|
||||
for (auto const &item : d_ptr->datasets) {
|
||||
std::thread thread(RxPrivate::initDataset, item.first, threads);
|
||||
thread.detach();
|
||||
}
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
std::thread thread(RxPrivate::initDataset, 0, threads);
|
||||
thread.detach();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue