From f7ea4b6dbd739fdad1d0d38aef0c8a8d3da3f08d Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 2 Aug 2019 16:44:55 +0700 Subject: [PATCH] Always stop mining threads in RandomX dataset change upcoming. --- src/backend/cpu/CpuBackend.cpp | 24 +++++++++++++----------- src/base/io/log/Log.h | 4 ++++ src/core/Miner.cpp | 10 ++++++++-- src/crypto/rx/Rx.cpp | 10 +++++++++- src/crypto/rx/Rx.h | 1 + 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index 005ff1dee..60ca8cf3b 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -49,7 +49,8 @@ namespace xmrig { extern template class Threads; -static const String kType = "cpu"; +static const char *tag = CYAN_BG_BOLD(" cpu "); +static const String kType = "cpu"; struct LaunchStatus @@ -94,7 +95,8 @@ public: inline void start() { - LOG_INFO(GREEN_BOLD("CPU") " use profile " BLUE_BG(WHITE_BOLD_S " %s ") WHITE_BOLD_S " (" CYAN_BOLD("%zu") WHITE_BOLD(" threads)") " scratchpad " CYAN_BOLD("%zu KB"), + LOG_INFO("%s use profile " BLUE_BG(WHITE_BOLD_S " %s ") WHITE_BOLD_S " (" CYAN_BOLD("%zu") WHITE_BOLD(" threads)") " scratchpad " CYAN_BOLD("%zu KB"), + tag, profileName.data(), threads.size(), algo.memory() / 1024 @@ -170,12 +172,8 @@ const xmrig::String &xmrig::CpuBackend::type() const } -void xmrig::CpuBackend::prepare(const Job &nextJob) +void xmrig::CpuBackend::prepare(const Job &) { - if (nextJob.algorithm().family() == Algorithm::RANDOM_X && nextJob.algorithm() != d_ptr->algo) { - d_ptr->workers.stop(); - d_ptr->threads.clear(); - } } @@ -207,9 +205,7 @@ void xmrig::CpuBackend::printHashrate(bool details) void xmrig::CpuBackend::setJob(const Job &job) { if (!isEnabled()) { - d_ptr->workers.stop(); - d_ptr->threads.clear(); - return; + return stop(); } const CpuConfig &cpu = d_ptr->controller->config()->cpu(); @@ -249,7 +245,8 @@ void xmrig::CpuBackend::start(IWorker *worker) const double percent = d_ptr->status.hugePages == 0 ? 0.0 : static_cast(d_ptr->status.hugePages) / d_ptr->status.pages * 100.0; const size_t memory = d_ptr->status.ways * d_ptr->status.memory / 1024; - LOG_INFO(GREEN_BOLD("CPU READY") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"), + LOG_INFO("%s" GREEN_BOLD(" READY") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"), + tag, d_ptr->status.threads, d_ptr->status.ways, (d_ptr->status.hugePages == d_ptr->status.pages ? GREEN_BOLD_S : (d_ptr->status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)), d_ptr->status.hugePages, d_ptr->status.pages, percent, memory, @@ -265,7 +262,12 @@ void xmrig::CpuBackend::start(IWorker *worker) void xmrig::CpuBackend::stop() { + const uint64_t ts = Chrono::steadyMSecs(); + d_ptr->workers.stop(); + d_ptr->threads.clear(); + + LOG_INFO("%s" YELLOW(" stopped") BLACK_BOLD(" (%" PRIu64 " ms)"), tag, Chrono::steadyMSecs() - ts); } diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h index 078a85460..d8bcb44a7 100644 --- a/src/base/io/log/Log.h +++ b/src/base/io/log/Log.h @@ -85,6 +85,8 @@ private: #define BLUE_BG_BOLD_S CSI "44;1m" #define MAGENTA_BG_S CSI "45m" #define MAGENTA_BG_BOLD_S CSI "45;1m" +#define CYAN_BG_S CSI "46m" +#define CYAN_BG_BOLD_S CSI "46;1m" //color wrappings #define BLACK(x) BLACK_S x CLEAR @@ -108,6 +110,8 @@ private: #define BLUE_BG_BOLD(x) BLUE_BG_BOLD_S x CLEAR #define MAGENTA_BG(x) MAGENTA_BG_S x CLEAR #define MAGENTA_BG_BOLD(x) MAGENTA_BG_BOLD_S x CLEAR +#define CYAN_BG(x) CYAN_BG_S x CLEAR +#define CYAN_BG_BOLD(x) CYAN_BG_BOLD_S x CLEAR #define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__) diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index ab4a8ef67..a1c65ed26 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -361,12 +361,18 @@ void xmrig::Miner::setEnabled(bool enabled) void xmrig::Miner::setJob(const Job &job, bool donate) { - d_ptr->algorithm = job.algorithm(); - for (IBackend *backend : d_ptr->backends) { backend->prepare(job); } +# ifdef XMRIG_ALGO_RANDOMX + if (d_ptr->algorithm.family() == Algorithm::RANDOM_X && job.algorithm().family() == Algorithm::RANDOM_X && !Rx::isReady(job)) { + stop(); + } +# endif + + d_ptr->algorithm = job.algorithm(); + uv_rwlock_wrlock(&d_ptr->rwlock); const uint8_t index = donate ? 1 : 0; diff --git a/src/crypto/rx/Rx.cpp b/src/crypto/rx/Rx.cpp index 5f5414c91..6df708be1 100644 --- a/src/crypto/rx/Rx.cpp +++ b/src/crypto/rx/Rx.cpp @@ -54,7 +54,7 @@ namespace xmrig { class RxPrivate; -static const char *tag = BLUE_BG(WHITE_BOLD_S " rx ") " "; +static const char *tag = BLUE_BG(WHITE_BOLD_S " rx ") " "; static RxPrivate *d_ptr = nullptr; @@ -231,6 +231,14 @@ private: } // namespace xmrig +bool xmrig::Rx::isReady(const Job &job) +{ + std::lock_guard lock(d_ptr->mutex); + + return d_ptr->isReady(job); +} + + xmrig::RxDataset *xmrig::Rx::dataset(const Job &job, uint32_t nodeId) { std::lock_guard lock(d_ptr->mutex); diff --git a/src/crypto/rx/Rx.h b/src/crypto/rx/Rx.h index 1ba6397e0..7cb94b4eb 100644 --- a/src/crypto/rx/Rx.h +++ b/src/crypto/rx/Rx.h @@ -44,6 +44,7 @@ class Job; class Rx { public: + static bool isReady(const Job &job); static RxDataset *dataset(const Job &job, uint32_t nodeId); static std::pair hugePages(); static void destroy();