From a152d6be42f8a158f8ff2965b953639c8789beb6 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 16 Oct 2020 02:18:07 +0700 Subject: [PATCH] Added CMake option WITH_BENCHMARK. --- CMakeLists.txt | 1 + src/backend/common/Worker.h | 24 +++++--- src/backend/common/Workers.cpp | 38 ++++++++---- src/backend/common/interfaces/IWorker.h | 7 ++- src/backend/cpu/CpuWorker.cpp | 30 +++++++--- src/base/base.cmake | 21 ++++--- src/base/kernel/config/BaseTransform.cpp | 27 ++++----- src/base/net/stratum/Job.cpp | 14 +++-- src/base/net/stratum/Job.h | 12 +++- src/base/net/stratum/NullClient.cpp | 2 +- src/base/net/stratum/NullClient.h | 56 +++++++++--------- src/base/net/stratum/Pool.cpp | 73 ++++++++++++++++-------- src/base/net/stratum/Pool.h | 21 ++++++- src/base/net/stratum/Pools.cpp | 12 ++++ src/base/net/stratum/Pools.h | 2 +- src/core/config/ConfigTransform.cpp | 15 +++++ src/core/config/Config_platform.h | 3 + src/core/config/usage.h | 3 + src/net/Network.cpp | 5 +- 19 files changed, 245 insertions(+), 121 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7219bc3..890cf886 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(WITH_STRICT_CACHE "Enable strict checks for OpenCL cache" ON) option(WITH_INTERLEAVE_DEBUG_LOG "Enable debug log for threads interleave" OFF) option(WITH_PROFILING "Enable profiling for developers" OFF) option(WITH_SSE4_1 "Enable SSE 4.1 for Blake2" ON) +option(WITH_BENCHMARK "Enable builtin RandomX benchmark and stress test" ON) option(BUILD_STATIC "Build static binary" OFF) option(ARM_TARGET "Force use specific ARM target 8 or 7" 0) diff --git a/src/backend/common/Worker.h b/src/backend/common/Worker.h index cc38450f..ba00fa3f 100644 --- a/src/backend/common/Worker.h +++ b/src/backend/common/Worker.h @@ -45,24 +45,30 @@ public: inline const VirtualMemory *memory() const override { return nullptr; } inline size_t id() const override { return m_id; } inline uint64_t rawHashes() const override { return m_count; } + inline void jobEarlyNotification(const Job&) override {} + + void getHashrateData(uint64_t& hashCount, uint64_t& timeStamp) const override; + +# ifdef XMRIG_FEATURE_BENCHMARK inline uint64_t benchData() const override { return m_benchData; } inline uint64_t benchDoneTime() const override { return m_benchDoneTime; } - void getHashrateData(uint64_t& hashCount, uint64_t& timeStamp) const override; - inline void jobEarlyNotification(const Job&) override {} +# endif protected: void storeStats(); const int64_t m_affinity; const size_t m_id; - uint64_t m_hashCount[2] = {}; - uint64_t m_timestamp[2] = {}; - std::atomic m_index = {}; - uint32_t m_node = 0; - uint64_t m_count = 0; + std::atomic m_index = {}; + uint32_t m_node = 0; + uint64_t m_count = 0; + uint64_t m_hashCount[2] = {}; + uint64_t m_timestamp[2] = {}; - uint64_t m_benchData = 0; - uint64_t m_benchDoneTime = 0; +# ifdef XMRIG_FEATURE_BENCHMARK + uint64_t m_benchData = 0; + uint64_t m_benchDoneTime = 0; +# endif }; diff --git a/src/backend/common/Workers.cpp b/src/backend/common/Workers.cpp index 8dd2b145..08743ab3 100644 --- a/src/backend/common/Workers.cpp +++ b/src/backend/common/Workers.cpp @@ -67,9 +67,11 @@ public: Hashrate *hashrate = nullptr; IBackend *backend = nullptr; - uint32_t bench = 0; +# ifdef XMRIG_FEATURE_BENCHMARK Algorithm benchAlgo = Algorithm::RX_0; + uint32_t bench = 0; uint64_t startTime = 0; +# endif }; @@ -108,10 +110,12 @@ void xmrig::Workers::setBackend(IBackend *backend) template void xmrig::Workers::start(const std::vector &data) { +# ifdef XMRIG_FEATURE_BENCHMARK if (!data.empty()) { - d_ptr->bench = data.front().miner->job().bench(); - d_ptr->benchAlgo = data.front().miner->job().algorithm(); + d_ptr->bench = data.front().miner->job().bench(); + d_ptr->benchAlgo = data.front().algorithm; } +# endif for (const T &item : data) { m_workers.push_back(new Thread(d_ptr->backend, m_workers.size(), item)); @@ -123,12 +127,17 @@ void xmrig::Workers::start(const std::vector &data) for (Thread *worker : m_workers) { worker->start(Workers::onReady); - if (!d_ptr->bench) { +# ifdef XMRIG_FEATURE_BENCHMARK + if (!d_ptr->bench) +# endif + { std::this_thread::sleep_for(std::chrono::milliseconds(20)); } } +# ifdef XMRIG_FEATURE_BENCHMARK d_ptr->startTime = Chrono::steadyMSecs(); +# endif } @@ -170,21 +179,22 @@ bool xmrig::Workers::tick(uint64_t) return true; } - uint64_t timeStamp = Chrono::steadyMSecs(); - - bool totalAvailable = true; + uint64_t ts = Chrono::steadyMSecs(); + bool totalAvailable = true; uint64_t totalHashCount = 0; - uint32_t benchDone = 0; - uint64_t benchData = 0; - uint64_t benchDoneTime = 0; +# ifdef XMRIG_FEATURE_BENCHMARK + uint32_t benchDone = 0; + uint64_t benchData = 0; + uint64_t benchDoneTime = 0; +# endif for (Thread *handle : m_workers) { IWorker* worker = handle->worker(); if (worker) { uint64_t hashCount; - getHashrateData(worker, hashCount, timeStamp); - d_ptr->hashrate->add(handle->id() + 1, hashCount, timeStamp); + getHashrateData(worker, hashCount, ts); + d_ptr->hashrate->add(handle->id() + 1, hashCount, ts); const uint64_t n = worker->rawHashes(); if (n == 0) { @@ -192,6 +202,7 @@ bool xmrig::Workers::tick(uint64_t) } totalHashCount += n; +# ifdef XMRIG_FEATURE_BENCHMARK if (d_ptr->bench && worker->benchDoneTime()) { ++benchDone; benchData ^= worker->benchData(); @@ -199,6 +210,7 @@ bool xmrig::Workers::tick(uint64_t) benchDoneTime = worker->benchDoneTime(); } } +# endif } } @@ -206,6 +218,7 @@ bool xmrig::Workers::tick(uint64_t) d_ptr->hashrate->add(0, totalHashCount, Chrono::steadyMSecs()); } +# ifdef XMRIG_FEATURE_BENCHMARK if (d_ptr->bench) { Pool::benchProgress = std::min(static_cast((totalHashCount * 100U) / d_ptr->bench), 100U); @@ -232,6 +245,7 @@ bool xmrig::Workers::tick(uint64_t) return false; } } +# endif return true; } diff --git a/src/backend/common/interfaces/IWorker.h b/src/backend/common/interfaces/IWorker.h index 3645f6a8..dcc925dc 100644 --- a/src/backend/common/interfaces/IWorker.h +++ b/src/backend/common/interfaces/IWorker.h @@ -47,11 +47,14 @@ public: virtual size_t id() const = 0; virtual size_t intensity() const = 0; virtual uint64_t rawHashes() const = 0; - virtual uint64_t benchData() const = 0; - virtual uint64_t benchDoneTime() const = 0; virtual void getHashrateData(uint64_t&, uint64_t&) const = 0; virtual void start() = 0; virtual void jobEarlyNotification(const Job&) = 0; + +# ifdef XMRIG_FEATURE_BENCHMARK + virtual uint64_t benchData() const = 0; + virtual uint64_t benchDoneTime() const = 0; +# endif }; diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index 5211bed2..4be13fba 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -60,10 +60,16 @@ static constexpr uint32_t kReserveCount = 32768; template inline bool nextRound(WorkerJob &job) { - const Job& curJob = job.currentJob(); - const uint32_t bench = curJob.bench(); - if (!job.nextRound(bench ? 1 : kReserveCount, 1)) { - JobResults::done(curJob); + const auto ¤tJob = job.currentJob(); + +# ifdef XMRIG_FEATURE_BENCHMARK + const uint32_t rounds = currentJob.bench() ? 1 : kReserveCount; +# else + constexpr uint32_t rounds = kReserveCount; +# endif + + if (!job.nextRound(rounds, 1)) { + JobResults::done(currentJob); return false; } @@ -270,6 +276,7 @@ void xmrig::CpuWorker::start() for (size_t i = 0; i < N; ++i) { const uint64_t value = *reinterpret_cast(m_hash + (i * 32) + 24); +# ifdef XMRIG_FEATURE_BENCHMARK if (job.bench()) { if (current_job_nonces[i] < job.bench()) { m_benchData ^= value; @@ -279,7 +286,9 @@ void xmrig::CpuWorker::start() return; } } - else if (value < job.target()) { + else +# endif + if (value < job.target()) { JobResults::submit(job, current_job_nonces[i], m_hash + (i * 32)); } } @@ -376,8 +385,15 @@ void xmrig::CpuWorker::consumeJob() return; } - const uint32_t bench = m_miner->job().bench(); - m_job.add(m_miner->job(), bench ? 1 : kReserveCount, Nonce::CPU); + auto job = m_miner->job(); + +# ifdef XMRIG_FEATURE_BENCHMARK + const uint32_t rounds = job.bench() ? 1 : kReserveCount; +# else + constexpr uint32_t rounds = kReserveCount; +# endif + + m_job.add(job, rounds, Nonce::CPU); # ifdef XMRIG_ALGO_RANDOMX if (m_job.currentJob().algorithm().family() == Algorithm::RANDOM_X) { diff --git a/src/base/base.cmake b/src/base/base.cmake index 230f4730..a49a717e 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -44,7 +44,6 @@ set(HEADERS_BASE src/base/net/http/HttpListener.h src/base/net/stratum/BaseClient.h src/base/net/stratum/Client.h - src/base/net/stratum/NullClient.h src/base/net/stratum/Job.h src/base/net/stratum/NetworkState.h src/base/net/stratum/Pool.h @@ -98,7 +97,6 @@ set(SOURCES_BASE src/base/net/http/Http.cpp src/base/net/stratum/BaseClient.cpp src/base/net/stratum/Client.cpp - src/base/net/stratum/NullClient.cpp src/base/net/stratum/Job.cpp src/base/net/stratum/NetworkState.cpp src/base/net/stratum/Pool.cpp @@ -229,11 +227,16 @@ endif() if (WITH_PROFILING) add_definitions(/DXMRIG_FEATURE_PROFILING) - list(APPEND HEADERS_BASE - src/base/tools/Profiler.h - ) - - list(APPEND SOURCES_BASE - src/base/tools/Profiler.cpp - ) + list(APPEND HEADERS_BASE src/base/tools/Profiler.h) + list(APPEND SOURCES_BASE src/base/tools/Profiler.cpp) +endif() + + +if (WITH_RANDOMX AND WITH_BENCHMARK) + add_definitions(/DXMRIG_FEATURE_BENCHMARK) + + list(APPEND HEADERS_BASE src/base/net/stratum/NullClient.h) + list(APPEND SOURCES_BASE src/base/net/stratum/NullClient.cpp) +else() + remove_definitions(/DXMRIG_FEATURE_BENCHMARK) endif() diff --git a/src/base/kernel/config/BaseTransform.cpp b/src/base/kernel/config/BaseTransform.cpp index 3694c73f..966bf2e0 100644 --- a/src/base/kernel/config/BaseTransform.cpp +++ b/src/base/kernel/config/BaseTransform.cpp @@ -151,9 +151,9 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch } break; - case IConfig::UrlKey: /* --url */ + case IConfig::UrlKey: /* --url */ case IConfig::StressKey: /* --stress */ - case IConfig::BenchKey: /* --bench */ + case IConfig::BenchKey: /* --bench */ { if (!doc.HasMember(Pools::kPools)) { doc.AddMember(rapidjson::StringRef(Pools::kPools), rapidjson::kArrayType, doc.GetAllocator()); @@ -164,19 +164,20 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch array.PushBack(rapidjson::kObjectType, doc.GetAllocator()); } - if (key == IConfig::UrlKey) { +# ifdef XMRIG_FEATURE_BENCHMARK + if (key != IConfig::UrlKey) { + set(doc, array[array.Size() - 1], Pool::kUrl, (key == IConfig::BenchKey) ? "benchmark" : +# ifdef XMRIG_FEATURE_TLS + "stratum+ssl://randomx.xmrig.com:443" +# else + "randomx.xmrig.com:3333" +# endif + ); + } else +# endif + { set(doc, array[array.Size() - 1], Pool::kUrl, arg); } - else { - set(doc, array[array.Size() - 1], Pool::kUrl, (key == IConfig::BenchKey) ? "offline" : "donate.v2.xmrig.com:3333"); - set(doc, "cpu", "huge-pages-jit", true); - set(doc, "cpu", "priority", 2); - set(doc, "cpu", "yield", false); - if (key == IConfig::BenchKey) { - set(doc, array[array.Size() - 1], Pool::kBenchmark, arg); - } - } - break; } diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index d790fccf..e826b8b8 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -6,9 +6,9 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018 SChernykh * Copyright 2019 Howard Chu - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -154,7 +154,6 @@ void xmrig::Job::copy(const Job &other) { m_algorithm = other.m_algorithm; m_nicehash = other.m_nicehash; - m_bench = other.m_bench; m_size = other.m_size; m_clientId = other.m_clientId; m_id = other.m_id; @@ -175,6 +174,10 @@ void xmrig::Job::copy(const Job &other) memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob)); memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget)); # endif + +# ifdef XMRIG_FEATURE_BENCHMARK + m_bench = other.m_bench; +# endif } @@ -182,7 +185,6 @@ void xmrig::Job::move(Job &&other) { m_algorithm = other.m_algorithm; m_nicehash = other.m_nicehash; - m_bench = other.m_bench; m_size = other.m_size; m_clientId = std::move(other.m_clientId); m_id = std::move(other.m_id); @@ -207,4 +209,8 @@ void xmrig::Job::move(Job &&other) memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob)); memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget)); # endif + +# ifdef XMRIG_FEATURE_BENCHMARK + m_bench = other.m_bench; +# endif } diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 31e37760..4507f67c 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -87,7 +87,6 @@ public: inline uint8_t *blob() { return m_blob; } inline uint8_t fixedByte() const { return *(m_blob + 42); } inline uint8_t index() const { return m_index; } - inline uint32_t bench() const { return m_bench; } inline void reset() { m_size = 0; m_diff = 0; } inline void setAlgorithm(const Algorithm::Id id) { m_algorithm = id; } inline void setAlgorithm(const char *algo) { m_algorithm = algo; } @@ -97,7 +96,6 @@ public: inline void setHeight(uint64_t height) { m_height = height; } inline void setIndex(uint8_t index) { m_index = index; } inline void setPoolWallet(const String &poolWallet) { m_poolWallet = poolWallet; } - inline void setBench(uint32_t bench) { m_bench = bench; } # ifdef XMRIG_PROXY_PROJECT inline char *rawBlob() { return m_rawBlob; } @@ -113,13 +111,17 @@ public: inline Job &operator=(const Job &other) { copy(other); return *this; } inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; } +# ifdef XMRIG_FEATURE_BENCHMARK + inline uint32_t bench() const { return m_bench; } + inline void setBench(uint32_t bench) { m_bench = bench; } +# endif + private: void copy(const Job &other); void move(Job &&other); Algorithm m_algorithm; bool m_nicehash = false; - uint32_t m_bench = 0; Buffer m_seed; size_t m_size = 0; String m_clientId; @@ -138,6 +140,10 @@ private: char m_rawTarget[24]{}; String m_rawSeedHash; # endif + +# ifdef XMRIG_FEATURE_BENCHMARK + uint32_t m_bench = 0; +# endif }; diff --git a/src/base/net/stratum/NullClient.cpp b/src/base/net/stratum/NullClient.cpp index a18638fe..a9358881 100644 --- a/src/base/net/stratum/NullClient.cpp +++ b/src/base/net/stratum/NullClient.cpp @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#include "3rdparty/rapidjson/document.h" #include "base/net/stratum/NullClient.h" +#include "3rdparty/rapidjson/document.h" #include "base/kernel/interfaces/IClientListener.h" diff --git a/src/base/net/stratum/NullClient.h b/src/base/net/stratum/NullClient.h index e6b024ba..d8fc6d96 100644 --- a/src/base/net/stratum/NullClient.h +++ b/src/base/net/stratum/NullClient.h @@ -34,37 +34,37 @@ public: NullClient(IClientListener* listener); ~NullClient() override = default; - virtual bool disconnect() override { return true; } - virtual bool hasExtension(Extension extension) const noexcept override { return false; } - virtual bool isEnabled() const override { return true; } - virtual bool isTLS() const override { return false; } - virtual const char* mode() const override { return "benchmark"; } - virtual const char* tag() const override { return "null"; } - virtual const char* tlsFingerprint() const override { return nullptr; } - virtual const char* tlsVersion() const override { return nullptr; } - virtual const Job& job() const override { return m_job; } - virtual const Pool& pool() const override { return m_pool; } - virtual const String& ip() const override { return m_ip; } - virtual int id() const override { return 0; } - virtual int64_t send(const rapidjson::Value& obj, Callback callback) override { return 0; } - virtual int64_t send(const rapidjson::Value& obj) override { return 0; } - virtual int64_t sequence() const override { return 0; } - virtual int64_t submit(const JobResult& result) override { return 0; } - virtual void connect() override; - virtual void connect(const Pool& pool) override { setPool(pool); } - virtual void deleteLater() override {} - virtual void setAlgo(const Algorithm& algo) override {} - virtual void setEnabled(bool enabled) override {} - virtual void setPool(const Pool& pool) override; - virtual void setProxy(const ProxyUrl& proxy) override {} - virtual void setQuiet(bool quiet) override {} - virtual void setRetries(int retries) override {} - virtual void setRetryPause(uint64_t ms) override {} - virtual void tick(uint64_t now) override {} + inline bool disconnect() override { return true; } + inline bool hasExtension(Extension extension) const noexcept override { return false; } + inline bool isEnabled() const override { return true; } + inline bool isTLS() const override { return false; } + inline const char *mode() const override { return "benchmark"; } + inline const char *tag() const override { return "null"; } + inline const char *tlsFingerprint() const override { return nullptr; } + inline const char *tlsVersion() const override { return nullptr; } + inline const Job &job() const override { return m_job; } + inline const Pool &pool() const override { return m_pool; } + inline const String &ip() const override { return m_ip; } + inline int id() const override { return 0; } + inline int64_t send(const rapidjson::Value& obj, Callback callback) override { return 0; } + inline int64_t send(const rapidjson::Value& obj) override { return 0; } + inline int64_t sequence() const override { return 0; } + inline int64_t submit(const JobResult& result) override { return 0; } + inline void connect(const Pool& pool) override { setPool(pool); } + inline void deleteLater() override {} + inline void setAlgo(const Algorithm& algo) override {} + inline void setEnabled(bool enabled) override {} + inline void setProxy(const ProxyUrl& proxy) override {} + inline void setQuiet(bool quiet) override {} + inline void setRetries(int retries) override {} + inline void setRetryPause(uint64_t ms) override {} + inline void tick(uint64_t now) override {} + + void connect() override; + void setPool(const Pool& pool) override; private: IClientListener* m_listener; - Job m_job; Pool m_pool; String m_ip; diff --git a/src/base/net/stratum/Pool.cpp b/src/base/net/stratum/Pool.cpp index bacc2182..847f4bfb 100644 --- a/src/base/net/stratum/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -50,7 +50,9 @@ #endif -#include "base/net/stratum/NullClient.h" +#ifdef XMRIG_FEATURE_BENCHMARK +# include "base/net/stratum/NullClient.h" +#endif #ifdef _MSC_VER @@ -80,10 +82,11 @@ const char *Pool::kSOCKS5 = "socks5"; const char *Pool::kTls = "tls"; const char *Pool::kUrl = "url"; const char *Pool::kUser = "user"; +const char *Pool::kNicehashHost = "nicehash.com"; + +#ifdef XMRIG_FEATURE_BENCHMARK const char *Pool::kBenchmark = "benchmark"; - - -const char *Pool::kNicehashHost = "nicehash.com"; +#endif uint32_t Pool::benchProgress = 0; @@ -137,35 +140,22 @@ xmrig::Pool::Pool(const rapidjson::Value &object) : m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash) || m_url.host().contains(kNicehashHost)); m_flags.set(FLAG_TLS, Json::getBool(object, kTls) || m_url.isTLS()); - const char* benchSize = Json::getString(object, kBenchmark, nullptr); - if (benchSize) { - std::string s; - for (int i = 1; i <= 10; ++i) { - s = std::to_string(i) + "M"; - if (strcasecmp(benchSize, s.c_str()) == 0) { - m_benchSize = i * 1000000; - break; - } - } - } + setKeepAlive(Json::getValue(object, kKeepalive)); - if (m_benchSize) { +# ifdef XMRIG_FEATURE_BENCHMARK + if (setBenchSize(Json::getString(object, kBenchmark, nullptr))) { m_mode = MODE_BENCHMARK; + + return; } - else if (m_daemon.isValid()) { +# endif + + if (m_daemon.isValid()) { m_mode = MODE_SELF_SELECT; } else if (Json::getBool(object, kDaemon)) { m_mode = MODE_DAEMON; } - - const rapidjson::Value &keepalive = Json::getValue(object, kKeepalive); - if (keepalive.IsInt()) { - setKeepAlive(keepalive.GetInt()); - } - else if (keepalive.IsBool()) { - setKeepAlive(keepalive.GetBool()); - } } @@ -244,9 +234,11 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con client = new AutoClient(id, Platform::userAgent(), listener); } # endif +# ifdef XMRIG_FEATURE_BENCHMARK else if (m_mode == MODE_BENCHMARK) { client = new NullClient(listener); } +# endif assert(client != nullptr); @@ -337,3 +329,34 @@ void xmrig::Pool::print() const LOG_DEBUG ("keepAlive: %d", m_keepAlive); } #endif + + +void xmrig::Pool::setKeepAlive(const rapidjson::Value &value) +{ + if (value.IsInt()) { + setKeepAlive(value.GetInt()); + } + else if (value.IsBool()) { + setKeepAlive(value.GetBool()); + } +} + + +#ifdef XMRIG_FEATURE_BENCHMARK +bool xmrig::Pool::setBenchSize(const char *benchmark) +{ + if (!benchmark) { + return false; + } + + const auto size = strtoul(benchmark, nullptr, 10); + if (size < 1 || size > 10) { + return false; + } + + const std::string s = std::to_string(size) + "M"; + m_benchSize = strcasecmp(benchmark, s.c_str()) == 0 ? size * 1000000 : 0; + + return m_benchSize > 0; +} +#endif diff --git a/src/base/net/stratum/Pool.h b/src/base/net/stratum/Pool.h index bb1aaf61..271e9106 100644 --- a/src/base/net/stratum/Pool.h +++ b/src/base/net/stratum/Pool.h @@ -51,7 +51,9 @@ public: MODE_DAEMON, MODE_SELF_SELECT, MODE_AUTO_ETH, +# ifdef XMRIG_FEATURE_BENCHMARK MODE_BENCHMARK, +# endif }; static const String kDefaultPassword; @@ -72,9 +74,12 @@ public: static const char *kTls; static const char *kUrl; static const char *kUser; - static const char* kBenchmark; static const char *kNicehashHost; +# ifdef XMRIG_FEATURE_BENCHMARK + static const char *kBenchmark; +# endif + constexpr static int kKeepAliveTimeout = 60; constexpr static uint16_t kDefaultPort = 3333; constexpr static uint64_t kDefaultPollInterval = 1000; @@ -99,7 +104,6 @@ public: inline const Url &daemon() const { return m_daemon; } inline int keepAlive() const { return m_keepAlive; } inline Mode mode() const { return m_mode; } - inline uint64_t benchSize() const { return m_benchSize; } inline uint16_t port() const { return m_url.port(); } inline uint64_t pollInterval() const { return m_pollInterval; } inline void setAlgo(const Algorithm &algorithm) { m_algorithm = algorithm; } @@ -108,6 +112,10 @@ public: inline void setRigId(const String &rigId) { m_rigId = rigId; } inline void setUser(const String &user) { m_user = user; } +# ifdef XMRIG_FEATURE_BENCHMARK + inline uint64_t benchSize() const { return m_benchSize; } +# endif + inline bool operator!=(const Pool &other) const { return !isEqual(other); } inline bool operator==(const Pool &other) const { return isEqual(other); } @@ -134,11 +142,12 @@ private: inline void setKeepAlive(bool enable) { setKeepAlive(enable ? kKeepAliveTimeout : 0); } inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } + void setKeepAlive(const rapidjson::Value &value); + Algorithm m_algorithm; Coin m_coin; int m_keepAlive = 0; Mode m_mode = MODE_POOL; - uint32_t m_benchSize = 0; ProxyUrl m_proxy; std::bitset m_flags = 0; String m_fingerprint; @@ -148,6 +157,12 @@ private: uint64_t m_pollInterval = kDefaultPollInterval; Url m_daemon; Url m_url; + +# ifdef XMRIG_FEATURE_BENCHMARK + bool setBenchSize(const char *benchmark); + + uint32_t m_benchSize = 0; +# endif }; diff --git a/src/base/net/stratum/Pools.cpp b/src/base/net/stratum/Pools.cpp index 90655547..b765a9ef 100644 --- a/src/base/net/stratum/Pools.cpp +++ b/src/base/net/stratum/Pools.cpp @@ -65,6 +65,18 @@ bool xmrig::Pools::isEqual(const Pools &other) const } +int xmrig::Pools::donateLevel() const +{ +# ifdef XMRIG_FEATURE_BENCHMARK + if (m_data.size() == 1 && m_data.front().mode() == Pool::MODE_BENCHMARK) { + return 0; + } +# endif + + return m_donateLevel; +} + + xmrig::IStrategy *xmrig::Pools::createStrategy(IStrategyListener *listener) const { if (active() == 1) { diff --git a/src/base/net/stratum/Pools.h b/src/base/net/stratum/Pools.h index c2713198..9c7bda67 100644 --- a/src/base/net/stratum/Pools.h +++ b/src/base/net/stratum/Pools.h @@ -58,7 +58,6 @@ public: Pools(); inline const std::vector &data() const { return m_data; } - inline int donateLevel() const { return m_donateLevel; } inline int retries() const { return m_retries; } inline int retryPause() const { return m_retryPause; } inline ProxyDonate proxyDonate() const { return m_proxyDonate; } @@ -67,6 +66,7 @@ public: inline bool operator==(const Pools &other) const { return isEqual(other); } bool isEqual(const Pools &other) const; + int donateLevel() const; IStrategy *createStrategy(IStrategyListener *listener) const; rapidjson::Value toJSON(rapidjson::Document &doc) const; size_t active() const; diff --git a/src/core/config/ConfigTransform.cpp b/src/core/config/ConfigTransform.cpp index 80e8d07d..ca6fadcf 100644 --- a/src/core/config/ConfigTransform.cpp +++ b/src/core/config/ConfigTransform.cpp @@ -24,6 +24,8 @@ #include "base/kernel/interfaces/IConfig.h" +#include "base/net/stratum/Pool.h" +#include "base/net/stratum/Pools.h" #include "core/config/ConfigTransform.h" #include "crypto/cn/CnHash.h" @@ -243,6 +245,19 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const return set(doc, "health-print-time", static_cast(strtol(arg, nullptr, 10))); # endif +# ifdef XMRIG_FEATURE_BENCHMARK + case IConfig::StressKey: /* --stress */ + case IConfig::BenchKey: /* --bench */ + set(doc, kCpu, "huge-pages-jit", true); + set(doc, kCpu, "priority", 2); + set(doc, kCpu, "yield", false); + + if (key == IConfig::BenchKey) { + add(doc, Pools::kPools, Pool::kBenchmark, arg); + } + break; +# endif + default: break; } diff --git a/src/core/config/Config_platform.h b/src/core/config/Config_platform.h index 817da6fe..44e94d91 100644 --- a/src/core/config/Config_platform.h +++ b/src/core/config/Config_platform.h @@ -96,8 +96,11 @@ static const option options[] = { { "title", 1, nullptr, IConfig::TitleKey }, { "no-title", 0, nullptr, IConfig::NoTitleKey }, { "pause-on-battery", 0, nullptr, IConfig::PauseOnBatteryKey }, +# ifdef XMRIG_FEATURE_BENCHMARK { "stress", 0, nullptr, IConfig::StressKey }, { "bench", 1, nullptr, IConfig::BenchKey }, + { "benchmark", 1, nullptr, IConfig::BenchKey }, +# endif # ifdef XMRIG_FEATURE_TLS { "tls", 0, nullptr, IConfig::TlsKey }, { "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey }, diff --git a/src/core/config/usage.h b/src/core/config/usage.h index c6fc4cf3..49d22d0f 100644 --- a/src/core/config/usage.h +++ b/src/core/config/usage.h @@ -178,8 +178,11 @@ static inline const std::string &usage() u += " --no-title disable setting console window title\n"; # endif u += " --pause-on-battery pause mine on battery power\n"; + +# ifdef XMRIG_FEATURE_BENCHMARK u += " --stress run continuous stress test to check system stability\n"; u += " --bench=N run benchmark in offline mode, N can be between 1M and 10M\n"; +# endif return u; } diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 18cec549..0bb741d4 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -74,10 +74,7 @@ xmrig::Network::Network(Controller *controller) : m_strategy = pools.createStrategy(m_state); if (pools.donateLevel() > 0) { - const bool bench = (pools.data().size() == 1) && (pools.data().front().mode() == xmrig::Pool::MODE_BENCHMARK); - if (!bench) { - m_donate = new DonateStrategy(controller, this); - } + m_donate = new DonateStrategy(controller, this); } m_timer = new Timer(this, kTickInterval, kTickInterval);