From a2a0defeef680de470bce97247f48ecd4100ac44 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Nov 2020 07:33:20 +0700 Subject: [PATCH] Submit top benchmark diff. --- src/backend/common/benchmark/BenchState.cpp | 6 ++++-- src/backend/common/benchmark/BenchState.h | 2 +- src/backend/common/benchmark/BenchState_test.h | 4 ++++ src/backend/common/interfaces/IBenchListener.h | 2 +- src/backend/cpu/CpuWorker.cpp | 14 +++----------- src/backend/cpu/CpuWorker.h | 1 + src/base/net/stratum/benchmark/BenchClient.cpp | 3 ++- src/base/net/stratum/benchmark/BenchClient.h | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/backend/common/benchmark/BenchState.cpp b/src/backend/common/benchmark/BenchState.cpp index 230435146..38edf6884 100644 --- a/src/backend/common/benchmark/BenchState.cpp +++ b/src/backend/common/benchmark/BenchState.cpp @@ -39,6 +39,7 @@ static std::shared_ptr async; static uint32_t remaining = 0; static uint64_t doneTime = 0; static uint64_t result = 0; +static uint64_t topDiff = 0; IBenchListener *BenchState::m_listener = nullptr; @@ -75,7 +76,7 @@ uint64_t xmrig::BenchState::start(size_t threads, const IBackend *backend) remaining = static_cast(threads); async = std::make_shared([] { - m_listener->onBenchDone(result, doneTime); + m_listener->onBenchDone(result, topDiff, doneTime); async.reset(); xmrig::done = true; }); @@ -94,7 +95,7 @@ void xmrig::BenchState::destroy() } -void xmrig::BenchState::done(uint64_t data, uint64_t ts) +void xmrig::BenchState::done(uint64_t data, uint64_t diff, uint64_t ts) { assert(async && remaining > 0); @@ -102,6 +103,7 @@ void xmrig::BenchState::done(uint64_t data, uint64_t ts) result ^= data; doneTime = std::max(doneTime, ts); + topDiff = std::max(topDiff, diff); --remaining; if (remaining == 0) { diff --git a/src/backend/common/benchmark/BenchState.h b/src/backend/common/benchmark/BenchState.h index 0f4890a96..e451f4a71 100644 --- a/src/backend/common/benchmark/BenchState.h +++ b/src/backend/common/benchmark/BenchState.h @@ -39,7 +39,7 @@ public: static uint64_t referenceHash(const Algorithm &algo, uint32_t size, uint32_t threads); static uint64_t start(size_t threads, const IBackend *backend); static void destroy(); - static void done(uint64_t data, uint64_t ts); + static void done(uint64_t data, uint64_t diff, uint64_t ts); inline static uint32_t size() { return m_size; } inline static void setListener(IBenchListener *listener) { m_listener = listener; } diff --git a/src/backend/common/benchmark/BenchState_test.h b/src/backend/common/benchmark/BenchState_test.h index 0e59a7457..3aa6d87d5 100644 --- a/src/backend/common/benchmark/BenchState_test.h +++ b/src/backend/common/benchmark/BenchState_test.h @@ -33,6 +33,7 @@ static const std::map > hashCheck = { { Algorithm::RX_0, { # ifndef NDEBUG { 10000U, 0x4A597463865ACF0EULL }, + { 20000U, 0xC82B490C757DA738ULL }, # endif { 250000U, 0x7D6054757BB08A63ULL }, { 500000U, 0x96607546DE1F5ECCULL }, @@ -50,6 +51,7 @@ static const std::map > hashCheck = { { Algorithm::RX_WOW, { # ifndef NDEBUG { 10000U, 0x6B0918757100B338ULL }, + { 20000U, 0x0B55785C1837F41BULL }, # endif { 250000U, 0xC7F712C9603E2603ULL }, { 500000U, 0x21A0E5AAE6DA7D8DULL }, @@ -71,6 +73,7 @@ static const std::map > hashCheck1T = { { Algorithm::RX_0, { # ifndef NDEBUG { 10000U, 0xADFC3A66F79BFE7FULL }, + { 20000U, 0x8ED578A60D55C0DBULL }, # endif { 250000U, 0x90A15B799486F3EBULL }, { 500000U, 0xAA83118FEE570F9AULL }, @@ -88,6 +91,7 @@ static const std::map > hashCheck1T = { { Algorithm::RX_WOW, { # ifndef NDEBUG { 10000U, 0x9EC1B9B8C8C7F082ULL }, + { 20000U, 0xF1DA44FA2A20D730ULL }, # endif { 250000U, 0x7B409F096C863207ULL }, { 500000U, 0x70B7B80D15654216ULL }, diff --git a/src/backend/common/interfaces/IBenchListener.h b/src/backend/common/interfaces/IBenchListener.h index 63575b8b7..91ec2e38f 100644 --- a/src/backend/common/interfaces/IBenchListener.h +++ b/src/backend/common/interfaces/IBenchListener.h @@ -37,7 +37,7 @@ public: IBenchListener() = default; virtual ~IBenchListener() = default; - virtual void onBenchDone(uint64_t result, uint64_t ts) = 0; + virtual void onBenchDone(uint64_t result, uint64_t diff, uint64_t ts) = 0; virtual void onBenchStart(uint64_t ts, uint32_t threads, const IBackend *backend) = 0; }; diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index 545754220..afc47766c 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -240,17 +240,8 @@ void xmrig::CpuWorker::start() # ifdef XMRIG_FEATURE_BENCHMARK if (m_benchSize) { - bool done = true; - for (size_t i = 0; i < N; ++i) { - if (current_job_nonces[i] < m_benchSize) { - done = false; - break; - } - } - - // Stop benchmark when all hashes have been counted - if (done) { - return BenchState::done(m_benchData, Chrono::steadyMSecs());; + if (current_job_nonces[0] >= m_benchSize) { + return BenchState::done(m_benchData, m_benchDiff, Chrono::steadyMSecs());; } // Make each hash dependent on the previous one in single thread benchmark to prevent cheating with multiple threads @@ -302,6 +293,7 @@ void xmrig::CpuWorker::start() if (m_benchSize) { if (current_job_nonces[i] < m_benchSize) { m_benchData ^= value; + m_benchDiff = std::max(m_benchDiff, Job::toDiff(value)); } } else diff --git a/src/backend/cpu/CpuWorker.h b/src/backend/cpu/CpuWorker.h index 640cba520..6669f5db3 100644 --- a/src/backend/cpu/CpuWorker.h +++ b/src/backend/cpu/CpuWorker.h @@ -94,6 +94,7 @@ private: # ifdef XMRIG_FEATURE_BENCHMARK uint64_t m_benchData = 0; + uint64_t m_benchDiff = 0; # endif }; diff --git a/src/base/net/stratum/benchmark/BenchClient.cpp b/src/base/net/stratum/benchmark/BenchClient.cpp index 1005ec668..18c7ee8ac 100644 --- a/src/base/net/stratum/benchmark/BenchClient.cpp +++ b/src/base/net/stratum/benchmark/BenchClient.cpp @@ -109,7 +109,7 @@ void xmrig::BenchClient::setPool(const Pool &pool) } -void xmrig::BenchClient::onBenchDone(uint64_t result, uint64_t ts) +void xmrig::BenchClient::onBenchDone(uint64_t result, uint64_t diff, uint64_t ts) { # ifdef XMRIG_FEATURE_HTTP if (!m_token.isEmpty()) { @@ -120,6 +120,7 @@ void xmrig::BenchClient::onBenchDone(uint64_t result, uint64_t ts) doc.AddMember("steady_done_ts", m_doneTime, allocator); doc.AddMember("hash", rapidjson::Value(fmt::format("{:016X}", result).c_str(), allocator), allocator); + doc.AddMember("diff", diff, allocator); doc.AddMember("backend", m_backend->toJSON(doc), allocator); update(doc); diff --git a/src/base/net/stratum/benchmark/BenchClient.h b/src/base/net/stratum/benchmark/BenchClient.h index 54e0f6dc2..65b9d05f2 100644 --- a/src/base/net/stratum/benchmark/BenchClient.h +++ b/src/base/net/stratum/benchmark/BenchClient.h @@ -67,7 +67,7 @@ public: void setPool(const Pool &pool) override; protected: - void onBenchDone(uint64_t result, uint64_t ts) override; + void onBenchDone(uint64_t result, uint64_t diff, uint64_t ts) override; void onBenchStart(uint64_t ts, uint32_t threads, const IBackend *backend) override; void onHttpData(const HttpData &data) override; void onResolved(const Dns &dns, int status) override;