Improved benchmark precision based on xmrig-amd findings

This commit is contained in:
MoneroOcean 2018-07-26 19:59:39 +02:00
parent d6a56a2e0a
commit 684feb38fd
3 changed files with 28 additions and 23 deletions

View file

@ -31,13 +31,11 @@
// start performance measurements for specified perf algo
void Benchmark::start_perf_bench(const xmrig::PerfAlgo pa) {
m_pa = pa; // current perf algo
m_hash_count = 0; // number of hashes calculated for current perf algo
m_time_start = get_now(); // time of measurements start (in ms)
Workers::switch_algo(xmrig::Algorithm(pa)); // switch workers to new algo (Algo part)
// prepare test job for benchmark runs
Job job;
job.setPoolId(-100); // to make sure we can detect benchmark jobs
job.setId(xmrig::Algorithm::perfAlgoName(pa)); // need to set different id so that workers will see job change
const static uint8_t test_input[76] = {
0x99, // 0x99 here to trigger all future algo versions for auto veriant detection based on block version
@ -48,24 +46,28 @@ void Benchmark::start_perf_bench(const xmrig::PerfAlgo pa) {
0x4F, 0xDD, 0x84, 0x93, 0xD1, 0x11, 0x56, 0x49, 0xC0, 0x5E, 0xB6, 0x01,
};
job.setRawBlob(test_input, 76);
job.setTarget("FFFFFFFFFFFFFFFF"); // set difficulty to 1 to get to onJobResult after every computed hash
job.setTarget("FFFFFFFFFFFFFF20"); // set difficulty to 8 cause onJobResult after every 8-th computed hash
job.setAlgorithm(xmrig::Algorithm(pa)); // set job algo (for Variant part)
if (!m_is_benchmark_time) { // write test before first benchmark round
Log::i()->text(m_controller->config()->isColors()
? GREEN_BOLD(" >>>>> ") WHITE_BOLD("STARTING ALGO PERFORMANCE CALIBRATION")
: " >>>>> STARTING ALGO PERFORMANCE CALIBRATION"
);
}
m_is_benchmark_time = true; // benchmarking is in process
m_pa = pa; // current perf algo
m_hash_count = 0; // number of hashes calculated for current perf algo
m_time_start = 0; // init time of measurements start (in ms) during the first onJobResult
Workers::setJob(job, false); // set job for workers to compute
}
void Benchmark::onJobResult(const JobResult& result) {
if (!m_is_benchmark_time) return; // ignore job results if we already stopeed benchmarking (before new job from the pool comes)
if (result.poolId != -100) { // switch to network pool jobs
Workers::setListener(m_controller->network());
static_cast<IJobResultListener*>(m_controller->network())->onJobResult(result);
return;
}
// ignore benchmark results for other perf algo
if (m_pa == xmrig::PA_INVALID || result.jobId != xmrig::Id(xmrig::Algorithm::perfAlgoName(m_pa))) return;
++ m_hash_count;
const uint64_t now = get_now();
if (now - m_time_start > m_bench_secs*1000) { // end of becnhmark round for m_pa
const float hashrate = static_cast<float>(m_hash_count) / (now - m_time_start) * 1000.0f;
if (!m_time_start) m_time_start = now; // time of measurements start (in ms)
else if (now - m_time_start > m_bench_secs*1000) { // end of becnhmark round for m_pa
const float hashrate = static_cast<float>(m_hash_count) * result.diff / (now - m_time_start) * 1000.0f;
m_controller->config()->set_algo_perf(m_pa, hashrate); // store hashrate result
Log::i()->text(m_controller->config()->isColors()
? GREEN_BOLD(" ===> ") CYAN_BOLD("%s") WHITE_BOLD(" hashrate: ") CYAN_BOLD("%f")
@ -73,14 +75,13 @@ void Benchmark::onJobResult(const JobResult& result) {
xmrig::Algorithm::perfAlgoName(m_pa),
hashrate
);
const xmrig::PerfAlgo pa = static_cast<xmrig::PerfAlgo>(m_pa + 1); // compute next perf algo to benchmark
if (pa != xmrig::PerfAlgo::PA_MAX) {
start_perf_bench(pa);
} else { // en of benchmarks and switching to jobs from the pool (network)
m_is_benchmark_time = false;
if (m_controller->config()->isSaveConfig()) m_controller->config()->save(); // save config with measured algo-perf
const xmrig::PerfAlgo next_pa = static_cast<xmrig::PerfAlgo>(m_pa + 1); // compute next perf algo to benchmark
if (next_pa != xmrig::PerfAlgo::PA_MAX) {
start_perf_bench(next_pa);
} else { // end of benchmarks and switching to jobs from the pool (network)
m_pa = xmrig::PA_INVALID;
m_controller->config()->save(); // save config with measured algo-perf
Workers::pause(); // do not compute anything before job from the pool
Workers::setListener(m_controller->network());
m_controller->network()->connect();
}
}

View file

@ -32,7 +32,6 @@
class Benchmark : public IJobResultListener {
const uint64_t m_bench_secs = 5; // time in seconds to benchmark each perf algo
bool m_is_benchmark_time; // true is we benchmark some perf algo now
xmrig::PerfAlgo m_pa; // current perf algo we benchmark
uint64_t m_hash_count; // number of hashes calculated for current perf algo
uint64_t m_time_start; // time of measurements start for current perf algo (in ms)
@ -43,7 +42,7 @@ class Benchmark : public IJobResultListener {
void onJobResult(const JobResult&) override; // onJobResult is called after each computed benchmark hash
public:
Benchmark() : m_is_benchmark_time(false) {}
Benchmark() {}
virtual ~Benchmark() {}
void set_controller(xmrig::Controller* controller) { m_controller = controller; }