mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 00:37:46 +00:00
Added initial support for new style threads launch method.
This commit is contained in:
parent
dff59fabc2
commit
27f3008d79
32 changed files with 1429 additions and 505 deletions
|
@ -33,6 +33,7 @@ set(HEADERS
|
|||
src/core/config/ConfigTransform.h
|
||||
src/core/config/usage.h
|
||||
src/core/Controller.h
|
||||
src/core/Miner.h
|
||||
src/Mem.h
|
||||
src/net/interfaces/IJobResultListener.h
|
||||
src/net/JobResult.h
|
||||
|
@ -44,8 +45,7 @@ set(HEADERS
|
|||
src/version.h
|
||||
src/workers/CpuThreadLegacy.h
|
||||
src/workers/Hashrate.h
|
||||
src/workers/ThreadHandle.h
|
||||
src/workers/Workers.h
|
||||
src/workers/WorkersLegacy.h
|
||||
)
|
||||
|
||||
set(HEADERS_CRYPTO
|
||||
|
@ -84,6 +84,7 @@ set(SOURCES
|
|||
src/core/config/Config.cpp
|
||||
src/core/config/ConfigTransform.cpp
|
||||
src/core/Controller.cpp
|
||||
src/core/Miner.cpp
|
||||
src/Mem.cpp
|
||||
src/net/JobResults.cpp
|
||||
src/net/Network.cpp
|
||||
|
@ -92,8 +93,7 @@ set(SOURCES
|
|||
src/Summary.cpp
|
||||
src/workers/CpuThreadLegacy.cpp
|
||||
src/workers/Hashrate.cpp
|
||||
src/workers/ThreadHandle.cpp
|
||||
src/workers/Workers.cpp
|
||||
src/workers/WorkersLegacy.cpp
|
||||
src/xmrig.cpp
|
||||
)
|
||||
|
||||
|
|
17
src/App.cpp
17
src/App.cpp
|
@ -36,11 +36,11 @@
|
|||
#include "base/kernel/Signals.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "core/Miner.h"
|
||||
#include "Mem.h"
|
||||
#include "net/Network.h"
|
||||
#include "Summary.h"
|
||||
#include "version.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
xmrig::App::App(Process *process) :
|
||||
|
@ -86,8 +86,6 @@ int xmrig::App::exec()
|
|||
return 0;
|
||||
}
|
||||
|
||||
Workers::start(m_controller);
|
||||
|
||||
m_controller->start();
|
||||
|
||||
const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
|
@ -102,23 +100,17 @@ void xmrig::App::onConsoleCommand(char command)
|
|||
switch (command) {
|
||||
case 'h':
|
||||
case 'H':
|
||||
Workers::printHashrate(true);
|
||||
m_controller->miner()->printHashrate(true);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
case 'P':
|
||||
if (Workers::isEnabled()) {
|
||||
LOG_INFO(YELLOW_BOLD("paused") ", press " MAGENTA_BOLD("r") " to resume");
|
||||
Workers::setEnabled(false);
|
||||
}
|
||||
m_controller->miner()->setEnabled(false);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
case 'R':
|
||||
if (!Workers::isEnabled()) {
|
||||
LOG_INFO(GREEN_BOLD("resumed"));
|
||||
Workers::setEnabled(true);
|
||||
}
|
||||
m_controller->miner()->setEnabled(true);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
@ -162,6 +154,5 @@ void xmrig::App::close()
|
|||
m_console->stop();
|
||||
m_controller->stop();
|
||||
|
||||
Workers::stop();
|
||||
Log::destroy();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#include "rapidjson/document.h"
|
||||
#include "version.h"
|
||||
#include "workers/Hashrate.h"
|
||||
#include "workers/Workers.h"
|
||||
#include "workers/WorkersLegacy.h"
|
||||
|
||||
|
||||
static inline rapidjson::Value normalize(double d)
|
||||
|
@ -107,13 +107,13 @@ void xmrig::ApiRouter::getHashrate(rapidjson::Value &reply, rapidjson::Document
|
|||
Value total(kArrayType);
|
||||
Value threads(kArrayType);
|
||||
|
||||
const Hashrate *hr = Workers::hashrate();
|
||||
const Hashrate *hr = WorkersLegacy::hashrate();
|
||||
|
||||
total.PushBack(normalize(hr->calc(Hashrate::ShortInterval)), allocator);
|
||||
total.PushBack(normalize(hr->calc(Hashrate::MediumInterval)), allocator);
|
||||
total.PushBack(normalize(hr->calc(Hashrate::LargeInterval)), allocator);
|
||||
|
||||
for (size_t i = 0; i < Workers::threads(); i++) {
|
||||
for (size_t i = 0; i < WorkersLegacy::threads(); i++) {
|
||||
Value thread(kArrayType);
|
||||
thread.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
|
||||
thread.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
|
||||
|
@ -144,7 +144,7 @@ void xmrig::ApiRouter::getMiner(rapidjson::Value &reply, rapidjson::Document &do
|
|||
reply.AddMember("kind", APP_KIND, allocator);
|
||||
reply.AddMember("ua", StringRef(Platform::userAgent()), allocator);
|
||||
reply.AddMember("cpu", cpu, allocator);
|
||||
reply.AddMember("hugepages", Workers::hugePages() > 0, allocator);
|
||||
reply.AddMember("hugepages", WorkersLegacy::hugePages() > 0, allocator);
|
||||
reply.AddMember("donate_level", m_base->config()->pools().donateLevel(), allocator);
|
||||
}
|
||||
|
||||
|
@ -153,9 +153,9 @@ void xmrig::ApiRouter::getThreads(rapidjson::Value &reply, rapidjson::Document &
|
|||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
const Hashrate *hr = Workers::hashrate();
|
||||
const Hashrate *hr = WorkersLegacy::hashrate();
|
||||
|
||||
Workers::threadsSummary(doc);
|
||||
WorkersLegacy::threadsSummary(doc);
|
||||
|
||||
const std::vector<IThread *> &threads = m_base->config()->threads();
|
||||
Value list(kArrayType);
|
||||
|
|
62
src/backend/common/Thread.h
Normal file
62
src/backend/common/Thread.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_THREAD_H
|
||||
#define XMRIG_THREAD_H
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IWorker;
|
||||
|
||||
|
||||
template<class T>
|
||||
class Thread
|
||||
{
|
||||
public:
|
||||
inline Thread(size_t index, const T &config) : m_index(index), m_config(config) {}
|
||||
inline ~Thread() { uv_thread_join(&m_thread); }
|
||||
|
||||
inline const T &config() const { return m_config; }
|
||||
inline IWorker *worker() const { return m_worker; }
|
||||
inline size_t index() const { return m_index; }
|
||||
inline void setWorker(IWorker *worker) { m_worker = worker; }
|
||||
inline void start(void (*callback) (void *)) { uv_thread_create(&m_thread, callback, this); }
|
||||
|
||||
private:
|
||||
const size_t m_index = 0;
|
||||
const T m_config;
|
||||
IWorker *m_worker = nullptr;
|
||||
uv_thread_t m_thread;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_THREAD_H */
|
|
@ -26,7 +26,6 @@
|
|||
#define XMRIG_WORKERJOB_H
|
||||
|
||||
|
||||
#include <atomic>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
|
152
src/backend/common/Workers.cpp
Normal file
152
src/backend/common/Workers.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "backend/common/Workers.h"
|
||||
#include "backend/cpu/CpuWorker.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class WorkersPrivate
|
||||
{
|
||||
public:
|
||||
inline WorkersPrivate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline ~WorkersPrivate()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
template<class T>
|
||||
xmrig::Workers<T>::Workers() :
|
||||
d_ptr(new WorkersPrivate())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
xmrig::Workers<T>::~Workers()
|
||||
{
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void xmrig::Workers<T>::add(const T &data)
|
||||
{
|
||||
m_workers.push_back(new Thread<T>(m_workers.size(), data));
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void xmrig::Workers<T>::start()
|
||||
{
|
||||
for (Thread<T> *worker : m_workers) {
|
||||
worker->start(Workers<T>::onReady);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void xmrig::Workers<T>::stop()
|
||||
{
|
||||
Nonce::stop(T::backend());
|
||||
|
||||
for (Thread<T> *worker : m_workers) {
|
||||
delete worker;
|
||||
}
|
||||
|
||||
m_workers.clear();
|
||||
Nonce::touch(T::backend());
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void xmrig::Workers<T>::onReady(void *arg)
|
||||
{
|
||||
printf("ON READY\n");
|
||||
}
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
template<>
|
||||
void xmrig::Workers<CpuLaunchData>::onReady(void *arg)
|
||||
{
|
||||
auto handle = static_cast<Thread<CpuLaunchData>* >(arg);
|
||||
|
||||
IWorker *worker = nullptr;
|
||||
|
||||
switch (handle->config().intensity) {
|
||||
case 1:
|
||||
worker = new CpuWorker<1>(handle->index(), handle->config());
|
||||
break;
|
||||
|
||||
case 2:
|
||||
worker = new CpuWorker<2>(handle->index(), handle->config());
|
||||
break;
|
||||
|
||||
case 3:
|
||||
worker = new CpuWorker<3>(handle->index(), handle->config());
|
||||
break;
|
||||
|
||||
case 4:
|
||||
worker = new CpuWorker<4>(handle->index(), handle->config());
|
||||
break;
|
||||
|
||||
case 5:
|
||||
worker = new CpuWorker<5>(handle->index(), handle->config());
|
||||
break;
|
||||
}
|
||||
|
||||
handle->setWorker(worker);
|
||||
|
||||
if (!worker->selfTest()) {
|
||||
LOG_ERR("thread %zu error: \"hash self-test failed\".", handle->worker()->id());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
worker->start();
|
||||
}
|
||||
|
||||
|
||||
template class Workers<CpuLaunchData>;
|
||||
|
||||
|
||||
} // namespace xmrig
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
|
@ -22,38 +23,47 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_THREADHANDLE_H
|
||||
#define XMRIG_THREADHANDLE_H
|
||||
#ifndef XMRIG_WORKERS_H
|
||||
#define XMRIG_WORKERS_H
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <uv.h>
|
||||
#include "backend/common/Thread.h"
|
||||
#include "backend/cpu/CpuLaunchData.h"
|
||||
|
||||
|
||||
#include "backend/common/interfaces/IThread.h"
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IWorker;
|
||||
class WorkersPrivate;
|
||||
|
||||
|
||||
class ThreadHandle
|
||||
template<class T>
|
||||
class Workers
|
||||
{
|
||||
public:
|
||||
ThreadHandle(xmrig::IThread *config);
|
||||
void join();
|
||||
void start(void (*callback) (void *));
|
||||
Workers();
|
||||
~Workers();
|
||||
|
||||
inline IWorker *worker() const { return m_worker; }
|
||||
inline size_t threadId() const { return m_config->index(); }
|
||||
inline void setWorker(IWorker *worker) { assert(worker != nullptr); m_worker = worker; }
|
||||
inline xmrig::IThread *config() const { return m_config; }
|
||||
void add(const T &data);
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
IWorker *m_worker;
|
||||
uv_thread_t m_thread;
|
||||
xmrig::IThread *m_config;
|
||||
static void onReady(void *arg);
|
||||
|
||||
std::vector<Thread<T> *> m_workers;
|
||||
WorkersPrivate *d_ptr;
|
||||
};
|
||||
|
||||
|
||||
#endif /* XMRIG_THREADHANDLE_H */
|
||||
template<>
|
||||
void Workers<CpuLaunchData>::onReady(void *arg);
|
||||
|
||||
|
||||
extern template class Workers<CpuLaunchData>;
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_WORKERS_H */
|
|
@ -1,12 +1,16 @@
|
|||
set(HEADERS_BACKEND_COMMON
|
||||
src/backend/common/interfaces/IBackend.h
|
||||
src/backend/common/interfaces/IThread.h
|
||||
src/backend/common/interfaces/IWorker.h
|
||||
src/backend/common/Thread.h
|
||||
src/backend/common/Threads.h
|
||||
src/backend/common/Worker.h
|
||||
src/backend/common/Workers.h
|
||||
src/backend/common/WorkerJob.h
|
||||
)
|
||||
|
||||
set(SOURCES_BACKEND_COMMON
|
||||
src/backend/common/Threads.cpp
|
||||
src/backend/common/Worker.cpp
|
||||
src/backend/common/Workers.cpp
|
||||
)
|
||||
|
|
|
@ -22,24 +22,34 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "workers/ThreadHandle.h"
|
||||
#ifndef XMRIG_IBACKEND_H
|
||||
#define XMRIG_IBACKEND_H
|
||||
|
||||
|
||||
ThreadHandle::ThreadHandle(xmrig::IThread *config) :
|
||||
m_worker(nullptr),
|
||||
m_config(config)
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Job;
|
||||
class String;
|
||||
|
||||
|
||||
class IBackend
|
||||
{
|
||||
}
|
||||
public:
|
||||
virtual ~IBackend() = default;
|
||||
|
||||
virtual const String &profileName() const = 0;
|
||||
virtual void printHashrate(bool details) = 0;
|
||||
virtual void setJob(const Job &job) = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void tick(uint64_t ticks) = 0;
|
||||
};
|
||||
|
||||
|
||||
void ThreadHandle::join()
|
||||
{
|
||||
uv_thread_join(&m_thread);
|
||||
}
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
void ThreadHandle::start(void (*callback) (void *))
|
||||
{
|
||||
uv_thread_create(&m_thread, callback, this);
|
||||
}
|
||||
#endif // XMRIG_IBACKEND_H
|
|
@ -29,6 +29,9 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IWorker
|
||||
{
|
||||
public:
|
||||
|
@ -42,4 +45,7 @@ public:
|
|||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif // XMRIG_IWORKER_H
|
||||
|
|
151
src/backend/cpu/CpuBackend.cpp
Normal file
151
src/backend/cpu/CpuBackend.cpp
Normal file
|
@ -0,0 +1,151 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "backend/common/Workers.h"
|
||||
#include "backend/cpu/CpuBackend.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
|
||||
|
||||
#include "base/io/log/Log.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
extern template class Threads<CpuThread>;
|
||||
|
||||
|
||||
class CpuBackendPrivate
|
||||
{
|
||||
public:
|
||||
inline CpuBackendPrivate(const Miner *miner, Controller *controller) :
|
||||
miner(miner),
|
||||
controller(controller)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline ~CpuBackendPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline bool isReady(const Algorithm &nextAlgo) const
|
||||
{
|
||||
if (!algo.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nextAlgo == algo) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const CpuThreads &nextThreads = controller->config()->cpu().threads().get(nextAlgo);
|
||||
|
||||
return algo.memory() == nextAlgo.memory()
|
||||
&& threads.size() == nextThreads.size()
|
||||
&& std::equal(threads.begin(), threads.end(), nextThreads.begin());
|
||||
}
|
||||
|
||||
|
||||
Algorithm algo;
|
||||
const Miner *miner;
|
||||
Controller *controller;
|
||||
CpuThreads threads;
|
||||
String profileName;
|
||||
Workers<CpuLaunchData> workers;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::CpuBackend::CpuBackend(const Miner *miner, Controller *controller) :
|
||||
d_ptr(new CpuBackendPrivate(miner, controller))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
xmrig::CpuBackend::~CpuBackend()
|
||||
{
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
|
||||
const xmrig::String &xmrig::CpuBackend::profileName() const
|
||||
{
|
||||
return d_ptr->profileName;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CpuBackend::printHashrate(bool details)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CpuBackend::setJob(const Job &job)
|
||||
{
|
||||
LOG_WARN("PROFILE %s %zu", d_ptr->controller->config()->cpu().threads().profileName(job.algorithm()).data(), job.algorithm().memory());
|
||||
|
||||
if (d_ptr->isReady(job.algorithm())) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO(GREEN_BOLD_S "INIT");
|
||||
|
||||
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
|
||||
const Threads<CpuThread> &threads = cpu.threads();
|
||||
|
||||
d_ptr->algo = job.algorithm();
|
||||
d_ptr->profileName = threads.profileName(job.algorithm());
|
||||
d_ptr->threads = threads.get(d_ptr->profileName);
|
||||
|
||||
LOG_INFO(BLUE_BG_S " %zu ", d_ptr->threads.size());
|
||||
|
||||
d_ptr->workers.stop();
|
||||
|
||||
for (const CpuThread &thread : d_ptr->threads) {
|
||||
d_ptr->workers.add(CpuLaunchData(d_ptr->miner, d_ptr->algo, cpu, thread));
|
||||
}
|
||||
|
||||
d_ptr->workers.start();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CpuBackend::stop()
|
||||
{
|
||||
d_ptr->workers.stop();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CpuBackend::tick(uint64_t ticks)
|
||||
{
|
||||
|
||||
}
|
61
src/backend/cpu/CpuBackend.h
Normal file
61
src/backend/cpu/CpuBackend.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_CPUBACKEND_H
|
||||
#define XMRIG_CPUBACKEND_H
|
||||
|
||||
|
||||
#include "backend/common/interfaces/IBackend.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Controller;
|
||||
class CpuBackendPrivate;
|
||||
class Miner;
|
||||
|
||||
|
||||
class CpuBackend : public IBackend
|
||||
{
|
||||
public:
|
||||
CpuBackend(const Miner *miner, Controller *controller);
|
||||
~CpuBackend() override;
|
||||
|
||||
protected:
|
||||
const String &profileName() const override;
|
||||
void printHashrate(bool details) override;
|
||||
void setJob(const Job &job) override;
|
||||
void stop() override;
|
||||
void tick(uint64_t ticks) override;
|
||||
|
||||
private:
|
||||
CpuBackendPrivate *d_ptr;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_CPUBACKEND_H */
|
51
src/backend/cpu/CpuLaunchData.cpp
Normal file
51
src/backend/cpu/CpuLaunchData.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "backend/cpu/CpuLaunchData.h"
|
||||
#include "backend/cpu/CpuConfig.h"
|
||||
|
||||
|
||||
xmrig::CpuLaunchData::CpuLaunchData(const Miner *miner, const Algorithm &algorithm, const CpuConfig &config, const CpuThread &thread) :
|
||||
algorithm(algorithm),
|
||||
assembly(config.assembly()),
|
||||
hugePages(config.isHugePages()),
|
||||
hwAES(config.isHwAES()),
|
||||
intensity(thread.intensity()),
|
||||
priority(config.priority()),
|
||||
affinity(thread.affinity()),
|
||||
miner(miner)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::CnHash::AlgoVariant xmrig::CpuLaunchData::av() const
|
||||
{
|
||||
if (intensity <= 2) {
|
||||
return static_cast<CnHash::AlgoVariant>(!hwAES ? (intensity + 2) : intensity);
|
||||
}
|
||||
|
||||
return static_cast<CnHash::AlgoVariant>(!hwAES ? (intensity + 5) : (intensity + 2));
|
||||
}
|
67
src/backend/cpu/CpuLaunchData.h
Normal file
67
src/backend/cpu/CpuLaunchData.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_CPULAUNCHDATA_H
|
||||
#define XMRIG_CPULAUNCHDATA_H
|
||||
|
||||
|
||||
#include "crypto/cn/CnHash.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "crypto/common/Assembly.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CpuConfig;
|
||||
class CpuThread;
|
||||
class Miner;
|
||||
|
||||
|
||||
class CpuLaunchData
|
||||
{
|
||||
public:
|
||||
CpuLaunchData(const Miner *miner, const Algorithm &algorithm, const CpuConfig &config, const CpuThread &thread);
|
||||
|
||||
CnHash::AlgoVariant av() const;
|
||||
|
||||
inline constexpr static Nonce::Backend backend() { return Nonce::CPU; }
|
||||
|
||||
const Algorithm algorithm;
|
||||
const Assembly assembly;
|
||||
const bool hugePages;
|
||||
const bool hwAES;
|
||||
const int intensity;
|
||||
const int priority;
|
||||
const int64_t affinity;
|
||||
const Miner *miner;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_CPULAUNCHDATA_H */
|
|
@ -38,19 +38,23 @@ namespace xmrig {
|
|||
class CpuThread
|
||||
{
|
||||
public:
|
||||
inline constexpr CpuThread(int intensity = 1, int affinity = -1) : m_affinity(affinity), m_intensity(intensity) {}
|
||||
inline constexpr CpuThread(int intensity = 1, int64_t affinity = -1) : m_intensity(intensity), m_affinity(affinity) {}
|
||||
|
||||
CpuThread(const rapidjson::Value &value);
|
||||
|
||||
inline bool isEqual(const CpuThread &other) const { return other.m_affinity == m_affinity && other.m_intensity == m_intensity; }
|
||||
inline bool isValid() const { return m_intensity >= 1 && m_intensity <= 5; }
|
||||
inline int affinity() const { return m_affinity; }
|
||||
inline int intensity() const { return m_intensity; }
|
||||
inline int64_t affinity() const { return m_affinity; }
|
||||
|
||||
inline bool operator!=(const CpuThread &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const CpuThread &other) const { return isEqual(other); }
|
||||
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
|
||||
private:
|
||||
int m_affinity = -1;
|
||||
int m_intensity = -1;
|
||||
int64_t m_affinity = -1;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -28,14 +28,17 @@
|
|||
|
||||
|
||||
#include "backend/cpu/CpuWorker.h"
|
||||
#include "core/Miner.h"
|
||||
#include "crypto/cn/CryptoNight_test.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
#include "crypto/rx/Rx.h"
|
||||
#include "crypto/rx/RxVm.h"
|
||||
#include "net/JobResults.h"
|
||||
#include "workers/CpuThreadLegacy.h"
|
||||
#include "workers/ThreadHandle.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_ALGO_RANDOMX
|
||||
# include "crypto/randomx/randomx.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -45,13 +48,18 @@ static constexpr uint32_t kReserveCount = 4096;
|
|||
} // namespace xmrig
|
||||
|
||||
|
||||
|
||||
template<size_t N>
|
||||
xmrig::CpuWorker<N>::CpuWorker(ThreadHandle *handle) :
|
||||
Worker(handle->threadId(), handle->config()->affinity(), handle->config()->priority()),
|
||||
m_thread(static_cast<xmrig::CpuThreadLegacy *>(handle->config()))
|
||||
xmrig::CpuWorker<N>::CpuWorker(size_t index, const CpuLaunchData &data) :
|
||||
Worker(index, data.affinity, data.priority),
|
||||
m_algorithm(data.algorithm),
|
||||
m_assembly(data.assembly),
|
||||
m_hwAES(data.hwAES),
|
||||
m_av(data.av()),
|
||||
m_miner(data.miner)
|
||||
{
|
||||
if (m_thread->algorithm().family() != Algorithm::RANDOM_X) {
|
||||
m_memory = Mem::create(m_ctx, m_thread->algorithm(), N);
|
||||
if (m_algorithm.family() != Algorithm::RANDOM_X) {
|
||||
m_memory = Mem::create(m_ctx, m_algorithm, N);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +81,7 @@ void xmrig::CpuWorker<N>::allocateRandomX_VM()
|
|||
{
|
||||
if (!m_vm) {
|
||||
RxDataset *dataset = Rx::dataset(m_job.currentJob().seedHash(), m_job.currentJob().algorithm());
|
||||
m_vm = new RxVm(dataset, true, m_thread->isSoftAES());
|
||||
m_vm = new RxVm(dataset, true, !m_hwAES);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -82,7 +90,7 @@ void xmrig::CpuWorker<N>::allocateRandomX_VM()
|
|||
template<size_t N>
|
||||
bool xmrig::CpuWorker<N>::selfTest()
|
||||
{
|
||||
if (m_thread->algorithm().family() == Algorithm::CN) {
|
||||
if (m_algorithm.family() == Algorithm::CN) {
|
||||
const bool rc = verify(Algorithm::CN_0, test_output_v0) &&
|
||||
verify(Algorithm::CN_1, test_output_v1) &&
|
||||
verify(Algorithm::CN_2, test_output_v2) &&
|
||||
|
@ -108,14 +116,14 @@ bool xmrig::CpuWorker<N>::selfTest()
|
|||
}
|
||||
|
||||
# ifdef XMRIG_ALGO_CN_LITE
|
||||
if (m_thread->algorithm().family() == Algorithm::CN_LITE) {
|
||||
if (m_algorithm.family() == Algorithm::CN_LITE) {
|
||||
return verify(Algorithm::CN_LITE_0, test_output_v0_lite) &&
|
||||
verify(Algorithm::CN_LITE_1, test_output_v1_lite);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_ALGO_CN_HEAVY
|
||||
if (m_thread->algorithm().family() == Algorithm::CN_HEAVY) {
|
||||
if (m_algorithm.family() == Algorithm::CN_HEAVY) {
|
||||
return verify(Algorithm::CN_HEAVY_0, test_output_v0_heavy) &&
|
||||
verify(Algorithm::CN_HEAVY_XHV, test_output_xhv_heavy) &&
|
||||
verify(Algorithm::CN_HEAVY_TUBE, test_output_tube_heavy);
|
||||
|
@ -123,13 +131,13 @@ bool xmrig::CpuWorker<N>::selfTest()
|
|||
# endif
|
||||
|
||||
# ifdef XMRIG_ALGO_CN_PICO
|
||||
if (m_thread->algorithm().family() == Algorithm::CN_PICO) {
|
||||
if (m_algorithm.family() == Algorithm::CN_PICO) {
|
||||
return verify(Algorithm::CN_PICO_0, test_output_pico_trtl);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_thread->algorithm().family() == Algorithm::RANDOM_X) {
|
||||
if (m_algorithm.family() == Algorithm::RANDOM_X) {
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
|
@ -141,21 +149,21 @@ bool xmrig::CpuWorker<N>::selfTest()
|
|||
template<size_t N>
|
||||
void xmrig::CpuWorker<N>::start()
|
||||
{
|
||||
while (Nonce::sequence() > 0) {
|
||||
if (Workers::isPaused()) {
|
||||
while (Nonce::sequence(Nonce::CPU) > 0) {
|
||||
if (Nonce::isPaused()) {
|
||||
do {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
while (Workers::isPaused());
|
||||
while (Nonce::isPaused());
|
||||
|
||||
if (Nonce::sequence() == 0) {
|
||||
if (Nonce::sequence(Nonce::CPU) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
consumeJob();
|
||||
}
|
||||
|
||||
while (!Nonce::isOutdated(m_job.sequence())) {
|
||||
while (!Nonce::isOutdated(Nonce::CPU, m_job.sequence())) {
|
||||
if ((m_count & 0x7) == 0) {
|
||||
storeStats();
|
||||
}
|
||||
|
@ -170,7 +178,7 @@ void xmrig::CpuWorker<N>::start()
|
|||
else
|
||||
# endif
|
||||
{
|
||||
m_thread->fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height());
|
||||
fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
|
@ -193,7 +201,7 @@ void xmrig::CpuWorker<N>::start()
|
|||
template<size_t N>
|
||||
bool xmrig::CpuWorker<N>::verify(const Algorithm &algorithm, const uint8_t *referenceValue)
|
||||
{
|
||||
cn_hash_fun func = m_thread->fn(algorithm);
|
||||
cn_hash_fun func = fn(algorithm);
|
||||
if (!func) {
|
||||
return false;
|
||||
}
|
||||
|
@ -206,7 +214,7 @@ bool xmrig::CpuWorker<N>::verify(const Algorithm &algorithm, const uint8_t *refe
|
|||
template<size_t N>
|
||||
bool xmrig::CpuWorker<N>::verify2(const Algorithm &algorithm, const uint8_t *referenceValue)
|
||||
{
|
||||
cn_hash_fun func = m_thread->fn(algorithm);
|
||||
cn_hash_fun func = fn(algorithm);
|
||||
if (!func) {
|
||||
return false;
|
||||
}
|
||||
|
@ -235,7 +243,7 @@ namespace xmrig {
|
|||
template<>
|
||||
bool CpuWorker<1>::verify2(const Algorithm &algorithm, const uint8_t *referenceValue)
|
||||
{
|
||||
cn_hash_fun func = m_thread->fn(algorithm);
|
||||
cn_hash_fun func = fn(algorithm);
|
||||
if (!func) {
|
||||
return false;
|
||||
}
|
||||
|
@ -257,7 +265,7 @@ bool CpuWorker<1>::verify2(const Algorithm &algorithm, const uint8_t *referenceV
|
|||
template<size_t N>
|
||||
void xmrig::CpuWorker<N>::consumeJob()
|
||||
{
|
||||
m_job.add(Workers::job(), Nonce::sequence(), kReserveCount);
|
||||
m_job.add(m_miner->job(), Nonce::sequence(Nonce::CPU), kReserveCount);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,20 +27,17 @@
|
|||
#define XMRIG_CPUWORKER_H
|
||||
|
||||
|
||||
#include "backend/common/Worker.h"
|
||||
#include "backend/common/WorkerJob.h"
|
||||
#include "backend/cpu/CpuLaunchData.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "Mem.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "backend/common/Worker.h"
|
||||
|
||||
|
||||
class ThreadHandle;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CpuThreadLegacy;
|
||||
class RxVm;
|
||||
|
||||
|
||||
|
@ -48,7 +45,7 @@ template<size_t N>
|
|||
class CpuWorker : public Worker
|
||||
{
|
||||
public:
|
||||
CpuWorker(ThreadHandle *handle);
|
||||
CpuWorker(size_t index, const CpuLaunchData &data);
|
||||
~CpuWorker() override;
|
||||
|
||||
inline const MemInfo &memory() const { return m_memory; }
|
||||
|
@ -58,6 +55,8 @@ protected:
|
|||
void start() override;
|
||||
|
||||
private:
|
||||
inline cn_hash_fun fn(const Algorithm &algorithm) const { return CnHash::fn(algorithm, m_av, m_assembly); }
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
void allocateRandomX_VM();
|
||||
# endif
|
||||
|
@ -66,7 +65,11 @@ private:
|
|||
bool verify2(const Algorithm &algorithm, const uint8_t *referenceValue);
|
||||
void consumeJob();
|
||||
|
||||
CpuThreadLegacy *m_thread;
|
||||
const Algorithm m_algorithm;
|
||||
const Assembly m_assembly;
|
||||
const bool m_hwAES;
|
||||
const CnHash::AlgoVariant m_av;
|
||||
const Miner *m_miner;
|
||||
cryptonight_ctx *m_ctx[N];
|
||||
MemInfo m_memory;
|
||||
uint8_t m_hash[N * 32];
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
set(HEADERS_BACKEND_CPU
|
||||
src/backend/cpu/Cpu.h
|
||||
src/backend/cpu/CpuBackend.h
|
||||
src/backend/cpu/CpuConfig.h
|
||||
src/backend/cpu/CpuLaunchData.cpp
|
||||
src/backend/cpu/CpuThread.h
|
||||
src/backend/cpu/CpuWorker.h
|
||||
src/backend/cpu/interfaces/ICpuInfo.h
|
||||
|
@ -8,7 +10,9 @@ set(HEADERS_BACKEND_CPU
|
|||
|
||||
set(SOURCES_BACKEND_CPU
|
||||
src/backend/cpu/Cpu.cpp
|
||||
src/backend/cpu/CpuBackend.cpp
|
||||
src/backend/cpu/CpuConfig.cpp
|
||||
src/backend/cpu/CpuLaunchData.h
|
||||
src/backend/cpu/CpuThread.cpp
|
||||
src/backend/cpu/CpuWorker.cpp
|
||||
)
|
||||
|
|
|
@ -83,6 +83,8 @@ private:
|
|||
|
||||
#define BLUE_BG_S CSI "44m"
|
||||
#define BLUE_BG_BOLD_S CSI "44;1m"
|
||||
#define MAGENTA_BG_S CSI "45m"
|
||||
#define MAGENTA_BG_BOLD_S CSI "45;1m"
|
||||
|
||||
//color wrappings
|
||||
#define BLACK(x) BLACK_S x CLEAR
|
||||
|
@ -104,6 +106,8 @@ private:
|
|||
|
||||
#define BLUE_BG(x) BLUE_BG_S x CLEAR
|
||||
#define BLUE_BG_BOLD(x) BLUE_BG_BOLD_S x CLEAR
|
||||
#define MAGENTA_BG(x) MAGENTA_BG_S x CLEAR
|
||||
#define MAGENTA_BG_BOLD(x) MAGENTA_BG_BOLD_S x CLEAR
|
||||
|
||||
|
||||
#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__)
|
||||
|
|
|
@ -28,12 +28,12 @@
|
|||
|
||||
#include "backend/cpu/Cpu.h"
|
||||
#include "core/Controller.h"
|
||||
#include "core/Miner.h"
|
||||
#include "net/Network.h"
|
||||
|
||||
|
||||
xmrig::Controller::Controller(Process *process) :
|
||||
Base(process),
|
||||
m_network(nullptr)
|
||||
Base(process)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,8 @@ void xmrig::Controller::start()
|
|||
{
|
||||
Base::start();
|
||||
|
||||
m_miner = new Miner(this);
|
||||
|
||||
network()->connect();
|
||||
}
|
||||
|
||||
|
@ -78,6 +80,19 @@ void xmrig::Controller::stop()
|
|||
|
||||
delete m_network;
|
||||
m_network = nullptr;
|
||||
|
||||
m_miner->stop();
|
||||
|
||||
delete m_miner;
|
||||
m_miner = nullptr;
|
||||
}
|
||||
|
||||
|
||||
xmrig::Miner *xmrig::Controller::miner() const
|
||||
{
|
||||
assert(m_miner != nullptr);
|
||||
|
||||
return m_miner;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
class Job;
|
||||
class Miner;
|
||||
class Network;
|
||||
|
||||
|
||||
|
@ -46,10 +48,12 @@ public:
|
|||
void start() override;
|
||||
void stop() override;
|
||||
|
||||
Miner *miner() const;
|
||||
Network *network() const;
|
||||
|
||||
private:
|
||||
Network *m_network;
|
||||
Miner *m_miner = nullptr;
|
||||
Network *m_network = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
|
215
src/core/Miner.cpp
Normal file
215
src/core/Miner.cpp
Normal file
|
@ -0,0 +1,215 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "backend/cpu/CpuBackend.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/Timer.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "core/Miner.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
|
||||
#include "base/tools/Chrono.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class MinerPrivate
|
||||
{
|
||||
public:
|
||||
inline MinerPrivate(Controller *controller) : controller(controller)
|
||||
{
|
||||
uv_rwlock_init(&rwlock);
|
||||
}
|
||||
|
||||
|
||||
inline ~MinerPrivate()
|
||||
{
|
||||
uv_rwlock_destroy(&rwlock);
|
||||
|
||||
delete timer;
|
||||
|
||||
for (IBackend *backend : backends) {
|
||||
delete backend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void handleJobChange()
|
||||
{
|
||||
active = true;
|
||||
if (enabled) {
|
||||
Nonce::pause(false);;
|
||||
}
|
||||
|
||||
for (IBackend *backend : backends) {
|
||||
backend->setJob(job);
|
||||
}
|
||||
|
||||
if (ticks == 0) {
|
||||
ticks++;
|
||||
timer->start(500, 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool active = false;
|
||||
bool enabled = true;
|
||||
Controller *controller;
|
||||
Job job;
|
||||
std::vector<IBackend *> backends;
|
||||
Timer *timer = nullptr;
|
||||
uint64_t ticks = 0;
|
||||
uv_rwlock_t rwlock;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
||||
xmrig::Miner::Miner(Controller *controller)
|
||||
: d_ptr(new MinerPrivate(controller))
|
||||
{
|
||||
d_ptr->timer = new Timer(this);
|
||||
|
||||
d_ptr->backends.push_back(new CpuBackend(this, controller));
|
||||
}
|
||||
|
||||
|
||||
xmrig::Miner::~Miner()
|
||||
{
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Miner::isEnabled() const
|
||||
{
|
||||
return d_ptr->enabled;
|
||||
}
|
||||
|
||||
|
||||
xmrig::Job xmrig::Miner::job() const
|
||||
{
|
||||
uv_rwlock_rdlock(&d_ptr->rwlock);
|
||||
Job job = d_ptr->job;
|
||||
uv_rwlock_rdunlock(&d_ptr->rwlock);
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Miner::pause()
|
||||
{
|
||||
d_ptr->active = false;
|
||||
|
||||
Nonce::pause(true);
|
||||
Nonce::touch();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Miner::printHashrate(bool details)
|
||||
{
|
||||
for (IBackend *backend : d_ptr->backends) {
|
||||
backend->printHashrate(details);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Miner::setEnabled(bool enabled)
|
||||
{
|
||||
if (d_ptr->enabled == enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
d_ptr->enabled = enabled;
|
||||
|
||||
if (enabled) {
|
||||
LOG_INFO(GREEN_BOLD("resumed"));
|
||||
}
|
||||
else {
|
||||
LOG_INFO(YELLOW_BOLD("paused") ", press " MAGENTA_BG_BOLD(" r ") " to resume");
|
||||
}
|
||||
|
||||
if (!d_ptr->active) {
|
||||
return;
|
||||
}
|
||||
|
||||
Nonce::pause(!enabled);
|
||||
Nonce::touch();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Miner::setJob(const Job &job, bool donate)
|
||||
{
|
||||
uv_rwlock_wrlock(&d_ptr->rwlock);
|
||||
|
||||
const uint8_t index = donate ? 1 : 0;
|
||||
|
||||
d_ptr->job = job;
|
||||
d_ptr->job.setIndex(index);
|
||||
|
||||
Nonce::reset(index);
|
||||
|
||||
uv_rwlock_wrunlock(&d_ptr->rwlock);
|
||||
|
||||
d_ptr->handleJobChange();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Miner::stop()
|
||||
{
|
||||
// xmrig::Handle::close(m_timer);
|
||||
// m_hashrate->stop();
|
||||
|
||||
Nonce::stop();
|
||||
|
||||
// for (size_t i = 0; i < m_workers.size(); ++i) {
|
||||
// m_workers[i]->join();
|
||||
// }
|
||||
|
||||
for (IBackend *backend : d_ptr->backends) {
|
||||
backend->stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Miner::onTimer(const Timer *)
|
||||
{
|
||||
for (IBackend *backend : d_ptr->backends) {
|
||||
backend->tick(d_ptr->ticks);
|
||||
}
|
||||
|
||||
if ((d_ptr->ticks % (d_ptr->controller->config()->printTime() * 2)) == 0) {
|
||||
printHashrate(false);
|
||||
}
|
||||
|
||||
d_ptr->ticks++;
|
||||
}
|
65
src/core/Miner.h
Normal file
65
src/core/Miner.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_MINER_H
|
||||
#define XMRIG_MINER_H
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/ITimerListener.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Controller;
|
||||
class Job;
|
||||
class MinerPrivate;
|
||||
|
||||
|
||||
class Miner : public ITimerListener
|
||||
{
|
||||
public:
|
||||
Miner(Controller *controller);
|
||||
~Miner() override;
|
||||
|
||||
bool isEnabled() const;
|
||||
Job job() const;
|
||||
void pause();
|
||||
void printHashrate(bool details);
|
||||
void setEnabled(bool enabled);
|
||||
void setJob(const Job &job, bool donate);
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
void onTimer(const Timer *timer) override;
|
||||
|
||||
private:
|
||||
MinerPrivate *d_ptr;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_MINER_H */
|
|
@ -202,6 +202,9 @@ static void patchAsmVariants()
|
|||
#endif
|
||||
|
||||
|
||||
static const xmrig::CnHash cnHash;
|
||||
|
||||
|
||||
xmrig::CnHash::CnHash()
|
||||
{
|
||||
ADD_FN(Algorithm::CN_0);
|
||||
|
@ -252,18 +255,18 @@ xmrig::CnHash::CnHash()
|
|||
}
|
||||
|
||||
|
||||
xmrig::cn_hash_fun xmrig::CnHash::fn(const Algorithm &algorithm, AlgoVariant av, Assembly::Id assembly) const
|
||||
xmrig::cn_hash_fun xmrig::CnHash::fn(const Algorithm &algorithm, AlgoVariant av, Assembly::Id assembly)
|
||||
{
|
||||
if (!algorithm.isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
# ifdef XMRIG_FEATURE_ASM
|
||||
cn_hash_fun fun = m_map[algorithm][av][assembly == Assembly::AUTO ? Cpu::info()->assembly() : assembly];
|
||||
cn_hash_fun fun = cnHash.m_map[algorithm][av][assembly == Assembly::AUTO ? Cpu::info()->assembly() : assembly];
|
||||
if (fun) {
|
||||
return fun;
|
||||
}
|
||||
# endif
|
||||
|
||||
return m_map[algorithm][av][Assembly::NONE];
|
||||
return cnHash.m_map[algorithm][av][Assembly::NONE];
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
|
||||
CnHash();
|
||||
|
||||
cn_hash_fun fn(const Algorithm &algorithm, AlgoVariant av, Assembly::Id assembly) const;
|
||||
static cn_hash_fun fn(const Algorithm &algorithm, AlgoVariant av, Assembly::Id assembly);
|
||||
|
||||
private:
|
||||
cn_hash_fun m_map[Algorithm::MAX][AV_MAX][Assembly::MAX] = {};
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
std::atomic<uint64_t> Nonce::m_sequence;
|
||||
std::atomic<bool> Nonce::m_paused;
|
||||
std::atomic<uint64_t> Nonce::m_sequence[Nonce::MAX];
|
||||
uint32_t Nonce::m_nonces[2] = { 0, 0 };
|
||||
|
||||
|
||||
|
@ -45,7 +46,11 @@ static Nonce nonce;
|
|||
|
||||
xmrig::Nonce::Nonce()
|
||||
{
|
||||
m_sequence = 1;
|
||||
m_paused = true;
|
||||
|
||||
for (int i = 0; i < MAX; ++i) {
|
||||
m_sequence[i] = 1;
|
||||
}
|
||||
|
||||
uv_mutex_init(&mutex);
|
||||
}
|
||||
|
@ -77,7 +82,25 @@ void xmrig::Nonce::reset(uint8_t index)
|
|||
uv_mutex_lock(&mutex);
|
||||
|
||||
m_nonces[index] = 0;
|
||||
m_sequence++;
|
||||
touch();
|
||||
|
||||
uv_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Nonce::stop()
|
||||
{
|
||||
pause(false);
|
||||
|
||||
for (int i = 0; i < MAX; ++i) {
|
||||
m_sequence[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Nonce::touch()
|
||||
{
|
||||
for (int i = 0; i < MAX; ++i) {
|
||||
m_sequence[i]++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,19 +35,32 @@ namespace xmrig {
|
|||
class Nonce
|
||||
{
|
||||
public:
|
||||
enum Backend {
|
||||
CPU,
|
||||
OPENCL,
|
||||
CUDA,
|
||||
MAX
|
||||
};
|
||||
|
||||
|
||||
Nonce();
|
||||
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void stop() { m_sequence = 0; }
|
||||
static inline void touch() { m_sequence++; }
|
||||
static inline bool isOutdated(Backend backend, uint64_t sequence) { return m_sequence[backend].load(std::memory_order_relaxed) != sequence; }
|
||||
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed); }
|
||||
static inline uint64_t sequence(Backend backend) { return m_sequence[backend].load(std::memory_order_relaxed); }
|
||||
static inline void pause(bool paused) { m_paused = paused; }
|
||||
static inline void stop(Backend backend) { m_sequence[backend] = 0; }
|
||||
static inline void touch(Backend backend) { m_sequence[backend]++; }
|
||||
|
||||
static uint32_t next(uint8_t index, uint32_t nonce, uint32_t reserveCount, bool nicehash);
|
||||
static void reset(uint8_t index);
|
||||
static void stop();
|
||||
static void touch();
|
||||
|
||||
private:
|
||||
static std::atomic<bool> m_paused;
|
||||
static std::atomic<uint64_t> m_sequence[MAX];
|
||||
static uint32_t m_nonces[2];
|
||||
static std::atomic<uint64_t> m_sequence;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -40,11 +40,12 @@
|
|||
#include "base/tools/Timer.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "core/Miner.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "net/JobResults.h"
|
||||
#include "net/Network.h"
|
||||
#include "net/strategies/DonateStrategy.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
|
@ -163,7 +164,8 @@ void xmrig::Network::onPause(IStrategy *strategy)
|
|||
if (!m_strategy->isActive()) {
|
||||
LOG_ERR("no active pools, stop mining");
|
||||
m_state.stop();
|
||||
return Workers::pause();
|
||||
|
||||
return m_controller->miner()->pause();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,7 +214,7 @@ void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
|
|||
}
|
||||
|
||||
m_state.diff = job.diff();
|
||||
Workers::setJob(job, donate);
|
||||
m_controller->miner()->setJob(job, donate);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,10 +34,6 @@
|
|||
#include "workers/CpuThreadLegacy.h"
|
||||
|
||||
|
||||
|
||||
static const xmrig::CnHash cnHash;
|
||||
|
||||
|
||||
xmrig::CpuThreadLegacy::CpuThreadLegacy(size_t index, Algorithm algorithm, CnHash::AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch, Assembly assembly) :
|
||||
m_algorithm(algorithm),
|
||||
m_av(av),
|
||||
|
@ -54,7 +50,7 @@ xmrig::CpuThreadLegacy::CpuThreadLegacy(size_t index, Algorithm algorithm, CnHas
|
|||
|
||||
xmrig::cn_hash_fun xmrig::CpuThreadLegacy::fn(const Algorithm &algorithm) const
|
||||
{
|
||||
return cnHash.fn(algorithm, m_av, m_assembly);
|
||||
return CnHash::fn(algorithm, m_av, m_assembly);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,330 +0,0 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <inttypes.h>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "api/Api.h"
|
||||
#include "backend/cpu/CpuWorker.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
#include "crypto/rx/RxAlgo.h"
|
||||
#include "crypto/rx/RxCache.h"
|
||||
#include "crypto/rx/RxDataset.h"
|
||||
#include "Mem.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "workers/Hashrate.h"
|
||||
#include "workers/ThreadHandle.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
bool Workers::m_active = false;
|
||||
bool Workers::m_enabled = true;
|
||||
Hashrate *Workers::m_hashrate = nullptr;
|
||||
xmrig::Job Workers::m_job;
|
||||
Workers::LaunchStatus Workers::m_status;
|
||||
std::atomic<int> Workers::m_paused;
|
||||
std::vector<ThreadHandle*> Workers::m_workers;
|
||||
uint64_t Workers::m_ticks = 0;
|
||||
uv_mutex_t Workers::m_mutex;
|
||||
uv_rwlock_t Workers::m_rwlock;
|
||||
uv_timer_t *Workers::m_timer = nullptr;
|
||||
xmrig::Controller *Workers::m_controller = nullptr;
|
||||
|
||||
|
||||
xmrig::Job Workers::job()
|
||||
{
|
||||
uv_rwlock_rdlock(&m_rwlock);
|
||||
xmrig::Job job = m_job;
|
||||
uv_rwlock_rdunlock(&m_rwlock);
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
|
||||
size_t Workers::hugePages()
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
const size_t hugePages = m_status.hugePages;
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
return hugePages;
|
||||
}
|
||||
|
||||
|
||||
size_t Workers::threads()
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
const size_t threads = m_status.threads;
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
return threads;
|
||||
}
|
||||
|
||||
|
||||
void Workers::pause()
|
||||
{
|
||||
m_active = false;
|
||||
m_paused = 1;
|
||||
|
||||
xmrig::Nonce::touch();
|
||||
}
|
||||
|
||||
|
||||
void Workers::printHashrate(bool detail)
|
||||
{
|
||||
assert(m_controller != nullptr);
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (detail) {
|
||||
char num1[8] = { 0 };
|
||||
char num2[8] = { 0 };
|
||||
char num3[8] = { 0 };
|
||||
|
||||
xmrig::Log::print(WHITE_BOLD_S "| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |");
|
||||
|
||||
size_t i = 0;
|
||||
for (const xmrig::IThread *thread : m_controller->config()->threads()) {
|
||||
xmrig::Log::print("| %6zu | %8" PRId64 " | %7s | %7s | %7s |",
|
||||
thread->index(),
|
||||
thread->affinity(),
|
||||
Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1),
|
||||
Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::MediumInterval), num2, sizeof num2),
|
||||
Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::LargeInterval), num3, sizeof num3)
|
||||
);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
m_hashrate->print();
|
||||
}
|
||||
|
||||
|
||||
void Workers::setEnabled(bool enabled)
|
||||
{
|
||||
if (m_enabled == enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_enabled = enabled;
|
||||
if (!m_active) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_paused = enabled ? 0 : 1;
|
||||
xmrig::Nonce::touch();
|
||||
}
|
||||
|
||||
|
||||
void Workers::setJob(const xmrig::Job &job, bool donate)
|
||||
{
|
||||
uv_rwlock_wrlock(&m_rwlock);
|
||||
|
||||
m_job = job;
|
||||
m_job.setIndex(donate ? 1 : 0);
|
||||
|
||||
xmrig::Nonce::reset(donate ? 1 : 0);
|
||||
|
||||
uv_rwlock_wrunlock(&m_rwlock);
|
||||
|
||||
m_active = true;
|
||||
if (!m_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_paused = 0;
|
||||
}
|
||||
|
||||
|
||||
void Workers::start(xmrig::Controller *controller)
|
||||
{
|
||||
# ifdef APP_DEBUG
|
||||
LOG_NOTICE("THREADS ------------------------------------------------------------------");
|
||||
for (const xmrig::IThread *thread : controller->config()->threads()) {
|
||||
thread->print();
|
||||
}
|
||||
LOG_NOTICE("--------------------------------------------------------------------------");
|
||||
# endif
|
||||
|
||||
m_controller = controller;
|
||||
|
||||
const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
|
||||
m_status.algo = xmrig::Algorithm::RX_WOW; // FIXME algo
|
||||
m_status.threads = threads.size();
|
||||
|
||||
for (const xmrig::IThread *thread : threads) {
|
||||
m_status.ways += thread->multiway();
|
||||
}
|
||||
|
||||
m_hashrate = new Hashrate(threads.size(), controller);
|
||||
|
||||
uv_mutex_init(&m_mutex);
|
||||
uv_rwlock_init(&m_rwlock);
|
||||
|
||||
m_paused = 1;
|
||||
|
||||
m_timer = new uv_timer_t;
|
||||
uv_timer_init(uv_default_loop(), m_timer);
|
||||
uv_timer_start(m_timer, Workers::onTick, 500, 500);
|
||||
|
||||
for (xmrig::IThread *thread : threads) {
|
||||
ThreadHandle *handle = new ThreadHandle(thread);
|
||||
|
||||
m_workers.push_back(handle);
|
||||
handle->start(Workers::onReady);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Workers::stop()
|
||||
{
|
||||
xmrig::Handle::close(m_timer);
|
||||
m_hashrate->stop();
|
||||
|
||||
m_paused = 0;
|
||||
|
||||
xmrig::Nonce::stop();
|
||||
|
||||
for (size_t i = 0; i < m_workers.size(); ++i) {
|
||||
m_workers[i]->join();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
void Workers::threadsSummary(rapidjson::Document &doc)
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
const uint64_t pages[2] = { m_status.hugePages, m_status.pages };
|
||||
const uint64_t memory = m_status.ways * xmrig::CnAlgo<>::memory(m_status.algo);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
rapidjson::Value hugepages(rapidjson::kArrayType);
|
||||
hugepages.PushBack(pages[0], allocator);
|
||||
hugepages.PushBack(pages[1], allocator);
|
||||
|
||||
doc.AddMember("hugepages", hugepages, allocator);
|
||||
doc.AddMember("memory", memory, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void Workers::onReady(void *arg)
|
||||
{
|
||||
auto handle = static_cast<ThreadHandle*>(arg);
|
||||
|
||||
IWorker *worker = nullptr;
|
||||
|
||||
switch (handle->config()->multiway()) {
|
||||
case 1:
|
||||
worker = new xmrig::CpuWorker<1>(handle);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
worker = new xmrig::CpuWorker<2>(handle);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
worker = new xmrig::CpuWorker<3>(handle);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
worker = new xmrig::CpuWorker<4>(handle);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
worker = new xmrig::CpuWorker<5>(handle);
|
||||
break;
|
||||
}
|
||||
|
||||
handle->setWorker(worker);
|
||||
|
||||
if (!worker->selfTest()) {
|
||||
LOG_ERR("thread %zu error: \"hash self-test failed\".", handle->worker()->id());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
start(worker);
|
||||
}
|
||||
|
||||
|
||||
void Workers::onTick(uv_timer_t *)
|
||||
{
|
||||
for (ThreadHandle *handle : m_workers) {
|
||||
if (!handle->worker()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_hashrate->add(handle->threadId(), handle->worker()->hashCount(), handle->worker()->timestamp());
|
||||
}
|
||||
|
||||
if ((m_ticks++ & 0xF) == 0) {
|
||||
m_hashrate->updateHighest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Workers::start(IWorker *worker)
|
||||
{
|
||||
// const Worker *w = static_cast<const Worker *>(worker);
|
||||
|
||||
uv_mutex_lock(&m_mutex);
|
||||
m_status.started++;
|
||||
// m_status.pages += w->memory().pages;
|
||||
// m_status.hugePages += w->memory().hugePages;
|
||||
|
||||
if (m_status.started == m_status.threads) {
|
||||
const double percent = (double) m_status.hugePages / m_status.pages * 100.0;
|
||||
const size_t memory = m_status.ways * xmrig::CnAlgo<>::memory(m_status.algo) / 1024;
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_status.algo.family() == xmrig::Algorithm::RANDOM_X) {
|
||||
LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " memory " CYAN_BOLD("%zu KB") "",
|
||||
m_status.threads, m_status.ways, memory);
|
||||
} else
|
||||
# endif
|
||||
{
|
||||
LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") "",
|
||||
m_status.threads, m_status.ways,
|
||||
(m_status.hugePages == m_status.pages ? GREEN_BOLD_S : (m_status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
|
||||
m_status.hugePages, m_status.pages, percent, memory);
|
||||
}
|
||||
}
|
||||
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
worker->start();
|
||||
}
|
331
src/workers/WorkersLegacy.cpp
Normal file
331
src/workers/WorkersLegacy.cpp
Normal file
|
@ -0,0 +1,331 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <inttypes.h>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "api/Api.h"
|
||||
#include "backend/cpu/CpuWorker.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
#include "crypto/rx/RxAlgo.h"
|
||||
#include "crypto/rx/RxCache.h"
|
||||
#include "crypto/rx/RxDataset.h"
|
||||
#include "Mem.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "workers/Hashrate.h"
|
||||
#include "workers/WorkersLegacy.h"
|
||||
|
||||
|
||||
bool WorkersLegacy::m_active = false;
|
||||
bool WorkersLegacy::m_enabled = true;
|
||||
Hashrate *WorkersLegacy::m_hashrate = nullptr;
|
||||
xmrig::Job WorkersLegacy::m_job;
|
||||
WorkersLegacy::LaunchStatus WorkersLegacy::m_status;
|
||||
std::vector<xmrig::Thread<xmrig::CpuLaunchData>* > WorkersLegacy::m_workers;
|
||||
uint64_t WorkersLegacy::m_ticks = 0;
|
||||
uv_mutex_t WorkersLegacy::m_mutex;
|
||||
uv_rwlock_t WorkersLegacy::m_rwlock;
|
||||
//uv_timer_t *Workers::m_timer = nullptr;
|
||||
xmrig::Controller *WorkersLegacy::m_controller = nullptr;
|
||||
|
||||
|
||||
//xmrig::Job WorkersLegacy::job()
|
||||
//{
|
||||
// uv_rwlock_rdlock(&m_rwlock);
|
||||
// xmrig::Job job = m_job;
|
||||
// uv_rwlock_rdunlock(&m_rwlock);
|
||||
|
||||
// return job;
|
||||
//}
|
||||
|
||||
|
||||
size_t WorkersLegacy::hugePages()
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
const size_t hugePages = m_status.hugePages;
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
return hugePages;
|
||||
}
|
||||
|
||||
|
||||
size_t WorkersLegacy::threads()
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
const size_t threads = m_status.threads;
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
return threads;
|
||||
}
|
||||
|
||||
|
||||
//void Workers::pause()
|
||||
//{
|
||||
// m_active = false;
|
||||
|
||||
// xmrig::Nonce::pause(true);
|
||||
// xmrig::Nonce::touch();
|
||||
//}
|
||||
|
||||
|
||||
//void Workers::printHashrate(bool detail)
|
||||
//{
|
||||
// assert(m_controller != nullptr);
|
||||
// if (!m_controller) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (detail) {
|
||||
// char num1[8] = { 0 };
|
||||
// char num2[8] = { 0 };
|
||||
// char num3[8] = { 0 };
|
||||
|
||||
// xmrig::Log::print(WHITE_BOLD_S "| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |");
|
||||
|
||||
// size_t i = 0;
|
||||
// for (const xmrig::IThread *thread : m_controller->config()->threads()) {
|
||||
// xmrig::Log::print("| %6zu | %8" PRId64 " | %7s | %7s | %7s |",
|
||||
// thread->index(),
|
||||
// thread->affinity(),
|
||||
// Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1),
|
||||
// Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::MediumInterval), num2, sizeof num2),
|
||||
// Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::LargeInterval), num3, sizeof num3)
|
||||
// );
|
||||
|
||||
// i++;
|
||||
// }
|
||||
// }
|
||||
|
||||
// m_hashrate->print();
|
||||
//}
|
||||
|
||||
|
||||
//void Workers::setEnabled(bool enabled)
|
||||
//{
|
||||
// if (m_enabled == enabled) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// m_enabled = enabled;
|
||||
// if (!m_active) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// xmrig::Nonce::pause(!enabled);
|
||||
// xmrig::Nonce::touch();
|
||||
//}
|
||||
|
||||
|
||||
//void Workers::setJob(const xmrig::Job &job, bool donate)
|
||||
//{
|
||||
// uv_rwlock_wrlock(&m_rwlock);
|
||||
|
||||
// m_job = job;
|
||||
// m_job.setIndex(donate ? 1 : 0);
|
||||
|
||||
// xmrig::Nonce::reset(donate ? 1 : 0);
|
||||
|
||||
// uv_rwlock_wrunlock(&m_rwlock);
|
||||
|
||||
// m_active = true;
|
||||
// if (!m_enabled) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// xmrig::Nonce::pause(false);
|
||||
//}
|
||||
|
||||
|
||||
void WorkersLegacy::start(xmrig::Controller *controller)
|
||||
{
|
||||
using namespace xmrig;
|
||||
|
||||
# ifdef APP_DEBUG
|
||||
LOG_NOTICE("THREADS ------------------------------------------------------------------");
|
||||
for (const xmrig::IThread *thread : controller->config()->threads()) {
|
||||
thread->print();
|
||||
}
|
||||
LOG_NOTICE("--------------------------------------------------------------------------");
|
||||
# endif
|
||||
|
||||
m_controller = controller;
|
||||
|
||||
m_status.algo = xmrig::Algorithm::RX_WOW; // FIXME algo
|
||||
const CpuThreads &threads = controller->config()->cpu().threads().get(m_status.algo);
|
||||
m_status.threads = threads.size();
|
||||
|
||||
for (const CpuThread &thread : threads) {
|
||||
m_status.ways += thread.intensity();
|
||||
}
|
||||
|
||||
m_hashrate = new Hashrate(threads.size(), controller);
|
||||
|
||||
uv_mutex_init(&m_mutex);
|
||||
uv_rwlock_init(&m_rwlock);
|
||||
|
||||
// m_timer = new uv_timer_t;
|
||||
// uv_timer_init(uv_default_loop(), m_timer);
|
||||
// uv_timer_start(m_timer, Workers::onTick, 500, 500);
|
||||
|
||||
// size_t index = 0;
|
||||
// for (const CpuThread &thread : threads) {
|
||||
// Thread<CpuLaunchData> *handle = new Thread<CpuLaunchData>(index++, CpuLaunchData(m_status.algo, controller->config()->cpu(), thread));
|
||||
|
||||
// m_workers.push_back(handle);
|
||||
// handle->start(WorkersLegacy::onReady);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
//void Workers::stop()
|
||||
//{
|
||||
// xmrig::Handle::close(m_timer);
|
||||
// m_hashrate->stop();
|
||||
|
||||
// xmrig::Nonce::stop();
|
||||
|
||||
// for (size_t i = 0; i < m_workers.size(); ++i) {
|
||||
// m_workers[i]->join();
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
void WorkersLegacy::threadsSummary(rapidjson::Document &doc)
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
const uint64_t pages[2] = { m_status.hugePages, m_status.pages };
|
||||
const uint64_t memory = m_status.ways * xmrig::CnAlgo<>::memory(m_status.algo);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
rapidjson::Value hugepages(rapidjson::kArrayType);
|
||||
hugepages.PushBack(pages[0], allocator);
|
||||
hugepages.PushBack(pages[1], allocator);
|
||||
|
||||
doc.AddMember("hugepages", hugepages, allocator);
|
||||
doc.AddMember("memory", memory, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//void WorkersLegacy::onReady(void *arg)
|
||||
//{
|
||||
// using namespace xmrig;
|
||||
|
||||
// auto handle = static_cast<Thread<CpuLaunchData>* >(arg);
|
||||
|
||||
// xmrig::IWorker *worker = nullptr;
|
||||
|
||||
// switch (handle->config().intensity) {
|
||||
// case 1:
|
||||
// worker = new CpuWorker<1>(handle->index(), handle->config());
|
||||
// break;
|
||||
|
||||
// case 2:
|
||||
// worker = new CpuWorker<2>(handle->index(), handle->config());
|
||||
// break;
|
||||
|
||||
// case 3:
|
||||
// worker = new CpuWorker<3>(handle->index(), handle->config());
|
||||
// break;
|
||||
|
||||
// case 4:
|
||||
// worker = new CpuWorker<4>(handle->index(), handle->config());
|
||||
// break;
|
||||
|
||||
// case 5:
|
||||
// worker = new CpuWorker<5>(handle->index(), handle->config());
|
||||
// break;
|
||||
// }
|
||||
|
||||
// handle->setWorker(worker);
|
||||
|
||||
// if (!worker->selfTest()) {
|
||||
// LOG_ERR("thread %zu error: \"hash self-test failed\".", handle->worker()->id());
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
// start(worker);
|
||||
//}
|
||||
|
||||
|
||||
void WorkersLegacy::onTick(uv_timer_t *)
|
||||
{
|
||||
using namespace xmrig;
|
||||
|
||||
for (Thread<CpuLaunchData> *handle : m_workers) {
|
||||
if (!handle->worker()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_hashrate->add(handle->index(), handle->worker()->hashCount(), handle->worker()->timestamp());
|
||||
}
|
||||
|
||||
if ((m_ticks++ & 0xF) == 0) {
|
||||
m_hashrate->updateHighest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WorkersLegacy::start(xmrig::IWorker *worker)
|
||||
{
|
||||
// const Worker *w = static_cast<const Worker *>(worker);
|
||||
|
||||
uv_mutex_lock(&m_mutex);
|
||||
m_status.started++;
|
||||
// m_status.pages += w->memory().pages;
|
||||
// m_status.hugePages += w->memory().hugePages;
|
||||
|
||||
if (m_status.started == m_status.threads) {
|
||||
const double percent = (double) m_status.hugePages / m_status.pages * 100.0;
|
||||
const size_t memory = m_status.ways * xmrig::CnAlgo<>::memory(m_status.algo) / 1024;
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_status.algo.family() == xmrig::Algorithm::RANDOM_X) {
|
||||
LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " memory " CYAN_BOLD("%zu KB") "",
|
||||
m_status.threads, m_status.ways, memory);
|
||||
} else
|
||||
# endif
|
||||
{
|
||||
LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") "",
|
||||
m_status.threads, m_status.ways,
|
||||
(m_status.hugePages == m_status.pages ? GREEN_BOLD_S : (m_status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
|
||||
m_status.hugePages, m_status.pages, percent, memory);
|
||||
}
|
||||
}
|
||||
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
worker->start();
|
||||
}
|
|
@ -22,8 +22,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_WORKERS_H
|
||||
#define XMRIG_WORKERS_H
|
||||
#ifndef XMRIG_WORKERSLEGACY_H
|
||||
#define XMRIG_WORKERSLEGACY_H
|
||||
|
||||
|
||||
#include <atomic>
|
||||
|
@ -35,36 +35,37 @@
|
|||
# include <randomx.h>
|
||||
#endif
|
||||
|
||||
#include "backend/common/Thread.h"
|
||||
#include "backend/cpu/CpuLaunchData.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
class Hashrate;
|
||||
class IWorker;
|
||||
class ThreadHandle;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class IWorker;
|
||||
class Controller;
|
||||
class ThreadHandle;
|
||||
}
|
||||
|
||||
|
||||
class Workers
|
||||
class WorkersLegacy
|
||||
{
|
||||
public:
|
||||
static size_t hugePages();
|
||||
static size_t threads();
|
||||
static void pause();
|
||||
static void printHashrate(bool detail);
|
||||
static void setEnabled(bool enabled);
|
||||
static void setJob(const xmrig::Job &job, bool donate);
|
||||
// static void pause();
|
||||
// static void printHashrate(bool detail);
|
||||
// static void setEnabled(bool enabled);
|
||||
// static void setJob(const xmrig::Job &job, bool donate);
|
||||
static void start(xmrig::Controller *controller);
|
||||
static void stop();
|
||||
static xmrig::Job job();
|
||||
// static void stop();
|
||||
// static xmrig::Job job();
|
||||
|
||||
static inline bool isEnabled() { return m_enabled; }
|
||||
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
|
||||
// static inline bool isEnabled() { return m_enabled; }
|
||||
static inline Hashrate *hashrate() { return m_hashrate; }
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
|
@ -72,9 +73,9 @@ public:
|
|||
# endif
|
||||
|
||||
private:
|
||||
static void onReady(void *arg);
|
||||
// static void onReady(void *arg);
|
||||
static void onTick(uv_timer_t *handle);
|
||||
static void start(IWorker *worker);
|
||||
static void start(xmrig::IWorker *worker);
|
||||
|
||||
class LaunchStatus
|
||||
{
|
||||
|
@ -100,14 +101,13 @@ private:
|
|||
static Hashrate *m_hashrate;
|
||||
static xmrig::Job m_job;
|
||||
static LaunchStatus m_status;
|
||||
static std::atomic<int> m_paused;
|
||||
static std::vector<ThreadHandle*> m_workers;
|
||||
static std::vector<xmrig::Thread<xmrig::CpuLaunchData>* > m_workers;
|
||||
static uint64_t m_ticks;
|
||||
static uv_mutex_t m_mutex;
|
||||
static uv_rwlock_t m_rwlock;
|
||||
static uv_timer_t *m_timer;
|
||||
// static uv_timer_t *m_timer;
|
||||
static xmrig::Controller *m_controller;
|
||||
};
|
||||
|
||||
|
||||
#endif /* XMRIG_WORKERS_H */
|
||||
#endif /* XMRIG_WORKERSLEGACY_H */
|
Loading…
Reference in a new issue