Restored "CPU READY" message.
This commit is contained in:
parent
4f49533e98
commit
8ce00adda4
13 changed files with 114 additions and 407 deletions
|
@ -32,6 +32,7 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
class IBackend;
|
||||
class IWorker;
|
||||
|
||||
|
||||
|
@ -39,10 +40,11 @@ template<class T>
|
|||
class Thread
|
||||
{
|
||||
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 const T &config() const { return m_config; }
|
||||
inline IBackend *backend() const { return m_backend; }
|
||||
inline IWorker *worker() const { return m_worker; }
|
||||
inline size_t index() const { return m_index; }
|
||||
inline void setWorker(IWorker *worker) { m_worker = worker; }
|
||||
|
@ -51,6 +53,7 @@ public:
|
|||
private:
|
||||
const size_t m_index = 0;
|
||||
const T m_config;
|
||||
IBackend *m_backend;
|
||||
IWorker *m_worker = nullptr;
|
||||
uv_thread_t m_thread;
|
||||
};
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
|
||||
#include "backend/common/Hashrate.h"
|
||||
#include "backend/common/interfaces/IBackend.h"
|
||||
#include "backend/common/Workers.h"
|
||||
#include "backend/cpu/CpuWorker.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
@ -48,6 +49,7 @@ public:
|
|||
|
||||
|
||||
Hashrate *hashrate = nullptr;
|
||||
IBackend *backend = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
@ -79,7 +81,14 @@ const xmrig::Hashrate *xmrig::Workers<T>::hashrate() const
|
|||
template<class T>
|
||||
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;
|
||||
}
|
||||
|
||||
worker->start();
|
||||
handle->backend()->start(worker);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
|
||||
const Hashrate *hashrate() const;
|
||||
void add(const T &data);
|
||||
void setBackend(IBackend *backend);
|
||||
void start();
|
||||
void stop();
|
||||
void tick(uint64_t ticks);
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace xmrig {
|
|||
|
||||
|
||||
class Hashrate;
|
||||
class IWorker;
|
||||
class Job;
|
||||
class String;
|
||||
|
||||
|
@ -46,6 +47,7 @@ public:
|
|||
virtual const String &profileName() const = 0;
|
||||
virtual void printHashrate(bool details) = 0;
|
||||
virtual void setJob(const Job &job) = 0;
|
||||
virtual void start(IWorker *worker) = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void tick(uint64_t ticks) = 0;
|
||||
};
|
||||
|
|
|
@ -23,7 +23,11 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "backend/common/Hashrate.h"
|
||||
#include "backend/common/interfaces/IWorker.h"
|
||||
#include "backend/common/Workers.h"
|
||||
#include "backend/cpu/CpuBackend.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
@ -31,6 +35,7 @@
|
|||
#include "base/tools/String.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "crypto/common/VirtualMemory.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -39,18 +44,41 @@ namespace xmrig {
|
|||
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
|
||||
{
|
||||
public:
|
||||
inline CpuBackendPrivate(const Miner *miner, Controller *controller) :
|
||||
miner(miner),
|
||||
inline CpuBackendPrivate(Controller *controller) :
|
||||
controller(controller)
|
||||
{
|
||||
uv_mutex_init(&mutex);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
const Miner *miner;
|
||||
Controller *controller;
|
||||
CpuThreads threads;
|
||||
LaunchStatus status;
|
||||
String profileName;
|
||||
uv_mutex_t mutex;
|
||||
Workers<CpuLaunchData> workers;
|
||||
};
|
||||
|
||||
|
@ -84,10 +143,10 @@ public:
|
|||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::CpuBackend::CpuBackend(const Miner *miner, Controller *controller) :
|
||||
d_ptr(new CpuBackendPrivate(miner, controller))
|
||||
xmrig::CpuBackend::CpuBackend(Controller *controller) :
|
||||
d_ptr(new CpuBackendPrivate(controller))
|
||||
{
|
||||
|
||||
d_ptr->workers.setBackend(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,26 +199,33 @@ void xmrig::CpuBackend::setJob(const Job &job)
|
|||
return;
|
||||
}
|
||||
|
||||
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
|
||||
const Threads<CpuThread> &threads = cpu.threads();
|
||||
d_ptr->start(job);
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
void xmrig::CpuBackend::start(IWorker *worker)
|
||||
{
|
||||
uv_mutex_lock(&d_ptr->mutex);
|
||||
|
||||
d_ptr->workers.stop();
|
||||
const auto pages = worker->memory()->hugePages();
|
||||
|
||||
for (const CpuThread &thread : d_ptr->threads) {
|
||||
d_ptr->workers.add(CpuLaunchData(d_ptr->miner, d_ptr->algo, cpu, thread));
|
||||
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);
|
||||
}
|
||||
|
||||
d_ptr->workers.start();
|
||||
uv_mutex_unlock(&d_ptr->mutex);
|
||||
|
||||
worker->start();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class Miner;
|
|||
class CpuBackend : public IBackend
|
||||
{
|
||||
public:
|
||||
CpuBackend(const Miner *miner, Controller *controller);
|
||||
CpuBackend(Controller *controller);
|
||||
~CpuBackend() override;
|
||||
|
||||
protected:
|
||||
|
@ -48,6 +48,7 @@ protected:
|
|||
const String &profileName() const override;
|
||||
void printHashrate(bool details) override;
|
||||
void setJob(const Job &job) override;
|
||||
void start(IWorker *worker) override;
|
||||
void stop() override;
|
||||
void tick(uint64_t ticks) override;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue