From 9660dfc7b3eff98495e0b379f30e62d4ef824504 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 21 Jul 2019 04:35:52 +0700 Subject: [PATCH] Workaround for unsupported intensity option + warning. --- src/backend/common/Threads.h | 2 +- src/backend/common/Workers.cpp | 82 +++++++++++++++++++++++----------- src/backend/common/Workers.h | 3 +- 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/backend/common/Threads.h b/src/backend/common/Threads.h index 126245f68..bc9e36fd8 100644 --- a/src/backend/common/Threads.h +++ b/src/backend/common/Threads.h @@ -43,7 +43,7 @@ class Threads { public: inline bool has(const char *profile) const { return m_profiles.count(profile) > 0; } - inline bool isDisabled(const Algorithm &algo) const { return m_disabled.count(algo) > 0 || algo == Algorithm::RX_0; } + inline bool isDisabled(const Algorithm &algo) const { return m_disabled.count(algo) > 0; } inline bool isExist(const Algorithm &algo) const { return isDisabled(algo) || m_aliases.count(algo) > 0 || has(algo.shortName()); } inline const std::vector &get(const Algorithm &algo, bool strict = false) const { return get(profileName(algo, strict)); } inline void disable(const Algorithm &algo) { m_disabled.insert(algo); } diff --git a/src/backend/common/Workers.cpp b/src/backend/common/Workers.cpp index d70546d31..6a369c1b5 100644 --- a/src/backend/common/Workers.cpp +++ b/src/backend/common/Workers.cpp @@ -137,52 +137,84 @@ void xmrig::Workers::tick(uint64_t) template -void xmrig::Workers::onReady(void *) +xmrig::IWorker *xmrig::Workers::create(Thread *) { + return nullptr; +} + + +template +void xmrig::Workers::onReady(void *arg) +{ + Thread *handle = static_cast* >(arg); + + IWorker *worker = create(handle); + if (!worker || !worker->selfTest()) { + LOG_ERR("thread %zu error: \"hash self-test failed\".", worker->id()); + + return; + } + + handle->setWorker(worker); + handle->backend()->start(worker); } namespace xmrig { -template<> -void xmrig::Workers::onReady(void *arg) +#if defined (XMRIG_ALGO_RANDOMX) || defined (XMRIG_ALGO_CN_GPU) +static void printIntensityWarning(Thread *handle) { - auto handle = static_cast* >(arg); + LOG_WARN("CPU thread %zu warning: \"intensity %d not supported for %s algorithm\".", handle->index(), handle->config().intensity, handle->config().algorithm.shortName()); +} +#endif - IWorker *worker = nullptr; - switch (handle->config().intensity) { +template<> +xmrig::IWorker *xmrig::Workers::create(Thread *handle) +{ + const int intensity = handle->config().intensity; + +# if defined (XMRIG_ALGO_RANDOMX) || defined (XMRIG_ALGO_CN_GPU) + if (intensity > 1) { +# ifdef XMRIG_ALGO_RANDOMX + if (handle->config().algorithm.family() == Algorithm::RANDOM_X) { + printIntensityWarning(handle); + + return new CpuWorker<1>(handle->index(), handle->config()); + } +# endif + +# ifdef XMRIG_ALGO_CN_GPU + if (handle->config().algorithm == Algorithm::CN_GPU) { + printIntensityWarning(handle); + + return new CpuWorker<1>(handle->index(), handle->config()); + } +# endif + } +# endif + + + switch (intensity) { case 1: - worker = new CpuWorker<1>(handle->index(), handle->config()); - break; + return new CpuWorker<1>(handle->index(), handle->config()); case 2: - worker = new CpuWorker<2>(handle->index(), handle->config()); - break; + return new CpuWorker<2>(handle->index(), handle->config()); case 3: - worker = new CpuWorker<3>(handle->index(), handle->config()); - break; + return new CpuWorker<3>(handle->index(), handle->config()); case 4: - worker = new CpuWorker<4>(handle->index(), handle->config()); - break; + return new CpuWorker<4>(handle->index(), handle->config()); case 5: - worker = new CpuWorker<5>(handle->index(), handle->config()); - break; + return new CpuWorker<5>(handle->index(), handle->config()); } - handle->setWorker(worker); - - if (!worker->selfTest()) { - LOG_ERR("thread %zu error: \"hash self-test failed\".", handle->worker()->id()); - - return; - } - - handle->backend()->start(worker); + return nullptr; } diff --git a/src/backend/common/Workers.h b/src/backend/common/Workers.h index 32d9458a0..77dd434c2 100644 --- a/src/backend/common/Workers.h +++ b/src/backend/common/Workers.h @@ -52,6 +52,7 @@ public: void tick(uint64_t ticks); private: + static IWorker *create(Thread *handle); static void onReady(void *arg); std::vector *> m_workers; @@ -60,7 +61,7 @@ private: template<> -void Workers::onReady(void *arg); +IWorker *Workers::create(Thread *handle); extern template class Workers;