Skip to content

Commit 72cd6d1

Browse files
committed
Now used IThread to start threads, cpu-affinity broken, nonce allocation in double mode probably broken too.
1 parent 6c97061 commit 72cd6d1

File tree

8 files changed

+47
-38
lines changed

8 files changed

+47
-38
lines changed

src/workers/CpuThread.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CpuThread : public IThread
3636
{
3737
public:
3838
enum Multiway {
39-
SingleWay,
39+
SingleWay = 1,
4040
DoubleWay,
4141
TripleWay,
4242
QuadWay,
@@ -55,7 +55,7 @@ class CpuThread : public IThread
5555
inline int multiway() const override { return m_multiway; }
5656
inline int priority() const override { return m_priority; }
5757
inline int64_t affinity() const override { return m_affinity; }
58-
inline size_t index() const override { return m_affinity; }
58+
inline size_t index() const override { return m_index; }
5959
inline Type type() const override { return CPU; }
6060

6161
# ifndef XMRIG_NO_API

src/workers/DoubleWorker.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ void DoubleWorker::consumeJob()
134134
memcpy(m_state->blob + m_state->job.size(), m_state->job.blob(), m_state->job.size());
135135

136136
if (m_state->job.isNicehash()) {
137-
m_state->nonce1 = (*Job::nonce(m_state->blob) & 0xff000000U) + (0xffffffU / (m_threads * 2) * m_id);
138-
m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / (m_threads * 2) * (m_id + m_threads));
137+
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));
139139
}
140140
else {
141-
m_state->nonce1 = 0xffffffffU / (m_threads * 2) * m_id;
142-
m_state->nonce2 = 0xffffffffU / (m_threads * 2) * (m_id + m_threads);
141+
m_state->nonce1 = 0xffffffffU / m_totalWays * m_id;
142+
m_state->nonce2 = 0xffffffffU / m_totalWays * (m_id + m_totalWays);
143143
}
144144
}
145145

src/workers/Handle.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
55
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
66
* Copyright 2016 Jay D Dee <[email protected]>
7-
* Copyright 2016-2017 XMRig <support@xmrig.com>
8-
*
7+
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
8+
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <[email protected]>
99
*
1010
* This program is free software: you can redistribute it and/or modify
1111
* it under the terms of the GNU General Public License as published by
@@ -25,12 +25,10 @@
2525
#include "workers/Handle.h"
2626

2727

28-
Handle::Handle(int threadId, int threads, int64_t affinity, int priority) :
29-
m_priority(priority),
30-
m_threadId(threadId),
31-
m_threads(threads),
32-
m_affinity(affinity),
33-
m_worker(nullptr)
28+
Handle::Handle(xmrig::IThread *config, size_t totalWays) :
29+
m_worker(nullptr),
30+
m_totalWays(totalWays),
31+
m_config(config)
3432
{
3533
}
3634

src/workers/Handle.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
55
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
66
* Copyright 2016 Jay D Dee <[email protected]>
7-
* Copyright 2016-2017 XMRig <support@xmrig.com>
8-
*
7+
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
8+
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <[email protected]>
99
*
1010
* This program is free software: you can redistribute it and/or modify
1111
* it under the terms of the GNU General Public License as published by
@@ -29,30 +29,30 @@
2929
#include <uv.h>
3030

3131

32+
#include "interfaces/IThread.h"
33+
34+
3235
class IWorker;
3336

3437

3538
class Handle
3639
{
3740
public:
38-
Handle(int threadId, int threads, int64_t affinity, int priority);
41+
Handle(xmrig::IThread *config, size_t totalWays);
3942
void join();
4043
void start(void (*callback) (void *));
4144

42-
inline int priority() const { return m_priority; }
43-
inline int threadId() const { return m_threadId; }
44-
inline int threads() const { return m_threads; }
45-
inline int64_t affinity() const { return m_affinity; }
4645
inline IWorker *worker() const { return m_worker; }
46+
inline size_t threadId() const { return m_config->index(); }
47+
inline size_t totalWays() const { return m_totalWays; }
4748
inline void setWorker(IWorker *worker) { m_worker = worker; }
49+
inline xmrig::IThread *config() const { return m_config; }
4850

4951
private:
50-
int m_priority;
51-
int m_threadId;
52-
int m_threads;
53-
int64_t m_affinity;
5452
IWorker *m_worker;
53+
size_t m_totalWays;
5554
uv_thread_t m_thread;
55+
xmrig::IThread *m_config;
5656
};
5757

