Implemented static benchmark verification (--bench --seed --hash)
This commit is contained in:
parent
027a6f8ae2
commit
36c1cb23e0
14 changed files with 220 additions and 107 deletions
|
@ -21,6 +21,7 @@
|
|||
#include "backend/common/interfaces/IWorker.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/io/log/Tags.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
|
||||
|
||||
|
@ -39,6 +40,17 @@ static uint64_t hashCheck[2][10] = {
|
|||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Benchmark::Benchmark(const Job &job, size_t workers, const IBackend *backend) :
|
||||
m_algo(job.algorithm()),
|
||||
m_backend(backend),
|
||||
m_workers(workers),
|
||||
m_token(job.benchToken()),
|
||||
m_end(job.benchSize()),
|
||||
m_hash(job.benchHash())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Benchmark::finish(uint64_t totalHashCount)
|
||||
{
|
||||
m_reset = true;
|
||||
|
@ -48,13 +60,8 @@ bool xmrig::Benchmark::finish(uint64_t totalHashCount)
|
|||
return false;
|
||||
}
|
||||
|
||||
const double dt = (m_doneTime - m_startTime) / 1000.0;
|
||||
uint64_t checkData = 0;
|
||||
const uint32_t N = (m_end / 1000000) - 1;
|
||||
|
||||
if (((m_algo == Algorithm::RX_0) || (m_algo == Algorithm::RX_WOW)) && ((m_end % 1000000) == 0) && (N < 10)) {
|
||||
checkData = hashCheck[(m_algo == Algorithm::RX_0) ? 0 : 1][N];
|
||||
}
|
||||
const double dt = static_cast<double>(m_doneTime - m_startTime) / 1000.0;
|
||||
uint64_t checkData = referenceHash();
|
||||
|
||||
const char *color = checkData ? ((m_data == checkData) ? GREEN_BOLD_S : RED_BOLD_S) : BLACK_BOLD_S;
|
||||
|
||||
|
@ -77,7 +84,7 @@ void xmrig::Benchmark::printProgress() const
|
|||
return;
|
||||
}
|
||||
|
||||
const double dt = (Chrono::steadyMSecs() - m_startTime) / 1000.0;
|
||||
const double dt = static_cast<double>(Chrono::steadyMSecs() - m_startTime) / 1000.0;
|
||||
const double percent = static_cast<double>(m_current) / m_end * 100.0;
|
||||
|
||||
LOG_NOTICE("%s " MAGENTA_BOLD("%5.2f%% ") CYAN_BOLD("%" PRIu64) CYAN("/%" PRIu64) BLACK_BOLD(" (%.3fs)"), Tags::bench(), percent, m_current, m_end, dt);
|
||||
|
@ -101,3 +108,18 @@ void xmrig::Benchmark::tick(IWorker *worker)
|
|||
m_data ^= worker->benchData();
|
||||
m_doneTime = std::max(doneTime, m_doneTime);
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::Benchmark::referenceHash() const
|
||||
{
|
||||
if (m_hash) {
|
||||
return m_hash;
|
||||
}
|
||||
|
||||
const uint32_t N = (m_end / 1000000) - 1;
|
||||
if (((m_algo == Algorithm::RX_0) || (m_algo == Algorithm::RX_WOW)) && ((m_end % 1000000) == 0) && (N < 10)) {
|
||||
return hashCheck[(m_algo == Algorithm::RX_0) ? 0 : 1][N];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -20,14 +20,17 @@
|
|||
#define XMRIG_BENCHMARK_H
|
||||
|
||||
|
||||
#include "base/tools/Object.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IBackend;
|
||||
class IWorker;
|
||||
class Job;
|
||||
|
||||
|
||||
class Benchmark
|
||||
|
@ -35,7 +38,7 @@ class Benchmark
|
|||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Benchmark)
|
||||
|
||||
Benchmark(uint32_t end, const Algorithm &algo, size_t workers) : m_algo(algo), m_workers(workers), m_end(end) {}
|
||||
Benchmark(const Job &job, size_t workers, const IBackend *backend);
|
||||
~Benchmark() = default;
|
||||
|
||||
bool finish(uint64_t totalHashCount);
|
||||
|
@ -44,10 +47,15 @@ public:
|
|||
void tick(IWorker *worker);
|
||||
|
||||
private:
|
||||
uint64_t referenceHash() const;
|
||||
|
||||
bool m_reset = false;
|
||||
const Algorithm m_algo = Algorithm::RX_0;
|
||||
const size_t m_workers = 0;
|
||||
const uint64_t m_end = 0;
|
||||
const Algorithm m_algo;
|
||||
const IBackend *m_backend;
|
||||
const size_t m_workers;
|
||||
const String m_token;
|
||||
const uint64_t m_end;
|
||||
const uint64_t m_hash;
|
||||
uint32_t m_done = 0;
|
||||
uint64_t m_current = 0;
|
||||
uint64_t m_data = 0;
|
||||
|
|
|
@ -87,13 +87,6 @@ xmrig::Workers<T>::~Workers()
|
|||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
xmrig::Benchmark *xmrig::Workers<T>::benchmark() const
|
||||
{
|
||||
return d_ptr->benchmark.get();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
static void getHashrateData(xmrig::IWorker* worker, uint64_t& hashCount, uint64_t& timeStamp)
|
||||
{
|
||||
|
@ -168,41 +161,6 @@ void xmrig::Workers<T>::setBackend(IBackend *backend)
|
|||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void xmrig::Workers<T>::start(const std::vector<T> &data)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
if (!data.empty() && data.front().benchSize) {
|
||||
d_ptr->benchmark = std::make_shared<Benchmark>(data.front().benchSize, data.front().algorithm, data.size());
|
||||
}
|
||||
# endif
|
||||
|
||||
for (const T &item : data) {
|
||||
m_workers.push_back(new Thread<T>(d_ptr->backend, m_workers.size(), item));
|
||||
}
|
||||
|
||||
d_ptr->hashrate = std::make_shared<Hashrate>(m_workers.size());
|
||||
Nonce::touch(T::backend());
|
||||
|
||||
for (Thread<T> *worker : m_workers) {
|
||||
worker->start(Workers<T>::onReady);
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
if (!d_ptr->benchmark)
|
||||
# endif
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
}
|
||||
}
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
if (d_ptr->benchmark) {
|
||||
d_ptr->benchmark->start();
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void xmrig::Workers<T>::stop()
|
||||
{
|
||||
|
@ -219,6 +177,22 @@ void xmrig::Workers<T>::stop()
|
|||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||
template<class T>
|
||||
void xmrig::Workers<T>::start(const std::vector<T> &data, const std::shared_ptr<Benchmark> &benchmark)
|
||||
{
|
||||
if (!benchmark) {
|
||||
return start(data, true);
|
||||
}
|
||||
|
||||
start(data, false);
|
||||
|
||||
d_ptr->benchmark = benchmark;
|
||||
d_ptr->benchmark->start();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
template<class T>
|
||||
xmrig::IWorker *xmrig::Workers<T>::create(Thread<T> *)
|
||||
{
|
||||
|
@ -250,6 +224,29 @@ void xmrig::Workers<T>::onReady(void *arg)
|
|||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void xmrig::Workers<T>::start(const std::vector<T> &data, bool sleep)
|
||||
{
|
||||
for (const auto &item : data) {
|
||||
m_workers.push_back(new Thread<T>(d_ptr->backend, m_workers.size(), item));
|
||||
}
|
||||
|
||||
d_ptr->hashrate = std::make_shared<Hashrate>(m_workers.size());
|
||||
Nonce::touch(T::backend());
|
||||
|
||||
for (auto worker : m_workers) {
|
||||
worker->start(Workers<T>::onReady);
|
||||
|
||||
// This sleep is important for optimal caching!
|
||||
// Threads must allocate scratchpads in order so that adjacent cores will use adjacent scratchpads
|
||||
// Sub-optimal caching can result in up to 0.5% hashrate penalty
|
||||
if (sleep) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
|
|
|
@ -59,18 +59,24 @@ public:
|
|||
Workers();
|
||||
~Workers();
|
||||
|
||||
Benchmark *benchmark() const;
|
||||
inline void start(const std::vector<T> &data) { start(data, true); }
|
||||
|
||||
bool tick(uint64_t ticks);
|
||||
const Hashrate *hashrate() const;
|
||||
void jobEarlyNotification(const Job&);
|
||||
void setBackend(IBackend *backend);
|
||||
void start(const std::vector<T> &data);
|
||||
void stop();
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
void start(const std::vector<T> &data, const std::shared_ptr<Benchmark> &benchmark);
|
||||
# endif
|
||||
|
||||
private:
|
||||
static IWorker *create(Thread<T> *handle);
|
||||
static void onReady(void *arg);
|
||||
|
||||
void start(const std::vector<T> &data, bool sleep);
|
||||
|
||||
std::vector<Thread<T> *> m_workers;
|
||||
WorkersPrivate *d_ptr;
|
||||
};
|
||||
|
|
|
@ -138,10 +138,7 @@ private:
|
|||
class CpuBackendPrivate
|
||||
{
|
||||
public:
|
||||
inline CpuBackendPrivate(Controller *controller) :
|
||||
controller(controller)
|
||||
{
|
||||
}
|
||||
inline CpuBackendPrivate(Controller *controller) : controller(controller) {}
|
||||
|
||||
|
||||
inline void start()
|
||||
|
@ -155,7 +152,12 @@ public:
|
|||
);
|
||||
|
||||
status.start(threads, algo.l3());
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
workers.start(threads, benchmark);
|
||||
# else
|
||||
workers.start(threads);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -204,6 +206,10 @@ public:
|
|||
std::vector<CpuLaunchData> threads;
|
||||
String profileName;
|
||||
Workers<CpuLaunchData> workers;
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
std::shared_ptr<Benchmark> benchmark;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
|
@ -338,7 +344,7 @@ void xmrig::CpuBackend::setJob(const Job &job)
|
|||
return stop();
|
||||
}
|
||||
|
||||
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
|
||||
const auto &cpu = d_ptr->controller->config()->cpu();
|
||||
|
||||
std::vector<CpuLaunchData> threads = cpu.get(d_ptr->controller->miner(), job.algorithm(), d_ptr->controller->config()->pools().benchSize());
|
||||
if (!d_ptr->threads.empty() && d_ptr->threads.size() == threads.size() && std::equal(d_ptr->threads.begin(), d_ptr->threads.end(), threads.begin())) {
|
||||
|
@ -356,6 +362,12 @@ void xmrig::CpuBackend::setJob(const Job &job)
|
|||
|
||||
stop();
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
if (job.benchSize()) {
|
||||
d_ptr->benchmark = std::make_shared<Benchmark>(job, threads.size(), this);
|
||||
}
|
||||
# endif
|
||||
|
||||
d_ptr->threads = std::move(threads);
|
||||
d_ptr->start();
|
||||
}
|
||||
|
@ -469,15 +481,14 @@ void xmrig::CpuBackend::handleRequest(IApiRequest &request)
|
|||
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||
xmrig::Benchmark *xmrig::CpuBackend::benchmark() const
|
||||
{
|
||||
return d_ptr->workers.benchmark();
|
||||
return d_ptr->benchmark.get();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CpuBackend::printBenchProgress() const
|
||||
{
|
||||
auto benchmark = d_ptr->workers.benchmark();
|
||||
if (benchmark) {
|
||||
benchmark->printProgress();
|
||||
if (d_ptr->benchmark) {
|
||||
d_ptr->benchmark->printProgress();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue