From 4a32494060990f3e30fef5f5c445f866cba635c1 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 25 Jul 2019 12:20:59 +0700 Subject: [PATCH] Added option "init-threads". --- src/backend/cpu/CpuConfig.cpp | 16 ++++++++++++++-- src/backend/cpu/CpuConfig.h | 1 + src/crypto/rx/Rx.cpp | 20 +++++++++++++++----- src/crypto/rx/Rx.h | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/backend/cpu/CpuConfig.cpp b/src/backend/cpu/CpuConfig.cpp index 4c86ceead..039c65f4a 100644 --- a/src/backend/cpu/CpuConfig.cpp +++ b/src/backend/cpu/CpuConfig.cpp @@ -29,12 +29,18 @@ #include "rapidjson/document.h" +#ifdef XMRIG_ALGO_RANDOMX +# include "crypto/rx/Rx.h" +#endif + + namespace xmrig { static const char *kCn = "cn"; static const char *kEnabled = "enabled"; static const char *kHugePages = "huge-pages"; static const char *kHwAes = "hw-aes"; +static const char *kInitThreads = "init-threads"; static const char *kPriority = "priority"; #ifdef XMRIG_FEATURE_ASM @@ -89,6 +95,7 @@ rapidjson::Value xmrig::CpuConfig::toJSON(rapidjson::Document &doc) const obj.AddMember(StringRef(kHugePages), m_hugePages, allocator); obj.AddMember(StringRef(kHwAes), m_aes == AES_AUTO ? Value(kNullType) : Value(m_aes == AES_HW), allocator); obj.AddMember(StringRef(kPriority), priority() != -1 ? Value(priority()) : Value(kNullType), allocator); + obj.AddMember(StringRef(kInitThreads), m_initThreads, allocator); # ifdef XMRIG_FEATURE_ASM obj.AddMember(StringRef(kAsm), m_assembly.toJSON(), allocator); @@ -122,8 +129,9 @@ std::vector xmrig::CpuConfig::get(const Miner *miner, cons void xmrig::CpuConfig::read(const rapidjson::Value &value) { if (value.IsObject()) { - m_enabled = Json::getBool(value, kEnabled, m_enabled); - m_hugePages = Json::getBool(value, kHugePages, m_hugePages); + m_enabled = Json::getBool(value, kEnabled, m_enabled); + m_hugePages = Json::getBool(value, kHugePages, m_hugePages); + m_initThreads = Json::getInt(value, kInitThreads, m_initThreads); setAesMode(Json::getValue(value, kHwAes)); setPriority(Json::getInt(value, kPriority, -1)); @@ -132,6 +140,10 @@ void xmrig::CpuConfig::read(const rapidjson::Value &value) m_assembly = Json::getValue(value, kAsm); # endif +# ifdef XMRIG_ALGO_RANDOMX + Rx::setInitThreads(m_initThreads); +# endif + if (!m_threads.read(value)) { generate(); } diff --git a/src/backend/cpu/CpuConfig.h b/src/backend/cpu/CpuConfig.h index 5b2f3f862..0c44972fe 100644 --- a/src/backend/cpu/CpuConfig.h +++ b/src/backend/cpu/CpuConfig.h @@ -69,6 +69,7 @@ private: bool m_enabled = true; bool m_hugePages = true; bool m_shouldSave = false; + int m_initThreads = -1; int m_priority = -1; Threads m_threads; }; diff --git a/src/crypto/rx/Rx.cpp b/src/crypto/rx/Rx.cpp index 4125d81ff..6f2085964 100644 --- a/src/crypto/rx/Rx.cpp +++ b/src/crypto/rx/Rx.cpp @@ -61,8 +61,8 @@ public: inline void unlock() { uv_mutex_unlock(&mutex); } - RxDataset *dataset = nullptr; - uint32_t initThreads = std::thread::hardware_concurrency(); + int initThreads = -1; + RxDataset *dataset = nullptr; uv_mutex_t mutex; }; @@ -121,13 +121,15 @@ xmrig::RxDataset *xmrig::Rx::dataset(const uint8_t *seed, const Algorithm &algor } if (!d_ptr->dataset->isReady(seed, algorithm)) { - const uint64_t ts = Chrono::steadyMSecs(); + const uint64_t ts = Chrono::steadyMSecs(); + const uint32_t threads = d_ptr->initThreads < 1 ? static_cast(Cpu::info()->threads()) + : static_cast(d_ptr->initThreads); if (d_ptr->dataset->get() != nullptr) { LOG_INFO("%s" MAGENTA_BOLD(" init dataset") " algo " WHITE_BOLD("%s (") CYAN_BOLD("%u") WHITE_BOLD(" threads)") BLACK_BOLD(" seed %s..."), tag, algorithm.shortName(), - d_ptr->initThreads, + threads, Buffer::toHex(seed, 8).data() ); } @@ -139,7 +141,7 @@ xmrig::RxDataset *xmrig::Rx::dataset(const uint8_t *seed, const Algorithm &algor ); } - d_ptr->dataset->init(seed, algorithm, d_ptr->initThreads); + d_ptr->dataset->init(seed, algorithm, threads); LOG_INFO("%s" GREEN(" init done") BLACK_BOLD(" (%" PRIu64 " ms)"), tag, Chrono::steadyMSecs() - ts); } @@ -151,6 +153,14 @@ xmrig::RxDataset *xmrig::Rx::dataset(const uint8_t *seed, const Algorithm &algor } +void xmrig::Rx::setInitThreads(int count) +{ + d_ptr->lock(); + d_ptr->initThreads = count; + d_ptr->unlock(); +} + + void xmrig::Rx::stop() { delete d_ptr; diff --git a/src/crypto/rx/Rx.h b/src/crypto/rx/Rx.h index 63bb2e142..1758c08ec 100644 --- a/src/crypto/rx/Rx.h +++ b/src/crypto/rx/Rx.h @@ -44,6 +44,7 @@ class Rx public: static RxDataset *dataset(); static RxDataset *dataset(const uint8_t *seed, const Algorithm &algorithm, bool hugePages = true); + static void setInitThreads(int count); static void stop(); };