Added new nonce allocation method for dynamic/variable threads.
This commit is contained in:
@ -35,6 +35,7 @@ set(HEADERS
|
||||
src/core/config/ConfigTransform.h
|
||||
src/core/config/usage.h
|
||||
src/core/Controller.h
|
||||
src/core/WorkerJob.h
|
||||
src/interfaces/IThread.h
|
||||
src/interfaces/IWorker.h
|
||||
src/Mem.h
|
||||
@ -71,6 +72,7 @@ set(HEADERS_CRYPTO
|
||||
src/crypto/cn/soft_aes.h
|
||||
src/crypto/common/Algorithm.h
|
||||
src/crypto/common/keccak.h
|
||||
src/crypto/common/Nonce.h
|
||||
src/crypto/common/portable/mm_malloc.h
|
||||
src/crypto/common/VirtualMemory.h
|
||||
)
|
||||
@ -113,6 +115,7 @@ set(SOURCES_CRYPTO
|
||||
src/crypto/cn/CnHash.cpp
|
||||
src/crypto/common/Algorithm.cpp
|
||||
src/crypto/common/keccak.cpp
|
||||
src/crypto/common/Nonce.cpp
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
|
143
src/core/WorkerJob.h
Normal file
143
src/core/WorkerJob.h
Normal file
@ -0,0 +1,143 @@
|
||||
/* 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-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* 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_WORKERJOB_H
|
||||
#define XMRIG_WORKERJOB_H
|
||||
|
||||
|
||||
#include <atomic>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
template<size_t N>
|
||||
class WorkerJob
|
||||
{
|
||||
public:
|
||||
inline const Job ¤tJob() const { return m_jobs[index()]; }
|
||||
inline uint32_t *nonce(size_t i = 0) { return reinterpret_cast<uint32_t*>(blob() + (i * currentJob().size()) + 39); }
|
||||
inline uint64_t sequence() const { return m_sequence; }
|
||||
inline uint8_t *blob() { return m_blobs[index()]; }
|
||||
inline uint8_t index() const { return m_index; }
|
||||
|
||||
|
||||
inline void add(const Job &job, uint64_t sequence, uint32_t reserveCount)
|
||||
{
|
||||
m_sequence = sequence;
|
||||
|
||||
if (currentJob() == job) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index() == 1 && job.poolId() >= 0 && job == m_jobs[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
save(job, reserveCount);
|
||||
}
|
||||
|
||||
|
||||
inline void nextRound(uint32_t reserveCount)
|
||||
{
|
||||
m_rounds[index()]++;
|
||||
|
||||
if ((m_rounds[index()] % reserveCount) == 0) {
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
*nonce(i) = Nonce::next(index(), *nonce(i), reserveCount, currentJob().isNicehash());
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
*nonce(i) += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
inline void save(const Job &job, uint32_t reserveCount)
|
||||
{
|
||||
m_index = job.poolId() == -1 ? 1 : 0;
|
||||
const size_t size = job.size();
|
||||
m_jobs[index()] = job;
|
||||
m_rounds[index()] = 0;
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
memcpy(m_blobs[index()] + (i * size), job.blob(), size);
|
||||
*nonce(i) = Nonce::next(index(), *nonce(i), reserveCount, job.isNicehash());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
alignas(16) uint8_t m_blobs[2][Job::kMaxBlobSize * N];
|
||||
Job m_jobs[2];
|
||||
uint32_t m_rounds[2] = { 0, 0 };
|
||||
uint64_t m_sequence = 0;
|
||||
uint8_t m_index = 0;
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
inline uint32_t *xmrig::WorkerJob<1>::nonce(size_t)
|
||||
{
|
||||
return reinterpret_cast<uint32_t*>(blob() + 39);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
inline void xmrig::WorkerJob<1>::nextRound(uint32_t reserveCount)
|
||||
{
|
||||
m_rounds[index()]++;
|
||||
|
||||
if ((m_rounds[index()] % reserveCount) == 0) {
|
||||
*nonce() = Nonce::next(index(), *nonce(), reserveCount, currentJob().isNicehash());
|
||||
}
|
||||
else {
|
||||
*nonce() += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
inline void xmrig::WorkerJob<1>::save(const Job &job, uint32_t reserveCount)
|
||||
{
|
||||
m_index = job.poolId() == -1 ? 1 : 0;
|
||||
m_jobs[index()] = job;
|
||||
m_rounds[index()] = 0;
|
||||
|
||||
memcpy(blob(), job.blob(), job.size());
|
||||
*nonce() = Nonce::next(index(), *nonce(), reserveCount, currentJob().isNicehash());
|
||||
}
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_WORKERJOB_H */
|
83
src/crypto/common/Nonce.cpp
Normal file
83
src/crypto/common/Nonce.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/* 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-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "crypto/common/Nonce.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
std::atomic<uint64_t> Nonce::m_sequence;
|
||||
uint32_t Nonce::m_nonces[2] = { 0, 0 };
|
||||
|
||||
|
||||
static uv_mutex_t mutex;
|
||||
static Nonce nonce;
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Nonce::Nonce()
|
||||
{
|
||||
m_sequence = 1;
|
||||
|
||||
uv_mutex_init(&mutex);
|
||||
}
|
||||
|
||||
|
||||
uint32_t xmrig::Nonce::next(uint8_t index, uint32_t nonce, uint32_t reserveCount, bool nicehash)
|
||||
{
|
||||
uint32_t next;
|
||||
|
||||
uv_mutex_lock(&mutex);
|
||||
|
||||
if (nicehash) {
|
||||
next = (nonce & 0xFF000000) | m_nonces[index];
|
||||
}
|
||||
else {
|
||||
next = m_nonces[index];
|
||||
}
|
||||
|
||||
m_nonces[index] += reserveCount;
|
||||
|
||||
uv_mutex_unlock(&mutex);
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Nonce::reset(uint8_t index)
|
||||
{
|
||||
uv_mutex_lock(&mutex);
|
||||
|
||||
m_nonces[index] = 0;
|
||||
m_sequence++;
|
||||
|
||||
uv_mutex_unlock(&mutex);
|
||||
}
|
57
src/crypto/common/Nonce.h
Normal file
57
src/crypto/common/Nonce.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* 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-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* 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_NONCE_H
|
||||
#define XMRIG_NONCE_H
|
||||
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Nonce
|
||||
{
|
||||
public:
|
||||
Nonce();
|
||||
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void stop() { m_sequence = 0; }
|
||||
static inline void touch() { m_sequence++; }
|
||||
|
||||
static uint32_t next(uint8_t index, uint32_t nonce, uint32_t reserveCount, bool nicehash);
|
||||
static void reset(uint8_t index);
|
||||
|
||||
private:
|
||||
static uint32_t m_nonces[2];
|
||||
static std::atomic<uint64_t> m_sequence;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_NONCE_H */
|
@ -28,6 +28,7 @@
|
||||
|
||||
|
||||
#include "crypto/cn/CryptoNight_test.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
#include "crypto/rx/Rx.h"
|
||||
#include "crypto/rx/RxVm.h"
|
||||
#include "net/JobResults.h"
|
||||
@ -36,6 +37,13 @@
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
static constexpr uint32_t kReserveCount = 4096;
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
template<size_t N>
|
||||
xmrig::MultiWorker<N>::MultiWorker(ThreadHandle *handle)
|
||||
: Worker(handle)
|
||||
@ -62,7 +70,7 @@ template<size_t N>
|
||||
void xmrig::MultiWorker<N>::allocateRandomX_VM()
|
||||
{
|
||||
if (!m_vm) {
|
||||
RxDataset *dataset = Rx::dataset(m_state.job.seedHash(), m_state.job.algorithm());
|
||||
RxDataset *dataset = Rx::dataset(m_job.currentJob().seedHash(), m_job.currentJob().algorithm());
|
||||
m_vm = new RxVm(dataset, true, m_thread->isSoftAES());
|
||||
}
|
||||
}
|
||||
@ -131,44 +139,45 @@ bool xmrig::MultiWorker<N>::selfTest()
|
||||
template<size_t N>
|
||||
void xmrig::MultiWorker<N>::start()
|
||||
{
|
||||
while (Workers::sequence() > 0) {
|
||||
while (Nonce::sequence() > 0) {
|
||||
if (Workers::isPaused()) {
|
||||
do {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
while (Workers::isPaused());
|
||||
|
||||
if (Workers::sequence() == 0) {
|
||||
if (Nonce::sequence() == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
consumeJob();
|
||||
}
|
||||
|
||||
while (!Workers::isOutdated(m_sequence)) {
|
||||
while (!Nonce::isOutdated(m_job.sequence())) {
|
||||
if ((m_count & 0x7) == 0) {
|
||||
storeStats();
|
||||
}
|
||||
|
||||
const Job &job = m_job.currentJob();
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_state.job.algorithm().family() == Algorithm::RANDOM_X) {
|
||||
if (job.algorithm().family() == Algorithm::RANDOM_X) {
|
||||
allocateRandomX_VM();
|
||||
randomx_calculate_hash(m_vm->get(), m_state.blob, m_state.job.size(), m_hash);
|
||||
randomx_calculate_hash(m_vm->get(), m_job.blob(), job.size(), m_hash);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
m_thread->fn(m_state.job.algorithm())(m_state.blob, m_state.job.size(), m_hash, m_ctx, m_state.job.height());
|
||||
m_thread->fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < m_state.job.target()) {
|
||||
JobResults::submit(JobResult(m_state.job.poolId(), m_state.job.id(), m_state.job.clientId(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm()));
|
||||
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < job.target()) {
|
||||
JobResults::submit(JobResult(job.poolId(), job.id(), job.clientId(), *m_job.nonce(i), m_hash + (i * 32), job.diff(), job.algorithm()));
|
||||
}
|
||||
|
||||
*nonce(i) += 1;
|
||||
}
|
||||
|
||||
m_job.nextRound(kReserveCount);
|
||||
m_count += N;
|
||||
|
||||
std::this_thread::yield();
|
||||
@ -179,18 +188,6 @@ void xmrig::MultiWorker<N>::start()
|
||||
}
|
||||
|
||||
|
||||
template<size_t N>
|
||||
bool xmrig::MultiWorker<N>::resume(const xmrig::Job &job)
|
||||
{
|
||||
if (m_state.job.poolId() == -1 && job.poolId() >= 0 && job.id() == m_pausedState.job.id()) {
|
||||
m_state = m_pausedState;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<size_t N>
|
||||
bool xmrig::MultiWorker<N>::verify(const Algorithm &algorithm, const uint8_t *referenceValue)
|
||||
{
|
||||
@ -215,10 +212,10 @@ bool xmrig::MultiWorker<N>::verify2(const Algorithm &algorithm, const uint8_t *r
|
||||
for (size_t i = 0; i < (sizeof(cn_r_test_input) / sizeof(cn_r_test_input[0])); ++i) {
|
||||
const size_t size = cn_r_test_input[i].size;
|
||||
for (size_t k = 0; k < N; ++k) {
|
||||
memcpy(m_state.blob + (k * size), cn_r_test_input[i].data, size);
|
||||
memcpy(m_job.blob() + (k * size), cn_r_test_input[i].data, size);
|
||||
}
|
||||
|
||||
func(m_state.blob, size, m_hash, m_ctx, cn_r_test_input[i].height);
|
||||
func(m_job.blob(), size, m_hash, m_ctx, cn_r_test_input[i].height);
|
||||
|
||||
for (size_t k = 0; k < N; ++k) {
|
||||
if (memcmp(m_hash + k * 32, referenceValue + i * 32, sizeof m_hash / N) != 0) {
|
||||
@ -258,46 +255,7 @@ bool MultiWorker<1>::verify2(const Algorithm &algorithm, const uint8_t *referenc
|
||||
template<size_t N>
|
||||
void xmrig::MultiWorker<N>::consumeJob()
|
||||
{
|
||||
Job job = Workers::job();
|
||||
m_sequence = Workers::sequence();
|
||||
if (m_state.job == job) {
|
||||
return;
|
||||
}
|
||||
|
||||
save(job);
|
||||
|
||||
if (resume(job)) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_state.job = job;
|
||||
|
||||
const size_t size = m_state.job.size();
|
||||
memcpy(m_state.blob, m_state.job.blob(), m_state.job.size());
|
||||
|
||||
if (N > 1) {
|
||||
for (size_t i = 1; i < N; ++i) {
|
||||
memcpy(m_state.blob + (i * size), m_state.blob, size);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
if (m_state.job.isNicehash()) {
|
||||
*nonce(i) = (*nonce(i) & 0xff000000U) + (0xffffffU / m_totalWays * (m_offset + i));
|
||||
}
|
||||
else {
|
||||
*nonce(i) = 0xffffffffU / m_totalWays * (m_offset + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<size_t N>
|
||||
void xmrig::MultiWorker<N>::save(const Job &job)
|
||||
{
|
||||
if (job.poolId() == -1 && m_state.job.poolId() >= 0) {
|
||||
m_pausedState = m_state;
|
||||
}
|
||||
m_job.add(Workers::job(), Nonce::sequence(), kReserveCount);
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "core/WorkerJob.h"
|
||||
#include "Mem.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "workers/Worker.h"
|
||||
@ -55,29 +56,15 @@ private:
|
||||
void allocateRandomX_VM();
|
||||
# endif
|
||||
|
||||
bool resume(const Job &job);
|
||||
bool verify(const Algorithm &algorithm, const uint8_t *referenceValue);
|
||||
bool verify2(const Algorithm &algorithm, const uint8_t *referenceValue);
|
||||
void consumeJob();
|
||||
void save(const Job &job);
|
||||
|
||||
inline uint32_t *nonce(size_t index)
|
||||
{
|
||||
return reinterpret_cast<uint32_t*>(m_state.blob + (index * m_state.job.size()) + 39);
|
||||
}
|
||||
|
||||
struct State
|
||||
{
|
||||
alignas(16) uint8_t blob[Job::kMaxBlobSize * N];
|
||||
Job job;
|
||||
};
|
||||
|
||||
|
||||
cryptonight_ctx *m_ctx[N];
|
||||
State m_pausedState;
|
||||
State m_state;
|
||||
uint8_t m_hash[N * 32];
|
||||
|
||||
WorkerJob<N> m_job;
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
RxVm *m_vm = nullptr;
|
||||
# endif
|
||||
|
@ -5,7 +5,9 @@
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* 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
|
||||
@ -38,7 +40,6 @@ Worker::Worker(ThreadHandle *handle) :
|
||||
m_hashCount(0),
|
||||
m_timestamp(0),
|
||||
m_count(0),
|
||||
m_sequence(0),
|
||||
m_thread(static_cast<xmrig::CpuThreadLegacy *>(handle->config()))
|
||||
{
|
||||
if (xmrig::Cpu::info()->threads() > 1 && m_thread->affinity() != -1L) {
|
||||
|
@ -5,7 +5,9 @@
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* 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
|
||||
@ -61,7 +63,6 @@ protected:
|
||||
std::atomic<uint64_t> m_hashCount;
|
||||
std::atomic<uint64_t> m_timestamp;
|
||||
uint64_t m_count;
|
||||
uint64_t m_sequence;
|
||||
xmrig::CpuThreadLegacy *m_thread;
|
||||
};
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "base/tools/Handle.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
#include "crypto/rx/RxAlgo.h"
|
||||
#include "crypto/rx/RxCache.h"
|
||||
#include "crypto/rx/RxDataset.h"
|
||||
@ -51,7 +52,6 @@ Hashrate *Workers::m_hashrate = nullptr;
|
||||
xmrig::Job Workers::m_job;
|
||||
Workers::LaunchStatus Workers::m_status;
|
||||
std::atomic<int> Workers::m_paused;
|
||||
std::atomic<uint64_t> Workers::m_sequence;
|
||||
std::vector<ThreadHandle*> Workers::m_workers;
|
||||
uint64_t Workers::m_ticks = 0;
|
||||
uv_mutex_t Workers::m_mutex;
|
||||
@ -90,6 +90,15 @@ size_t Workers::threads()
|
||||
}
|
||||
|
||||
|
||||
void Workers::pause()
|
||||
{
|
||||
m_active = false;
|
||||
m_paused = 1;
|
||||
|
||||
xmrig::Nonce::touch();
|
||||
}
|
||||
|
||||
|
||||
void Workers::printHashrate(bool detail)
|
||||
{
|
||||
assert(m_controller != nullptr);
|
||||
@ -134,7 +143,7 @@ void Workers::setEnabled(bool enabled)
|
||||
}
|
||||
|
||||
m_paused = enabled ? 0 : 1;
|
||||
m_sequence++;
|
||||
xmrig::Nonce::touch();
|
||||
}
|
||||
|
||||
|
||||
@ -146,6 +155,9 @@ void Workers::setJob(const xmrig::Job &job, bool donate)
|
||||
if (donate) {
|
||||
m_job.setPoolId(-1);
|
||||
}
|
||||
|
||||
xmrig::Nonce::reset(donate ? 1 : 0);
|
||||
|
||||
uv_rwlock_wrunlock(&m_rwlock);
|
||||
|
||||
m_active = true;
|
||||
@ -153,7 +165,6 @@ void Workers::setJob(const xmrig::Job &job, bool donate)
|
||||
return;
|
||||
}
|
||||
|
||||
m_sequence++;
|
||||
m_paused = 0;
|
||||
}
|
||||
|
||||
@ -183,7 +194,6 @@ void Workers::start(xmrig::Controller *controller)
|
||||
uv_mutex_init(&m_mutex);
|
||||
uv_rwlock_init(&m_rwlock);
|
||||
|
||||
m_sequence = 1;
|
||||
m_paused = 1;
|
||||
|
||||
m_timer = new uv_timer_t;
|
||||
@ -208,7 +218,8 @@ void Workers::stop()
|
||||
m_hashrate->stop();
|
||||
|
||||
m_paused = 0;
|
||||
m_sequence = 0;
|
||||
|
||||
xmrig::Nonce::stop();
|
||||
|
||||
for (size_t i = 0; i < m_workers.size(); ++i) {
|
||||
m_workers[i]->join();
|
||||
|
@ -53,21 +53,19 @@ namespace xmrig {
|
||||
class Workers
|
||||
{
|
||||
public:
|
||||
static xmrig::Job job();
|
||||
static size_t hugePages();
|
||||
static size_t threads();
|
||||
static void pause();
|
||||
static void printHashrate(bool detail);
|
||||
static void setEnabled(bool enabled);
|
||||
static void setJob(const xmrig::Job &job, bool donate);
|
||||
static void start(xmrig::Controller *controller);
|
||||
static void stop();
|
||||
static xmrig::Job job();
|
||||
|
||||
static inline bool isEnabled() { return m_enabled; }
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
|
||||
static inline Hashrate *hashrate() { return m_hashrate; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void pause() { m_active = false; m_paused = 1; m_sequence++; }
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
static void threadsSummary(rapidjson::Document &doc);
|
||||
@ -103,7 +101,6 @@ private:
|
||||
static xmrig::Job m_job;
|
||||
static LaunchStatus m_status;
|
||||
static std::atomic<int> m_paused;
|
||||
static std::atomic<uint64_t> m_sequence;
|
||||
static std::vector<ThreadHandle*> m_workers;
|
||||
static uint64_t m_ticks;
|
||||
static uv_mutex_t m_mutex;
|
||||
|
Reference in New Issue
Block a user