diff --git a/src/workers/CpuThread.h b/src/workers/CpuThread.h index 2b2144237..ee0a3d575 100644 --- a/src/workers/CpuThread.h +++ b/src/workers/CpuThread.h @@ -36,7 +36,7 @@ class CpuThread : public IThread { public: enum Multiway { - SingleWay, + SingleWay = 1, DoubleWay, TripleWay, QuadWay, @@ -55,7 +55,7 @@ public: inline int multiway() const override { return m_multiway; } inline int priority() const override { return m_priority; } inline int64_t affinity() const override { return m_affinity; } - inline size_t index() const override { return m_affinity; } + inline size_t index() const override { return m_index; } inline Type type() const override { return CPU; } # ifndef XMRIG_NO_API diff --git a/src/workers/DoubleWorker.cpp b/src/workers/DoubleWorker.cpp index 46c8ed2ea..3dba4a9fb 100644 --- a/src/workers/DoubleWorker.cpp +++ b/src/workers/DoubleWorker.cpp @@ -134,12 +134,12 @@ void DoubleWorker::consumeJob() memcpy(m_state->blob + m_state->job.size(), m_state->job.blob(), m_state->job.size()); if (m_state->job.isNicehash()) { - m_state->nonce1 = (*Job::nonce(m_state->blob) & 0xff000000U) + (0xffffffU / (m_threads * 2) * m_id); - m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / (m_threads * 2) * (m_id + m_threads)); + 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)); } else { - m_state->nonce1 = 0xffffffffU / (m_threads * 2) * m_id; - m_state->nonce2 = 0xffffffffU / (m_threads * 2) * (m_id + m_threads); + m_state->nonce1 = 0xffffffffU / m_totalWays * m_id; + m_state->nonce2 = 0xffffffffU / m_totalWays * (m_id + m_totalWays); } } diff --git a/src/workers/Handle.cpp b/src/workers/Handle.cpp index c461cee75..6d7b969a3 100644 --- a/src/workers/Handle.cpp +++ b/src/workers/Handle.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * 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 @@ -25,12 +25,10 @@ #include "workers/Handle.h" -Handle::Handle(int threadId, int threads, int64_t affinity, int priority) : - m_priority(priority), - m_threadId(threadId), - m_threads(threads), - m_affinity(affinity), - m_worker(nullptr) +Handle::Handle(xmrig::IThread *config, size_t totalWays) : + m_worker(nullptr), + m_totalWays(totalWays), + m_config(config) { } diff --git a/src/workers/Handle.h b/src/workers/Handle.h index 9faae0d0c..d63dc0988 100644 --- a/src/workers/Handle.h +++ b/src/workers/Handle.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * 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 @@ -29,30 +29,30 @@ #include +#include "interfaces/IThread.h" + + class IWorker; class Handle { public: - Handle(int threadId, int threads, int64_t affinity, int priority); + Handle(xmrig::IThread *config, size_t totalWays); void join(); void start(void (*callback) (void *)); - inline int priority() const { return m_priority; } - inline int threadId() const { return m_threadId; } - inline int threads() const { return m_threads; } - inline int64_t affinity() const { return m_affinity; } inline IWorker *worker() const { return m_worker; } + inline size_t threadId() const { return m_config->index(); } + 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: - int m_priority; - int m_threadId; - int m_threads; - int64_t m_affinity; IWorker *m_worker; + size_t m_totalWays; uv_thread_t m_thread; + xmrig::IThread *m_config; }; diff --git a/src/workers/SingleWorker.cpp b/src/workers/SingleWorker.cpp index 9f4a7484c..9d47d947e 100644 --- a/src/workers/SingleWorker.cpp +++ b/src/workers/SingleWorker.cpp @@ -104,10 +104,10 @@ void SingleWorker::consumeJob() m_result = m_job; if (m_job.isNicehash()) { - m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_threads * m_id); + m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_totalWays * m_id); } else { - m_result.nonce = 0xffffffffU / m_threads * m_id; + m_result.nonce = 0xffffffffU / m_totalWays * m_id; } } diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 7a7ff9865..648bf7edb 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -33,17 +33,17 @@ Worker::Worker(Handle *handle) : m_id(handle->threadId()), - m_threads(handle->threads()), + m_totalWays(handle->totalWays()), m_hashCount(0), m_timestamp(0), m_count(0), m_sequence(0) { - if (Cpu::threads() > 1 && handle->affinity() != -1L) { - Cpu::setAffinity(m_id, handle->affinity()); - } +// if (Cpu::threads() > 1 && handle->affinity() != -1L) { +// Cpu::setAffinity(m_id, handle->affinity()); +// } - Platform::setThreadPriority(handle->priority()); + Platform::setThreadPriority(handle->config()->priority()); m_ctx = Mem::create(m_id); } diff --git a/src/workers/Worker.h b/src/workers/Worker.h index 08a0551f1..a9c15ef40 100644 --- a/src/workers/Worker.h +++ b/src/workers/Worker.h @@ -49,8 +49,8 @@ protected: void storeStats(); cryptonight_ctx *m_ctx; - int m_id; - int m_threads; + size_t m_id; + size_t m_totalWays; std::atomic m_hashCount; std::atomic m_timestamp; uint64_t m_count; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 5642751a5..faa207a0a 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -25,7 +25,10 @@ #include "api/Api.h" +#include "core/Config.h" +#include "core/Controller.h" #include "interfaces/IJobResultListener.h" +#include "interfaces/IThread.h" #include "Mem.h" #include "workers/DoubleWorker.h" #include "workers/Handle.h" @@ -33,6 +36,8 @@ #include "workers/SingleWorker.h" #include "workers/Workers.h" +#include "log/Log.h" + bool Workers::m_active = false; bool Workers::m_enabled = true; @@ -104,8 +109,14 @@ void Workers::setJob(const Job &job, bool donate) void Workers::start(int64_t affinity, int priority, xmrig::Controller *controller) { - const int threads = Mem::threads(); - m_hashrate = new Hashrate(threads, controller); + const std::vector &threads = controller->config()->threads(); + + size_t totalWays = 0; + for (const xmrig::IThread *thread : threads) { + totalWays += thread->multiway(); + } + + m_hashrate = new Hashrate(threads.size(), controller); uv_mutex_init(&m_mutex); uv_rwlock_init(&m_rwlock); @@ -117,8 +128,8 @@ void Workers::start(int64_t affinity, int priority, xmrig::Controller *controlle uv_timer_init(uv_default_loop(), &m_timer); uv_timer_start(&m_timer, Workers::onTick, 500, 500); - for (int i = 0; i < threads; ++i) { - Handle *handle = new Handle(i, threads, affinity, priority); + for (xmrig::IThread *thread : threads) { + Handle *handle = new Handle(thread, totalWays); m_workers.push_back(handle); handle->start(Workers::onReady); }