Added class RxSeed.

This commit is contained in:
XMRig 2019-10-03 04:48:36 +07:00
parent 542a27a032
commit 6d8cf91568
3 changed files with 78 additions and 9 deletions

View file

@ -7,6 +7,7 @@ if (WITH_RANDOMX)
src/crypto/rx/RxCache.h src/crypto/rx/RxCache.h
src/crypto/rx/RxConfig.h src/crypto/rx/RxConfig.h
src/crypto/rx/RxDataset.h src/crypto/rx/RxDataset.h
src/crypto/rx/RxSeed.h
src/crypto/rx/RxVm.h src/crypto/rx/RxVm.h
) )

View file

@ -39,6 +39,7 @@
#include "crypto/rx/RxAlgo.h" #include "crypto/rx/RxAlgo.h"
#include "crypto/rx/RxCache.h" #include "crypto/rx/RxCache.h"
#include "crypto/rx/RxDataset.h" #include "crypto/rx/RxDataset.h"
#include "crypto/rx/RxSeed.h"
#ifdef XMRIG_FEATURE_HWLOC #ifdef XMRIG_FEATURE_HWLOC
@ -133,9 +134,8 @@ public:
inline bool isNUMA() const { return m_numa; } 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 bool isReady(const Job &job) const { return m_ready == count() && m_seed == job; }
inline const Algorithm &algorithm() const { return m_algorithm; } inline const Algorithm &algorithm() const { return m_seed.algorithm(); }
inline const Buffer &seed() const { return m_seed; }
inline size_t count() const { return isNUMA() ? datasets.size() : 1; } inline size_t count() const { return isNUMA() ? datasets.size() : 1; }
inline uint64_t counter() { return m_counter.load(std::memory_order_relaxed); } 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); } } 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(); 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); 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); 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) inline void setState(const Job &job, bool hugePages, bool numa, IRxListener *listener)
{ {
if (m_algorithm != job.algorithm()) { if (m_seed.algorithm() != job.algorithm()) {
m_algorithm = RxAlgo::apply(job.algorithm()); RxAlgo::apply(job.algorithm());
} }
m_ready = 0; m_ready = 0;
m_numa = numa && Cpu::info()->nodes() > 1; m_numa = numa && Cpu::info()->nodes() > 1;
m_hugePages = hugePages; m_hugePages = hugePages;
m_listener = listener; m_listener = listener;
m_seed = job.seed(); m_seed = job;
++m_counter; ++m_counter;
} }
@ -242,10 +242,9 @@ private:
} }
Algorithm m_algorithm;
bool m_hugePages = true; bool m_hugePages = true;
bool m_numa = true; bool m_numa = true;
Buffer m_seed; RxSeed m_seed;
IRxListener *m_listener = nullptr; IRxListener *m_listener = nullptr;
size_t m_ready = 0; size_t m_ready = 0;
std::atomic<uint64_t> m_counter; std::atomic<uint64_t> m_counter;

69
src/crypto/rx/RxSeed.h Normal file
View file

@ -0,0 +1,69 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 tevador <tevador@gmail.com>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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 */