mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-11 05:14:40 +00:00
Make CpuLaunchStatus more high level.
This commit is contained in:
parent
4f1d4695cd
commit
4a5e185973
2 changed files with 67 additions and 52 deletions
|
@ -61,29 +61,63 @@ extern template class Threads<CpuThreads>;
|
|||
|
||||
static const char *tag = CYAN_BG_BOLD(" cpu ");
|
||||
static const String kType = "cpu";
|
||||
static std::mutex mutex;
|
||||
|
||||
|
||||
struct CpuLaunchStatus
|
||||
{
|
||||
public:
|
||||
inline void reset()
|
||||
inline size_t hugePages() const { return m_hugePages; }
|
||||
inline size_t memory() const { return m_ways * m_memory; }
|
||||
inline size_t pages() const { return m_pages; }
|
||||
inline size_t threads() const { return m_threads; }
|
||||
inline size_t ways() const { return m_ways; }
|
||||
|
||||
inline void start(const std::vector<CpuLaunchData> &threads, size_t memory)
|
||||
{
|
||||
hugePages = 0;
|
||||
memory = 0;
|
||||
pages = 0;
|
||||
started = 0;
|
||||
threads = 0;
|
||||
ways = 0;
|
||||
ts = Chrono::steadyMSecs();
|
||||
m_hugePages = 0;
|
||||
m_memory = memory;
|
||||
m_pages = 0;
|
||||
m_started = 0;
|
||||
m_threads = threads.size();
|
||||
m_ways = 0;
|
||||
m_ts = Chrono::steadyMSecs();
|
||||
|
||||
for (const CpuLaunchData &data : threads) {
|
||||
m_ways += data.intensity;
|
||||
}
|
||||
}
|
||||
|
||||
size_t hugePages = 0;
|
||||
size_t memory = 0;
|
||||
size_t pages = 0;
|
||||
size_t started = 0;
|
||||
size_t threads = 0;
|
||||
size_t ways = 0;
|
||||
uint64_t ts = 0;
|
||||
inline bool started(const std::pair<size_t, size_t> &hugePages)
|
||||
{
|
||||
m_started++;
|
||||
m_hugePages += hugePages.first;
|
||||
m_pages += hugePages.second;
|
||||
|
||||
return m_started == m_threads;
|
||||
}
|
||||
|
||||
inline void print() const
|
||||
{
|
||||
LOG_INFO("%s" GREEN_BOLD(" READY") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"),
|
||||
tag,
|
||||
m_threads, m_ways,
|
||||
(m_hugePages == m_pages ? GREEN_BOLD_S : (m_hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
|
||||
m_hugePages, m_pages,
|
||||
m_hugePages == 0 ? 0.0 : static_cast<double>(m_hugePages) / m_pages * 100.0,
|
||||
m_ways * m_memory / 1024,
|
||||
Chrono::steadyMSecs() - m_ts
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_hugePages = 0;
|
||||
size_t m_memory = 0;
|
||||
size_t m_pages = 0;
|
||||
size_t m_started = 0;
|
||||
size_t m_threads = 0;
|
||||
size_t m_ways = 0;
|
||||
uint64_t m_ts = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -107,14 +141,7 @@ public:
|
|||
|
||||
workers.stop();
|
||||
|
||||
status.reset();
|
||||
status.memory = algo.l3();
|
||||
status.threads = threads.size();
|
||||
|
||||
for (const CpuLaunchData &data : threads) {
|
||||
status.ways += static_cast<size_t>(data.intensity);
|
||||
}
|
||||
|
||||
status.start(threads, algo.l3());
|
||||
workers.start(threads);
|
||||
}
|
||||
|
||||
|
@ -123,7 +150,7 @@ public:
|
|||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
return status.ways;
|
||||
return status.ways();
|
||||
}
|
||||
|
||||
|
||||
|
@ -139,8 +166,8 @@ public:
|
|||
|
||||
mutex.lock();
|
||||
|
||||
pages.first += status.hugePages;
|
||||
pages.second += status.pages;
|
||||
pages.first += status.hugePages();
|
||||
pages.second += status.pages();
|
||||
|
||||
mutex.unlock();
|
||||
|
||||
|
@ -162,7 +189,6 @@ public:
|
|||
Algorithm algo;
|
||||
Controller *controller;
|
||||
CpuLaunchStatus status;
|
||||
std::mutex mutex;
|
||||
std::vector<CpuLaunchData> threads;
|
||||
String profileName;
|
||||
Workers<CpuLaunchData> workers;
|
||||
|
@ -291,28 +317,13 @@ void xmrig::CpuBackend::setJob(const Job &job)
|
|||
|
||||
void xmrig::CpuBackend::start(IWorker *worker)
|
||||
{
|
||||
d_ptr->mutex.lock();
|
||||
mutex.lock();
|
||||
|
||||
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("%s" GREEN_BOLD(" READY") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"),
|
||||
tag,
|
||||
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,
|
||||
Chrono::steadyMSecs() - d_ptr->status.ts
|
||||
);
|
||||
if (d_ptr->status.started(worker->memory()->hugePages())) {
|
||||
d_ptr->status.print();
|
||||
}
|
||||
|
||||
d_ptr->mutex.unlock();
|
||||
mutex.unlock();
|
||||
|
||||
worker->start();
|
||||
}
|
||||
|
|
|
@ -71,9 +71,17 @@ struct OclLaunchStatus
|
|||
public:
|
||||
inline bool started() { m_started++; return m_started == m_threads; }
|
||||
inline size_t threads() const { return m_threads; }
|
||||
inline uint64_t ts() const { return Chrono::steadyMSecs() - m_ts; }
|
||||
inline void start(size_t threads) { m_started = 0; m_threads = threads; m_ts = Chrono::steadyMSecs(); }
|
||||
|
||||
inline void print() const
|
||||
{
|
||||
LOG_INFO("%s" GREEN_BOLD(" READY") " threads " CYAN_BOLD("%zu") BLACK_BOLD(" (%" PRIu64 " ms)"),
|
||||
tag,
|
||||
m_threads,
|
||||
Chrono::steadyMSecs() - m_ts
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_started = 0;
|
||||
size_t m_threads = 0;
|
||||
|
@ -279,11 +287,7 @@ void xmrig::OclBackend::start(IWorker *worker)
|
|||
mutex.lock();
|
||||
|
||||
if (d_ptr->status.started()) {
|
||||
LOG_INFO("%s" GREEN_BOLD(" READY") " threads " CYAN_BOLD("%zu") BLACK_BOLD(" (%" PRIu64 " ms)"),
|
||||
tag,
|
||||
d_ptr->status.threads(),
|
||||
d_ptr->status.ts()
|
||||
);
|
||||
d_ptr->status.print();
|
||||
}
|
||||
|
||||
mutex.unlock();
|
||||
|
|
Loading…
Reference in a new issue