From 4ed53584892886c3a9976817e2734f25190a6328 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 28 Jul 2018 12:25:21 +0200 Subject: [PATCH 01/24] Added new --calibrate-algo and --save-config command line options --- src/common/config/CommonConfig.cpp | 11 +++++++++++ src/common/config/CommonConfig.h | 5 +++++ src/common/interfaces/IConfig.h | 3 +++ src/core/ConfigLoader_platform.h | 5 +++++ 4 files changed, 24 insertions(+) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 7e43b39d..c9cbc971 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -183,6 +184,14 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) m_dryRun = enable; break; + case IConfig::CalibrateAlgoKey: /* --calibrate-algo */ + m_calibrateAlgo = enable; + break; + + case IConfig::SaveConfigKey: /* --save-config */ + m_saveConfig = enable; + break; + default: break; } @@ -267,6 +276,8 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) case NicehashKey: /* --nicehash */ case ApiIPv6Key: /* --api-ipv6 */ case DryRunKey: /* --dry-run */ + case CalibrateAlgoKey: /* --calibrate-algo */ + case SaveConfigKey: /* --save-config */ return parseBoolean(key, true); case ColorKey: /* --no-color */ diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index ffebb6b2..17bab1d8 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -48,6 +49,8 @@ class CommonConfig : public IConfig inline bool isBackground() const { return m_background; } inline bool isColors() const { return m_colors; } inline bool isDryRun() const { return m_dryRun; } + inline bool isCalibrateAlgo() const { return m_calibrateAlgo; } + inline bool isSaveConfig() const { return m_saveConfig; } inline bool isSyslog() const { return m_syslog; } inline const char *apiToken() const { return m_apiToken.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } @@ -87,6 +90,8 @@ class CommonConfig : public IConfig bool m_background; bool m_colors; bool m_dryRun; + bool m_calibrateAlgo; + bool m_saveConfig; bool m_syslog; bool m_watch; int m_apiPort; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 4b3f8788..5c2c928e 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2016-2018 XMRig + * Copyright 2018 MoneroOcean , * * 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 @@ -67,6 +68,8 @@ class IConfig CPUPriorityKey = 1021, NicehashKey = 1006, PrintTimeKey = 1007, + CalibrateAlgoKey = 10001, + SaveConfigKey = 10002, // xmrig cpu AVKey = 'v', diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index da191cdb..ccf355b3 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * * This program is free software: you can redistribute it and/or modify @@ -54,6 +55,7 @@ Options:\n\ cryptonight-heavy\n" #endif "\ + --calibrate-algo run benchmarks before mining to measure hashrates of all supported algos\n\ -o, --url=URL URL of mining server\n\ -O, --userpass=U:P username:password pair for mining server\n\ -u, --user=USERNAME username for mining server\n\ @@ -87,6 +89,7 @@ Options:\n\ --api-worker-id=ID custom worker-id for API\n\ --api-ipv6 enable IPv6 support for API\n\ --api-no-restricted enable full remote access (only if API token set)\n\ + --save-config save config file including generated configuration\n\ -h, --help display this help and exit\n\ -V, --version output version information and exit\n\ "; @@ -106,6 +109,8 @@ static struct option const options[] = { { "config", 1, nullptr, xmrig::IConfig::ConfigKey }, { "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey }, { "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey }, + { "calibrate-algo", 0, nullptr, xmrig::IConfig::CalibrateAlgoKey }, + { "save-config", 0, nullptr, xmrig::IConfig::SaveConfigKey }, { "help", 0, nullptr, xmrig::IConfig::HelpKey }, { "keepalive", 0, nullptr, xmrig::IConfig::KeepAliveKey }, { "log-file", 1, nullptr, xmrig::IConfig::LogFileKey }, From 27c508b4b49e6a7e0bec5db71b8aba65f42d716a Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 28 Jul 2018 12:38:55 +0200 Subject: [PATCH 02/24] Report all possible algorithms to the pool --- src/common/net/Client.h | 2 +- src/common/net/Pool.cpp | 60 +++++++++++------------------------------ src/common/net/Pool.h | 4 +-- 3 files changed, 17 insertions(+), 49 deletions(-) diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 4be8badb..f98efe1f 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -74,7 +75,6 @@ class Client inline int id() const { return m_id; } inline SocketState state() const { return m_state; } inline uint16_t port() const { return m_pool.port(); } - inline void setAlgo(const xmrig::Algorithm &algo) { m_pool.setAlgo(algo); } inline void setQuiet(bool quiet) { m_quiet = quiet; } inline void setRetries(int retries) { m_retries = retries; } inline void setRetryPause(int ms) { m_retryPause = ms; } diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 053f2507..26a0468e 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -48,6 +49,20 @@ Pool::Pool() : m_keepAlive(0), m_port(kDefaultPort) { + // here xmrig now resuts all possible supported algorithms + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_1)); + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_0)); + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL)); + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR)); + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO)); + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_RTO)); + + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1)); + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0)); + + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0)); + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV)); + m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE)); } @@ -233,16 +248,6 @@ void Pool::adjust(const xmrig::Algorithm &algorithm) m_algorithm.setAlgo(algorithm.algo()); adjustVariant(algorithm.variant()); } - - rebuild(); -} - - -void Pool::setAlgo(const xmrig::Algorithm &algorithm) -{ - m_algorithm = algorithm; - - rebuild(); } @@ -285,17 +290,6 @@ bool Pool::parseIPv6(const char *addr) } -void Pool::addVariant(xmrig::Variant variant) -{ - const xmrig::Algorithm algorithm(m_algorithm.algo(), variant); - if (!algorithm.isValid() || m_algorithm == algorithm) { - return; - } - - m_algorithms.push_back(algorithm); -} - - void Pool::adjustVariant(const xmrig::Variant variantHint) { # ifndef XMRIG_PROXY_PROJECT @@ -364,27 +358,3 @@ void Pool::adjustVariant(const xmrig::Variant variantHint) } # endif } - - -void Pool::rebuild() -{ - m_algorithms.clear(); - - if (!m_algorithm.isValid()) { - return; - } - - m_algorithms.push_back(m_algorithm); - -# ifndef XMRIG_PROXY_PROJECT - addVariant(xmrig::VARIANT_1); - addVariant(xmrig::VARIANT_0); - addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_TUBE); - addVariant(xmrig::VARIANT_MSR); - addVariant(xmrig::VARIANT_XHV); - addVariant(xmrig::VARIANT_XAO); - addVariant(xmrig::VARIANT_RTO); - addVariant(xmrig::VARIANT_AUTO); -# endif -} diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index 57a30d1e..04a26818 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -78,7 +79,6 @@ class Pool bool setUserpass(const char *userpass); rapidjson::Value toJSON(rapidjson::Document &doc) const; void adjust(const xmrig::Algorithm &algorithm); - void setAlgo(const xmrig::Algorithm &algorithm); # ifdef APP_DEBUG void print() const; @@ -86,9 +86,7 @@ class Pool private: bool parseIPv6(const char *addr); - void addVariant(xmrig::Variant variant); void adjustVariant(const xmrig::Variant variantHint); - void rebuild(); bool m_nicehash; int m_keepAlive; From 456cbbf71862cb0cf5813f52fd69bb0c5f154b3a Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 28 Jul 2018 12:43:24 +0200 Subject: [PATCH 03/24] Added perf algo (PerfAlgo) basic support --- src/common/crypto/Algorithm.cpp | 49 +++++++++++++++++++++++++++++++++ src/common/crypto/Algorithm.h | 6 ++++ src/common/xmrig.h | 10 +++++++ 3 files changed, 65 insertions(+) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index 31035fb1..c253d9c8 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -7,6 +7,7 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -223,3 +224,51 @@ const char *xmrig::Algorithm::name(bool shortName) const return "invalid"; } + + +// returns string name of the PerfAlgo +const char *xmrig::Algorithm::perfAlgoName(const xmrig::PerfAlgo pa) { + static const char* perf_algo_names[xmrig::PerfAlgo::PA_MAX] = { + "cn", + "cn-fast", + "cn-lite", + "cn-heavy", + }; + return perf_algo_names[pa]; +} + +// constructs Algorithm from PerfAlgo +xmrig::Algorithm::Algorithm(const xmrig::PerfAlgo pa) { + switch (pa) { + case PA_CN: + m_algo = xmrig::CRYPTONIGHT; + m_variant = xmrig::VARIANT_1; + break; + case PA_CN_FAST: + m_algo = xmrig::CRYPTONIGHT; + m_variant = xmrig::VARIANT_MSR; + break; + case PA_CN_LITE: + m_algo = xmrig::CRYPTONIGHT_LITE; + m_variant = xmrig::VARIANT_1; + break; + case PA_CN_HEAVY: + m_algo = xmrig::CRYPTONIGHT_HEAVY; + m_variant = xmrig::VARIANT_0; + break; + default: + m_algo = xmrig::INVALID_ALGO; + m_variant = xmrig::VARIANT_AUTO; + } +} + +// returns PerfAlgo that corresponds to current Algorithm +xmrig::PerfAlgo xmrig::Algorithm::perf_algo() const { + if (m_variant == VARIANT_MSR) return PA_CN_FAST; + switch (m_algo) { + case CRYPTONIGHT: return PA_CN; + case CRYPTONIGHT_LITE: return PA_CN_LITE; + case CRYPTONIGHT_HEAVY: return PA_CN_HEAVY; + default: return PA_INVALID; + } +} diff --git a/src/common/crypto/Algorithm.h b/src/common/crypto/Algorithm.h index bcf029d8..77e2dfff 100644 --- a/src/common/crypto/Algorithm.h +++ b/src/common/crypto/Algorithm.h @@ -7,6 +7,7 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -49,6 +50,9 @@ class Algorithm setAlgo(algo); } + // constructs Algorithm from PerfAlgo + Algorithm(const xmrig::PerfAlgo); + inline Algorithm(const char *algo) { parseAlgorithm(algo); @@ -56,8 +60,10 @@ class Algorithm bool isEqual(const Algorithm &other) const { return m_algo == other.m_algo && m_variant == other.m_variant; } inline Algo algo() const { return m_algo; } + xmrig::PerfAlgo perf_algo() const; // returns PerfAlgo that corresponds to current Algorithm inline const char *name() const { return name(false); } inline const char *shortName() const { return name(true); } + static const char *perfAlgoName(xmrig::PerfAlgo); // returns string name of the PerfAlgo inline Variant variant() const { return m_variant; } inline void setVariant(Variant variant) { m_variant = variant; } diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 58a3540c..5402d84b 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -36,6 +37,15 @@ enum Algo { CRYPTONIGHT_HEAVY /* CryptoNight-Heavy (RYO) */ }; +// algorithms that can has different performance +enum PerfAlgo { + PA_INVALID = -1, + PA_CN, /* CryptoNight (Monero) */ + PA_CN_FAST, /* CryptoNight-Fast (Masari) */ + PA_CN_LITE, /* CryptoNight-Lite (AEON) */ + PA_CN_HEAVY, /* CryptoNight-Heavy (RYO) */ + PA_MAX +}; //--av=1 For CPUs with hardware AES. //--av=2 Lower power mode (double hash) of 1. From 96eacfb6c18ecee3cce9cec99aa186acd9016c24 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 28 Jul 2018 12:50:43 +0200 Subject: [PATCH 04/24] Added support for extended threads and algo-perf config parameters --- src/config.json | 6 +++ src/core/Config.cpp | 85 ++++++++++++++++++++++++++++++++++------- src/core/Config.h | 20 ++++++++-- src/core/Controller.cpp | 4 +- 4 files changed, 97 insertions(+), 18 deletions(-) diff --git a/src/config.json b/src/config.json index 45d4759e..f590e5a0 100644 --- a/src/config.json +++ b/src/config.json @@ -27,6 +27,12 @@ "retries": 5, "retry-pause": 5, "threads": null, + "algo-perf": { + "cn": 1000.0, + "cn-fast": 2000.0, + "cn-lite": 2000.0, + "cn-heavy": 700.0 + }, "user-agent": null, "syslog": false, "watch": false diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 874acd7d..fb6c64c4 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -40,6 +41,12 @@ #include "workers/OclThread.h" +// for usage in Client::login to get_algo_perf +namespace xmrig { + Config* pconfig = nullptr; +}; + + xmrig::Config::Config() : xmrig::CommonConfig(), m_autoConf(false), m_cache(true), @@ -51,6 +58,11 @@ xmrig::Config::Config() : xmrig::CommonConfig(), m_loader("libOpenCL.so") # endif { + // 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; + } } @@ -63,10 +75,13 @@ bool xmrig::Config::oclInit() { LOG_WARN("compiling code and initializing GPUs. This will take a while..."); - if (m_threads.empty() && !m_oclCLI.setup(m_threads)) { - m_autoConf = true; - m_shouldSave = true; - m_oclCLI.autoConf(m_threads, &m_platformIndex, this); + for (int a = 0; a != xmrig::PerfAlgo::PA_MAX; ++ a) { + const xmrig::PerfAlgo pa = static_cast(a); + if (m_threads[pa].empty() && !m_oclCLI.setup(m_threads[pa])) { + m_autoConf = true; + m_shouldSave = true; + m_oclCLI.autoConf(m_threads[pa], &m_platformIndex, xmrig::Algorithm(pa), this); + } } return true; @@ -116,12 +131,28 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("retries", retries(), allocator); doc.AddMember("retry-pause", retryPause(), allocator); - Value threads(kArrayType); - for (const IThread *thread : m_threads) { - threads.PushBack(thread->toConfig(doc), allocator); + // 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); + Value threads2(kArrayType); + for (const IThread *thread : m_threads[pa]) { + threads2.PushBack(thread->toConfig(doc), allocator); + } + threads.AddMember(key, threads2, allocator); } doc.AddMember("threads", threads, allocator); + // save "algo-perf" based on m_algo_perf + Value algo_perf(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); + algo_perf.AddMember(key, Value(m_algo_perf[pa]), allocator); + } + doc.AddMember("algo-perf", algo_perf, allocator); + doc.AddMember("user-agent", userAgent() ? Value(StringRef(userAgent())).Move() : Value(kNullType).Move(), allocator); doc.AddMember("syslog", isSyslog(), allocator); doc.AddMember("watch", m_watch, allocator); @@ -228,26 +259,52 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg) return true; } +// parse specific perf algo (or generic) threads config +void xmrig::Config::parseThreadsJSON(const rapidjson::Value &threads, const xmrig::PerfAlgo pa) +{ + for (const rapidjson::Value &value : threads.GetArray()) { + if (!value.IsObject()) { + continue; + } + + if (value.HasMember("intensity")) { + parseThread(value, pa); + } + } +} void xmrig::Config::parseJSON(const rapidjson::Document &doc) { const rapidjson::Value &threads = doc["threads"]; if (threads.IsArray()) { - for (const rapidjson::Value &value : threads.GetArray()) { - if (!value.IsObject()) { - continue; + // parse generic (old) threads + parseThreadsJSON(threads, m_algorithm.perf_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)]; + if (threads2.IsArray()) { + parseThreadsJSON(threads2, pa); } + } + } - if (value.HasMember("intensity")) { - parseThread(value); + const rapidjson::Value &algo_perf = doc["algo-perf"]; + if (algo_perf.IsObject()) { + for (int a = 0; a != xmrig::PerfAlgo::PA_MAX; ++ a) { + const xmrig::PerfAlgo pa = static_cast(a); + const rapidjson::Value &key = algo_perf[xmrig::Algorithm::perfAlgoName(pa)]; + if (key.IsDouble()) { + m_algo_perf[pa] = key.GetDouble(); } } } } -void xmrig::Config::parseThread(const rapidjson::Value &object) +void xmrig::Config::parseThread(const rapidjson::Value &object, const xmrig::PerfAlgo pa) { - m_threads.push_back(new OclThread(object)); + m_threads[pa].push_back(new OclThread(object)); } diff --git a/src/core/Config.h b/src/core/Config.h index a7faea95..c83bdafe 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -57,9 +58,16 @@ class Config : public CommonConfig inline bool isOclCache() const { return m_cache; } inline bool isShouldSave() const { return m_shouldSave; } inline const char *loader() const { return m_loader.data(); } - inline const std::vector &threads() const { return m_threads; } + // 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]; + } inline int platformIndex() const { return m_platformIndex; } + // access to perf algo results + inline float get_algo_perf(const xmrig::PerfAlgo pa) const { return m_algo_perf[pa]; } + inline void set_algo_perf(const xmrig::PerfAlgo pa, const float value) { m_algo_perf[pa] = value; } + static Config *load(int argc, char **argv, IWatcherListener *listener); protected: @@ -68,19 +76,25 @@ class Config : public CommonConfig bool parseString(int key, const char *arg) override; 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); private: - void parseThread(const rapidjson::Value &object); + void parseThread(const rapidjson::Value &object, const xmrig::PerfAlgo); bool m_autoConf; bool m_cache; bool m_shouldSave; int m_platformIndex; OclCLI m_oclCLI; - std::vector m_threads; + // threads config for each perf algo + std::vector m_threads[xmrig::PerfAlgo::PA_MAX]; + // perf algo hashrate results + float m_algo_perf[xmrig::PerfAlgo::PA_MAX]; xmrig::c_str m_loader; }; +extern Config* pconfig; } /* namespace xmrig */ diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 5f11f05c..bc667a2c 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -103,7 +104,8 @@ int xmrig::Controller::init(int argc, char **argv) { Cpu::init(); - d_ptr->config = xmrig::Config::load(argc, argv, this); + // init pconfig global pointer to config + pconfig = d_ptr->config = xmrig::Config::load(argc, argv, this); if (!d_ptr->config) { return 1; } From c17bfd32becab170849031ddaea4a70e60a1c0b8 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 28 Jul 2018 12:54:19 +0200 Subject: [PATCH 05/24] Added xmrig::Algorithm parameter to autoConf function --- src/amd/OclCLI.cpp | 7 ++++--- src/amd/OclCLI.h | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/amd/OclCLI.cpp b/src/amd/OclCLI.cpp index 6206097b..196cc67b 100644 --- a/src/amd/OclCLI.cpp +++ b/src/amd/OclCLI.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -56,7 +57,7 @@ bool OclCLI::setup(std::vector &threads) } -void OclCLI::autoConf(std::vector &threads, int *platformIndex, xmrig::Config *config) +void OclCLI::autoConf(std::vector &threads, int *platformIndex, const xmrig::Algorithm& algorithm, xmrig::Config *config) { *platformIndex = getAMDPlatformIdx(config); if (*platformIndex == -1) { @@ -71,7 +72,7 @@ void OclCLI::autoConf(std::vector &threads, int *platformIndex } constexpr size_t byteToMiB = 1024u * 1024u; - const size_t hashMemSize = xmrig::cn_select_memory(config->algorithm().algo()); + const size_t hashMemSize = xmrig::cn_select_memory(algorithm.algo()); for (GpuContext &ctx : devices) { // Vega APU slow and can cause BSOD, skip from autoconfig. @@ -96,7 +97,7 @@ void OclCLI::autoConf(std::vector &threads, int *platformIndex maxThreads = 2024u; } - if (config->algorithm().algo() == xmrig::CRYPTONIGHT_LITE) { + if (algorithm.algo() == xmrig::CRYPTONIGHT_LITE) { maxThreads *= 2u; } diff --git a/src/amd/OclCLI.h b/src/amd/OclCLI.h index 686db6f6..4c897257 100644 --- a/src/amd/OclCLI.h +++ b/src/amd/OclCLI.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -29,6 +30,7 @@ #include "common/xmrig.h" +#include "common/crypto/Algorithm.h" // need it for new xmrig::Algorithm autoConf param class OclThread; @@ -46,7 +48,8 @@ class OclCLI OclCLI(); bool setup(std::vector &threads); - void autoConf(std::vector &threads, int *platformIndex, xmrig::Config *config); + // autoConf now takes Algorithm parameter as input + void autoConf(std::vector &threads, int *platformIndex, const xmrig::Algorithm&, xmrig::Config *config); void parseLaunch(const char *arg); inline void parseAffinity(const char *arg) { parse(m_affinity, arg); } From 692088cf7b87ba919af2707cc66a3935fc5bf262 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 28 Jul 2018 13:08:05 +0200 Subject: [PATCH 06/24] Support for OpenCL object release --- src/amd/GpuContext.h | 43 ++++++++++++++++++++++++++++++- src/amd/OclGPU.cpp | 6 ++++- src/amd/OclLib.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/amd/OclLib.h | 7 ++++++ 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/src/amd/GpuContext.h b/src/amd/GpuContext.h index 733ca238..749b53a5 100644 --- a/src/amd/GpuContext.h +++ b/src/amd/GpuContext.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -25,7 +26,7 @@ #define __GPUCONTEXT_H__ -#include "3rdparty/CL/cl.h" +#include "amd/OclLib.h" #include @@ -73,6 +74,46 @@ struct GpuContext Nonce(0) {} + void release() { // stops all opencl kernels and releases all opencl resources (in destructor and copy constructor) + if (CommandQueues) { + OclLib::finish(CommandQueues); + OclLib::releaseCommandQueue(CommandQueues); + } + if (InputBuffer) OclLib::releaseMemObject(InputBuffer); + if (OutputBuffer) OclLib::releaseMemObject(OutputBuffer); + for (int i = 0; i < 6; ++ i) if (ExtraBuffers[i]) OclLib::releaseMemObject(ExtraBuffers[i]); + for (int i = 0; i < 11; ++ i) if (Kernels[i]) OclLib::releaseKernel(Kernels[i]); + if (Program) OclLib::releaseProgram(Program); + } + + ~GpuContext() { release(); } + + GpuContext& operator=(const GpuContext& other) { // copy contructor we need to override default one to properly release OpenCL stuff + release(); + + deviceIdx = other.deviceIdx; + rawIntensity = other.rawIntensity; + workSize = other.workSize; + stridedIndex = other.stridedIndex; + memChunk = other.memChunk; + compMode = other.compMode; + + DeviceID = other.DeviceID; + CommandQueues = other.CommandQueues; + InputBuffer = other.InputBuffer; + OutputBuffer = other.OutputBuffer; + for (int i = 0; i < 6; ++ i) ExtraBuffers[i] = other.ExtraBuffers[i]; + Program = other.Program; + for (int i = 0; i < 11; ++ i) Kernels[i] = other.Kernels[i]; + + freeMem = other.freeMem; + computeUnits = other.computeUnits; + name = other.name; + + Nonce = other.Nonce; + return *this; + } + /*Input vars*/ size_t deviceIdx; size_t rawIntensity; diff --git a/src/amd/OclGPU.cpp b/src/amd/OclGPU.cpp index 03b056b2..a9c4d62e 100644 --- a/src/amd/OclGPU.cpp +++ b/src/amd/OclGPU.cpp @@ -7,6 +7,7 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -410,7 +411,10 @@ size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, xmrig::Config *config) TempDeviceList[i] = DeviceIDList[ctx[i].deviceIdx]; } - cl_context opencl_ctx = OclLib::createContext(nullptr, num_gpus, TempDeviceList, nullptr, nullptr, &ret); + // we store previous OpenCL context in static variable to be able to release it next time we do algo switch + static cl_context opencl_ctx = nullptr; + if (opencl_ctx) OclLib::releaseContext(opencl_ctx); + opencl_ctx = OclLib::createContext(nullptr, num_gpus, TempDeviceList, nullptr, nullptr, &ret); if(ret != CL_SUCCESS) { return OCL_ERR_API; } diff --git a/src/amd/OclLib.cpp b/src/amd/OclLib.cpp index bcf183c1..a97c73e6 100644 --- a/src/amd/OclLib.cpp +++ b/src/amd/OclLib.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -53,6 +54,11 @@ static const char *kGetPlatformInfo = "clGetPlatformInfo"; static const char *kGetProgramBuildInfo = "clGetProgramBuildInfo"; static const char *kGetProgramInfo = "clGetProgramInfo"; static const char *kSetKernelArg = "clSetKernelArg"; +static const char *kReleaseContext = "clReleaseContext"; +static const char *kReleaseProgram = "clReleaseProgram"; +static const char *kReleaseCommandQueue = "clReleaseCommandQueue"; +static const char *kReleaseMemObject = "clReleaseMemObject"; +static const char *kReleaseKernel = "clReleaseKernel"; typedef cl_command_queue (CL_API_CALL *createCommandQueueWithProperties_t)(cl_context, cl_device_id, const cl_queue_properties *, cl_int *); typedef cl_command_queue (CL_API_CALL *createCommandQueue_t)(cl_context, cl_device_id, cl_command_queue_properties, cl_int *); @@ -73,6 +79,11 @@ typedef cl_kernel (CL_API_CALL *createKernel_t)(cl_program, const char *, cl_int typedef cl_mem (CL_API_CALL *createBuffer_t)(cl_context, cl_mem_flags, size_t, void *, cl_int *); typedef cl_program (CL_API_CALL *createProgramWithBinary_t)(cl_context, cl_uint, const cl_device_id *, const size_t *, const unsigned char **, cl_int *, cl_int *); typedef cl_program (CL_API_CALL *createProgramWithSource_t)(cl_context, cl_uint, const char **, const size_t *, cl_int *); +typedef cl_int (CL_API_CALL *releaseContext_t)(cl_context); +typedef cl_int (CL_API_CALL *releaseProgram_t)(cl_program); +typedef cl_int (CL_API_CALL *releaseCommandQueue_t)(cl_command_queue); +typedef cl_int (CL_API_CALL *releaseMemObject_t)(cl_mem); +typedef cl_int (CL_API_CALL *releaseKernel_t)(cl_kernel); static createCommandQueueWithProperties_t pCreateCommandQueueWithProperties = nullptr; static createCommandQueue_t pCreateCommandQueue = nullptr; @@ -93,6 +104,11 @@ static createKernel_t pCreateKernel = nu static createBuffer_t pCreateBuffer = nullptr; static createProgramWithBinary_t pCreateProgramWithBinary = nullptr; static createProgramWithSource_t pCreateProgramWithSource = nullptr; +static releaseContext_t pReleaseContext = nullptr; +static releaseProgram_t pReleaseProgram = nullptr; +static releaseCommandQueue_t pReleaseCommandQueue = nullptr; +static releaseMemObject_t pReleaseMemObject = nullptr; +static releaseKernel_t pReleaseKernel = nullptr; #define DLSYM(x) if (uv_dlsym(&oclLib, k##x, reinterpret_cast(&p##x)) == -1) { return false; } @@ -128,6 +144,11 @@ bool OclLib::load() DLSYM(CreateBuffer); DLSYM(CreateProgramWithBinary); DLSYM(CreateProgramWithSource); + DLSYM(ReleaseContext); + DLSYM(ReleaseProgram); + DLSYM(ReleaseCommandQueue); + DLSYM(ReleaseMemObject); + DLSYM(ReleaseKernel); uv_dlsym(&oclLib, kCreateCommandQueueWithProperties, reinterpret_cast(&pCreateCommandQueueWithProperties)); @@ -335,3 +356,42 @@ cl_program OclLib::createProgramWithSource(cl_context context, cl_uint count, co return result; } + +cl_int OclLib::releaseContext(cl_context context) +{ + assert(pReleaseContext != nullptr); + + return pReleaseContext(context); +} + + +cl_int OclLib::releaseProgram(cl_program program) +{ + assert(pReleaseProgram != nullptr); + + return pReleaseProgram(program); +} + + +cl_int OclLib::releaseCommandQueue(cl_command_queue command_queue) +{ + assert(pReleaseCommandQueue != nullptr); + + return pReleaseCommandQueue(command_queue); +} + + +cl_int OclLib::releaseMemObject(cl_mem memobj) +{ + assert(pReleaseMemObject != nullptr); + + return pReleaseMemObject(memobj); +} + + +cl_int OclLib::releaseKernel(cl_kernel kernel) +{ + assert(pReleaseKernel != nullptr); + + return pReleaseKernel(kernel); +} \ No newline at end of file diff --git a/src/amd/OclLib.h b/src/amd/OclLib.h index 987859a2..a96c36e2 100644 --- a/src/amd/OclLib.h +++ b/src/amd/OclLib.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -51,6 +52,12 @@ class OclLib static cl_mem createBuffer(cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret); static cl_program createProgramWithBinary(cl_context context, cl_uint num_devices, const cl_device_id *device_list, const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, cl_int *errcode_ret); static cl_program createProgramWithSource(cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_int *errcode_ret); + // we need to properly release OpenCL we created to be able to do algo switching + static cl_int releaseContext(cl_context context); + static cl_int releaseProgram(cl_program program); + static cl_int releaseCommandQueue(cl_command_queue command_queue); + static cl_int releaseMemObject(cl_mem memobj); + static cl_int releaseKernel(cl_kernel kernel); private: static bool load(); From 5e7c5b52ad381f9af58791e2a164c792ae595396 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 28 Jul 2018 13:10:48 +0200 Subject: [PATCH 07/24] Semantic bug fix for cryptonight-heavy/0 OpenCL code --- src/amd/opencl/cryptonight.cl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/amd/opencl/cryptonight.cl b/src/amd/opencl/cryptonight.cl index 16413d9f..8a79ccff 100644 --- a/src/amd/opencl/cryptonight.cl +++ b/src/amd/opencl/cryptonight.cl @@ -468,9 +468,11 @@ __kernel void cn0(__global ulong *input, __global uint4 *Scratchpad, __global ul mem_fence(CLK_LOCAL_MEM_FENCE); # if (ALGO == CRYPTONIGHT_HEAVY) - { - __local uint4 xin[8][WORKSIZE]; + __local uint4 xin[8][WORKSIZE]; +# endif +# if (ALGO == CRYPTONIGHT_HEAVY) + { /* Also left over threads perform this loop. * The left over thread results will be ignored */ From 0abc18501bcb3cf1f7bf49b75e204af2927cb394 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 28 Jul 2018 13:16:12 +0200 Subject: [PATCH 08/24] Added algo performance calibration (benchmarking) functionality --- CMakeLists.txt | 2 + src/App.cpp | 20 ++++++- src/common/config/CommonConfig.h | 1 + src/common/net/Job.cpp | 7 +++ src/common/net/Job.h | 4 ++ src/crypto/CryptoNight.cpp | 2 + src/workers/Benchmark.cpp | 92 ++++++++++++++++++++++++++++++++ src/workers/Benchmark.h | 50 +++++++++++++++++ src/workers/Workers.cpp | 84 ++++++++++++++++++++++++++--- src/workers/Workers.h | 4 ++ 10 files changed, 259 insertions(+), 7 deletions(-) create mode 100644 src/workers/Benchmark.cpp create mode 100644 src/workers/Benchmark.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8be1adcf..e58f6107 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ set(HEADERS src/net/strategies/DonateStrategy.h src/Summary.h src/version.h + src/workers/Benchmark.h src/workers/Handle.h src/workers/Hashrate.h src/workers/OclThread.h @@ -120,6 +121,7 @@ set(SOURCES src/net/Network.cpp src/net/strategies/DonateStrategy.cpp src/Summary.cpp + src/workers/Benchmark.cpp src/workers/Handle.cpp src/workers/Hashrate.cpp src/workers/OclThread.cpp diff --git a/src/App.cpp b/src/App.cpp index c6de81c8..554fa1c1 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -39,6 +40,7 @@ #include "Summary.h" #include "version.h" #include "workers/Workers.h" +#include "workers/Benchmark.h" #ifndef XMRIG_NO_HTTPD @@ -83,6 +85,8 @@ App::~App() # endif } +// this should be global since we register onJobResult using this object method +static Benchmark benchmark; int App::exec() { @@ -128,7 +132,21 @@ int App::exec() return 1; } - m_controller->network()->connect(); + // run benchmark before pool mining or not? + 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" + if (m_controller->config()->isShouldSave() || m_controller->config()->isSaveConfig()) m_controller->config()->save(); + m_controller->network()->connect(); + } const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_loop_close(uv_default_loop()); diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 17bab1d8..27714f58 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -66,6 +66,7 @@ class CommonConfig : public IConfig inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } inline const Algorithm &algorithm() const override { return m_algorithm; } + inline void set_algorithm(const Algorithm& algorithm) { m_algorithm = algorithm; } inline const char *fileName() const override { return m_fileName.data(); } bool save() override; diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 80b521ea..2e7204fb 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -7,6 +7,7 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -120,6 +121,12 @@ bool Job::setBlob(const char *blob) return true; } +// for algo benchmarking +void Job::setRawBlob(const uint8_t *blob, const size_t size) +{ + memcpy(m_blob, blob, m_size = size); +} + bool Job::setTarget(const char *target) { diff --git a/src/common/net/Job.h b/src/common/net/Job.h index 049eb7d4..050bff48 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -7,6 +7,7 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -42,7 +43,10 @@ class Job ~Job(); bool setBlob(const char *blob); + void setRawBlob(const uint8_t *blob, const size_t size); // for algo benchmarking bool setTarget(const char *target); + // for algo benchmarking to set PoW variant + void setAlgorithm(const xmrig::Algorithm& algorithm) { m_algorithm = algorithm; } xmrig::Variant variant() const; inline bool isNicehash() const { return m_nicehash; } diff --git a/src/crypto/CryptoNight.cpp b/src/crypto/CryptoNight.cpp index 6e02e8fa..ef21015b 100644 --- a/src/crypto/CryptoNight.cpp +++ b/src/crypto/CryptoNight.cpp @@ -7,6 +7,7 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -152,6 +153,7 @@ CryptoNight::cn_hash_fun CryptoNight::fn(xmrig::Algo algorithm, xmrig::AlgoVerif cryptonight_ctx *CryptoNight::createCtx(xmrig::Algo algorithm) { + m_algorithm = algorithm; // register algo switch in m_algorithm after its context creation cryptonight_ctx *ctx = static_cast(_mm_malloc(sizeof(cryptonight_ctx), 16)); ctx->memory = static_cast(_mm_malloc(xmrig::cn_select_memory(algorithm), 16)); diff --git a/src/workers/Benchmark.cpp b/src/workers/Benchmark.cpp new file mode 100644 index 00000000..dec39171 --- /dev/null +++ b/src/workers/Benchmark.cpp @@ -0,0 +1,92 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , + * + * 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 . + */ + +#include "workers/Benchmark.h" +#include "workers/Workers.h" +#include "core/Config.h" +#include "net/Network.h" +#include "common/log/Log.h" +#include + +// start performance measurements for specified perf algo +void Benchmark::start_perf_bench(const xmrig::PerfAlgo pa) { + 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 + 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("FFFFFFFFFFFFFF00"); // set difficulty to 256 cause onJobResult after every 256-th computed hash + job.setAlgorithm(xmrig::Algorithm(pa)); // set job algo (for Variant part) + 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 (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 (!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 benchmark 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") + : " ===> %s hasrate: %f", + xmrig::Algorithm::perfAlgoName(m_pa), + hashrate + ); + 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 + m_controller->network()->connect(); + } + } +} + +uint64_t Benchmark::get_now() const { // get current time in ms + using namespace std::chrono; + return time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); +} diff --git a/src/workers/Benchmark.h b/src/workers/Benchmark.h new file mode 100644 index 00000000..52670f04 --- /dev/null +++ b/src/workers/Benchmark.h @@ -0,0 +1,50 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , + * + * 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 . + */ + +#pragma once + +#include + +#include "common/xmrig.h" +#include "interfaces/IJobResultListener.h" +#include "core/Controller.h" + +class Benchmark : public IJobResultListener { + const uint64_t m_bench_secs = 30; // time in seconds to benchmark each perf algo + 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 + + void onJobResult(const JobResult&) override; // onJobResult is called after each computed benchmark hash + + public: + Benchmark() {} + virtual ~Benchmark() {} + + void set_controller(xmrig::Controller* controller) { m_controller = controller; } + void start_perf_bench(const xmrig::PerfAlgo); // start benchmark for specified perf algo +}; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 8ec04855..e62c077b 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -212,13 +213,78 @@ bool Workers::start(xmrig::Controller *controller) handle->start(Workers::onReady); } - if (controller->config()->isShouldSave()) { - controller->config()->save(); + return true; +} + +void Workers::soft_stop() // stop current workers leaving uv stuff intact (used in switch_algo) +{ + if (m_hashrate) { + m_hashrate->stop(); + delete m_hashrate; } - return true; + m_sequence = 0; + m_paused = 0; + + for (size_t i = 0; i < m_workers.size(); ++i) { + m_workers[i]->join(); + delete m_workers[i]; + } + m_workers.clear(); } +// setups workers based on specified algorithm (or its basic perf algo more specifically) +bool Workers::switch_algo(const xmrig::Algorithm& algorithm) +{ + if (m_controller->config()->algorithm().algo() == algorithm.algo()) return true; + + soft_stop(); + + m_sequence = 1; + m_paused = 1; + + const std::vector &threads = m_controller->config()->threads(algorithm.perf_algo()); + m_controller->config()->set_algorithm(algorithm); + + Log::i()->text(m_controller->config()->isColors() + ? GREEN_BOLD(" >>> ") WHITE_BOLD("ALGO CHANGE: ") CYAN_BOLD("%s") + : " >>> ALGO CHANGE: %s", + algorithm.name() + ); + + size_t ways = 0; + for (const xmrig::IThread *thread : threads) { + ways += thread->multiway(); + } + + m_threadsCount = threads.size(); + m_hashrate = new Hashrate(m_threadsCount, m_controller); + + contexts.resize(m_threadsCount); + + for (size_t i = 0; i < m_threadsCount; ++i) { + const OclThread *thread = static_cast(threads[i]); + contexts[i] = GpuContext(thread->index(), thread->intensity(), thread->worksize(), thread->stridedIndex(), thread->memChunk(), thread->isCompMode()); + } + + if (InitOpenCL(contexts.data(), m_threadsCount, m_controller->config()) != 0) { + return false; + } + + uint32_t offset = 0; + + size_t i = 0; + for (xmrig::IThread *thread : threads) { + Handle *handle = new Handle(i, thread, &contexts[i], offset, ways); + offset += thread->multiway(); + i++; + + m_workers.push_back(handle); + handle->start(Workers::onReady); + } + + return true; +} void Workers::stop() { @@ -294,12 +360,18 @@ void Workers::onResult(uv_async_t *handle) return; } - cryptonight_ctx *ctx = CryptoNight::createCtx(baton->jobs[0].algorithm().algo()); + xmrig::Algo algo = baton->jobs[0].algorithm().algo(); + cryptonight_ctx *ctx = CryptoNight::createCtx(algo); for (const Job &job : baton->jobs) { JobResult result(job); - if (CryptoNight::hash(job, result, ctx)) { + if (job.algorithm().algo() != algo) { + CryptoNight::freeCtx(ctx); + ctx = CryptoNight::createCtx(algo = job.algorithm().algo()); + } + + if (job.poolId() == -100 || CryptoNight::hash(job, result, ctx)) { baton->results.push_back(result); } else { @@ -317,7 +389,7 @@ void Workers::onResult(uv_async_t *handle) } if (baton->errors > 0 && !baton->jobs.empty()) { - LOG_ERR("THREAD #%d COMPUTE ERROR", baton->jobs[0].threadId()); + LOG_ERR("THREAD #%d COMPUTE ERROR(s): %i", baton->jobs[0].threadId(), baton->errors); } delete baton; diff --git a/src/workers/Workers.h b/src/workers/Workers.h index e58c760a..04e92eda 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -56,6 +57,8 @@ class Workers static void setEnabled(bool enabled); static void setJob(const Job &job, bool donate); static bool start(xmrig::Controller *controller); + // setups workers based on specified algorithm (or its basic perf algo more specifically) + static bool switch_algo(const xmrig::Algorithm&); static void stop(); static void submit(const Job &result); @@ -76,6 +79,7 @@ class Workers static void onResult(uv_async_t *handle); static void onTick(uv_timer_t *handle); static void start(IWorker *worker); + static void soft_stop(); // stop current workers leaving uv stuff intact (used in switch_algo) static bool m_active; static bool m_enabled; From 976973b13cb2a7e0a59e8e91fe091e802c1854b6 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 28 Jul 2018 13:19:45 +0200 Subject: [PATCH 09/24] Added pool job algo switch functionality --- src/common/net/Client.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index f4553d97..8ca39775 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , + * Copyright 2018 MoneroOcean , * * 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 @@ -33,6 +34,8 @@ #include "common/log/Log.h" #include "common/net/Client.h" #include "net/JobResult.h" +#include "core/Config.h" // for pconfig to access pconfig->get_algo_perf +#include "workers/Workers.h" // to do Workers::switch_algo #include "rapidjson/document.h" #include "rapidjson/error/en.h" #include "rapidjson/stringbuffer.h" @@ -269,10 +272,6 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } - if (params.HasMember("algo")) { - job.algorithm().parseAlgorithm(params["algo"].GetString()); - } - if (params.HasMember("variant")) { const rapidjson::Value &variant = params["variant"]; @@ -284,6 +283,11 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) } } + // moved algo after variant parsing to override variant that is considered to be outdated now + if (params.HasMember("algo")) { + job.algorithm().parseAlgorithm(params["algo"].GetString()); + } + if (!verifyAlgorithm(job.algorithm())) { *code = 6; @@ -291,6 +295,9 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } + // retarget workers for possible new Algo profile (same algo profile is not reapplied) + Workers::switch_algo(job.algorithm()); + if (m_job != job) { m_jobs++; m_job = std::move(job); @@ -495,6 +502,16 @@ void Client::login() } params.AddMember("algo", algo, allocator); + + // addding algo-perf based on pconfig->get_algo_perf + Value algo_perf(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); + algo_perf.AddMember(key, Value(xmrig::pconfig->get_algo_perf(pa)), allocator); + } + + params.AddMember("algo-perf", algo_perf, allocator); } doc.AddMember("params", params, allocator); From 968a8f7afa35f27826837c7ae83de51103a36f9b Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 1 Aug 2018 16:44:02 +0200 Subject: [PATCH 10/24] Set m_calibrateAlgo to false by default --- src/common/config/CommonConfig.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index c9cbc971..24a45d50 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -46,6 +46,7 @@ xmrig::CommonConfig::CommonConfig() : m_background(false), m_colors(true), m_dryRun(false), + m_calibrateAlgo(false), m_syslog(false), # ifdef XMRIG_PROXY_PROJECT From 3a3c628f63cb58235887f7ceab025572e5b7c893 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 1 Aug 2018 16:46:27 +0200 Subject: [PATCH 11/24] Set m_saveConfig to false by default --- src/common/config/CommonConfig.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 24a45d50..f79c492a 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -47,6 +47,7 @@ xmrig::CommonConfig::CommonConfig() : m_colors(true), m_dryRun(false), m_calibrateAlgo(false), + m_saveConfig(false), m_syslog(false), # ifdef XMRIG_PROXY_PROJECT From 93f34fcaf310adb560002b146b24d720fbb1434c Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 1 Aug 2018 18:01:25 +0200 Subject: [PATCH 12/24] Calibrate and save algo-perf automatically --- src/App.cpp | 2 +- src/config.json | 7 +------ src/core/Config.cpp | 4 +++- src/workers/Benchmark.cpp | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 554fa1c1..3687c6f6 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -133,7 +133,7 @@ int App::exec() } // 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 diff --git a/src/config.json b/src/config.json index f590e5a0..69d52575 100644 --- a/src/config.json +++ b/src/config.json @@ -27,12 +27,7 @@ "retries": 5, "retry-pause": 5, "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, "syslog": false, "watch": false diff --git a/src/core/Config.cpp b/src/core/Config.cpp index fb6c64c4..8ba8afa6 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -61,7 +61,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; } } @@ -301,6 +301,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/workers/Benchmark.cpp b/src/workers/Benchmark.cpp index dec39171..2bdbc2c1 100644 --- a/src/workers/Benchmark.cpp +++ b/src/workers/Benchmark.cpp @@ -79,7 +79,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(); } From 84b024051ff2d1af5b4382784769899ecf7e57e9 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 4 Aug 2018 10:19:43 +0200 Subject: [PATCH 13/24] Added --calibrate-algo-time command line switch support --- src/common/config/CommonConfig.cpp | 7 +++++++ src/common/config/CommonConfig.h | 2 ++ src/common/interfaces/IConfig.h | 3 ++- src/core/ConfigLoader_platform.h | 2 ++ src/workers/Benchmark.cpp | 2 +- src/workers/Benchmark.h | 1 - 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index f79c492a..0f0ef541 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -47,6 +47,7 @@ xmrig::CommonConfig::CommonConfig() : m_colors(true), m_dryRun(false), m_calibrateAlgo(false), + m_calibrateAlgoTime(60), m_saveConfig(false), m_syslog(false), @@ -357,6 +358,12 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) } break; + case CalibrateAlgoTimeKey: /* --calibrate-algo-time */ + if (arg >= 5 && arg <= 3600) { + m_calibrateAlgoTime = arg; + } + break; + default: break; } diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 27714f58..56e9129e 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -50,6 +50,7 @@ class CommonConfig : public IConfig inline bool isColors() const { return m_colors; } inline bool isDryRun() const { return m_dryRun; } inline bool isCalibrateAlgo() const { return m_calibrateAlgo; } + inline int calibrateAlgoTime() const { return m_calibrateAlgoTime; } inline bool isSaveConfig() const { return m_saveConfig; } inline bool isSyslog() const { return m_syslog; } inline const char *apiToken() const { return m_apiToken.data(); } @@ -92,6 +93,7 @@ class CommonConfig : public IConfig bool m_colors; bool m_dryRun; bool m_calibrateAlgo; + int m_calibrateAlgoTime; bool m_saveConfig; bool m_syslog; bool m_watch; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 5c2c928e..536e57f1 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -69,7 +69,8 @@ class IConfig NicehashKey = 1006, PrintTimeKey = 1007, CalibrateAlgoKey = 10001, - SaveConfigKey = 10002, + CalibrateAlgoTimeKey = 10002, + SaveConfigKey = 10003, // xmrig cpu AVKey = 'v', diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index ccf355b3..4c6a36a6 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -56,6 +56,7 @@ Options:\n\ #endif "\ --calibrate-algo run benchmarks before mining to measure hashrates of all supported algos\n\ + --calibrate-algo-time=N time in seconds to run each algo benchmark round (default: 60)\n\ -o, --url=URL URL of mining server\n\ -O, --userpass=U:P username:password pair for mining server\n\ -u, --user=USERNAME username for mining server\n\ @@ -110,6 +111,7 @@ static struct option const options[] = { { "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey }, { "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey }, { "calibrate-algo", 0, nullptr, xmrig::IConfig::CalibrateAlgoKey }, + { "calibrate-algo-time", 1, nullptr, xmrig::IConfig::CalibrateAlgoTimeKey }, { "save-config", 0, nullptr, xmrig::IConfig::SaveConfigKey }, { "help", 0, nullptr, xmrig::IConfig::HelpKey }, { "keepalive", 0, nullptr, xmrig::IConfig::KeepAliveKey }, diff --git a/src/workers/Benchmark.cpp b/src/workers/Benchmark.cpp index 2bdbc2c1..b712a3e3 100644 --- a/src/workers/Benchmark.cpp +++ b/src/workers/Benchmark.cpp @@ -65,7 +65,7 @@ void Benchmark::onJobResult(const JobResult& result) { ++ m_hash_count; const uint64_t now = get_now(); 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 benchmark round for m_pa + else if (now - m_time_start > m_controller->config()->calibrateAlgoTime()*1000) { // end of benchmark 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() diff --git a/src/workers/Benchmark.h b/src/workers/Benchmark.h index 52670f04..ae74310e 100644 --- a/src/workers/Benchmark.h +++ b/src/workers/Benchmark.h @@ -31,7 +31,6 @@ #include "core/Controller.h" class Benchmark : public IJobResultListener { - const uint64_t m_bench_secs = 30; // time in seconds to benchmark each perf algo 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) From 922fb98b171ca87a09fdc772944a86b40715544e Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 4 Aug 2018 10:22:29 +0200 Subject: [PATCH 14/24] Fixed warning about signed/unsigned comparision --- src/workers/Benchmark.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workers/Benchmark.cpp b/src/workers/Benchmark.cpp index b712a3e3..90e48543 100644 --- a/src/workers/Benchmark.cpp +++ b/src/workers/Benchmark.cpp @@ -65,7 +65,7 @@ void Benchmark::onJobResult(const JobResult& result) { ++ m_hash_count; const uint64_t now = get_now(); if (!m_time_start) m_time_start = now; // time of measurements start (in ms) - else if (now - m_time_start > m_controller->config()->calibrateAlgoTime()*1000) { // end of benchmark round for m_pa + else if (now - m_time_start > static_cast(m_controller->config()->calibrateAlgoTime())*1000) { // end of benchmark 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() From 36b3494d3e9a3233e1d72d89858ad47ad3535c71 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 4 Aug 2018 10:24:54 +0200 Subject: [PATCH 15/24] Added user info about current benchmark round length --- src/App.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 3687c6f6..77f55dad 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -138,8 +138,9 @@ int App::exec() 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" + ? GREEN_BOLD(" >>>>> ") WHITE_BOLD("STARTING ALGO PERFORMANCE CALIBRATION (with %i seconds round)") + : " >>>>> 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 } else { From 979102a614f1dae2e61bdfb03efd1524b31c56c5 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sat, 4 Aug 2018 12:03:55 +0200 Subject: [PATCH 16/24] Added calibrate-algo and calibrate-algo-time save in config file and removed --save-config option --- src/App.cpp | 2 +- src/common/config/CommonConfig.cpp | 9 +++------ src/common/config/CommonConfig.h | 2 -- src/common/interfaces/IConfig.h | 3 +-- src/config.json | 2 ++ src/core/Config.cpp | 3 +++ src/core/ConfigLoader_platform.h | 6 +++--- src/workers/Benchmark.cpp | 2 +- 8 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 77f55dad..cebcdfa6 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -145,7 +145,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()->isShouldSave() || m_controller->config()->isSaveConfig()) m_controller->config()->save(); + if (m_controller->config()->isShouldSave()) m_controller->config()->save(); m_controller->network()->connect(); } diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 0f0ef541..49c17055 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -48,7 +48,6 @@ xmrig::CommonConfig::CommonConfig() : m_dryRun(false), m_calibrateAlgo(false), m_calibrateAlgoTime(60), - m_saveConfig(false), m_syslog(false), # ifdef XMRIG_PROXY_PROJECT @@ -191,10 +190,6 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) m_calibrateAlgo = enable; break; - case IConfig::SaveConfigKey: /* --save-config */ - m_saveConfig = enable; - break; - default: break; } @@ -280,7 +275,6 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) case ApiIPv6Key: /* --api-ipv6 */ case DryRunKey: /* --dry-run */ case CalibrateAlgoKey: /* --calibrate-algo */ - case SaveConfigKey: /* --save-config */ return parseBoolean(key, true); case ColorKey: /* --no-color */ @@ -297,6 +291,9 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) # endif return parseUint64(key, strtol(arg, nullptr, 10)); + case CalibrateAlgoTimeKey: /* --calibrate-algo-time */ + return parseUint64(key, strtol(arg, nullptr, 10)); + default: break; } diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 56e9129e..c048d337 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -51,7 +51,6 @@ class CommonConfig : public IConfig inline bool isDryRun() const { return m_dryRun; } inline bool isCalibrateAlgo() const { return m_calibrateAlgo; } inline int calibrateAlgoTime() const { return m_calibrateAlgoTime; } - inline bool isSaveConfig() const { return m_saveConfig; } inline bool isSyslog() const { return m_syslog; } inline const char *apiToken() const { return m_apiToken.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } @@ -94,7 +93,6 @@ class CommonConfig : public IConfig bool m_dryRun; bool m_calibrateAlgo; int m_calibrateAlgoTime; - bool m_saveConfig; bool m_syslog; bool m_watch; int m_apiPort; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 536e57f1..db480ca9 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -68,9 +68,8 @@ class IConfig CPUPriorityKey = 1021, NicehashKey = 1006, PrintTimeKey = 1007, - CalibrateAlgoKey = 10001, + CalibrateAlgoKey = 10001, CalibrateAlgoTimeKey = 10002, - SaveConfigKey = 10003, // xmrig cpu AVKey = 'v', diff --git a/src/config.json b/src/config.json index 69d52575..bb6d2180 100644 --- a/src/config.json +++ b/src/config.json @@ -28,6 +28,8 @@ "retry-pause": 5, "threads": null, "algo-perf": null, + "calibrate-algo": false, + "calibrate-algo-time": 60, "user-agent": null, "syslog": false, "watch": false diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 8ba8afa6..d686c439 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -153,6 +153,9 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const } doc.AddMember("algo-perf", algo_perf, allocator); + doc.AddMember("calibrate-algo", isCalibrateAlgo(), allocator); + doc.AddMember("calibrate-algo-time", calibrateAlgoTime(), allocator); + doc.AddMember("user-agent", userAgent() ? Value(StringRef(userAgent())).Move() : Value(kNullType).Move(), allocator); doc.AddMember("syslog", isSyslog(), allocator); doc.AddMember("watch", m_watch, allocator); diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 4c6a36a6..4447429b 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -90,7 +90,6 @@ Options:\n\ --api-worker-id=ID custom worker-id for API\n\ --api-ipv6 enable IPv6 support for API\n\ --api-no-restricted enable full remote access (only if API token set)\n\ - --save-config save config file including generated configuration\n\ -h, --help display this help and exit\n\ -V, --version output version information and exit\n\ "; @@ -110,9 +109,8 @@ static struct option const options[] = { { "config", 1, nullptr, xmrig::IConfig::ConfigKey }, { "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey }, { "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey }, - { "calibrate-algo", 0, nullptr, xmrig::IConfig::CalibrateAlgoKey }, + { "calibrate-algo", 0, nullptr, xmrig::IConfig::CalibrateAlgoKey }, { "calibrate-algo-time", 1, nullptr, xmrig::IConfig::CalibrateAlgoTimeKey }, - { "save-config", 0, nullptr, xmrig::IConfig::SaveConfigKey }, { "help", 0, nullptr, xmrig::IConfig::HelpKey }, { "keepalive", 0, nullptr, xmrig::IConfig::KeepAliveKey }, { "log-file", 1, nullptr, xmrig::IConfig::LogFileKey }, @@ -147,6 +145,8 @@ static struct option const config_options[] = { { "colors", 0, nullptr, xmrig::IConfig::ColorKey }, { "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey }, { "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey }, + { "calibrate-algo", 0, nullptr, xmrig::IConfig::CalibrateAlgoKey }, + { "calibrate-algo-time", 1, nullptr, xmrig::IConfig::CalibrateAlgoTimeKey }, { "log-file", 1, nullptr, xmrig::IConfig::LogFileKey }, { "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey }, { "retries", 1, nullptr, xmrig::IConfig::RetriesKey }, diff --git a/src/workers/Benchmark.cpp b/src/workers/Benchmark.cpp index 90e48543..c9be2f0b 100644 --- a/src/workers/Benchmark.cpp +++ b/src/workers/Benchmark.cpp @@ -79,7 +79,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()->isSaveConfig()) m_controller->config()->save(); // save config with measured algo-perf + if (m_controller->config()->isShouldSave()) 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(); } From 3a47cf580d4049ec39c2b7d663aa07dd5ad47e51 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Sun, 5 Aug 2018 14:57:14 +0200 Subject: [PATCH 17/24] Script for Windows build --- build.bat | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 build.bat diff --git a/build.bat b/build.bat new file mode 100644 index 00000000..10d7c16b --- /dev/null +++ b/build.bat @@ -0,0 +1,18 @@ +@echo off +call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" +rmdir /S /Q build +del %~dp0\xmrig-amd-%1-win64.zip +mkdir build &&^ +cd build &&^ +git clone https://github.com/MoneroOcean/xmrig-amd.git &&^ +git clone https://github.com/xmrig/xmrig-deps.git &&^ +mkdir xmrig-amd\build &&^ +cd xmrig-amd\build &&^ +git checkout %1 &&^ +cmake .. -G "Visual Studio 15 2017 Win64" -DXMRIG_DEPS=%~dp0\build\xmrig-deps\msvc2017\x64 &&^ +msbuild /p:Configuration=Release xmrig-amd.sln &&^ +cd Release &&^ +copy ..\..\src\config.json . &&^ +7za a -tzip -mx %~dp0\xmrig-amd-%1-win64.zip xmrig-amd.exe config.json &&^ +cd %~dp0 &&^ +rmdir /S /Q build From 982eedbc678c0c7968489dcb784708f0f78bb762 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Mon, 6 Aug 2018 11:13:37 +0200 Subject: [PATCH 18/24] Moved from PerfAlgo to Algo in threads to removed not really used cn-fast threads setup --- src/App.cpp | 9 ++++++--- src/common/crypto/Algorithm.h | 2 +- src/common/xmrig.h | 3 ++- src/core/Config.cpp | 36 +++++++++++++++++------------------ src/core/Config.h | 10 +++++----- src/workers/Benchmark.cpp | 2 +- src/workers/Benchmark.h | 4 +++- src/workers/Workers.cpp | 2 +- 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index cebcdfa6..17f9ce37 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -132,6 +132,9 @@ int App::exec() return 1; } + // save config here to have option to store automatically generated "threads" + if (m_controller->config()->isShouldSave()) m_controller->config()->save(); + // run benchmark before pool mining or not? 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 @@ -142,10 +145,10 @@ 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.should_save_config(); + benchmark.start_perf_bench(xmrig::PerfAlgo::PA_CN); } else { - // save config here to have option to store automatically generated "threads" - if (m_controller->config()->isShouldSave()) m_controller->config()->save(); m_controller->network()->connect(); } 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 @@ class Algorithm 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 5402d84b..b7c9d0dd 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 (RYO) */ + CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (RYO) */ + ALGO_MAX }; // algorithms that can has different performance diff --git a/src/core/Config.cpp b/src/core/Config.cpp index d686c439..c08bb104 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -75,12 +75,12 @@ bool xmrig::Config::oclInit() { LOG_WARN("compiling code and initializing GPUs. This will take a while..."); - for (int a = 0; a != xmrig::PerfAlgo::PA_MAX; ++ a) { - const xmrig::PerfAlgo pa = static_cast(a); - if (m_threads[pa].empty() && !m_oclCLI.setup(m_threads[pa])) { + for (int a = 0; a != xmrig::Algo::ALGO_MAX; ++ a) { + const xmrig::Algo algo = static_cast(a); + if (m_threads[algo].empty() && !m_oclCLI.setup(m_threads[algo])) { m_autoConf = true; m_shouldSave = true; - m_oclCLI.autoConf(m_threads[pa], &m_platformIndex, xmrig::Algorithm(pa), this); + m_oclCLI.autoConf(m_threads[algo], &m_platformIndex, xmrig::Algorithm(algo), this); } } @@ -133,11 +133,11 @@ 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); + 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); Value threads2(kArrayType); - for (const IThread *thread : m_threads[pa]) { + for (const IThread *thread : m_threads[algo]) { threads2.PushBack(thread->toConfig(doc), allocator); } threads.AddMember(key, threads2, allocator); @@ -263,7 +263,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()) { @@ -271,7 +271,7 @@ void xmrig::Config::parseThreadsJSON(const rapidjson::Value &threads, const xmri } if (value.HasMember("intensity")) { - parseThread(value, pa); + parseThread(value, algo); } } } @@ -282,14 +282,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); } } } @@ -304,12 +304,10 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc) } } } - - if (m_algo_perf[xmrig::PA_CN] == 0.0f) m_shouldSave = true; } -void xmrig::Config::parseThread(const rapidjson::Value &object, const xmrig::PerfAlgo pa) +void xmrig::Config::parseThread(const rapidjson::Value &object, const xmrig::Algo algo) { - m_threads[pa].push_back(new OclThread(object)); + m_threads[algo].push_back(new OclThread(object)); } diff --git a/src/core/Config.h b/src/core/Config.h index c83bdafe..b7736dbd 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -59,8 +59,8 @@ class Config : public CommonConfig inline bool isShouldSave() const { return m_shouldSave; } inline const char *loader() const { return m_loader.data(); } // 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]; + inline const std::vector &threads(const xmrig::Algo algo = ALGO_INVALID) const { + return m_threads[algo == ALGO_INVALID ? m_algorithm.algo() : algo]; } inline int platformIndex() const { return m_platformIndex; } @@ -77,10 +77,10 @@ class Config : public CommonConfig 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: - void parseThread(const rapidjson::Value &object, const xmrig::PerfAlgo); + void parseThread(const rapidjson::Value &object, const xmrig::Algo); bool m_autoConf; bool m_cache; @@ -88,7 +88,7 @@ class Config : public CommonConfig int m_platformIndex; OclCLI m_oclCLI; // threads config for each perf algo - std::vector m_threads[xmrig::PerfAlgo::PA_MAX]; + std::vector m_threads[xmrig::Algo::ALGO_MAX]; // perf algo hashrate results float m_algo_perf[xmrig::PerfAlgo::PA_MAX]; xmrig::c_str m_loader; diff --git a/src/workers/Benchmark.cpp b/src/workers/Benchmark.cpp index c9be2f0b..c0273c00 100644 --- a/src/workers/Benchmark.cpp +++ b/src/workers/Benchmark.cpp @@ -79,7 +79,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..eef642df 100644 --- a/src/workers/Benchmark.h +++ b/src/workers/Benchmark.h @@ -31,6 +31,7 @@ #include "core/Controller.h" class Benchmark : public IJobResultListener { + 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) @@ -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 should_save_config() { m_shouldSaveConfig = true; } void start_perf_bench(const xmrig::PerfAlgo); // start benchmark for specified perf algo }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index e62c077b..bdbd7b14 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -243,7 +243,7 @@ bool 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_controller->config()->set_algorithm(algorithm); Log::i()->text(m_controller->config()->isColors() From c8c3628aa04ef7a959d925b22e4b8004173c2fef Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Mon, 6 Aug 2018 11:16:23 +0200 Subject: [PATCH 19/24] ALGO_INVALID -> INVALID_ALGO --- src/core/Config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/Config.h b/src/core/Config.h index b7736dbd..7a740b6e 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -59,8 +59,8 @@ class Config : public CommonConfig inline bool isShouldSave() const { return m_shouldSave; } inline const char *loader() const { return m_loader.data(); } // access to m_threads taking into accoun that it is now separated for each perf algo - inline const std::vector &threads(const xmrig::Algo algo = ALGO_INVALID) const { - return m_threads[algo == ALGO_INVALID ? m_algorithm.algo() : algo]; + inline const std::vector &threads(const xmrig::Algo algo = INVALID_ALGO) const { + return m_threads[algo == INVALID_ALGO ? m_algorithm.algo() : algo]; } inline int platformIndex() const { return m_platformIndex; } From 249723f3a1f1d77b3b8e70e1a48c3031b000b9ba Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Mon, 6 Aug 2018 15:13:25 +0200 Subject: [PATCH 20/24] Restore original algorithm after benchmark --- src/App.cpp | 1 + src/workers/Benchmark.cpp | 1 + src/workers/Benchmark.h | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/App.cpp b/src/App.cpp index 17f9ce37..c862d38a 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -138,6 +138,7 @@ int App::exec() // run benchmark before pool mining or not? 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 + benchmark.set_original_algorithm(m_controller->config()->algorithm()); 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() diff --git a/src/workers/Benchmark.cpp b/src/workers/Benchmark.cpp index c0273c00..b164df39 100644 --- a/src/workers/Benchmark.cpp +++ b/src/workers/Benchmark.cpp @@ -81,6 +81,7 @@ void Benchmark::onJobResult(const JobResult& result) { m_pa = xmrig::PA_INVALID; if (m_shouldSaveConfig) m_controller->config()->save(); // save config with measured algo-perf Workers::pause(); // do not compute anything before job from the pool + Workers::switch_algo(m_algorithm_orig); // switch workers to the original algorithm m_controller->network()->connect(); } } diff --git a/src/workers/Benchmark.h b/src/workers/Benchmark.h index eef642df..3c20dc6f 100644 --- a/src/workers/Benchmark.h +++ b/src/workers/Benchmark.h @@ -36,6 +36,7 @@ class Benchmark : public IJobResultListener { 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 + const xmrig::Algorithm m_algorithm_orig; // previous algorithm to restore after benchmarking uint64_t get_now() const; // get current time in ms @@ -46,6 +47,7 @@ class Benchmark : public IJobResultListener { virtual ~Benchmark() {} void set_controller(xmrig::Controller* controller) { m_controller = controller; } + void set_original_algorithm(const xmrig::Algorithm& algorithm) { m_algorithm_orig = algorithm; } void should_save_config() { m_shouldSaveConfig = true; } void start_perf_bench(const xmrig::PerfAlgo); // start benchmark for specified perf algo }; From 20a53987a34ab11962bab71b41331a19c46cc7f8 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Mon, 6 Aug 2018 15:15:41 +0200 Subject: [PATCH 21/24] Removed wrong const word --- src/workers/Benchmark.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workers/Benchmark.h b/src/workers/Benchmark.h index 3c20dc6f..57f9b720 100644 --- a/src/workers/Benchmark.h +++ b/src/workers/Benchmark.h @@ -36,7 +36,7 @@ class Benchmark : public IJobResultListener { 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 - const xmrig::Algorithm m_algorithm_orig; // previous algorithm to restore after benchmarking + xmrig::Algorithm m_algorithm_orig; // previous algorithm to restore after benchmarking uint64_t get_now() const; // get current time in ms From cd13031897f7a5e91acc8574612caef88ae960ae Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Mon, 6 Aug 2018 15:18:20 +0200 Subject: [PATCH 22/24] Added Algorithm.h --- src/workers/Benchmark.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/workers/Benchmark.h b/src/workers/Benchmark.h index 57f9b720..2729616c 100644 --- a/src/workers/Benchmark.h +++ b/src/workers/Benchmark.h @@ -29,6 +29,7 @@ #include "common/xmrig.h" #include "interfaces/IJobResultListener.h" #include "core/Controller.h" +#include "common/crypto/Algorithm.h" class Benchmark : public IJobResultListener { bool m_shouldSaveConfig; // should save config after all benchmark rounds From a7b79022584ea035c5db20c1e827479c3370cdff Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 8 Aug 2018 21:34:58 +0200 Subject: [PATCH 23/24] Fixed GPU context handling bugs --- src/amd/GpuContext.h | 30 +----------------------------- src/amd/OclGPU.cpp | 2 +- src/workers/Workers.cpp | 2 ++ 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/amd/GpuContext.h b/src/amd/GpuContext.h index 749b53a5..fa7fb2ee 100644 --- a/src/amd/GpuContext.h +++ b/src/amd/GpuContext.h @@ -74,7 +74,7 @@ struct GpuContext Nonce(0) {} - void release() { // stops all opencl kernels and releases all opencl resources (in destructor and copy constructor) + void release() { // stops all opencl kernels and releases all opencl resources if (CommandQueues) { OclLib::finish(CommandQueues); OclLib::releaseCommandQueue(CommandQueues); @@ -86,34 +86,6 @@ struct GpuContext if (Program) OclLib::releaseProgram(Program); } - ~GpuContext() { release(); } - - GpuContext& operator=(const GpuContext& other) { // copy contructor we need to override default one to properly release OpenCL stuff - release(); - - deviceIdx = other.deviceIdx; - rawIntensity = other.rawIntensity; - workSize = other.workSize; - stridedIndex = other.stridedIndex; - memChunk = other.memChunk; - compMode = other.compMode; - - DeviceID = other.DeviceID; - CommandQueues = other.CommandQueues; - InputBuffer = other.InputBuffer; - OutputBuffer = other.OutputBuffer; - for (int i = 0; i < 6; ++ i) ExtraBuffers[i] = other.ExtraBuffers[i]; - Program = other.Program; - for (int i = 0; i < 11; ++ i) Kernels[i] = other.Kernels[i]; - - freeMem = other.freeMem; - computeUnits = other.computeUnits; - name = other.name; - - Nonce = other.Nonce; - return *this; - } - /*Input vars*/ size_t deviceIdx; size_t rawIntensity; diff --git a/src/amd/OclGPU.cpp b/src/amd/OclGPU.cpp index a9c4d62e..9db52fd8 100644 --- a/src/amd/OclGPU.cpp +++ b/src/amd/OclGPU.cpp @@ -403,7 +403,7 @@ size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, xmrig::Config *config) # ifdef __GNUC__ cl_device_id TempDeviceList[num_gpus]; # else - cl_device_id* TempDeviceList = (cl_device_id*)_alloca(entries * sizeof(cl_device_id)); + cl_device_id* TempDeviceList = (cl_device_id*)_alloca(num_gpus * sizeof(cl_device_id)); # endif for (size_t i = 0; i < num_gpus; ++i) { diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index bdbd7b14..7d6990de 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -231,6 +231,8 @@ void Workers::soft_stop() // stop current workers leaving uv stuff intact (used delete m_workers[i]; } m_workers.clear(); + + for (size_t i = 0; i < contexts.size(); ++i) contexts[i].release(); } // setups workers based on specified algorithm (or its basic perf algo more specifically) From 66a50b4ed350146f33024f8068b2048fba683087 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 8 Aug 2018 21:41:27 +0200 Subject: [PATCH 24/24] Allow integer algo-perf values --- src/core/Config.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index c08bb104..1b0c152e 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -300,7 +300,9 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc) const xmrig::PerfAlgo pa = static_cast(a); const rapidjson::Value &key = algo_perf[xmrig::Algorithm::perfAlgoName(pa)]; if (key.IsDouble()) { - m_algo_perf[pa] = key.GetDouble(); + m_algo_perf[pa] = static_cast(key.GetDouble()); + } else if (key.IsInt()) { + m_algo_perf[pa] = static_cast(key.GetInt()); } } }