diff --git a/src/App.cpp b/src/App.cpp index c2e5ba9c..66abc1b5 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -133,6 +133,11 @@ int App::exec() if (m_controller->config()->isCalibrateAlgo()) { benchmark.set_controller(m_controller); // we need controller there to access config and network objects Workers::setListener(&benchmark); // register benchmark as job reault listener to compute hashrates there + // write text before first benchmark round + Log::i()->text(m_controller->config()->isColors() + ? GREEN_BOLD(" >>>>> ") WHITE_BOLD("STARTING ALGO PERFORMANCE CALIBRATION") + : " >>>>> STARTING ALGO PERFORMANCE CALIBRATION" + ); benchmark.start_perf_bench(xmrig::PerfAlgo::PA_CN); // start benchmarking from first PerfAlgo in the list } else { // save config here to have option to store automatically generated "threads" diff --git a/src/workers/Benchmark.cpp b/src/workers/Benchmark.cpp index b2969f68..d7e4cdb2 100644 --- a/src/workers/Benchmark.cpp +++ b/src/workers/Benchmark.cpp @@ -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(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(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(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(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(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(); } } diff --git a/src/workers/Benchmark.h b/src/workers/Benchmark.h index 479b14b3..f3262725 100644 --- a/src/workers/Benchmark.h +++ b/src/workers/Benchmark.h @@ -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; }