5858

src/workers/SingleWorker.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ void SingleWorker::consumeJob()
104104
m_result = m_job;
105105

106106
if (m_job.isNicehash()) {
107-
m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_threads * m_id);
107+
m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_totalWays * m_id);
108108
}
109109
else {
110-
m_result.nonce = 0xffffffffU / m_threads * m_id;
110+
m_result.nonce = 0xffffffffU / m_totalWays * m_id;
111111
}
112112
}
113113

src/workers/Worker.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333

3434
Worker::Worker(Handle *handle) :
3535
m_id(handle->threadId()),
36-
m_threads(handle->threads()),
36+
m_totalWays(handle->totalWays()),
3737
m_hashCount(0),
3838
m_timestamp(0),
3939
m_count(0),
4040
m_sequence(0)
4141
{
42-
if (Cpu::threads() > 1 && handle->affinity() != -1L) {
43-
Cpu::setAffinity(m_id, handle->affinity());
44-
}
42+
// if (Cpu::threads() > 1 && handle->affinity() != -1L) {
43+
// Cpu::setAffinity(m_id, handle->affinity());
44+
// }
4545

46-
Platform::setThreadPriority(handle->priority());
46+
Platform::setThreadPriority(handle->config()->priority());
4747
m_ctx = Mem::create(m_id);
4848
}
4949

src/workers/Worker.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class Worker : public IWorker
4949
void storeStats();
5050

5151
cryptonight_ctx *m_ctx;
52-
int m_id;
53-
int m_threads;
52+
size_t m_id;
53+
size_t m_totalWays;
5454
std::atomic<uint64_t> m_hashCount;
5555
std::atomic<uint64_t> m_timestamp;
5656
uint64_t m_count;

src/workers/Workers.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@
2525

2626

2727
#include "api/Api.h"
28+
#include "core/Config.h"
29+
#include "core/Controller.h"
2830
#include "interfaces/IJobResultListener.h"
31+
#include "interfaces/IThread.h"
2932
#include "Mem.h"
3033
#include "workers/DoubleWorker.h"
3134
#include "workers/Handle.h"
3235
#include "workers/Hashrate.h"
3336
#include "workers/SingleWorker.h"
3437
#include "workers/Workers.h"
3538

39+
#include "log/Log.h"
40+
3641

3742
bool Workers::m_active = false;
3843
bool Workers::m_enabled = true;
@@ -104,8 +109,14 @@ void Workers::setJob(const Job &job, bool donate)
104109

105110
void Workers::start(int64_t affinity, int priority, xmrig::Controller *controller)
106111
{
107-
const int threads = Mem::threads();
108-
m_hashrate = new Hashrate(threads, controller);
112+
const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
113+
114+
size_t totalWays = 0;
115+
for (const xmrig::IThread *thread : threads) {
116+
totalWays += thread->multiway();
117+
}
118+
119+
m_hashrate = new Hashrate(threads.size(), controller);
109120

110121
uv_mutex_init(&m_mutex);
111122
uv_rwlock_init(&m_rwlock);
@@ -117,8 +128,8 @@ void Workers::start(int64_t affinity, int priority, xmrig::Controller *controlle
117128
uv_timer_init(uv_default_loop(), &m_timer);
118129
uv_timer_start(&m_timer, Workers::onTick, 500, 500);
119130

120-
for (int i = 0; i < threads; ++i) {
121-
Handle *handle = new Handle(i, threads, affinity, priority);
131+
for (xmrig::IThread *thread : threads) {
132+
Handle *handle = new Handle(thread, totalWays);
122133
m_workers.push_back(handle);
123134
handle->start(Workers::onReady);
124135
}

0 commit comments

Comments
 (0)