Skip to content

Commit d7c5630

Browse files
committed
Fix nonce allocation in DoubleWorker.
1 parent c1bc6ac commit d7c5630

File tree

9 files changed

+14
-9
lines changed

9 files changed

+14
-9
lines changed

src/App.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int App::exec()
136136
m_httpd->start();
137137
# endif
138138

139-
Workers::start(m_controller->config()->affinity(), m_controller->config()->priority(), m_controller);
139+
Workers::start(m_controller);
140140

141141
m_controller->network()->connect();
142142

src/Mem_unix.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
4646
m_threads = threads;
4747
m_doubleHash = doubleHash;
4848

49-
const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
49+
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
5050
m_size = MONERO_MEMORY * (threads * ratio + 1);
5151

5252
if (!enabled) {

src/workers/DoubleWorker.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ void DoubleWorker::consumeJob()
135135

136136
if (m_state->job.isNicehash()) {
137137
m_state->nonce1 = (*Job::nonce(m_state->blob) & 0xff000000U) + (0xffffffU / m_totalWays * m_id);
138-
m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / m_totalWays * (m_id + m_totalWays));
138+
m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / m_totalWays * (m_id + m_totalThreads));
139139
}
140140
else {
141141
m_state->nonce1 = 0xffffffffU / m_totalWays * m_id;
142-
m_state->nonce2 = 0xffffffffU / m_totalWays * (m_id + m_totalWays);
142+
m_state->nonce2 = 0xffffffffU / m_totalWays * (m_id + m_totalThreads);
143143
}
144144
}
145145

src/workers/Handle.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
#include "workers/Handle.h"
2626

2727

28-
Handle::Handle(xmrig::IThread *config, size_t totalWays) :
28+
Handle::Handle(xmrig::IThread *config, size_t totalThreads, size_t totalWays) :
2929
m_worker(nullptr),
30+
m_totalThreads(totalThreads),
3031
m_totalWays(totalWays),
3132
m_config(config)
3233
{

src/workers/Handle.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@ class IWorker;
3838
class Handle
3939
{
4040
public:
41-
Handle(xmrig::IThread *config, size_t totalWays);
41+
Handle(xmrig::IThread *config, size_t totalThreads, size_t totalWays);
4242
void join();
4343
void start(void (*callback) (void *));
4444

4545
inline IWorker *worker() const { return m_worker; }
4646
inline size_t threadId() const { return m_config->index(); }
47+
inline size_t totalThreads() const { return m_totalThreads; }
4748
inline size_t totalWays() const { return m_totalWays; }
4849
inline void setWorker(IWorker *worker) { m_worker = worker; }
4950
inline xmrig::IThread *config() const { return m_config; }
5051

5152
private:
5253
IWorker *m_worker;
54+
size_t m_totalThreads;
5355
size_t m_totalWays;
5456
uv_thread_t m_thread;
5557
xmrig::IThread *m_config;

src/workers/Worker.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
Worker::Worker(Handle *handle) :
3636
m_id(handle->threadId()),
37+
m_totalThreads(handle->totalThreads()),
3738
m_totalWays(handle->totalWays()),
3839
m_hashCount(0),
3940
m_timestamp(0),

src/workers/Worker.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Worker : public IWorker
5555

5656
cryptonight_ctx *m_ctx;
5757
size_t m_id;
58+
size_t m_totalThreads;
5859
size_t m_totalWays;
5960
std::atomic<uint64_t> m_hashCount;
6061
std::atomic<uint64_t> m_timestamp;

src/workers/Workers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void Workers::setJob(const Job &job, bool donate)
107107
}
108108

109109

110-
void Workers::start(int64_t affinity, int priority, xmrig::Controller *controller)
110+
void Workers::start(xmrig::Controller *controller)
111111
{
112112
const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
113113

@@ -129,7 +129,7 @@ void Workers::start(int64_t affinity, int priority, xmrig::Controller *controlle
129129
uv_timer_start(&m_timer, Workers::onTick, 500, 500);
130130

131131
for (xmrig::IThread *thread : threads) {
132-
Handle *handle = new Handle(thread, totalWays);
132+
Handle *handle = new Handle(thread, threads.size(), totalWays);
133133
m_workers.push_back(handle);
134134
handle->start(Workers::onReady);
135135
}

src/workers/Workers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Workers
5151
static void printHashrate(bool detail);
5252
static void setEnabled(bool enabled);
5353
static void setJob(const Job &job, bool donate);
54-
static void start(int64_t affinity, int priority, xmrig::Controller *controller);
54+
static void start(xmrig::Controller *controller);
5555
static void stop();
5656
static void submit(const JobResult &result);
5757

0 commit comments

Comments
 (0)