From 6d8cf91568202c9c6f5313950afce34665e4ca7e Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 3 Oct 2019 04:48:36 +0700 Subject: [PATCH] Added class RxSeed. --- cmake/randomx.cmake | 1 + src/crypto/rx/Rx.cpp | 17 +++++------ src/crypto/rx/RxSeed.h | 69 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 src/crypto/rx/RxSeed.h diff --git a/cmake/randomx.cmake b/cmake/randomx.cmake index 27b6e5e64..ac0acde9b 100644 --- a/cmake/randomx.cmake +++ b/cmake/randomx.cmake @@ -7,6 +7,7 @@ if (WITH_RANDOMX) src/crypto/rx/RxCache.h src/crypto/rx/RxConfig.h src/crypto/rx/RxDataset.h + src/crypto/rx/RxSeed.h src/crypto/rx/RxVm.h ) diff --git a/src/crypto/rx/Rx.cpp b/src/crypto/rx/Rx.cpp index d0674b299..4382e10d7 100644 --- a/src/crypto/rx/Rx.cpp +++ b/src/crypto/rx/Rx.cpp @@ -39,6 +39,7 @@ #include "crypto/rx/RxAlgo.h" #include "crypto/rx/RxCache.h" #include "crypto/rx/RxDataset.h" +#include "crypto/rx/RxSeed.h" #ifdef XMRIG_FEATURE_HWLOC @@ -133,9 +134,8 @@ public: inline bool isNUMA() const { return m_numa; } - inline bool isReady(const Job &job) const { return m_ready == count() && m_algorithm == job.algorithm() && m_seed == job.seed(); } - inline const Algorithm &algorithm() const { return m_algorithm; } - inline const Buffer &seed() const { return m_seed; } + inline bool isReady(const Job &job) const { return m_ready == count() && m_seed == job; } + inline const Algorithm &algorithm() const { return m_seed.algorithm(); } inline size_t count() const { return isNUMA() ? datasets.size() : 1; } inline uint64_t counter() { return m_counter.load(std::memory_order_relaxed); } inline void asyncSend(uint64_t counter) { m_ready++; if (m_ready == count()) { m_last = counter; uv_async_send(m_async); } } @@ -186,7 +186,7 @@ public: const uint64_t ts = Chrono::steadyMSecs(); - d_ptr->getOrAllocate(nodeId)->init(d_ptr->seed(), threads); + d_ptr->getOrAllocate(nodeId)->init(d_ptr->m_seed.data(), threads); d_ptr->asyncSend(counter); LOG_INFO("%s" CYAN_BOLD("#%u") GREEN(" init done ") CYAN_BOLD("%zu/%zu") BLACK_BOLD(" (%" PRIu64 " ms)"), tag, nodeId, d_ptr->m_ready, d_ptr->count(), Chrono::steadyMSecs() - ts); @@ -217,15 +217,15 @@ public: inline void setState(const Job &job, bool hugePages, bool numa, IRxListener *listener) { - if (m_algorithm != job.algorithm()) { - m_algorithm = RxAlgo::apply(job.algorithm()); + if (m_seed.algorithm() != job.algorithm()) { + RxAlgo::apply(job.algorithm()); } m_ready = 0; m_numa = numa && Cpu::info()->nodes() > 1; m_hugePages = hugePages; m_listener = listener; - m_seed = job.seed(); + m_seed = job; ++m_counter; } @@ -242,10 +242,9 @@ private: } - Algorithm m_algorithm; bool m_hugePages = true; bool m_numa = true; - Buffer m_seed; + RxSeed m_seed; IRxListener *m_listener = nullptr; size_t m_ready = 0; std::atomic m_counter; diff --git a/src/crypto/rx/RxSeed.h b/src/crypto/rx/RxSeed.h new file mode 100644 index 000000000..c8993a18f --- /dev/null +++ b/src/crypto/rx/RxSeed.h @@ -0,0 +1,69 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2019 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 tevador + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_RX_SEED_H +#define XMRIG_RX_SEED_H + + +#include "base/net/stratum/Job.h" +#include "base/tools/Buffer.h" + + +namespace xmrig +{ + + +class RxSeed; + + +class RxSeed +{ +public: + RxSeed() = default; + + inline RxSeed(const Algorithm &algorithm, const Buffer &seed) : m_algorithm(algorithm), m_data(seed) {} + inline RxSeed(const Job &job) : m_algorithm(job.algorithm()), m_data(job.seed()) {} + + inline bool isEqual(const Job &job) const { return m_algorithm == job.algorithm() && m_data == job.seed(); } + inline bool isEqual(const RxSeed &other) const { return m_algorithm == other.m_algorithm && m_data == other.m_data; } + inline const Algorithm &algorithm() const { return m_algorithm; } + inline const Buffer &data() const { return m_data; } + + inline bool operator!=(const Job &job) const { return !isEqual(job); } + inline bool operator!=(const RxSeed &other) const { return !isEqual(other); } + inline bool operator==(const Job &job) const { return isEqual(job); } + inline bool operator==(const RxSeed &other) const { return isEqual(other); } + +private: + Algorithm m_algorithm; + Buffer m_data; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_RX_CACHE_H */