From 30a4f53c8ff411a11d426e09e0c1632ee9c6af5a Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 1 Aug 2018 18:01:16 +0200 Subject: [PATCH] Calibrate and save algo-perf and threads automatically --- src/App.cpp | 4 ++-- src/config.json | 7 +------ src/core/Config.cpp | 9 +++++++-- src/core/Config.h | 2 ++ src/workers/Benchmark.cpp | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 66abc1b5..f1dcdfce 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -130,7 +130,7 @@ int App::exec() Workers::start(m_controller); // run benchmark before pool mining or not? - if (m_controller->config()->isCalibrateAlgo()) { + if (m_controller->config()->get_algo_perf(xmrig::PA_CN) == 0.0f || 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 @@ -141,7 +141,7 @@ int App::exec() 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" - if (m_controller->config()->isSaveConfig()) m_controller->config()->save(); + if (m_controller->config()->isShouldSave() || m_controller->config()->isSaveConfig()) m_controller->config()->save(); m_controller->network()->connect(); } diff --git a/src/config.json b/src/config.json index ed5d8e37..ede1ba6c 100644 --- a/src/config.json +++ b/src/config.json @@ -33,12 +33,7 @@ "retry-pause": 5, "safe": false, "threads": null, - "algo-perf": { - "cn": 1000.0, - "cn-fast": 2000.0, - "cn-lite": 2000.0, - "cn-heavy": 700.0 - }, + "algo-perf": null, "user-agent": null, "watch": false } \ No newline at end of file diff --git a/src/core/Config.cpp b/src/core/Config.cpp index f37e2e0f..ad2af466 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -46,6 +46,7 @@ static char affinity_tmp[20] = { 0 }; xmrig::Config::Config() : xmrig::CommonConfig(), + m_shouldSave(false), m_aesMode(AES_AUTO), m_algoVariant(AV_AUTO), m_hugePages(true), @@ -56,7 +57,7 @@ xmrig::Config::Config() : xmrig::CommonConfig(), // not defined algo performance is considered to be 0 for (int a = 0; a != xmrig::PerfAlgo::PA_MAX; ++ a) { const xmrig::PerfAlgo pa = static_cast(a); - m_algo_perf[pa] = 0; + m_algo_perf[pa] = 0.0f; } } @@ -176,7 +177,7 @@ bool xmrig::Config::finalize() return false; } - // parse "threads" into m_threads + // auto configure m_threads for (int a = 0; a != xmrig::PerfAlgo::PA_MAX; ++ a) { const xmrig::PerfAlgo pa = static_cast(a); if (!m_threads[pa].cpu.empty()) { @@ -205,6 +206,8 @@ bool xmrig::Config::finalize() for (size_t i = 0; i < m_threads[pa].count; ++i) { m_threads[pa].list.push_back(CpuThread::createFromAV(i, xmrig::Algorithm(pa).algo(), av, m_threads[pa].mask, m_priority)); } + + m_shouldSave = true; } } @@ -346,6 +349,8 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc) } } } + + if (m_algo_perf[xmrig::PA_CN] == 0.0f) m_shouldSave = true; } diff --git a/src/core/Config.h b/src/core/Config.h index 0bf7488d..ec7141e1 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -76,6 +76,7 @@ public: void getJSON(rapidjson::Document &doc) const override; + inline bool isShouldSave() const { return m_shouldSave; } inline AesMode aesMode() const { return m_aesMode; } inline AlgoVariant algoVariant() const { return m_algoVariant; } inline bool isHugePages() const { return m_hugePages; } @@ -131,6 +132,7 @@ private: }; + bool m_shouldSave; AesMode m_aesMode; AlgoVariant m_algoVariant; bool m_hugePages; diff --git a/src/workers/Benchmark.cpp b/src/workers/Benchmark.cpp index d7e4cdb2..1ba1d23b 100644 --- a/src/workers/Benchmark.cpp +++ b/src/workers/Benchmark.cpp @@ -80,7 +80,7 @@ void Benchmark::onJobResult(const JobResult& result) { 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 + if (m_controller->config()->isShouldSave() || 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 m_controller->network()->connect(); }