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: public:
enum Multiway { enum Multiway {
SingleWay, SingleWay = 1,
DoubleWay, DoubleWay,
TripleWay, TripleWay,
QuadWay, QuadWay,
@ -55,7 +55,7 @@ public:
inline int multiway() const override { return m_multiway; } inline int multiway() const override { return m_multiway; }
inline int priority() const override { return m_priority; } inline int priority() const override { return m_priority; }
inline int64_t affinity() const override { return m_affinity; } 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; } inline Type type() const override { return CPU; }
# ifndef XMRIG_NO_API # 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()); memcpy(m_state->blob + m_state->job.size(), m_state->job.blob(), m_state->job.size());
if (m_state->job.isNicehash()) { if (m_state->job.isNicehash()) {
m_state->nonce1 = (*Job::nonce(m_state->blob) & 0xff000000U) + (0xffffffU / (m_threads * 2) * m_id); 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_threads * 2) * (m_id + m_threads)); m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / m_totalWays * (m_id + m_totalWays));
} }
else { else {
m_state->nonce1 = 0xffffffffU / (m_threads * 2) * m_id; m_state->nonce1 = 0xffffffffU / m_totalWays * m_id;
m_state->nonce2 = 0xffffffffU / (m_threads * 2) * (m_id + m_threads); 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 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -25,12 +25,10 @@
#include "workers/Handle.h" #include "workers/Handle.h"
Handle::Handle(int threadId, int threads, int64_t affinity, int priority) : Handle::Handle(xmrig::IThread *config, size_t totalWays) :
m_priority(priority), m_worker(nullptr),
m_threadId(threadId), m_totalWays(totalWays),
m_threads(threads), m_config(config)
m_affinity(affinity),
m_worker(nullptr)
{ {
} }

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -29,30 +29,30 @@
#include <uv.h> #include <uv.h>
#include "interfaces/IThread.h"
class IWorker; class IWorker;
class Handle class Handle
{ {
public: public:
Handle(int threadId, int threads, int64_t affinity, int priority); Handle(xmrig::IThread *config, size_t totalWays);
void join(); void join();
void start(void (*callback) (void *)); 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 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 void setWorker(IWorker *worker) { m_worker = worker; }
inline xmrig::IThread *config() const { return m_config; }
private: private:
int m_priority;
int m_threadId;
int m_threads;
int64_t m_affinity;
IWorker *m_worker; IWorker *m_worker;
size_t m_totalWays;
uv_thread_t m_thread; uv_thread_t m_thread;
xmrig::IThread *m_config;
}; };

View file

@ -104,10 +104,10 @@ void SingleWorker::consumeJob()
m_result = m_job; m_result = m_job;
if (m_job.isNicehash()) { 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 { 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) : Worker::Worker(Handle *handle) :
m_id(handle->threadId()), m_id(handle->threadId()),
m_threads(handle->threads()), m_totalWays(handle->totalWays()),
m_hashCount(0), m_hashCount(0),
m_timestamp(0), m_timestamp(0),
m_count(0), m_count(0),
m_sequence(0) m_sequence(0)
{ {
if (Cpu::threads() > 1 && handle->affinity() != -1L) { // if (Cpu::threads() > 1 && handle->affinity() != -1L) {
Cpu::setAffinity(m_id, handle->affinity()); // Cpu::setAffinity(m_id, handle->affinity());
} // }
Platform::setThreadPriority(handle->priority()); Platform::setThreadPriority(handle->config()->priority());
m_ctx = Mem::create(m_id); m_ctx = Mem::create(m_id);
} }

View file

@ -49,8 +49,8 @@ protected:
void storeStats(); void storeStats();
cryptonight_ctx *m_ctx; cryptonight_ctx *m_ctx;
int m_id; size_t m_id;
int m_threads; size_t m_totalWays;
std::atomic<uint64_t> m_hashCount; std::atomic<uint64_t> m_hashCount;
std::atomic<uint64_t> m_timestamp; std::atomic<uint64_t> m_timestamp;
uint64_t m_count; uint64_t m_count;

View file

@ -25,7 +25,10 @@
#include "api/Api.h" #include "api/Api.h"
#include "core/Config.h"
#include "core/Controller.h"
#include "interfaces/IJobResultListener.h" #include "interfaces/IJobResultListener.h"
#include "interfaces/IThread.h"
#include "Mem.h" #include "Mem.h"
#include "workers/DoubleWorker.h" #include "workers/DoubleWorker.h"
#include "workers/Handle.h" #include "workers/Handle.h"
@ -33,6 +36,8 @@
#include "workers/SingleWorker.h" #include "workers/SingleWorker.h"
#include "workers/Workers.h" #include "workers/Workers.h"
#include "log/Log.h"
bool Workers::m_active = false; bool Workers::m_active = false;
bool Workers::m_enabled = true; 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) void Workers::start(int64_t affinity, int priority, xmrig::Controller *controller)
{ {
const int threads = Mem::threads(); const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
m_hashrate = new Hashrate(threads, controller);
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_mutex_init(&m_mutex);
uv_rwlock_init(&m_rwlock); 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_init(uv_default_loop(), &m_timer);
uv_timer_start(&m_timer, Workers::onTick, 500, 500); uv_timer_start(&m_timer, Workers::onTick, 500, 500);
for (int i = 0; i < threads; ++i) { for (xmrig::IThread *thread : threads) {
Handle *handle = new Handle(i, threads, affinity, priority); Handle *handle = new Handle(thread, totalWays);
m_workers.push_back(handle); m_workers.push_back(handle);
handle->start(Workers::onReady); handle->start(Workers::onReady);
} }