From 67ed81f1ec0feb1a7e26c3adcf6e41984df3c98c Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Mon, 6 Aug 2018 10:40:55 +0200 Subject: [PATCH 1/3] Moved from PerfAlgo to Algo in threads to removed not really used cn-fast threads setup --- src/common/crypto/Algorithm.h | 2 +- src/common/xmrig.h | 3 +- src/core/Config.cpp | 60 +++++++++++++++++------------------ src/core/Config.h | 22 ++++++------- src/workers/Workers.cpp | 2 +- 5 files changed, 45 insertions(+), 44 deletions(-) diff --git a/src/common/crypto/Algorithm.h b/src/common/crypto/Algorithm.h index 77e2dfff..bb8c5220 100644 --- a/src/common/crypto/Algorithm.h +++ b/src/common/crypto/Algorithm.h @@ -44,7 +44,7 @@ public: m_variant(VARIANT_AUTO) {} - inline Algorithm(Algo algo, Variant variant) : + inline Algorithm(Algo algo, Variant variant = VARIANT_AUTO) : m_variant(variant) { setAlgo(algo); diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 515c6709..9e17624d 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -34,7 +34,8 @@ enum Algo { INVALID_ALGO = -1, CRYPTONIGHT, /* CryptoNight (Monero) */ CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */ - CRYPTONIGHT_HEAVY /* CryptoNight-Heavy (SUMO) */ + CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (SUMO) */ + ALGO_MAX }; // algorithms that can has different performance diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 0fc1bc5e..a8a51d42 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -124,20 +124,20 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const // save extended "threads" based on m_threads Value threads(kObjectType); - for (int a = 0; a != xmrig::PerfAlgo::PA_MAX; ++ a) { - const xmrig::PerfAlgo pa = static_cast(a); - Value key(xmrig::Algorithm::perfAlgoName(pa), allocator); - if (threadsMode(pa) == Advanced) { + for (int a = 0; a != xmrig::Algo::ALGO_MAX; ++ a) { + const xmrig::Algo algo = static_cast(a); + Value key(xmrig::Algorithm::perfAlgoName(xmrig::Algorithm(algo).perf_algo()), allocator); + if (threadsMode(algo) == Advanced) { Value threads2(kArrayType); - for (const IThread *thread : m_threads[pa].list) { + for (const IThread *thread : m_threads[algo].list) { threads2.PushBack(thread->toConfig(doc), allocator); } threads.AddMember(key, threads2, allocator); } else { - threads.AddMember(key, threadsMode(pa) == Automatic ? Value(kNullType) : Value(threadsCount(pa)), allocator); + threads.AddMember(key, threadsMode(algo) == Automatic ? Value(kNullType) : Value(threadsCount(algo)), allocator); } } doc.AddMember("threads", threads, allocator); @@ -181,33 +181,33 @@ bool xmrig::Config::finalize() } // 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()) { - m_threads[pa].mode = Advanced; + for (int a = 0; a != xmrig::Algo::ALGO_MAX; ++ a) { + const xmrig::Algo algo = static_cast(a); + if (!m_threads[algo].cpu.empty()) { + m_threads[algo].mode = Advanced; const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT; - for (size_t i = 0; i < m_threads[pa].cpu.size(); ++i) { - m_threads[pa].list.push_back(CpuThread::createFromData(i, xmrig::Algorithm(pa).algo(), m_threads[pa].cpu[i], m_priority, softAES)); + for (size_t i = 0; i < m_threads[algo].cpu.size(); ++i) { + m_threads[algo].list.push_back(CpuThread::createFromData(i, algo, m_threads[algo].cpu[i], m_priority, softAES)); } } else { const AlgoVariant av = getAlgoVariant(); - m_threads[pa].mode = m_threads[pa].count ? Simple : Automatic; + m_threads[algo].mode = m_threads[algo].count ? Simple : Automatic; - const size_t size = CpuThread::multiway(av) * cn_select_memory(xmrig::Algorithm(pa).algo()) / 1024; + const size_t size = CpuThread::multiway(av) * cn_select_memory(algo) / 1024; - if (!m_threads[pa].count) { - m_threads[pa].count = Cpu::optimalThreadsCount(size, m_maxCpuUsage); + if (!m_threads[algo].count) { + m_threads[algo].count = Cpu::optimalThreadsCount(size, m_maxCpuUsage); } else if (m_safe) { const size_t count = Cpu::optimalThreadsCount(size, m_maxCpuUsage); - if (m_threads[pa].count > count) { - m_threads[pa].count = count; + if (m_threads[algo].count > count) { + m_threads[algo].count = count; } } - 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)); + for (size_t i = 0; i < m_threads[algo].count; ++i) { + m_threads[algo].list.push_back(CpuThread::createFromAV(i, algo, av, m_threads[algo].mask, m_priority)); } } } @@ -263,7 +263,7 @@ bool xmrig::Config::parseString(int key, const char *arg) case ThreadsKey: /* --threads */ if (strncmp(arg, "all", 3) == 0) { - m_threads[m_algorithm.perf_algo()].count = Cpu::threads(); // sets default algo threads + m_threads[m_algorithm.algo()].count = Cpu::threads(); // sets default algo threads return true; } @@ -292,7 +292,7 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg) switch (key) { case CPUAffinityKey: /* --cpu-affinity */ if (arg) { - m_threads[m_algorithm.perf_algo()].mask = arg; // sets default algo threads + m_threads[m_algorithm.algo()].mask = arg; // sets default algo threads } break; @@ -305,7 +305,7 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg) // parse specific perf algo (or generic) threads config -void xmrig::Config::parseThreadsJSON(const rapidjson::Value &threads, const xmrig::PerfAlgo pa) +void xmrig::Config::parseThreadsJSON(const rapidjson::Value &threads, const xmrig::Algo algo) { for (const rapidjson::Value &value : threads.GetArray()) { if (!value.IsObject()) { @@ -316,7 +316,7 @@ void xmrig::Config::parseThreadsJSON(const rapidjson::Value &threads, const xmri auto data = CpuThread::parse(value); if (data.valid) { - m_threads[pa].cpu.push_back(std::move(data)); + m_threads[algo].cpu.push_back(std::move(data)); } } } @@ -328,14 +328,14 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc) if (threads.IsArray()) { // parse generic (old) threads - parseThreadsJSON(threads, m_algorithm.perf_algo()); + parseThreadsJSON(threads, m_algorithm.algo()); } else if (threads.IsObject()) { // parse new specific perf algo threads - for (int a = 0; a != xmrig::PerfAlgo::PA_MAX; ++ a) { - const xmrig::PerfAlgo pa = static_cast(a); - const rapidjson::Value &threads2 = threads[xmrig::Algorithm::perfAlgoName(pa)]; + for (int a = 0; a != xmrig::Algo::ALGO_MAX; ++ a) { + const xmrig::Algo algo = static_cast(a); + const rapidjson::Value &threads2 = threads[xmrig::Algorithm::perfAlgoName(xmrig::Algorithm(algo).perf_algo())]; if (threads2.IsArray()) { - parseThreadsJSON(threads2, pa); + parseThreadsJSON(threads2, algo); } } } @@ -360,7 +360,7 @@ bool xmrig::Config::parseInt(int key, int arg) switch (key) { case ThreadsKey: /* --threads */ if (arg >= 0 && arg < 1024) { - m_threads[m_algorithm.perf_algo()].count = arg; // sets default algo threads + m_threads[m_algorithm.algo()].count = arg; // sets default algo threads } break; diff --git a/src/core/Config.h b/src/core/Config.h index ec7141e1..539944d4 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -83,17 +83,17 @@ public: inline int priority() const { return m_priority; } // access to m_threads taking into accoun that it is now separated for each perf algo - inline const std::vector &threads(const xmrig::PerfAlgo pa = PA_INVALID) const { - return m_threads[pa == PA_INVALID ? m_algorithm.perf_algo() : pa].list; + inline const std::vector &threads(const xmrig::Algo algo = INVALID_ALGO) const { + return m_threads[algo == INVALID_ALGO ? m_algorithm.algo() : algo].list; } - inline int threadsCount(const xmrig::PerfAlgo pa = PA_INVALID) const { - return m_threads[pa == PA_INVALID ? m_algorithm.perf_algo() : pa].list.size(); + inline int threadsCount(const xmrig::Algo algo = INVALID_ALGO) const { + return m_threads[algo == INVALID_ALGO ? m_algorithm.algo() : algo].list.size(); } - inline int64_t affinity(const xmrig::PerfAlgo pa = PA_INVALID) const { - return m_threads[pa == PA_INVALID ? m_algorithm.perf_algo() : pa].mask; + inline int64_t affinity(const xmrig::Algo algo = INVALID_ALGO) const { + return m_threads[algo == INVALID_ALGO ? m_algorithm.algo() : algo].mask; } - inline ThreadsMode threadsMode(const xmrig::PerfAlgo pa = PA_INVALID) const { - return m_threads[pa == PA_INVALID ? m_algorithm.perf_algo() : pa].mode; + inline ThreadsMode threadsMode(const xmrig::Algo algo = INVALID_ALGO) const { + return m_threads[algo == INVALID_ALGO ? m_algorithm.algo() : algo].mode; } // access to perf algo results @@ -109,7 +109,7 @@ protected: bool parseUint64(int key, uint64_t arg) override; void parseJSON(const rapidjson::Document &doc) override; // parse specific perf algo (or generic) threads config - void parseThreadsJSON(const rapidjson::Value &threads, xmrig::PerfAlgo); + void parseThreadsJSON(const rapidjson::Value &threads, xmrig::Algo); private: bool parseInt(int key, int arg); @@ -139,8 +139,8 @@ private: bool m_safe; int m_maxCpuUsage; int m_priority; - // threads config for each perf algo - Threads m_threads[xmrig::PerfAlgo::PA_MAX]; + // threads config for each algo + Threads m_threads[xmrig::Algo::ALGO_MAX]; // perf algo hashrate results float m_algo_perf[xmrig::PerfAlgo::PA_MAX]; }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 7e58548c..b9d0cf50 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -223,7 +223,7 @@ void Workers::switch_algo(const xmrig::Algorithm& algorithm) m_sequence = 1; m_paused = 1; - const std::vector &threads = m_controller->config()->threads(algorithm.perf_algo()); + const std::vector &threads = m_controller->config()->threads(algorithm.algo()); m_status.algo = algorithm.algo(); m_status.threads = threads.size(); From feeb226507ca14b0e33f7d90b990bf8cdcec041a Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Mon, 6 Aug 2018 10:58:35 +0200 Subject: [PATCH 2/3] Moved benchmark config save flag to the benchmark class --- src/App.cpp | 4 +++- src/core/Config.cpp | 3 --- src/core/Config.h | 2 -- src/workers/Benchmark.cpp | 2 +- src/workers/Benchmark.h | 10 ++++++---- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 1f6fc2fb..1af0c92e 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -139,7 +139,9 @@ int App::exec() : " >>>>> STARTING ALGO PERFORMANCE CALIBRATION (with %i seconds round)", m_controller->config()->calibrateAlgoTime() ); - benchmark.start_perf_bench(xmrig::PerfAlgo::PA_CN); // start benchmarking from first PerfAlgo in the list + // start benchmarking from first PerfAlgo in the list + if (m_controller->config()->get_algo_perf(xmrig::PA_CN) == 0.0f) benchmark.shoud_save_config(); + benchmark.start_perf_bench(xmrig::PerfAlgo::PA_CN); } else { m_controller->network()->connect(); } diff --git a/src/core/Config.cpp b/src/core/Config.cpp index a8a51d42..d72ae86f 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -46,7 +46,6 @@ 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), @@ -350,8 +349,6 @@ 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 539944d4..ffb85f40 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -76,7 +76,6 @@ 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; } @@ -132,7 +131,6 @@ 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 1663a9e9..c32db0d0 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; - if (m_controller->config()->isShouldSave()) m_controller->config()->save(); // save config with measured algo-perf + if (m_shouldSaveConfig) 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(); } diff --git a/src/workers/Benchmark.h b/src/workers/Benchmark.h index ae74310e..e639c0d0 100644 --- a/src/workers/Benchmark.h +++ b/src/workers/Benchmark.h @@ -31,9 +31,10 @@ #include "core/Controller.h" class Benchmark : public IJobResultListener { - 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) + bool m_shouldSaveConfig; // should save config after all benchmark rounds + 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) xmrig::Controller* m_controller; // to get access to config and network uint64_t get_now() const; // get current time in ms @@ -41,9 +42,10 @@ class Benchmark : public IJobResultListener { void onJobResult(const JobResult&) override; // onJobResult is called after each computed benchmark hash public: - Benchmark() {} + Benchmark() : m_shouldSaveConfig(false) {} virtual ~Benchmark() {} void set_controller(xmrig::Controller* controller) { m_controller = controller; } + void shoud_save_config() { m_shouldSaveConfig = true; } void start_perf_bench(const xmrig::PerfAlgo); // start benchmark for specified perf algo }; From bd56b8892c7274776a153303cdcea20d321740d9 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Mon, 6 Aug 2018 11:01:10 +0200 Subject: [PATCH 3/3] Typo fix --- src/App.cpp | 2 +- src/workers/Benchmark.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 1af0c92e..48ac379d 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -140,7 +140,7 @@ int App::exec() m_controller->config()->calibrateAlgoTime() ); // start benchmarking from first PerfAlgo in the list - if (m_controller->config()->get_algo_perf(xmrig::PA_CN) == 0.0f) benchmark.shoud_save_config(); + if (m_controller->config()->get_algo_perf(xmrig::PA_CN) == 0.0f) benchmark.should_save_config(); benchmark.start_perf_bench(xmrig::PerfAlgo::PA_CN); } else { m_controller->network()->connect(); diff --git a/src/workers/Benchmark.h b/src/workers/Benchmark.h index e639c0d0..795edc6d 100644 --- a/src/workers/Benchmark.h +++ b/src/workers/Benchmark.h @@ -46,6 +46,6 @@ class Benchmark : public IJobResultListener { virtual ~Benchmark() {} void set_controller(xmrig::Controller* controller) { m_controller = controller; } - void shoud_save_config() { m_shouldSaveConfig = true; } + void should_save_config() { m_shouldSaveConfig = true; } void start_perf_bench(const xmrig::PerfAlgo); // start benchmark for specified perf algo };