From d7c56305094902818b47ac7714b2296d7f3e24c2 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 3 Apr 2018 03:27:44 +0700 Subject: [PATCH] Fix nonce allocation in DoubleWorker. --- src/App.cpp | 2 +- src/Mem_unix.cpp | 2 +- src/workers/DoubleWorker.cpp | 4 ++-- src/workers/Handle.cpp | 3 ++- src/workers/Handle.h | 4 +++- src/workers/Worker.cpp | 1 + src/workers/Worker.h | 1 + src/workers/Workers.cpp | 4 ++-- src/workers/Workers.h | 2 +- 9 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index a9d10774..8c7a16ea 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -136,7 +136,7 @@ int App::exec() m_httpd->start(); # endif - Workers::start(m_controller->config()->affinity(), m_controller->config()->priority(), m_controller); + Workers::start(m_controller); m_controller->network()->connect(); diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index 3b69f267..7978d241 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -46,7 +46,7 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) m_threads = threads; m_doubleHash = doubleHash; - const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; + const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1; m_size = MONERO_MEMORY * (threads * ratio + 1); if (!enabled) { diff --git a/src/workers/DoubleWorker.cpp b/src/workers/DoubleWorker.cpp index 7bde7df9..8971f0c0 100644 --- a/src/workers/DoubleWorker.cpp +++ b/src/workers/DoubleWorker.cpp @@ -135,11 +135,11 @@ void DoubleWorker::consumeJob() if (m_state->job.isNicehash()) { m_state->nonce1 = (*Job::nonce(m_state->blob) & 0xff000000U) + (0xffffffU / m_totalWays * m_id); - m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / m_totalWays * (m_id + m_totalWays)); + m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / m_totalWays * (m_id + m_totalThreads)); } else { m_state->nonce1 = 0xffffffffU / m_totalWays * m_id; - m_state->nonce2 = 0xffffffffU / m_totalWays * (m_id + m_totalWays); + m_state->nonce2 = 0xffffffffU / m_totalWays * (m_id + m_totalThreads); } } diff --git a/src/workers/Handle.cpp b/src/workers/Handle.cpp index 6d7b969a..29f57fb2 100644 --- a/src/workers/Handle.cpp +++ b/src/workers/Handle.cpp @@ -25,8 +25,9 @@ #include "workers/Handle.h" -Handle::Handle(xmrig::IThread *config, size_t totalWays) : +Handle::Handle(xmrig::IThread *config, size_t totalThreads, size_t totalWays) : m_worker(nullptr), + m_totalThreads(totalThreads), m_totalWays(totalWays), m_config(config) { diff --git a/src/workers/Handle.h b/src/workers/Handle.h index d63dc098..b3a7c76f 100644 --- a/src/workers/Handle.h +++ b/src/workers/Handle.h @@ -38,18 +38,20 @@ class IWorker; class Handle { public: - Handle(xmrig::IThread *config, size_t totalWays); + Handle(xmrig::IThread *config, size_t totalThreads, size_t totalWays); void join(); void start(void (*callback) (void *)); inline IWorker *worker() const { return m_worker; } inline size_t threadId() const { return m_config->index(); } + inline size_t totalThreads() const { return m_totalThreads; } inline size_t totalWays() const { return m_totalWays; } inline void setWorker(IWorker *worker) { m_worker = worker; } inline xmrig::IThread *config() const { return m_config; } private: IWorker *m_worker; + size_t m_totalThreads; size_t m_totalWays; uv_thread_t m_thread; xmrig::IThread *m_config; diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 2672f49f..bf4f62da 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -34,6 +34,7 @@ Worker::Worker(Handle *handle) : m_id(handle->threadId()), + m_totalThreads(handle->totalThreads()), m_totalWays(handle->totalWays()), m_hashCount(0), m_timestamp(0), diff --git a/src/workers/Worker.h b/src/workers/Worker.h index cb52c149..9fbce1a2 100644 --- a/src/workers/Worker.h +++ b/src/workers/Worker.h @@ -55,6 +55,7 @@ protected: cryptonight_ctx *m_ctx; size_t m_id; + size_t m_totalThreads; size_t m_totalWays; std::atomic m_hashCount; std::atomic m_timestamp; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index faa207a0..8ac256da 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -107,7 +107,7 @@ void Workers::setJob(const Job &job, bool donate) } -void Workers::start(int64_t affinity, int priority, xmrig::Controller *controller) +void Workers::start(xmrig::Controller *controller) { const std::vector &threads = controller->config()->threads(); @@ -129,7 +129,7 @@ void Workers::start(int64_t affinity, int priority, xmrig::Controller *controlle uv_timer_start(&m_timer, Workers::onTick, 500, 500); for (xmrig::IThread *thread : threads) { - Handle *handle = new Handle(thread, totalWays); + Handle *handle = new Handle(thread, threads.size(), totalWays); m_workers.push_back(handle); handle->start(Workers::onReady); } diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 942a5b58..ecec9e30 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -51,7 +51,7 @@ public: static void printHashrate(bool detail); static void setEnabled(bool enabled); static void setJob(const Job &job, bool donate); - static void start(int64_t affinity, int priority, xmrig::Controller *controller); + static void start(xmrig::Controller *controller); static void stop(); static void submit(const JobResult &result);