Now used IThread to start threads, cpu-affinity broken, nonce allocation in double mode probably broken too.

This commit is contained in:
XMRig 2018-04-02 15:03:56 +07:00
parent 6c970612bf
commit 72cd6d168e
8 changed files with 47 additions and 38 deletions

View file

@ -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

View file

@ -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);
}
}

View file

@ -4,8 +4,8 @@
* 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 2016-2017 XMRig <support@xmrig.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>
*
* 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)
{
}

View file

@ -4,8 +4,8 @@
* 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 2016-2017 XMRig <support@xmrig.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>
*
* 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 <uv.h>
#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;
};

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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<uint64_t> m_hashCount;
std::atomic<uint64_t> m_timestamp;
uint64_t m_count;

View file

@ -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<xmrig::IThread *> &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);
}