mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 10:01:06 +00:00
Restored "CPU READY" message.
This commit is contained in:
parent
4f49533e98
commit
8ce00adda4
13 changed files with 114 additions and 407 deletions
|
@ -43,7 +43,6 @@ set(HEADERS
|
||||||
src/Summary.h
|
src/Summary.h
|
||||||
src/version.h
|
src/version.h
|
||||||
src/workers/CpuThreadLegacy.h
|
src/workers/CpuThreadLegacy.h
|
||||||
src/workers/WorkersLegacy.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(HEADERS_CRYPTO
|
set(HEADERS_CRYPTO
|
||||||
|
@ -90,7 +89,6 @@ set(SOURCES
|
||||||
src/net/strategies/DonateStrategy.cpp
|
src/net/strategies/DonateStrategy.cpp
|
||||||
src/Summary.cpp
|
src/Summary.cpp
|
||||||
src/workers/CpuThreadLegacy.cpp
|
src/workers/CpuThreadLegacy.cpp
|
||||||
src/workers/WorkersLegacy.cpp
|
|
||||||
src/xmrig.cpp
|
src/xmrig.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,6 @@
|
||||||
#include "core/config/Config.h"
|
#include "core/config/Config.h"
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
//#include "workers/Hashrate.h"
|
|
||||||
#include "workers/WorkersLegacy.h"
|
|
||||||
|
|
||||||
|
|
||||||
static inline rapidjson::Value normalize(double d)
|
static inline rapidjson::Value normalize(double d)
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class IBackend;
|
||||||
class IWorker;
|
class IWorker;
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,10 +40,11 @@ template<class T>
|
||||||
class Thread
|
class Thread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline Thread(size_t index, const T &config) : m_index(index), m_config(config) {}
|
inline Thread(IBackend *backend, size_t index, const T &config) : m_index(index), m_config(config), m_backend(backend) {}
|
||||||
inline ~Thread() { uv_thread_join(&m_thread); }
|
inline ~Thread() { uv_thread_join(&m_thread); }
|
||||||
|
|
||||||
inline const T &config() const { return m_config; }
|
inline const T &config() const { return m_config; }
|
||||||
|
inline IBackend *backend() const { return m_backend; }
|
||||||
inline IWorker *worker() const { return m_worker; }
|
inline IWorker *worker() const { return m_worker; }
|
||||||
inline size_t index() const { return m_index; }
|
inline size_t index() const { return m_index; }
|
||||||
inline void setWorker(IWorker *worker) { m_worker = worker; }
|
inline void setWorker(IWorker *worker) { m_worker = worker; }
|
||||||
|
@ -51,6 +53,7 @@ public:
|
||||||
private:
|
private:
|
||||||
const size_t m_index = 0;
|
const size_t m_index = 0;
|
||||||
const T m_config;
|
const T m_config;
|
||||||
|
IBackend *m_backend;
|
||||||
IWorker *m_worker = nullptr;
|
IWorker *m_worker = nullptr;
|
||||||
uv_thread_t m_thread;
|
uv_thread_t m_thread;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "backend/common/Hashrate.h"
|
#include "backend/common/Hashrate.h"
|
||||||
|
#include "backend/common/interfaces/IBackend.h"
|
||||||
#include "backend/common/Workers.h"
|
#include "backend/common/Workers.h"
|
||||||
#include "backend/cpu/CpuWorker.h"
|
#include "backend/cpu/CpuWorker.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
|
@ -48,6 +49,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
Hashrate *hashrate = nullptr;
|
Hashrate *hashrate = nullptr;
|
||||||
|
IBackend *backend = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +81,14 @@ const xmrig::Hashrate *xmrig::Workers<T>::hashrate() const
|
||||||
template<class T>
|
template<class T>
|
||||||
void xmrig::Workers<T>::add(const T &data)
|
void xmrig::Workers<T>::add(const T &data)
|
||||||
{
|
{
|
||||||
m_workers.push_back(new Thread<T>(m_workers.size(), data));
|
m_workers.push_back(new Thread<T>(d_ptr->backend, m_workers.size(), data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void xmrig::Workers<T>::setBackend(IBackend *backend)
|
||||||
|
{
|
||||||
|
d_ptr->backend = backend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,7 +185,7 @@ void xmrig::Workers<CpuLaunchData>::onReady(void *arg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
worker->start();
|
handle->backend()->start(worker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
|
|
||||||
const Hashrate *hashrate() const;
|
const Hashrate *hashrate() const;
|
||||||
void add(const T &data);
|
void add(const T &data);
|
||||||
|
void setBackend(IBackend *backend);
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
void tick(uint64_t ticks);
|
void tick(uint64_t ticks);
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class Hashrate;
|
class Hashrate;
|
||||||
|
class IWorker;
|
||||||
class Job;
|
class Job;
|
||||||
class String;
|
class String;
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ public:
|
||||||
virtual const String &profileName() const = 0;
|
virtual const String &profileName() const = 0;
|
||||||
virtual void printHashrate(bool details) = 0;
|
virtual void printHashrate(bool details) = 0;
|
||||||
virtual void setJob(const Job &job) = 0;
|
virtual void setJob(const Job &job) = 0;
|
||||||
|
virtual void start(IWorker *worker) = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
virtual void tick(uint64_t ticks) = 0;
|
virtual void tick(uint64_t ticks) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
#include "backend/common/Hashrate.h"
|
#include "backend/common/Hashrate.h"
|
||||||
|
#include "backend/common/interfaces/IWorker.h"
|
||||||
#include "backend/common/Workers.h"
|
#include "backend/common/Workers.h"
|
||||||
#include "backend/cpu/CpuBackend.h"
|
#include "backend/cpu/CpuBackend.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
|
@ -31,6 +35,7 @@
|
||||||
#include "base/tools/String.h"
|
#include "base/tools/String.h"
|
||||||
#include "core/config/Config.h"
|
#include "core/config/Config.h"
|
||||||
#include "core/Controller.h"
|
#include "core/Controller.h"
|
||||||
|
#include "crypto/common/VirtualMemory.h"
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -39,18 +44,41 @@ namespace xmrig {
|
||||||
extern template class Threads<CpuThread>;
|
extern template class Threads<CpuThread>;
|
||||||
|
|
||||||
|
|
||||||
|
struct LaunchStatus
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline void reset()
|
||||||
|
{
|
||||||
|
hugePages = 0;
|
||||||
|
memory = 0;
|
||||||
|
pages = 0;
|
||||||
|
started = 0;
|
||||||
|
threads = 0;
|
||||||
|
ways = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t hugePages;
|
||||||
|
size_t memory;
|
||||||
|
size_t pages;
|
||||||
|
size_t started;
|
||||||
|
size_t threads;
|
||||||
|
size_t ways;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class CpuBackendPrivate
|
class CpuBackendPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline CpuBackendPrivate(const Miner *miner, Controller *controller) :
|
inline CpuBackendPrivate(Controller *controller) :
|
||||||
miner(miner),
|
|
||||||
controller(controller)
|
controller(controller)
|
||||||
{
|
{
|
||||||
|
uv_mutex_init(&mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline ~CpuBackendPrivate()
|
inline ~CpuBackendPrivate()
|
||||||
{
|
{
|
||||||
|
uv_mutex_destroy(&mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,11 +100,42 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void start(const Job &job)
|
||||||
|
{
|
||||||
|
const CpuConfig &cpu = controller->config()->cpu();
|
||||||
|
|
||||||
|
algo = job.algorithm();
|
||||||
|
profileName = cpu.threads().profileName(job.algorithm());
|
||||||
|
threads = cpu.threads().get(profileName);
|
||||||
|
|
||||||
|
LOG_INFO(GREEN_BOLD("CPU") " use profile " BLUE_BG(WHITE_BOLD_S " %s ") WHITE_BOLD_S " (" CYAN_BOLD("%zu") WHITE_BOLD(" threads)") " scratchpad " CYAN_BOLD("%zu KB"),
|
||||||
|
profileName.data(),
|
||||||
|
threads.size(),
|
||||||
|
algo.memory() / 1024
|
||||||
|
);
|
||||||
|
|
||||||
|
workers.stop();
|
||||||
|
|
||||||
|
status.reset();
|
||||||
|
status.memory = algo.memory();
|
||||||
|
status.threads = threads.size();
|
||||||
|
|
||||||
|
for (const CpuThread &thread : threads) {
|
||||||
|
workers.add(CpuLaunchData(controller->miner(), algo, cpu, thread));
|
||||||
|
|
||||||
|
status.ways += static_cast<size_t>(thread.intensity());
|
||||||
|
}
|
||||||
|
|
||||||
|
workers.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Algorithm algo;
|
Algorithm algo;
|
||||||
const Miner *miner;
|
|
||||||
Controller *controller;
|
Controller *controller;
|
||||||
CpuThreads threads;
|
CpuThreads threads;
|
||||||
|
LaunchStatus status;
|
||||||
String profileName;
|
String profileName;
|
||||||
|
uv_mutex_t mutex;
|
||||||
Workers<CpuLaunchData> workers;
|
Workers<CpuLaunchData> workers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -84,10 +143,10 @@ public:
|
||||||
} // namespace xmrig
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
xmrig::CpuBackend::CpuBackend(const Miner *miner, Controller *controller) :
|
xmrig::CpuBackend::CpuBackend(Controller *controller) :
|
||||||
d_ptr(new CpuBackendPrivate(miner, controller))
|
d_ptr(new CpuBackendPrivate(controller))
|
||||||
{
|
{
|
||||||
|
d_ptr->workers.setBackend(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,26 +199,33 @@ void xmrig::CpuBackend::setJob(const Job &job)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
|
d_ptr->start(job);
|
||||||
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(GREEN_BOLD("CPU") " use profile " BLUE_BG(WHITE_BOLD_S " %s ") WHITE_BOLD_S " (" CYAN_BOLD("%zu") WHITE_BOLD(" threads)") " scratchpad " CYAN_BOLD("%zu KB"),
|
|
||||||
d_ptr->profileName.data(),
|
|
||||||
d_ptr->threads.size(),
|
|
||||||
d_ptr->algo.memory() / 1024
|
|
||||||
);
|
|
||||||
|
|
||||||
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::start(IWorker *worker)
|
||||||
|
{
|
||||||
|
uv_mutex_lock(&d_ptr->mutex);
|
||||||
|
|
||||||
|
const auto pages = worker->memory()->hugePages();
|
||||||
|
|
||||||
|
d_ptr->status.started++;
|
||||||
|
d_ptr->status.hugePages += pages.first;
|
||||||
|
d_ptr->status.pages += pages.second;
|
||||||
|
|
||||||
|
if (d_ptr->status.started == d_ptr->status.threads) {
|
||||||
|
const double percent = d_ptr->status.hugePages == 0 ? 0.0 : static_cast<double>(d_ptr->status.hugePages) / d_ptr->status.pages * 100.0;
|
||||||
|
const size_t memory = d_ptr->status.ways * d_ptr->status.memory / 1024;
|
||||||
|
|
||||||
|
LOG_INFO(GREEN_BOLD("CPU READY") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") "",
|
||||||
|
d_ptr->status.threads, d_ptr->status.ways,
|
||||||
|
(d_ptr->status.hugePages == d_ptr->status.pages ? GREEN_BOLD_S : (d_ptr->status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
|
||||||
|
d_ptr->status.hugePages, d_ptr->status.pages, percent, memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
uv_mutex_unlock(&d_ptr->mutex);
|
||||||
|
|
||||||
|
worker->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Miner;
|
||||||
class CpuBackend : public IBackend
|
class CpuBackend : public IBackend
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CpuBackend(const Miner *miner, Controller *controller);
|
CpuBackend(Controller *controller);
|
||||||
~CpuBackend() override;
|
~CpuBackend() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -48,6 +48,7 @@ protected:
|
||||||
const String &profileName() const override;
|
const String &profileName() const override;
|
||||||
void printHashrate(bool details) override;
|
void printHashrate(bool details) override;
|
||||||
void setJob(const Job &job) override;
|
void setJob(const Job &job) override;
|
||||||
|
void start(IWorker *worker) override;
|
||||||
void stop() override;
|
void stop() override;
|
||||||
void tick(uint64_t ticks) override;
|
void tick(uint64_t ticks) override;
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ xmrig::Miner::Miner(Controller *controller)
|
||||||
{
|
{
|
||||||
d_ptr->timer = new Timer(this);
|
d_ptr->timer = new Timer(this);
|
||||||
|
|
||||||
d_ptr->backends.push_back(new CpuBackend(this, controller));
|
d_ptr->backends.push_back(new CpuBackend(controller));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,15 +210,8 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
|
||||||
|
|
||||||
void xmrig::Miner::stop()
|
void xmrig::Miner::stop()
|
||||||
{
|
{
|
||||||
// xmrig::Handle::close(m_timer);
|
|
||||||
// m_hashrate->stop();
|
|
||||||
|
|
||||||
Nonce::stop();
|
Nonce::stop();
|
||||||
|
|
||||||
// for (size_t i = 0; i < m_workers.size(); ++i) {
|
|
||||||
// m_workers[i]->join();
|
|
||||||
// }
|
|
||||||
|
|
||||||
for (IBackend *backend : d_ptr->backends) {
|
for (IBackend *backend : d_ptr->backends) {
|
||||||
backend->stop();
|
backend->stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -43,10 +44,14 @@ public:
|
||||||
~VirtualMemory();
|
~VirtualMemory();
|
||||||
|
|
||||||
inline bool isHugePages() const { return m_flags & HUGEPAGES; }
|
inline bool isHugePages() const { return m_flags & HUGEPAGES; }
|
||||||
inline size_t hugePages() const { return isHugePages() ? (align(size()) / 2097152) : 0; }
|
|
||||||
inline size_t size() const { return m_size; }
|
inline size_t size() const { return m_size; }
|
||||||
inline uint8_t *scratchpad() const { return m_scratchpad; }
|
inline uint8_t *scratchpad() const { return m_scratchpad; }
|
||||||
|
|
||||||
|
inline std::pair<size_t, size_t> hugePages() const
|
||||||
|
{
|
||||||
|
return std::pair<size_t, size_t>(isHugePages() ? (align(size()) / 2097152) : 0, align(size()) / 2097152);
|
||||||
|
}
|
||||||
|
|
||||||
static void *allocateExecutableMemory(size_t size);
|
static void *allocateExecutableMemory(size_t size);
|
||||||
static void *allocateLargePagesMemory(size_t size);
|
static void *allocateLargePagesMemory(size_t size);
|
||||||
static void flushInstructionCache(void *p, size_t size);
|
static void flushInstructionCache(void *p, size_t size);
|
||||||
|
|
|
@ -113,7 +113,7 @@ xmrig::RxDataset *xmrig::Rx::dataset(const uint8_t *seed, const Algorithm &algor
|
||||||
const uint64_t ts = Chrono::steadyMSecs();
|
const uint64_t ts = Chrono::steadyMSecs();
|
||||||
|
|
||||||
if (d_ptr->dataset->get() != nullptr) {
|
if (d_ptr->dataset->get() != nullptr) {
|
||||||
LOG_INFO("%s" MAGENTA_BOLD(" init dataset") " algo " WHITE_BOLD("%s") " threads " WHITE_BOLD("%u") BLACK_BOLD(" seed %s..."),
|
LOG_INFO("%s" MAGENTA_BOLD(" init dataset") " algo " WHITE_BOLD("%s (") CYAN_BOLD("%u") WHITE_BOLD(" threads)") BLACK_BOLD(" seed %s..."),
|
||||||
tag,
|
tag,
|
||||||
algorithm.shortName(),
|
algorithm.shortName(),
|
||||||
d_ptr->initThreads,
|
d_ptr->initThreads,
|
||||||
|
|
|
@ -1,256 +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 "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::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::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();
|
|
||||||
}
|
|
|
@ -1,113 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef XMRIG_WORKERSLEGACY_H
|
|
||||||
#define XMRIG_WORKERSLEGACY_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <list>
|
|
||||||
#include <uv.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifdef XMRIG_ALGO_RANDOMX
|
|
||||||
# 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;
|
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
|
||||||
class IWorker;
|
|
||||||
class Controller;
|
|
||||||
class ThreadHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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 start(xmrig::Controller *controller);
|
|
||||||
// static void stop();
|
|
||||||
// static xmrig::Job job();
|
|
||||||
|
|
||||||
// static inline bool isEnabled() { return m_enabled; }
|
|
||||||
// static inline Hashrate *hashrate() { return m_hashrate; }
|
|
||||||
|
|
||||||
//# ifdef XMRIG_FEATURE_API
|
|
||||||
// static void threadsSummary(rapidjson::Document &doc);
|
|
||||||
//# endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
// static void onReady(void *arg);
|
|
||||||
// static void onTick(uv_timer_t *handle);
|
|
||||||
static void start(xmrig::IWorker *worker);
|
|
||||||
|
|
||||||
class LaunchStatus
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline LaunchStatus() :
|
|
||||||
hugePages(0),
|
|
||||||
pages(0),
|
|
||||||
started(0),
|
|
||||||
threads(0),
|
|
||||||
ways(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
size_t hugePages;
|
|
||||||
size_t pages;
|
|
||||||
size_t started;
|
|
||||||
size_t threads;
|
|
||||||
size_t ways;
|
|
||||||
xmrig::Algorithm algo;
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool m_active;
|
|
||||||
static bool m_enabled;
|
|
||||||
// static Hashrate *m_hashrate;
|
|
||||||
static xmrig::Job m_job;
|
|
||||||
static LaunchStatus m_status;
|
|
||||||
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 xmrig::Controller *m_controller;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* XMRIG_WORKERSLEGACY_H */
|
|
Loading…
Reference in a new issue