Added algo performance calibration (benchmarking) functionality
This commit is contained in:
parent
a8d399e450
commit
9951bd756d
9 changed files with 244 additions and 1 deletions
92
src/workers/Benchmark.cpp
Normal file
92
src/workers/Benchmark.cpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
/* 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 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
|
||||
*
|
||||
* 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 "workers/Benchmark.h"
|
||||
#include "workers/Workers.h"
|
||||
#include "core/Config.h"
|
||||
#include "net/Network.h"
|
||||
#include "common/log/Log.h"
|
||||
#include <chrono>
|
||||
|
||||
// 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.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
|
||||
0x05, 0xA0, 0xDB, 0xD6, 0xBF, 0x05, 0xCF, 0x16, 0xE5, 0x03, 0xF3, 0xA6, 0x6F, 0x78, 0x00,
|
||||
0x7C, 0xBF, 0x34, 0x14, 0x43, 0x32, 0xEC, 0xBF, 0xC2, 0x2E, 0xD9, 0x5C, 0x87, 0x00, 0x38, 0x3B,
|
||||
0x30, 0x9A, 0xCE, 0x19, 0x23, 0xA0, 0x96, 0x4B, 0x00, 0x00, 0x00, 0x08, 0xBA, 0x93, 0x9A, 0x62,
|
||||
0x72, 0x4C, 0x0D, 0x75, 0x81, 0xFC, 0xE5, 0x76, 0x1E, 0x9D, 0x8A, 0x0E, 0x6A, 0x1C, 0x3F, 0x92,
|
||||
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.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
|
||||
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)
|
||||
++ 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;
|
||||
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")
|
||||
: " ===> %s hasrate: %f",
|
||||
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
|
||||
Workers::pause(); // do not compute anything before job from the pool
|
||||
Workers::setListener(m_controller->network());
|
||||
m_controller->network()->connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t Benchmark::get_now() const { // get current time in ms
|
||||
using namespace std::chrono;
|
||||
return time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue