From be253808d4f46ce7589f6483f688172f853944fa Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 16 Dec 2019 00:17:08 +0700 Subject: [PATCH 01/31] v5.3.1-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 13656306..3c6d49b5 100644 --- a/src/version.h +++ b/src/version.h @@ -28,7 +28,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig miner" -#define APP_VERSION "5.3.0" +#define APP_VERSION "5.3.1-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" @@ -36,7 +36,7 @@ #define APP_VER_MAJOR 5 #define APP_VER_MINOR 3 -#define APP_VER_PATCH 0 +#define APP_VER_PATCH 1 #ifdef _MSC_VER # if (_MSC_VER >= 1920) From 2e001677df81ae8d34db9344675c8d59bd87b996 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 15 Dec 2019 19:28:14 +0100 Subject: [PATCH 02/31] Use unique service name for WinRing0 driver To avoid error 1072 --- src/crypto/rx/Rx_windows.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/crypto/rx/Rx_windows.cpp b/src/crypto/rx/Rx_windows.cpp index a12030e4..675596b7 100644 --- a/src/crypto/rx/Rx_windows.cpp +++ b/src/crypto/rx/Rx_windows.cpp @@ -40,9 +40,7 @@ #include #include #include - - -#define SERVICE_NAME L"WinRing0_1_2_0" +#include namespace xmrig { @@ -132,12 +130,20 @@ static HANDLE wrmsr_install_driver() std::wstring driverPath = dir.data(); driverPath += L"WinRing0x64.sys"; - hService = OpenServiceW(hManager, SERVICE_NAME, SERVICE_ALL_ACCESS); + FILETIME curTime; + GetSystemTimeAsFileTime(&curTime); + + std::wstringstream s; + s << L"xmrig_WinRing0_service_" << curTime.dwLowDateTime; + + const std::wstring serviceName = s.str(); + + hService = OpenServiceW(hManager, serviceName.c_str(), SERVICE_ALL_ACCESS); if (hService && !wrmsr_uninstall_driver()) { return nullptr; } - hService = CreateServiceW(hManager, SERVICE_NAME, SERVICE_NAME, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, driverPath.c_str(), nullptr, nullptr, nullptr, nullptr, nullptr); + hService = CreateServiceW(hManager, serviceName.c_str(), serviceName.c_str(), SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, driverPath.c_str(), nullptr, nullptr, nullptr, nullptr, nullptr); if (!hService) { LOG_ERR(CLEAR "%s" RED_S "failed to install WinRing0 driver, error %u", tag, GetLastError()); @@ -156,7 +162,7 @@ static HANDLE wrmsr_install_driver() } } - HANDLE hDriver = CreateFileW(L"\\\\.\\" SERVICE_NAME, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + HANDLE hDriver = CreateFileW(L"\\\\.\\WinRing0_1_2_0", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (!hDriver) { LOG_ERR(CLEAR "%s" RED_S "failed to connect to WinRing0 driver, error %u", tag, GetLastError()); From 8dbb83f99b65bbf31f3e8806c0b2cf1a4e3e0bce Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 16 Dec 2019 02:17:57 +0700 Subject: [PATCH 03/31] Revert changes. --- src/crypto/rx/Rx_windows.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/crypto/rx/Rx_windows.cpp b/src/crypto/rx/Rx_windows.cpp index 675596b7..a12030e4 100644 --- a/src/crypto/rx/Rx_windows.cpp +++ b/src/crypto/rx/Rx_windows.cpp @@ -40,7 +40,9 @@ #include #include #include -#include + + +#define SERVICE_NAME L"WinRing0_1_2_0" namespace xmrig { @@ -130,20 +132,12 @@ static HANDLE wrmsr_install_driver() std::wstring driverPath = dir.data(); driverPath += L"WinRing0x64.sys"; - FILETIME curTime; - GetSystemTimeAsFileTime(&curTime); - - std::wstringstream s; - s << L"xmrig_WinRing0_service_" << curTime.dwLowDateTime; - - const std::wstring serviceName = s.str(); - - hService = OpenServiceW(hManager, serviceName.c_str(), SERVICE_ALL_ACCESS); + hService = OpenServiceW(hManager, SERVICE_NAME, SERVICE_ALL_ACCESS); if (hService && !wrmsr_uninstall_driver()) { return nullptr; } - hService = CreateServiceW(hManager, serviceName.c_str(), serviceName.c_str(), SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, driverPath.c_str(), nullptr, nullptr, nullptr, nullptr, nullptr); + hService = CreateServiceW(hManager, SERVICE_NAME, SERVICE_NAME, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, driverPath.c_str(), nullptr, nullptr, nullptr, nullptr, nullptr); if (!hService) { LOG_ERR(CLEAR "%s" RED_S "failed to install WinRing0 driver, error %u", tag, GetLastError()); @@ -162,7 +156,7 @@ static HANDLE wrmsr_install_driver() } } - HANDLE hDriver = CreateFileW(L"\\\\.\\WinRing0_1_2_0", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + HANDLE hDriver = CreateFileW(L"\\\\.\\" SERVICE_NAME, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (!hDriver) { LOG_ERR(CLEAR "%s" RED_S "failed to connect to WinRing0 driver, error %u", tag, GetLastError()); From b633b593ad6139d4bea4ed351d82f997893a5fbb Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 16 Dec 2019 02:45:07 +0700 Subject: [PATCH 04/31] Strict wrmsr error handling. --- src/crypto/rx/Rx_windows.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/crypto/rx/Rx_windows.cpp b/src/crypto/rx/Rx_windows.cpp index a12030e4..3436c1ae 100644 --- a/src/crypto/rx/Rx_windows.cpp +++ b/src/crypto/rx/Rx_windows.cpp @@ -216,6 +216,7 @@ void xmrig::Rx::osInit(const RxConfig &config) } const uint64_t ts = Chrono::steadyMSecs(); + bool success = true; HANDLE hDriver = wrmsr_install_driver(); if (!hDriver) { @@ -228,18 +229,24 @@ void xmrig::Rx::osInit(const RxConfig &config) return; } - std::thread wrmsr_thread([hDriver, mod, &config]() { + std::thread wrmsr_thread([hDriver, mod, &config, &success]() { for (uint32_t i = 0, n = Cpu::info()->threads(); i < n; ++i) { - Platform::setThreadAffinity(i); + if (!Platform::setThreadAffinity(i)) { + continue; + } if (mod == MSR_MOD_RYZEN) { - wrmsr(hDriver, 0xC0011020, 0); - wrmsr(hDriver, 0xC0011021, 0x40); - wrmsr(hDriver, 0xC0011022, 0x510000); - wrmsr(hDriver, 0xC001102b, 0x1808cc16); + success = wrmsr(hDriver, 0xC0011020, 0) && + wrmsr(hDriver, 0xC0011021, 0x40) && + wrmsr(hDriver, 0xC0011022, 0x510000) && + wrmsr(hDriver, 0xC001102b, 0x1808cc16); } else if (mod == MSR_MOD_INTEL) { - wrmsr(hDriver, 0x1a4, config.wrmsr()); + success = wrmsr(hDriver, 0x1a4, config.wrmsr()); + } + + if (!success) { + break; } } }); @@ -251,5 +258,10 @@ void xmrig::Rx::osInit(const RxConfig &config) wrmsr_uninstall_driver(); CloseServiceHandle(hManager); - LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for %s has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, modNames[mod], Chrono::steadyMSecs() - ts); + if (success) { + LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for %s has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, modNames[mod], Chrono::steadyMSecs() - ts); + } + else { + LOG_ERR(CLEAR "%s" RED_BOLD_S "failed to write MSR registers" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, Chrono::steadyMSecs() - ts); + } } From 1d4c8dda96640e9e2bffb8c86bfa0dcc4d1ed173 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 16 Dec 2019 03:41:58 +0700 Subject: [PATCH 05/31] #1423 Implemented driver reuse. --- src/crypto/rx/Rx_windows.cpp | 67 +++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/src/crypto/rx/Rx_windows.cpp b/src/crypto/rx/Rx_windows.cpp index 3436c1ae..0c46eb0d 100644 --- a/src/crypto/rx/Rx_windows.cpp +++ b/src/crypto/rx/Rx_windows.cpp @@ -58,6 +58,7 @@ enum MsrMod : uint32_t { static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " msr ") " "; static const std::array modNames = { nullptr, "Ryzen", "Intel" }; +static bool reuseDriver = false; static SC_HANDLE hManager; @@ -71,16 +72,18 @@ static bool wrmsr_uninstall_driver() } bool result = true; - SERVICE_STATUS serviceStatus; - if (!ControlService(hService, SERVICE_CONTROL_STOP, &serviceStatus)) { - LOG_ERR(CLEAR "%s" RED_S "failed to stop WinRing0 driver, error %u", tag, GetLastError()); - result = false; - } + if (!reuseDriver) { + SERVICE_STATUS serviceStatus; - if (!DeleteService(hService)) { - LOG_ERR(CLEAR "%s" RED_S "failed to remove WinRing0 driver, error %u", tag, GetLastError()); - result = false; + if (!ControlService(hService, SERVICE_CONTROL_STOP, &serviceStatus)) { + result = false; + } + + if (!DeleteService(hService)) { + LOG_ERR(CLEAR "%s" RED_S "failed to remove WinRing0 driver, error %u", tag, GetLastError()); + result = false; + } } CloseServiceHandle(hService); @@ -133,27 +136,43 @@ static HANDLE wrmsr_install_driver() driverPath += L"WinRing0x64.sys"; hService = OpenServiceW(hManager, SERVICE_NAME, SERVICE_ALL_ACCESS); - if (hService && !wrmsr_uninstall_driver()) { - return nullptr; + if (hService) { + LOG_WARN(CLEAR "%s" YELLOW("service ") YELLOW_BOLD("WinRing0_1_2_0") YELLOW(" is already exists"), tag); + + SERVICE_STATUS status; + const auto rc = QueryServiceStatus(hService, &status); + + if (rc && status.dwCurrentState == SERVICE_RUNNING) { + reuseDriver = true; + } + else if (!wrmsr_uninstall_driver()) { + return nullptr; + } } - hService = CreateServiceW(hManager, SERVICE_NAME, SERVICE_NAME, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, driverPath.c_str(), nullptr, nullptr, nullptr, nullptr, nullptr); - if (!hService) { - LOG_ERR(CLEAR "%s" RED_S "failed to install WinRing0 driver, error %u", tag, GetLastError()); - - return nullptr; - } - - if (!StartService(hService, 0, nullptr)) { - err = GetLastError(); - if (err != ERROR_SERVICE_ALREADY_RUNNING) { - LOG_ERR(CLEAR "%s" RED_S "failed to start WinRing0 driver, error %u", tag, err); - - CloseServiceHandle(hService); - hService = nullptr; + if (!reuseDriver) { + hService = CreateServiceW(hManager, SERVICE_NAME, SERVICE_NAME, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, driverPath.c_str(), nullptr, nullptr, nullptr, nullptr, nullptr); + if (!hService) { + LOG_ERR(CLEAR "%s" RED_S "failed to install WinRing0 driver, error %u", tag, GetLastError()); return nullptr; } + + if (!StartService(hService, 0, nullptr)) { + err = GetLastError(); + if (err != ERROR_SERVICE_ALREADY_RUNNING) { + if (err == ERROR_FILE_NOT_FOUND) { + LOG_ERR(CLEAR "%s" RED("failed to start WinRing0 driver: ") RED_BOLD("\"WinRing0x64.sys not found\""), tag); + } + else { + LOG_ERR(CLEAR "%s" RED_S "failed to start WinRing0 driver, error %u", tag, err); + } + + wrmsr_uninstall_driver(); + + return nullptr; + } + } } HANDLE hDriver = CreateFileW(L"\\\\.\\" SERVICE_NAME, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); From 33e7a54c294e233608e47f8a344aecafb9885326 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 16 Dec 2019 14:09:03 +0700 Subject: [PATCH 06/31] #1421 Use dynamic size send buffer. --- src/base/net/stratum/Client.cpp | 23 +++++++++++------------ src/base/net/stratum/Client.h | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index f9c56e05..ab493585 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -79,7 +79,8 @@ static const char *states[] = { xmrig::Client::Client(int id, const char *agent, IClientListener *listener) : BaseClient(id, listener), - m_agent(agent) + m_agent(agent), + m_sendBuf(1024) { m_key = m_storage.add(this); m_dns = new Dns(this); @@ -158,13 +159,11 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj) obj.Accept(writer); const size_t size = buffer.GetSize(); - if (size > (sizeof(m_sendBuf) - 2)) { - LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", url(), size, (sizeof(m_sendBuf) - 2)); - close(); - return -1; + if (size > (m_sendBuf.size() - 2)) { + m_sendBuf.resize(((size + 1) / 1024 + 1) * 1024); } - memcpy(m_sendBuf, buffer.GetString(), size); + memcpy(m_sendBuf.data(), buffer.GetString(), size); m_sendBuf[size] = '\n'; m_sendBuf[size + 1] = '\0'; @@ -186,8 +185,8 @@ int64_t xmrig::Client::submit(const JobResult &result) const char *nonce = result.nonce; const char *data = result.result; # else - char *nonce = m_sendBuf; - char *data = m_sendBuf + 16; + char *nonce = m_sendBuf.data(); + char *data = m_sendBuf.data() + 16; Buffer::toHex(reinterpret_cast(&result.nonce), 4, nonce); nonce[8] = '\0'; @@ -529,11 +528,11 @@ int xmrig::Client::resolve(const String &host) int64_t xmrig::Client::send(size_t size) { - LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast(size) - 1, m_sendBuf); + LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast(size) - 1, m_sendBuf.data()); # ifdef XMRIG_FEATURE_TLS if (isTLS()) { - if (!m_tls->send(m_sendBuf, size)) { + if (!m_tls->send(m_sendBuf.data(), size)) { return -1; } } @@ -545,7 +544,7 @@ int64_t xmrig::Client::send(size_t size) return -1; } - uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size); + uv_buf_t buf = uv_buf_init(m_sendBuf.data(), (unsigned int) size); if (uv_try_write(m_stream, &buf, 1) < 0) { close(); @@ -795,7 +794,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co void xmrig::Client::ping() { - send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data())); + send(snprintf(m_sendBuf.data(), m_sendBuf.size(), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data())); m_keepAlive = 0; } diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index fbf594a5..4db21219 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -128,11 +128,11 @@ private: static inline Client *getClient(void *data) { return m_storage.get(data); } - char m_sendBuf[4096] = { 0 }; const char *m_agent; Dns *m_dns; RecvBuf m_recvBuf; std::bitset m_extensions; + std::vector m_sendBuf; String m_rpcId; Tls *m_tls = nullptr; uint64_t m_expire = 0; From 4da37baf8c93bf8a78427f026e2b0a5a65528d70 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 16 Dec 2019 19:36:29 +0100 Subject: [PATCH 07/31] RandomSFX (Safex Cash variant) support --- src/backend/opencl/cl/cn/algorithm.cl | 5 +++-- src/backend/opencl/runners/OclRxBaseRunner.cpp | 5 ++++- src/crypto/common/Algorithm.cpp | 5 +++++ src/crypto/common/Algorithm.h | 1 + src/crypto/randomx/randomx.cpp | 6 ++++++ src/crypto/randomx/randomx.h | 2 ++ src/crypto/rx/RxAlgo.cpp | 3 +++ 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/backend/opencl/cl/cn/algorithm.cl b/src/backend/opencl/cl/cn/algorithm.cl index 1625edfd..a1bed3cc 100644 --- a/src/backend/opencl/cl/cn/algorithm.cl +++ b/src/backend/opencl/cl/cn/algorithm.cl @@ -20,8 +20,9 @@ #define ALGO_RX_WOW 19 #define ALGO_RX_LOKI 20 #define ALGO_RX_ARQMA 21 -#define ALGO_AR2_CHUKWA 22 -#define ALGO_AR2_WRKZ 23 +#define ALGO_RX_SFX 22 +#define ALGO_AR2_CHUKWA 23 +#define ALGO_AR2_WRKZ 24 #define FAMILY_UNKNOWN 0 #define FAMILY_CN 1 diff --git a/src/backend/opencl/runners/OclRxBaseRunner.cpp b/src/backend/opencl/runners/OclRxBaseRunner.cpp index 278c4f76..8eb390e6 100644 --- a/src/backend/opencl/runners/OclRxBaseRunner.cpp +++ b/src/backend/opencl/runners/OclRxBaseRunner.cpp @@ -56,7 +56,10 @@ xmrig::OclRxBaseRunner::OclRxBaseRunner(size_t index, const OclLaunchData &data) m_gcn_version = 14; } - m_options += " -DALGO=" + std::to_string(m_algorithm.id()); + // rx/sfx is the same as rx/0 except Argon salt for dataset generation + Algorithm::Id id = (m_algorithm.id() == Algorithm::RX_SFX) ? Algorithm::RX_0 : m_algorithm.id(); + + m_options += " -DALGO=" + std::to_string(id); m_options += " -DWORKERS_PER_HASH=" + std::to_string(m_worksize); m_options += " -DGCN_VERSION=" + std::to_string(m_gcn_version); } diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index d3c2838a..99883daa 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -112,6 +112,8 @@ static AlgoName const algorithm_names[] = { { "RandomXL", nullptr, Algorithm::RX_LOKI }, { "randomx/arq", "rx/arq", Algorithm::RX_ARQ }, { "RandomARQ", nullptr, Algorithm::RX_ARQ }, + { "randomx/sfx", "rx/sfx", Algorithm::RX_SFX }, + { "RandomSFX", nullptr, Algorithm::RX_SFX }, # endif # ifdef XMRIG_ALGO_ARGON2 { "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA }, @@ -138,6 +140,7 @@ size_t xmrig::Algorithm::l2() const switch (m_id) { case RX_0: case RX_LOKI: + case RX_SFX: return 0x40000; case RX_WOW: @@ -173,6 +176,7 @@ size_t xmrig::Algorithm::l3() const switch (m_id) { case RX_0: case RX_LOKI: + case RX_SFX: return oneMiB * 2; case RX_WOW: @@ -272,6 +276,7 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) case RX_WOW: case RX_LOKI: case RX_ARQ: + case RX_SFX: return RANDOM_X; # endif diff --git a/src/crypto/common/Algorithm.h b/src/crypto/common/Algorithm.h index 0c6f2649..bfdcea5a 100644 --- a/src/crypto/common/Algorithm.h +++ b/src/crypto/common/Algorithm.h @@ -67,6 +67,7 @@ public: RX_WOW, // "rx/wow" RandomWOW (Wownero). RX_LOKI, // "rx/loki" RandomXL (Loki). RX_ARQ, // "rx/arq" RandomARQ (Arqma). + RX_SFX, // "rx/sfx" RandomSFX (Safex Cash). AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa). AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ) MAX diff --git a/src/crypto/randomx/randomx.cpp b/src/crypto/randomx/randomx.cpp index 8b1cfe2c..dfbda968 100644 --- a/src/crypto/randomx/randomx.cpp +++ b/src/crypto/randomx/randomx.cpp @@ -92,6 +92,11 @@ RandomX_ConfigurationArqma::RandomX_ConfigurationArqma() ScratchpadL3_Size = 262144; } +RandomX_ConfigurationSafex::RandomX_ConfigurationSafex() +{ + ArgonSalt = "RandomSFX\x01"; +} + RandomX_ConfigurationBase::RandomX_ConfigurationBase() : ArgonMemory(262144) , ArgonIterations(3) @@ -267,6 +272,7 @@ RandomX_ConfigurationMonero RandomX_MoneroConfig; RandomX_ConfigurationWownero RandomX_WowneroConfig; RandomX_ConfigurationLoki RandomX_LokiConfig; RandomX_ConfigurationArqma RandomX_ArqmaConfig; +RandomX_ConfigurationSafex RandomX_SafexConfig; RandomX_ConfigurationBase RandomX_CurrentConfig; diff --git a/src/crypto/randomx/randomx.h b/src/crypto/randomx/randomx.h index 1ed5aa53..793e6e1b 100644 --- a/src/crypto/randomx/randomx.h +++ b/src/crypto/randomx/randomx.h @@ -182,11 +182,13 @@ struct RandomX_ConfigurationMonero : public RandomX_ConfigurationBase {}; struct RandomX_ConfigurationWownero : public RandomX_ConfigurationBase { RandomX_ConfigurationWownero(); }; struct RandomX_ConfigurationLoki : public RandomX_ConfigurationBase { RandomX_ConfigurationLoki(); }; struct RandomX_ConfigurationArqma : public RandomX_ConfigurationBase { RandomX_ConfigurationArqma(); }; +struct RandomX_ConfigurationSafex : public RandomX_ConfigurationBase { RandomX_ConfigurationSafex(); }; extern RandomX_ConfigurationMonero RandomX_MoneroConfig; extern RandomX_ConfigurationWownero RandomX_WowneroConfig; extern RandomX_ConfigurationLoki RandomX_LokiConfig; extern RandomX_ConfigurationArqma RandomX_ArqmaConfig; +extern RandomX_ConfigurationSafex RandomX_SafexConfig; extern RandomX_ConfigurationBase RandomX_CurrentConfig; diff --git a/src/crypto/rx/RxAlgo.cpp b/src/crypto/rx/RxAlgo.cpp index 4de97876..4630303e 100644 --- a/src/crypto/rx/RxAlgo.cpp +++ b/src/crypto/rx/RxAlgo.cpp @@ -49,6 +49,9 @@ const RandomX_ConfigurationBase *xmrig::RxAlgo::base(Algorithm::Id algorithm) case Algorithm::RX_ARQ: return &RandomX_ArqmaConfig; + case Algorithm::RX_SFX: + return &RandomX_SafexConfig; + default: break; } From 8bef964f68ba32d401a76625bcd6f4af78d8daa0 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 02:27:07 +0700 Subject: [PATCH 08/31] Added support for write custom MSR. --- CMakeLists.txt | 1 + cmake/randomx.cmake | 19 +++- src/backend/cpu/interfaces/ICpuInfo.h | 11 +- src/backend/cpu/platform/AdvancedCpuInfo.cpp | 8 +- src/backend/cpu/platform/AdvancedCpuInfo.h | 2 + src/backend/cpu/platform/BasicCpuInfo.cpp | 9 +- src/backend/cpu/platform/BasicCpuInfo.h | 2 + src/crypto/rx/Rx.cpp | 18 +++- src/crypto/rx/Rx.h | 3 +- src/crypto/rx/RxConfig.cpp | 108 ++++++++++++++++--- src/crypto/rx/RxConfig.h | 24 ++++- src/crypto/rx/Rx_linux.cpp | 84 ++++++++++----- src/crypto/rx/Rx_windows.cpp | 89 +++++++-------- src/crypto/rx/msr/MsrItem.cpp | 65 +++++++++++ src/crypto/rx/msr/MsrItem.h | 71 ++++++++++++ 15 files changed, 408 insertions(+), 106 deletions(-) create mode 100644 src/crypto/rx/msr/MsrItem.cpp create mode 100644 src/crypto/rx/msr/MsrItem.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b990d67d..8d7084e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ option(WITH_HTTP "Enable HTTP protocol support (client/server)" ON) option(WITH_DEBUG_LOG "Enable debug log output" OFF) option(WITH_TLS "Enable OpenSSL support" ON) option(WITH_ASM "Enable ASM PoW implementations" ON) +option(WITH_MSR "Enable MSR support" ON) option(WITH_EMBEDDED_CONFIG "Enable internal embedded JSON config" OFF) option(WITH_OPENCL "Enable OpenCL backend" ON) option(WITH_CUDA "Enable CUDA backend" ON) diff --git a/cmake/randomx.cmake b/cmake/randomx.cmake index 18939970..4f3bacb7 100644 --- a/cmake/randomx.cmake +++ b/cmake/randomx.cmake @@ -79,10 +79,21 @@ if (WITH_RANDOMX) ) endif() - if (WIN32) - list(APPEND SOURCES_CRYPTO src/crypto/rx/Rx_windows.cpp) - elseif (XMRIG_OS_LINUX AND NOT XMRIG_ARM) - list(APPEND SOURCES_CRYPTO src/crypto/rx/Rx_linux.cpp) + if (WITH_MSR AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND (XMRIG_OS_WIN OR XMRIG_OS_LINUX)) + add_definitions(/DXMRIG_FEATURE_MSR) + message("-- WITH_MSR=ON") + + if (XMRIG_OS_WIN) + list(APPEND SOURCES_CRYPTO src/crypto/rx/Rx_windows.cpp) + elseif (XMRIG_OS_LINUX) + list(APPEND SOURCES_CRYPTO src/crypto/rx/Rx_linux.cpp) + endif() + + list(APPEND HEADERS_CRYPTO src/crypto/rx/msr/MsrItem.h) + list(APPEND SOURCES_CRYPTO src/crypto/rx/msr/MsrItem.cpp) + else() + remove_definitions(/DXMRIG_FEATURE_MSR) + message("-- WITH_MSR=OFF") endif() else() remove_definitions(/DXMRIG_ALGO_RANDOMX) diff --git a/src/backend/cpu/interfaces/ICpuInfo.h b/src/backend/cpu/interfaces/ICpuInfo.h index 674668b5..f7e9fcfa 100644 --- a/src/backend/cpu/interfaces/ICpuInfo.h +++ b/src/backend/cpu/interfaces/ICpuInfo.h @@ -37,12 +37,20 @@ namespace xmrig { class ICpuInfo { public: - enum Vendor { + enum Vendor : uint32_t { VENDOR_UNKNOWN, VENDOR_INTEL, VENDOR_AMD }; + enum MsrMod : uint32_t { + MSR_MOD_NONE, + MSR_MOD_RYZEN, + MSR_MOD_INTEL, + MSR_MOD_CUSTOM, + MSR_MOD_MAX + }; + virtual ~ICpuInfo() = default; # if defined(__x86_64__) || defined(_M_AMD64) || defined (__arm64__) || defined (__aarch64__) @@ -58,6 +66,7 @@ public: virtual const char *backend() const = 0; virtual const char *brand() const = 0; virtual CpuThreads threads(const Algorithm &algorithm, uint32_t limit) const = 0; + virtual MsrMod msrMod() const = 0; virtual size_t cores() const = 0; virtual size_t L2() const = 0; virtual size_t L3() const = 0; diff --git a/src/backend/cpu/platform/AdvancedCpuInfo.cpp b/src/backend/cpu/platform/AdvancedCpuInfo.cpp index 4a3c6f62..20496ff1 100644 --- a/src/backend/cpu/platform/AdvancedCpuInfo.cpp +++ b/src/backend/cpu/platform/AdvancedCpuInfo.cpp @@ -139,7 +139,13 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : m_aes = true; if (m_vendor == VENDOR_AMD) { - m_assembly = (data.ext_family >= 23) ? Assembly::RYZEN : Assembly::BULLDOZER; + if (data.ext_family >= 23) { + m_assembly = Assembly::RYZEN; + m_msrMod = MSR_MOD_RYZEN; + } + else { + m_assembly = Assembly::BULLDOZER; + } } else if (m_vendor == VENDOR_INTEL) { m_assembly = Assembly::INTEL; diff --git a/src/backend/cpu/platform/AdvancedCpuInfo.h b/src/backend/cpu/platform/AdvancedCpuInfo.h index f6691b8f..beafa57c 100644 --- a/src/backend/cpu/platform/AdvancedCpuInfo.h +++ b/src/backend/cpu/platform/AdvancedCpuInfo.h @@ -46,6 +46,7 @@ protected: inline bool hasOneGbPages() const override { return m_pdpe1gb; } inline const char *backend() const override { return m_backend; } inline const char *brand() const override { return m_brand; } + inline MsrMod msrMod() const override { return m_msrMod; } inline size_t cores() const override { return m_cores; } inline size_t L2() const override { return m_L2; } inline size_t L3() const override { return m_L3; } @@ -62,6 +63,7 @@ private: char m_backend[32]{}; char m_brand[64 + 5]{}; const bool m_pdpe1gb = false; + MsrMod m_msrMod = MSR_MOD_NONE; size_t m_cores = 0; size_t m_L2 = 0; size_t m_L3 = 0; diff --git a/src/backend/cpu/platform/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp index b586fad0..1dfede21 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -175,11 +175,18 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : cpuid(PROCESSOR_INFO, data); const int32_t family = get_masked(data[EAX_Reg], 12, 8) + get_masked(data[EAX_Reg], 28, 20); - m_assembly = family >= 23 ? Assembly::RYZEN : Assembly::BULLDOZER; + if (family >= 23) { + m_assembly = Assembly::RYZEN; + m_msrMod = MSR_MOD_RYZEN; + } + else { + m_assembly = Assembly::BULLDOZER; + } } else if (memcmp(vendor, "GenuineIntel", 12) == 0) { m_vendor = VENDOR_INTEL; m_assembly = Assembly::INTEL; + m_msrMod = MSR_MOD_INTEL; } } # endif diff --git a/src/backend/cpu/platform/BasicCpuInfo.h b/src/backend/cpu/platform/BasicCpuInfo.h index 019c1dc0..b1139920 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.h +++ b/src/backend/cpu/platform/BasicCpuInfo.h @@ -46,6 +46,7 @@ protected: inline bool hasAVX2() const override { return m_avx2; } inline bool hasOneGbPages() const override { return m_pdpe1gb; } inline const char *brand() const override { return m_brand; } + inline MsrMod msrMod() const override { return m_msrMod; } inline size_t cores() const override { return 0; } inline size_t L2() const override { return 0; } inline size_t L3() const override { return 0; } @@ -63,6 +64,7 @@ private: bool m_aes = false; const bool m_avx2 = false; const bool m_pdpe1gb = false; + MsrMod m_msrMod = MSR_MOD_NONE; Vendor m_vendor = VENDOR_UNKNOWN; }; diff --git a/src/crypto/rx/Rx.cpp b/src/crypto/rx/Rx.cpp index 8ee611f9..7ff7e1c4 100644 --- a/src/crypto/rx/Rx.cpp +++ b/src/crypto/rx/Rx.cpp @@ -73,7 +73,7 @@ bool xmrig::Rx::init(const Job &job, const RxConfig &config, const CpuConfig &cp } if (!osInitialized) { - osInit(config); + msrInit(config); osInitialized = true; } @@ -103,6 +103,10 @@ xmrig::RxDataset *xmrig::Rx::dataset(const Job &job, uint32_t nodeId) void xmrig::Rx::destroy() { + if (osInitialized) { + msrDestroy(); + } + delete d_ptr; d_ptr = nullptr; @@ -115,8 +119,16 @@ void xmrig::Rx::init(IRxListener *listener) } -#if (!defined(XMRIG_OS_LINUX) && !defined(_WIN32)) || defined(XMRIG_ARM) -void xmrig::Rx::osInit(const RxConfig &) +#ifndef XMRIG_FEATURE_MSR +void xmrig::Rx::msrInit(const RxConfig &) +{ +} + + +void xmrig::Rx::msrDestroy() { } #endif + + + diff --git a/src/crypto/rx/Rx.h b/src/crypto/rx/Rx.h index 1a289b05..200523e9 100644 --- a/src/crypto/rx/Rx.h +++ b/src/crypto/rx/Rx.h @@ -58,7 +58,8 @@ public: static void init(IRxListener *listener); private: - static void osInit(const RxConfig &config); + static void msrInit(const RxConfig &config); + static void msrDestroy(); }; diff --git a/src/crypto/rx/RxConfig.cpp b/src/crypto/rx/RxConfig.cpp index e11aaba6..bdd3db2d 100644 --- a/src/crypto/rx/RxConfig.cpp +++ b/src/crypto/rx/RxConfig.cpp @@ -57,6 +57,23 @@ static const char *kNUMA = "numa"; static const std::array modeNames = { "auto", "fast", "light" }; + +#ifdef XMRIG_FEATURE_MSR +constexpr size_t kMsrArraySize = 4; + +static const std::array msrPresets = { + MsrItems(), + MsrItems{{ 0xC0011020, 0x0 }, { 0xC0011021, 0x40 }, { 0xC0011022, 0x510000 }, { 0xC001102b, 0x1808cc16 }}, + MsrItems{{ 0x1a4, 0x6 }}, + MsrItems() +}; + +static const std::array modNames = { "none", "ryzen", "intel", "custom" }; + +static_assert (kMsrArraySize == ICpuInfo::MSR_MOD_MAX, "kMsrArraySize and MSR_MOD_MAX mismatch"); +#endif + + } @@ -65,7 +82,10 @@ bool xmrig::RxConfig::read(const rapidjson::Value &value) if (value.IsObject()) { m_threads = Json::getInt(value, kInit, m_threads); m_mode = readMode(Json::getValue(value, kMode)); - m_wrmsr = readMSR(Json::getValue(value, kWrmsr)); + +# ifdef XMRIG_FEATURE_MSR + readMSR(Json::getValue(value, kWrmsr)); +# endif # ifdef XMRIG_OS_LINUX m_oneGbPages = Json::getBool(value, kOneGbPages, m_oneGbPages); @@ -110,12 +130,23 @@ rapidjson::Value xmrig::RxConfig::toJSON(rapidjson::Document &doc) const obj.AddMember(StringRef(kMode), StringRef(modeName()), allocator); obj.AddMember(StringRef(kOneGbPages), m_oneGbPages, allocator); - if (m_wrmsr < 0 || m_wrmsr == 6) { - obj.AddMember(StringRef(kWrmsr), m_wrmsr == 6, allocator); +# ifdef XMRIG_FEATURE_MSR + if (!m_msrPreset.empty()) { + Value wrmsr(kArrayType); + wrmsr.Reserve(m_msrPreset.size(), allocator); + + for (const auto &i : m_msrPreset) { + wrmsr.PushBack(i.toJSON(doc), allocator); + } + + obj.AddMember(StringRef(kWrmsr), wrmsr, allocator); } else { obj.AddMember(StringRef(kWrmsr), m_wrmsr, allocator); } +# else + obj.AddMember(StringRef(kWrmsr), false, allocator); +# endif # ifdef XMRIG_FEATURE_HWLOC if (!m_nodeset.empty()) { @@ -168,20 +199,71 @@ uint32_t xmrig::RxConfig::threads(uint32_t limit) const } -int xmrig::RxConfig::readMSR(const rapidjson::Value &value) const +#ifdef XMRIG_FEATURE_MSR +const char *xmrig::RxConfig::msrPresetName() const { - if (value.IsInt()) { - return std::min(value.GetInt(), 15); - } - - if (value.IsBool() && !value.GetBool()) { - return -1; - } - - return m_wrmsr; + return modNames[msrMod()]; } +const xmrig::MsrItems &xmrig::RxConfig::msrPreset() const +{ + const auto mod = msrMod(); + + if (mod == ICpuInfo::MSR_MOD_CUSTOM) { + return m_msrPreset; + } + + return msrPresets[mod]; +} + + +uint32_t xmrig::RxConfig::msrMod() const +{ + if (!wrmsr()) { + return ICpuInfo::MSR_MOD_NONE; + } + + if (!m_msrPreset.empty()) { + return ICpuInfo::MSR_MOD_CUSTOM; + } + + return Cpu::info()->msrMod(); +} + + +void xmrig::RxConfig::readMSR(const rapidjson::Value &value) +{ + if (value.IsBool()) { + m_wrmsr = value.GetBool(); + + return; + } + + if (value.IsInt()) { + const int i = std::min(value.GetInt(), 15); + if (i >= 0) { + m_msrPreset.emplace_back(0x1a4, i); + } + else { + m_wrmsr = false; + } + } + + if (value.IsArray()) { + for (const auto &i : value.GetArray()) { + MsrItem item(i); + if (item.isValid()) { + m_msrPreset.emplace_back(item); + } + } + + m_wrmsr = !m_msrPreset.empty(); + } +} +#endif + + xmrig::RxConfig::Mode xmrig::RxConfig::readMode(const rapidjson::Value &value) const { if (value.IsUint()) { diff --git a/src/crypto/rx/RxConfig.h b/src/crypto/rx/RxConfig.h index bf5992a3..f29a593d 100644 --- a/src/crypto/rx/RxConfig.h +++ b/src/crypto/rx/RxConfig.h @@ -29,6 +29,11 @@ #include "rapidjson/fwd.h" +#ifdef XMRIG_FEATURE_MSR +# include "crypto/rx/msr/MsrItem.h" +#endif + + #include @@ -58,17 +63,30 @@ public: uint32_t threads(uint32_t limit = 100) const; inline bool isOneGbPages() const { return m_oneGbPages; } - inline int wrmsr() const { return m_wrmsr; } + inline bool wrmsr() const { return m_wrmsr; } inline Mode mode() const { return m_mode; } +# ifdef XMRIG_FEATURE_MSR + const char *msrPresetName() const; + const MsrItems &msrPreset() const; +# endif + private: - int readMSR(const rapidjson::Value &value) const; +# ifdef XMRIG_FEATURE_MSR + uint32_t msrMod() const; + void readMSR(const rapidjson::Value &value); + + bool m_wrmsr = true; + MsrItems m_msrPreset; +# else + bool m_wrmsr = false; +# endif + Mode readMode(const rapidjson::Value &value) const; bool m_numa = true; bool m_oneGbPages = false; int m_threads = -1; - int m_wrmsr = 6; Mode m_mode = AutoMode; # ifdef XMRIG_FEATURE_HWLOC diff --git a/src/crypto/rx/Rx_linux.cpp b/src/crypto/rx/Rx_linux.cpp index 98d343f4..ad33b171 100644 --- a/src/crypto/rx/Rx_linux.cpp +++ b/src/crypto/rx/Rx_linux.cpp @@ -120,42 +120,74 @@ static bool wrmsr_modprobe() } +static bool wrmsr(const MsrItems &preset) +{ + if (!wrmsr_modprobe()) { + return false; + } + + for (const auto &i : preset) { + if (!wrmsr_on_all_cpus(i.reg(), i.value())) { + return false; + } + } + + return true; +} + + } // namespace xmrig -void xmrig::Rx::osInit(const RxConfig &config) +void xmrig::Rx::msrInit(const RxConfig &config) { - if (config.wrmsr() < 0) { - return; - } - - MsrMod mod = MSR_MOD_NONE; - if (Cpu::info()->assembly() == Assembly::RYZEN) { - mod = MSR_MOD_RYZEN; - } - else if (Cpu::info()->vendor() == ICpuInfo::VENDOR_INTEL) { - mod = MSR_MOD_INTEL; - } - - if (mod == MSR_MOD_NONE) { + const auto &preset = config.msrPreset(); + if (preset.empty()) { return; } const uint64_t ts = Chrono::steadyMSecs(); - if (!wrmsr_modprobe()) { - return; + if (wrmsr(preset)) { + LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for \"%s\" preset has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, config.msrPresetName(), Chrono::steadyMSecs() - ts); } - if (mod == MSR_MOD_RYZEN) { - wrmsr_on_all_cpus(0xC0011020, 0); - wrmsr_on_all_cpus(0xC0011021, 0x40); - wrmsr_on_all_cpus(0xC0011022, 0x510000); - wrmsr_on_all_cpus(0xC001102b, 0x1808cc16); - } - else if (mod == MSR_MOD_INTEL) { - wrmsr_on_all_cpus(0x1a4, config.wrmsr()); - } +// if (config.wrmsr() < 0) { +// return; +// } - LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for %s has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, modNames[mod], Chrono::steadyMSecs() - ts); +// MsrMod mod = MSR_MOD_NONE; +// if (Cpu::info()->assembly() == Assembly::RYZEN) { +// mod = MSR_MOD_RYZEN; +// } +// else if (Cpu::info()->vendor() == ICpuInfo::VENDOR_INTEL) { +// mod = MSR_MOD_INTEL; +// } + +// if (mod == MSR_MOD_NONE) { +// return; +// } + +// const uint64_t ts = Chrono::steadyMSecs(); + +// if (!wrmsr_modprobe()) { +// return; +// } + +// if (mod == MSR_MOD_RYZEN) { +// wrmsr_on_all_cpus(0xC0011020, 0); +// wrmsr_on_all_cpus(0xC0011021, 0x40); +// wrmsr_on_all_cpus(0xC0011022, 0x510000); +// wrmsr_on_all_cpus(0xC001102b, 0x1808cc16); +// } +// else if (mod == MSR_MOD_INTEL) { +// wrmsr_on_all_cpus(0x1a4, config.wrmsr()); +// } + +// LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for %s has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, modNames[mod], Chrono::steadyMSecs() - ts); +} + + +void xmrig::Rx::msrDestroy() +{ } diff --git a/src/crypto/rx/Rx_windows.cpp b/src/crypto/rx/Rx_windows.cpp index 0c46eb0d..b7ab5219 100644 --- a/src/crypto/rx/Rx_windows.cpp +++ b/src/crypto/rx/Rx_windows.cpp @@ -48,17 +48,8 @@ namespace xmrig { -enum MsrMod : uint32_t { - MSR_MOD_NONE, - MSR_MOD_RYZEN, - MSR_MOD_INTEL, - MSR_MOD_MAX -}; - - -static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " msr ") " "; -static const std::array modNames = { nullptr, "Ryzen", "Intel" }; -static bool reuseDriver = false; +static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " msr ") " "; +static bool reuseDriver = false; static SC_HANDLE hManager; @@ -189,7 +180,7 @@ static HANDLE wrmsr_install_driver() #define IOCTL_WRITE_MSR CTL_CODE(40000, 0x822, METHOD_BUFFERED, FILE_ANY_ACCESS) -static bool wrmsr(HANDLE hDriver, uint32_t reg, uint64_t value) { +static bool wrmsr(HANDLE driver, uint32_t reg, uint64_t value) { struct { uint32_t reg = 0; uint32_t value[2]{}; @@ -198,12 +189,12 @@ static bool wrmsr(HANDLE hDriver, uint32_t reg, uint64_t value) { static_assert(sizeof(input) == 12, "Invalid struct size for WinRing0 driver"); input.reg = reg; - *((uint64_t*)input.value) = value; + *(reinterpret_cast(input.value)) = value; DWORD output; DWORD k; - if (!DeviceIoControl(hDriver, IOCTL_WRITE_MSR, &input, sizeof(input), &output, sizeof(output), &k, nullptr)) { + if (!DeviceIoControl(driver, IOCTL_WRITE_MSR, &input, sizeof(input), &output, sizeof(output), &k, nullptr)) { LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "cannot set MSR 0x%08" PRIx32 " to 0x%08" PRIx64, tag, reg, value); return false; @@ -213,55 +204,29 @@ static bool wrmsr(HANDLE hDriver, uint32_t reg, uint64_t value) { } -} // namespace xmrig - - -void xmrig::Rx::osInit(const RxConfig &config) +static bool wrmsr(const MsrItems &preset) { - if ((config.wrmsr() < 0) || !ICpuInfo::isX64()) { - return; - } + bool success = true; - MsrMod mod = MSR_MOD_NONE; - if (Cpu::info()->assembly() == Assembly::RYZEN) { - mod = MSR_MOD_RYZEN; - } - else if (Cpu::info()->vendor() == ICpuInfo::VENDOR_INTEL) { - mod = MSR_MOD_INTEL; - } - - if (mod == MSR_MOD_NONE) { - return; - } - - const uint64_t ts = Chrono::steadyMSecs(); - bool success = true; - - HANDLE hDriver = wrmsr_install_driver(); - if (!hDriver) { + HANDLE driver = wrmsr_install_driver(); + if (!driver) { wrmsr_uninstall_driver(); if (hManager) { CloseServiceHandle(hManager); } - return; + return false; } - std::thread wrmsr_thread([hDriver, mod, &config, &success]() { + std::thread wrmsr_thread([driver, &preset, &success]() { for (uint32_t i = 0, n = Cpu::info()->threads(); i < n; ++i) { if (!Platform::setThreadAffinity(i)) { continue; } - if (mod == MSR_MOD_RYZEN) { - success = wrmsr(hDriver, 0xC0011020, 0) && - wrmsr(hDriver, 0xC0011021, 0x40) && - wrmsr(hDriver, 0xC0011022, 0x510000) && - wrmsr(hDriver, 0xC001102b, 0x1808cc16); - } - else if (mod == MSR_MOD_INTEL) { - success = wrmsr(hDriver, 0x1a4, config.wrmsr()); + for (const auto &i : preset) { + success = wrmsr(driver, i.reg(), i.value()); } if (!success) { @@ -272,15 +237,33 @@ void xmrig::Rx::osInit(const RxConfig &config) wrmsr_thread.join(); - CloseHandle(hDriver); + CloseHandle(driver); wrmsr_uninstall_driver(); CloseServiceHandle(hManager); - if (success) { - LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for %s has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, modNames[mod], Chrono::steadyMSecs() - ts); + return success; +} + + +} // namespace xmrig + + +void xmrig::Rx::msrInit(const RxConfig &config) +{ + const auto &preset = config.msrPreset(); + if (preset.empty()) { + return; } - else { - LOG_ERR(CLEAR "%s" RED_BOLD_S "failed to write MSR registers" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, Chrono::steadyMSecs() - ts); + + const uint64_t ts = Chrono::steadyMSecs(); + + if (wrmsr(preset)) { + LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for \"%s\" preset has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, config.msrPresetName(), Chrono::steadyMSecs() - ts); } } + + +void xmrig::Rx::msrDestroy() +{ +} diff --git a/src/crypto/rx/msr/MsrItem.cpp b/src/crypto/rx/msr/MsrItem.cpp new file mode 100644 index 00000000..b97498e9 --- /dev/null +++ b/src/crypto/rx/msr/MsrItem.cpp @@ -0,0 +1,65 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2019 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 tevador + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * 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 "crypto/rx/msr/MsrItem.h" +#include "rapidjson/document.h" + + +#include + + +xmrig::MsrItem::MsrItem(const rapidjson::Value &value) +{ + if (!value.IsString()) { + return; + } + + auto kv = String(value.GetString()).split(':'); + if (kv.size() < 2) { + return; + } + + m_reg = strtoul(kv[0], nullptr, 0); + m_value = strtoul(kv[1], nullptr, 0); +} + + +rapidjson::Value xmrig::MsrItem::toJSON(rapidjson::Document &doc) const +{ + return toString().toJSON(doc); +} + + +xmrig::String xmrig::MsrItem::toString() const +{ + constexpr size_t size = 32; + + auto buf = new char[size](); + snprintf(buf, size, "0x%" PRIx32 ":0x%" PRIx64, m_reg, m_value); + + return buf; +} diff --git a/src/crypto/rx/msr/MsrItem.h b/src/crypto/rx/msr/MsrItem.h new file mode 100644 index 00000000..ff04bdba --- /dev/null +++ b/src/crypto/rx/msr/MsrItem.h @@ -0,0 +1,71 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2019 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 tevador + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * 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 . + */ + +#ifndef XMRIG_MSRITEM_H +#define XMRIG_MSRITEM_H + + +#include "base/tools/String.h" + + +#include + + +namespace xmrig +{ + + +class RxDataset; + + +class MsrItem +{ +public: + inline MsrItem() = default; + inline MsrItem(uint32_t reg, uint64_t value) : m_reg(reg), m_value(value) {} + + MsrItem(const rapidjson::Value &value); + + inline bool isValid() const { return m_reg > 0; } + inline uint32_t reg() const { return m_reg; } + inline uint64_t value() const { return m_value; } + + rapidjson::Value toJSON(rapidjson::Document &doc) const; + String toString() const; + +private: + uint32_t m_reg = 0; + uint64_t m_value = 0; +}; + + +using MsrItems = std::vector; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_MSRITEM_H */ From 17f82280d0b1edc350a989605ca6f4027411432c Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 02:52:47 +0700 Subject: [PATCH 09/31] v5.4.0-dev --- src/version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/version.h b/src/version.h index 3c6d49b5..b59c082f 100644 --- a/src/version.h +++ b/src/version.h @@ -28,15 +28,15 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig miner" -#define APP_VERSION "5.3.1-dev" +#define APP_VERSION "5.4.0-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" #define APP_KIND "miner" #define APP_VER_MAJOR 5 -#define APP_VER_MINOR 3 -#define APP_VER_PATCH 1 +#define APP_VER_MINOR 4 +#define APP_VER_PATCH 0 #ifdef _MSC_VER # if (_MSC_VER >= 1920) From a5089638ea5e15fb8d6e2ac557a842d2809479a6 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 03:18:25 +0700 Subject: [PATCH 10/31] #1421 Added limit for maximum send buffer size. --- src/base/net/stratum/Client.cpp | 7 +++++++ src/base/net/stratum/Client.h | 12 ++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index ab493585..a995bef3 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -159,6 +159,13 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj) obj.Accept(writer); const size_t size = buffer.GetSize(); + if (size > kMaxSendBufferSize) { + LOG_ERR("[%s] send failed: \"max send buffer size exceeded: %zu\"", url(), size); + close(); + + return -1; + } + if (size > (m_sendBuf.size() - 2)) { m_sendBuf.resize(((size + 1) / 1024 + 1) * 1024); } diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index 4db21219..1949e61f 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -60,14 +60,10 @@ class Client : public BaseClient, public IDnsListener, public ILineListener public: XMRIG_DISABLE_COPY_MOVE_DEFAULT(Client) - constexpr static uint64_t kConnectTimeout = 20 * 1000; - constexpr static uint64_t kResponseTimeout = 20 * 1000; - -# ifdef XMRIG_FEATURE_TLS - constexpr static size_t kInputBufferSize = 1024 * 16; -# else - constexpr static size_t kInputBufferSize = 1024 * 2; -# endif + constexpr static uint64_t kConnectTimeout = 20 * 1000; + constexpr static uint64_t kResponseTimeout = 20 * 1000; + constexpr static size_t kInputBufferSize = 1024 * 16; + constexpr static size_t kMaxSendBufferSize = 1024 * 16; Client(int id, const char *agent, IClientListener *listener); ~Client() override; From d2d501c821e4d168a1a9496ad6358164ae26fbe6 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 14:45:01 +0700 Subject: [PATCH 11/31] Added RandomX option "rdmsr" and save/restore MSR registers on Windows. --- src/config.json | 1 + src/crypto/rx/RxConfig.cpp | 3 ++ src/crypto/rx/RxConfig.h | 2 ++ src/crypto/rx/Rx_windows.cpp | 54 +++++++++++++++++++++++++++++++++--- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/config.json b/src/config.json index fcdb9494..7156e905 100644 --- a/src/config.json +++ b/src/config.json @@ -17,6 +17,7 @@ "init": -1, "mode": "auto", "1gb-pages": false, + "rdmsr": true, "wrmsr": true, "numa": true }, diff --git a/src/crypto/rx/RxConfig.cpp b/src/crypto/rx/RxConfig.cpp index bdd3db2d..07600681 100644 --- a/src/crypto/rx/RxConfig.cpp +++ b/src/crypto/rx/RxConfig.cpp @@ -49,6 +49,7 @@ namespace xmrig { static const char *kInit = "init"; static const char *kMode = "mode"; static const char *kOneGbPages = "1gb-pages"; +static const char *kRdmsr = "rdmsr"; static const char *kWrmsr = "wrmsr"; #ifdef XMRIG_FEATURE_HWLOC @@ -82,6 +83,7 @@ bool xmrig::RxConfig::read(const rapidjson::Value &value) if (value.IsObject()) { m_threads = Json::getInt(value, kInit, m_threads); m_mode = readMode(Json::getValue(value, kMode)); + m_rdmsr = Json::getBool(value, kRdmsr, m_rdmsr); # ifdef XMRIG_FEATURE_MSR readMSR(Json::getValue(value, kWrmsr)); @@ -129,6 +131,7 @@ rapidjson::Value xmrig::RxConfig::toJSON(rapidjson::Document &doc) const obj.AddMember(StringRef(kInit), m_threads, allocator); obj.AddMember(StringRef(kMode), StringRef(modeName()), allocator); obj.AddMember(StringRef(kOneGbPages), m_oneGbPages, allocator); + obj.AddMember(StringRef(kRdmsr), m_rdmsr, allocator); # ifdef XMRIG_FEATURE_MSR if (!m_msrPreset.empty()) { diff --git a/src/crypto/rx/RxConfig.h b/src/crypto/rx/RxConfig.h index f29a593d..225c019e 100644 --- a/src/crypto/rx/RxConfig.h +++ b/src/crypto/rx/RxConfig.h @@ -63,6 +63,7 @@ public: uint32_t threads(uint32_t limit = 100) const; inline bool isOneGbPages() const { return m_oneGbPages; } + inline bool rdmsr() const { return m_rdmsr; } inline bool wrmsr() const { return m_wrmsr; } inline Mode mode() const { return m_mode; } @@ -86,6 +87,7 @@ private: bool m_numa = true; bool m_oneGbPages = false; + bool m_rdmsr = true; int m_threads = -1; Mode m_mode = AutoMode; diff --git a/src/crypto/rx/Rx_windows.cpp b/src/crypto/rx/Rx_windows.cpp index b7ab5219..ef565756 100644 --- a/src/crypto/rx/Rx_windows.cpp +++ b/src/crypto/rx/Rx_windows.cpp @@ -48,8 +48,9 @@ namespace xmrig { -static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " msr ") " "; static bool reuseDriver = false; +static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " msr ") " "; +static MsrItems savedState; static SC_HANDLE hManager; @@ -177,10 +178,12 @@ static HANDLE wrmsr_install_driver() } +#define IOCTL_READ_MSR CTL_CODE(40000, 0x821, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_WRITE_MSR CTL_CODE(40000, 0x822, METHOD_BUFFERED, FILE_ANY_ACCESS) -static bool wrmsr(HANDLE driver, uint32_t reg, uint64_t value) { +static bool wrmsr(HANDLE driver, uint32_t reg, uint64_t value) +{ struct { uint32_t reg = 0; uint32_t value[2]{}; @@ -204,7 +207,32 @@ static bool wrmsr(HANDLE driver, uint32_t reg, uint64_t value) { } -static bool wrmsr(const MsrItems &preset) +static bool rdmsr(HANDLE driver, uint32_t reg, uint64_t &value) +{ + DWORD size = 0; + + if (!DeviceIoControl(driver, IOCTL_READ_MSR, ®, sizeof(reg), &value, sizeof(value), &size, nullptr)) { + LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "cannot read MSR 0x%08" PRIx32, tag, reg); + + return false; + } + + return true; +} + + +static MsrItem rdmsr(HANDLE driver, uint32_t reg) +{ + uint64_t value = 0; + if (!rdmsr(driver, reg, value)) { + return {}; + } + + return { reg, value }; +} + + +static bool wrmsr(const MsrItems &preset, bool save) { bool success = true; @@ -219,6 +247,15 @@ static bool wrmsr(const MsrItems &preset) return false; } + if (save) { + for (const auto &i : preset) { + auto item = rdmsr(driver, i.reg()); + if (item.isValid()) { + savedState.emplace_back(item); + } + } + } + std::thread wrmsr_thread([driver, &preset, &success]() { for (uint32_t i = 0, n = Cpu::info()->threads(); i < n; ++i) { if (!Platform::setThreadAffinity(i)) { @@ -258,7 +295,7 @@ void xmrig::Rx::msrInit(const RxConfig &config) const uint64_t ts = Chrono::steadyMSecs(); - if (wrmsr(preset)) { + if (wrmsr(preset, config.rdmsr())) { LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for \"%s\" preset has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, config.msrPresetName(), Chrono::steadyMSecs() - ts); } } @@ -266,4 +303,13 @@ void xmrig::Rx::msrInit(const RxConfig &config) void xmrig::Rx::msrDestroy() { + if (savedState.empty()) { + return; + } + + const uint64_t ts = Chrono::steadyMSecs(); + + if (!wrmsr(savedState, false)) { + LOG_ERR(CLEAR "%s" RED_BOLD_S "failed to restore initial state" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, Chrono::steadyMSecs() - ts); + } } From 9cea70b77ca2e785cbad3a6ebab235cf36892a48 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 15:16:37 +0700 Subject: [PATCH 12/31] Rename Rx_windows.cpp to Rx_win.cpp. --- cmake/randomx.cmake | 2 +- src/crypto/rx/{Rx_windows.cpp => Rx_win.cpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/crypto/rx/{Rx_windows.cpp => Rx_win.cpp} (100%) diff --git a/cmake/randomx.cmake b/cmake/randomx.cmake index 4f3bacb7..c7b64aab 100644 --- a/cmake/randomx.cmake +++ b/cmake/randomx.cmake @@ -84,7 +84,7 @@ if (WITH_RANDOMX) message("-- WITH_MSR=ON") if (XMRIG_OS_WIN) - list(APPEND SOURCES_CRYPTO src/crypto/rx/Rx_windows.cpp) + list(APPEND SOURCES_CRYPTO src/crypto/rx/Rx_win.cpp) elseif (XMRIG_OS_LINUX) list(APPEND SOURCES_CRYPTO src/crypto/rx/Rx_linux.cpp) endif() diff --git a/src/crypto/rx/Rx_windows.cpp b/src/crypto/rx/Rx_win.cpp similarity index 100% rename from src/crypto/rx/Rx_windows.cpp rename to src/crypto/rx/Rx_win.cpp From a877b1d2696cba90b92eb5b8514a372850aeb7cb Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 16:17:11 +0700 Subject: [PATCH 13/31] Added save/restore MSR registers on Linux. --- src/crypto/rx/Rx_linux.cpp | 99 ++++++++++++++++++++------------------ src/crypto/rx/Rx_win.cpp | 10 ++-- 2 files changed, 56 insertions(+), 53 deletions(-) diff --git a/src/crypto/rx/Rx_linux.cpp b/src/crypto/rx/Rx_linux.cpp index ad33b171..23d9d51f 100644 --- a/src/crypto/rx/Rx_linux.cpp +++ b/src/crypto/rx/Rx_linux.cpp @@ -48,16 +48,8 @@ namespace xmrig { -enum MsrMod : uint32_t { - MSR_MOD_NONE, - MSR_MOD_RYZEN, - MSR_MOD_INTEL, - MSR_MOD_MAX -}; - - -static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " msr ") " "; -static const std::array modNames = { nullptr, "Ryzen", "Intel" }; +static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " msr ") " "; +static MsrItems savedState; static inline int dir_filter(const struct dirent *dirp) @@ -108,6 +100,37 @@ static bool wrmsr_on_all_cpus(uint32_t reg, uint64_t value) } +bool rdmsr_on_cpu(uint32_t reg, uint32_t cpu, uint64_t &value) +{ + char msr_file_name[64]{}; + + sprintf(msr_file_name, "/dev/cpu/%u/msr", cpu); + int fd = open(msr_file_name, O_RDONLY); + if (fd < 0) { + return false; + } + + const bool success = pread(fd, &value, sizeof value, reg) == sizeof value; + + close(fd); + + return success; +} + + +static MsrItem rdmsr(uint32_t reg) +{ + uint64_t value = 0; + if (!rdmsr_on_cpu(reg, 0, value)) { + LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "cannot read MSR 0x%08" PRIx32, tag, reg); + + return {}; + } + + return { reg, value }; +} + + static bool wrmsr_modprobe() { if (system("/sbin/modprobe msr > /dev/null 2>&1") != 0) { @@ -120,12 +143,21 @@ static bool wrmsr_modprobe() } -static bool wrmsr(const MsrItems &preset) +static bool wrmsr(const MsrItems &preset, bool save) { if (!wrmsr_modprobe()) { return false; } + if (save) { + for (const auto &i : preset) { + auto item = rdmsr(i.reg()); + if (item.isValid()) { + savedState.emplace_back(item); + } + } + } + for (const auto &i : preset) { if (!wrmsr_on_all_cpus(i.reg(), i.value())) { return false; @@ -148,46 +180,21 @@ void xmrig::Rx::msrInit(const RxConfig &config) const uint64_t ts = Chrono::steadyMSecs(); - if (wrmsr(preset)) { + if (wrmsr(preset, config.rdmsr())) { LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for \"%s\" preset has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, config.msrPresetName(), Chrono::steadyMSecs() - ts); } - -// if (config.wrmsr() < 0) { -// return; -// } - -// MsrMod mod = MSR_MOD_NONE; -// if (Cpu::info()->assembly() == Assembly::RYZEN) { -// mod = MSR_MOD_RYZEN; -// } -// else if (Cpu::info()->vendor() == ICpuInfo::VENDOR_INTEL) { -// mod = MSR_MOD_INTEL; -// } - -// if (mod == MSR_MOD_NONE) { -// return; -// } - -// const uint64_t ts = Chrono::steadyMSecs(); - -// if (!wrmsr_modprobe()) { -// return; -// } - -// if (mod == MSR_MOD_RYZEN) { -// wrmsr_on_all_cpus(0xC0011020, 0); -// wrmsr_on_all_cpus(0xC0011021, 0x40); -// wrmsr_on_all_cpus(0xC0011022, 0x510000); -// wrmsr_on_all_cpus(0xC001102b, 0x1808cc16); -// } -// else if (mod == MSR_MOD_INTEL) { -// wrmsr_on_all_cpus(0x1a4, config.wrmsr()); -// } - -// LOG_NOTICE(CLEAR "%s" GREEN_BOLD_S "register values for %s has been set successfully" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, modNames[mod], Chrono::steadyMSecs() - ts); } void xmrig::Rx::msrDestroy() { + if (savedState.empty()) { + return; + } + + const uint64_t ts = Chrono::steadyMSecs(); + + if (!wrmsr(savedState, false)) { + LOG_ERR(CLEAR "%s" RED_BOLD_S "failed to restore initial state" BLACK_BOLD(" (%" PRIu64 " ms)"), tag, Chrono::steadyMSecs() - ts); + } } diff --git a/src/crypto/rx/Rx_win.cpp b/src/crypto/rx/Rx_win.cpp index ef565756..30b76ae3 100644 --- a/src/crypto/rx/Rx_win.cpp +++ b/src/crypto/rx/Rx_win.cpp @@ -211,13 +211,7 @@ static bool rdmsr(HANDLE driver, uint32_t reg, uint64_t &value) { DWORD size = 0; - if (!DeviceIoControl(driver, IOCTL_READ_MSR, ®, sizeof(reg), &value, sizeof(value), &size, nullptr)) { - LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "cannot read MSR 0x%08" PRIx32, tag, reg); - - return false; - } - - return true; + return DeviceIoControl(driver, IOCTL_READ_MSR, ®, sizeof(reg), &value, sizeof(value), &size, nullptr) != 0; } @@ -225,6 +219,8 @@ static MsrItem rdmsr(HANDLE driver, uint32_t reg) { uint64_t value = 0; if (!rdmsr(driver, reg, value)) { + LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "cannot read MSR 0x%08" PRIx32, tag, reg); + return {}; } From f8865b1498db7d911934be4dd3e2fc7e3689a550 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 21:46:11 +0700 Subject: [PATCH 14/31] Added "verbose" option. --- src/base/io/log/Log.cpp | 7 +- src/base/io/log/Log.h | 19 ++-- src/base/kernel/config/BaseConfig.cpp | 134 +++++++++++--------------- src/base/kernel/config/BaseConfig.h | 2 + src/config.json | 1 + src/core/config/Config.cpp | 1 + src/crypto/rx/Rx_linux.cpp | 2 + src/crypto/rx/Rx_win.cpp | 16 +++ 8 files changed, 94 insertions(+), 88 deletions(-) diff --git a/src/base/io/log/Log.cpp b/src/base/io/log/Log.cpp index 2cd37242..49e08fc4 100644 --- a/src/base/io/log/Log.cpp +++ b/src/base/io/log/Log.cpp @@ -195,9 +195,10 @@ private: }; -bool Log::background = false; -bool Log::colors = true; -LogPrivate *Log::d = new LogPrivate(); +bool Log::background = false; +bool Log::colors = true; +LogPrivate *Log::d = new LogPrivate(); +uint32_t Log::verbose = 0; } /* namespace xmrig */ diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h index c7e0c3f4..7b391412 100644 --- a/src/base/io/log/Log.h +++ b/src/base/io/log/Log.h @@ -27,6 +27,9 @@ #define XMRIG_LOG_H +#include + + namespace xmrig { @@ -56,6 +59,7 @@ public: static bool background; static bool colors; + static uint32_t verbose; private: static LogPrivate *d; @@ -119,13 +123,14 @@ private: #define CYAN_BG_BOLD(x) CYAN_BG_BOLD_S x CLEAR -#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__) -#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__) -#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__) -#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__) -#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) -#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__) -#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__) +#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__) +#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__) +#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__) +#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__) +#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) +#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__) +#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__) +#define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } #ifdef APP_DEBUG # define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__) diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index 76056449..07de7947 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -23,10 +23,18 @@ */ -#include -#include -#include -#include +#include "base/kernel/config/BaseConfig.h" +#include "base/io/json/Json.h" +#include "base/io/log/Log.h" +#include "base/kernel/interfaces/IJsonReader.h" +#include "rapidjson/document.h" +#include "version.h" + + +#include +#include +#include +#include #include @@ -38,80 +46,6 @@ # include "backend/cpu/Cpu.h" #endif -#ifdef XMRIG_AMD_PROJECT -# if defined(__APPLE__) -# include -# else -# include "3rdparty/CL/cl.h" -# endif -#endif - - -#ifdef XMRIG_NVIDIA_PROJECT -# include "nvidia/cryptonight.h" -#endif - - -#include "base/io/json/Json.h" -#include "base/io/log/Log.h" -#include "base/kernel/config/BaseConfig.h" -#include "base/kernel/interfaces/IJsonReader.h" -#include "donate.h" -#include "rapidjson/document.h" -#include "rapidjson/filewritestream.h" -#include "rapidjson/prettywriter.h" -#include "version.h" - - -void xmrig::BaseConfig::printVersions() -{ - char buf[256] = { 0 }; - -# if defined(__clang__) - snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); -# elif defined(__GNUC__) - snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# elif defined(_MSC_VER) - snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION); -# endif - - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf); - -# if defined(XMRIG_AMD_PROJECT) -# if CL_VERSION_2_0 - const char *ocl = "2.0"; -# elif CL_VERSION_1_2 - const char *ocl = "1.2"; -# elif CL_VERSION_1_1 - const char *ocl = "1.1"; -# elif CL_VERSION_1_0 - const char *ocl = "1.0"; -# else - const char *ocl = "0.0"; -# endif - int length = snprintf(buf, sizeof buf, "OpenCL/%s ", ocl); -# elif defined(XMRIG_NVIDIA_PROJECT) - const int cudaVersion = cuda_get_runtime_version(); - int length = snprintf(buf, sizeof buf, "CUDA/%d.%d ", cudaVersion / 1000, cudaVersion % 100); -# endif - - std::string libs; - -# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT) - { - constexpr const char *v = OPENSSL_VERSION_TEXT + 8; - snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast(strchr(v, ' ') - v), v); - libs += buf; - } -# endif - -# if defined(XMRIG_FEATURE_HWLOC) - libs += Cpu::info()->backend(); -# endif - - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str()); -} - bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) { @@ -132,6 +66,7 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) m_version = reader.getUint("version"); setPrintTime(reader.getUint("print-time", 60)); + setVerbose(reader.getValue("verbose")); const rapidjson::Value &api = reader.getObject("api"); if (api.IsObject()) { @@ -162,3 +97,46 @@ bool xmrig::BaseConfig::save() return false; } + + +void xmrig::BaseConfig::printVersions() +{ + char buf[256] = { 0 }; + +# if defined(__clang__) + snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); +# elif defined(__GNUC__) + snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); +# elif defined(_MSC_VER) + snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION); +# endif + + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf); + + std::string libs; + +# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT) + { + constexpr const char *v = OPENSSL_VERSION_TEXT + 8; + snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast(strchr(v, ' ') - v), v); + libs += buf; + } +# endif + +# if defined(XMRIG_FEATURE_HWLOC) + libs += Cpu::info()->backend(); +# endif + + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str()); +} + + +void xmrig::BaseConfig::setVerbose(const rapidjson::Value &value) +{ + if (value.IsBool()) { + Log::verbose = value.GetBool() ? 1 : 0; + } + else if (value.IsUint()) { + Log::verbose = value.GetUint(); + } +} diff --git a/src/base/kernel/config/BaseConfig.h b/src/base/kernel/config/BaseConfig.h index c700d109..7be81828 100644 --- a/src/base/kernel/config/BaseConfig.h +++ b/src/base/kernel/config/BaseConfig.h @@ -82,6 +82,8 @@ protected: private: inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } } + + void setVerbose(const rapidjson::Value &value); }; diff --git a/src/config.json b/src/config.json index 7156e905..a973ff2c 100644 --- a/src/config.json +++ b/src/config.json @@ -75,5 +75,6 @@ "retry-pause": 5, "syslog": false, "user-agent": null, + "verbose": 0, "watch": true } diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index a445961f..b0c92463 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -246,5 +246,6 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("retry-pause", m_pools.retryPause(), allocator); doc.AddMember("syslog", isSyslog(), allocator); doc.AddMember("user-agent", m_userAgent.toJSON(), allocator); + doc.AddMember("verbose", Log::verbose, allocator); doc.AddMember("watch", m_watch, allocator); } diff --git a/src/crypto/rx/Rx_linux.cpp b/src/crypto/rx/Rx_linux.cpp index 23d9d51f..3b3a0f1f 100644 --- a/src/crypto/rx/Rx_linux.cpp +++ b/src/crypto/rx/Rx_linux.cpp @@ -152,6 +152,8 @@ static bool wrmsr(const MsrItems &preset, bool save) if (save) { for (const auto &i : preset) { auto item = rdmsr(i.reg()); + LOG_VERBOSE(CLEAR "%s" CYAN_BOLD("0x%08" PRIx32) CYAN(":0x%016" PRIx64) CYAN_BOLD(" -> 0x%016" PRIx64), tag, i.reg(), item.value(), i.value()); + if (item.isValid()) { savedState.emplace_back(item); } diff --git a/src/crypto/rx/Rx_win.cpp b/src/crypto/rx/Rx_win.cpp index 30b76ae3..bfd923ab 100644 --- a/src/crypto/rx/Rx_win.cpp +++ b/src/crypto/rx/Rx_win.cpp @@ -134,6 +134,20 @@ static HANDLE wrmsr_install_driver() SERVICE_STATUS status; const auto rc = QueryServiceStatus(hService, &status); + if (rc && Log::verbose) { + DWORD dwBytesNeeded; + + QueryServiceConfigA(hService, nullptr, 0, &dwBytesNeeded); + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + std::vector buffer(dwBytesNeeded); + auto config = reinterpret_cast(buffer.data()); + + if (QueryServiceConfigA(hService, config, buffer.size(), &dwBytesNeeded)) { + LOG_INFO(CLEAR "%s" YELLOW("service path: ") YELLOW_BOLD("\"%s\""), tag, config->lpBinaryPathName); + } + } + } + if (rc && status.dwCurrentState == SERVICE_RUNNING) { reuseDriver = true; } @@ -246,6 +260,8 @@ static bool wrmsr(const MsrItems &preset, bool save) if (save) { for (const auto &i : preset) { auto item = rdmsr(driver, i.reg()); + LOG_VERBOSE(CLEAR "%s" CYAN_BOLD("0x%08" PRIx32) CYAN(":0x%016" PRIx64) CYAN_BOLD(" -> 0x%016" PRIx64), tag, i.reg(), item.value(), i.value()); + if (item.isValid()) { savedState.emplace_back(item); } From 3cc8b19ca00191241fedfbec152df0b1c787444d Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 22:03:50 +0700 Subject: [PATCH 15/31] Added command line option --verbose. --- README.md | 1 + src/base/kernel/config/BaseTransform.cpp | 4 ++++ src/core/config/Config_platform.h | 1 + src/core/config/usage.h | 1 + 4 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 7ed04212..58c76659 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ Logging: --print-time=N print hashrate report every N seconds --health-print-time=N print health report every N seconds --no-color disable colored output + --verbose verbose output Misc: -c, --config=FILE load a JSON-format configuration file diff --git a/src/base/kernel/config/BaseTransform.cpp b/src/base/kernel/config/BaseTransform.cpp index ccf5ccf1..8a3a140e 100644 --- a/src/base/kernel/config/BaseTransform.cpp +++ b/src/base/kernel/config/BaseTransform.cpp @@ -222,6 +222,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch case IConfig::DryRunKey: /* --dry-run */ case IConfig::HttpEnabledKey: /* --http-enabled */ case IConfig::DaemonKey: /* --daemon */ + case IConfig::VerboseKey: /* --verbose */ return transformBoolean(doc, key, true); case IConfig::ColorKey: /* --no-color */ @@ -273,6 +274,9 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b case IConfig::DryRunKey: /* --dry-run */ return set(doc, "dry-run", enable); + case IConfig::VerboseKey: /* --verbose */ + return set(doc, "verbose", enable); + default: break; } diff --git a/src/core/config/Config_platform.h b/src/core/config/Config_platform.h index 14ae5b2e..2a1725e3 100644 --- a/src/core/config/Config_platform.h +++ b/src/core/config/Config_platform.h @@ -87,6 +87,7 @@ static const option options[] = { { "cpu-max-threads-hint", 1, nullptr, IConfig::CPUMaxThreadsKey }, { "cpu-memory-pool", 1, nullptr, IConfig::MemoryPoolKey }, { "cpu-no-yield", 0, nullptr, IConfig::YieldKey }, + { "verbose", 0, nullptr, IConfig::VerboseKey }, # ifdef XMRIG_FEATURE_TLS { "tls", 0, nullptr, IConfig::TlsKey }, { "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey }, diff --git a/src/core/config/usage.h b/src/core/config/usage.h index 27edee3d..4fb62a48 100644 --- a/src/core/config/usage.h +++ b/src/core/config/usage.h @@ -136,6 +136,7 @@ static inline const std::string &usage() u += " --health-print-time=N print health report every N seconds\n"; # endif u += " --no-color disable colored output\n"; + u += " --verbose verbose output\n"; u += "\nMisc:\n"; From 5142a406b0e4c3ece6b9db4b6c7acc85e2cb8a70 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 18 Dec 2019 02:20:31 +0700 Subject: [PATCH 16/31] Less error prone log interface. --- src/Summary.cpp | 2 +- src/base/io/log/Log.cpp | 8 ++++---- src/base/io/log/Log.h | 16 ++++++++++++---- src/base/io/log/backends/ConsoleLog.cpp | 6 +++--- src/base/kernel/Base.cpp | 2 +- src/base/kernel/config/BaseConfig.cpp | 6 +++--- src/core/config/Config.cpp | 4 ++-- src/crypto/rx/Rx_win.cpp | 2 +- 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Summary.cpp b/src/Summary.cpp index 695138d1..d2a723c0 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -159,7 +159,7 @@ static void print_threads(Config *config) static void print_commands(Config *) { - if (Log::colors) { + if (Log::isColors()) { Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BG(WHITE_BOLD_S "h") WHITE_BOLD("ashrate, ") MAGENTA_BG(WHITE_BOLD_S "p") WHITE_BOLD("ause, ") MAGENTA_BG(WHITE_BOLD_S "r") WHITE_BOLD("esume")); diff --git a/src/base/io/log/Log.cpp b/src/base/io/log/Log.cpp index 49e08fc4..a091f923 100644 --- a/src/base/io/log/Log.cpp +++ b/src/base/io/log/Log.cpp @@ -92,7 +92,7 @@ public: std::lock_guard lock(m_mutex); - if (Log::background && m_backends.empty()) { + if (Log::isBackground() && m_backends.empty()) { return; } @@ -195,10 +195,10 @@ private: }; -bool Log::background = false; -bool Log::colors = true; +bool Log::m_background = false; +bool Log::m_colors = true; LogPrivate *Log::d = new LogPrivate(); -uint32_t Log::verbose = 0; +uint32_t Log::m_verbose = 0; } /* namespace xmrig */ diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h index 7b391412..3181f934 100644 --- a/src/base/io/log/Log.h +++ b/src/base/io/log/Log.h @@ -57,11 +57,19 @@ public: static void print(const char *fmt, ...); static void print(Level level, const char *fmt, ...); - static bool background; - static bool colors; - static uint32_t verbose; + static inline bool isBackground() { return m_background; } + static inline bool isColors() { return m_colors; } + static inline bool isVerbose() { return m_verbose > 0; } + static inline uint32_t verbose() { return m_verbose; } + static inline void setBackground(bool background) { m_background = background; } + static inline void setColors(bool colors) { m_colors = colors; } + static inline void setVerbose(uint32_t verbose) { m_verbose = verbose; } private: + static bool m_background; + static bool m_colors; + static uint32_t m_verbose; + static LogPrivate *d; }; @@ -130,7 +138,7 @@ private: #define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) #define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__) #define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__) -#define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } +#define LOG_VERBOSE(x, ...) if (xmrig::Log::isVerbose()) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } #ifdef APP_DEBUG # define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__) diff --git a/src/base/io/log/backends/ConsoleLog.cpp b/src/base/io/log/backends/ConsoleLog.cpp index de907318..4d3c532a 100644 --- a/src/base/io/log/backends/ConsoleLog.cpp +++ b/src/base/io/log/backends/ConsoleLog.cpp @@ -35,14 +35,14 @@ xmrig::ConsoleLog::ConsoleLog() { if (!isSupported()) { - Log::colors = false; + Log::setColors(false); return; } m_tty = new uv_tty_t; if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) { - Log::colors = false; + Log::setColors(false); return; } @@ -71,7 +71,7 @@ xmrig::ConsoleLog::~ConsoleLog() void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool colors) { - if (!m_tty || Log::colors != colors) { + if (!m_tty || Log::isColors() != colors) { return; } diff --git a/src/base/kernel/Base.cpp b/src/base/kernel/Base.cpp index 5718a115..03aaaca5 100644 --- a/src/base/kernel/Base.cpp +++ b/src/base/kernel/Base.cpp @@ -177,7 +177,7 @@ int xmrig::Base::init() Platform::init(config()->userAgent()); if (isBackground()) { - Log::background = true; + Log::setBackground(true); } else { Log::add(new ConsoleLog()); diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index 07de7947..7b647ed0 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -60,11 +60,11 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) m_dryRun = reader.getBool("dry-run", m_dryRun); m_syslog = reader.getBool("syslog", m_syslog); m_watch = reader.getBool("watch", m_watch); - Log::colors = reader.getBool("colors", Log::colors); m_logFile = reader.getString("log-file"); m_userAgent = reader.getString("user-agent"); m_version = reader.getUint("version"); + Log::setColors(reader.getBool("colors", Log::isColors())); setPrintTime(reader.getUint("print-time", 60)); setVerbose(reader.getValue("verbose")); @@ -134,9 +134,9 @@ void xmrig::BaseConfig::printVersions() void xmrig::BaseConfig::setVerbose(const rapidjson::Value &value) { if (value.IsBool()) { - Log::verbose = value.GetBool() ? 1 : 0; + Log::setVerbose(value.GetBool() ? 1 : 0); } else if (value.IsUint()) { - Log::verbose = value.GetUint(); + Log::setVerbose(value.GetUint()); } } diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index b0c92463..dde626f7 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -218,7 +218,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("http", m_http.toJSON(doc), allocator); doc.AddMember("autosave", isAutoSave(), allocator); doc.AddMember("background", isBackground(), allocator); - doc.AddMember("colors", Log::colors, allocator); + doc.AddMember("colors", Log::isColors(), allocator); # ifdef XMRIG_ALGO_RANDOMX doc.AddMember(StringRef(kRandomX), rx().toJSON(doc), allocator); @@ -246,6 +246,6 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("retry-pause", m_pools.retryPause(), allocator); doc.AddMember("syslog", isSyslog(), allocator); doc.AddMember("user-agent", m_userAgent.toJSON(), allocator); - doc.AddMember("verbose", Log::verbose, allocator); + doc.AddMember("verbose", Log::verbose(), allocator); doc.AddMember("watch", m_watch, allocator); } diff --git a/src/crypto/rx/Rx_win.cpp b/src/crypto/rx/Rx_win.cpp index bfd923ab..af2919b7 100644 --- a/src/crypto/rx/Rx_win.cpp +++ b/src/crypto/rx/Rx_win.cpp @@ -134,7 +134,7 @@ static HANDLE wrmsr_install_driver() SERVICE_STATUS status; const auto rc = QueryServiceStatus(hService, &status); - if (rc && Log::verbose) { + if (rc && Log::isVerbose()) { DWORD dwBytesNeeded; QueryServiceConfigA(hService, nullptr, 0, &dwBytesNeeded); From 59e8fdb9ed2273c52212143797b8c98b51593109 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 17 Dec 2019 23:55:22 +0100 Subject: [PATCH 17/31] Added bit masks for MSR registers --- src/crypto/rx/RxConfig.cpp | 2 +- src/crypto/rx/Rx_linux.cpp | 94 +++++++++++++++++++---------------- src/crypto/rx/Rx_win.cpp | 60 ++++++++++++---------- src/crypto/rx/msr/MsrItem.cpp | 1 + src/crypto/rx/msr/MsrItem.h | 4 +- 5 files changed, 90 insertions(+), 71 deletions(-) diff --git a/src/crypto/rx/RxConfig.cpp b/src/crypto/rx/RxConfig.cpp index 07600681..5472bfa5 100644 --- a/src/crypto/rx/RxConfig.cpp +++ b/src/crypto/rx/RxConfig.cpp @@ -64,7 +64,7 @@ constexpr size_t kMsrArraySize = 4; static const std::array msrPresets = { MsrItems(), - MsrItems{{ 0xC0011020, 0x0 }, { 0xC0011021, 0x40 }, { 0xC0011022, 0x510000 }, { 0xC001102b, 0x1808cc16 }}, + MsrItems{{ 0xC0011020, 0x0 }, { 0xC0011021, 0x40, ~0x20ULL }, { 0xC0011022, 0x510000 }, { 0xC001102b, 0x1808cc16 }}, MsrItems{{ 0x1a4, 0x6 }}, MsrItems() }; diff --git a/src/crypto/rx/Rx_linux.cpp b/src/crypto/rx/Rx_linux.cpp index 3b3a0f1f..46f13c04 100644 --- a/src/crypto/rx/Rx_linux.cpp +++ b/src/crypto/rx/Rx_linux.cpp @@ -58,48 +58,6 @@ static inline int dir_filter(const struct dirent *dirp) } -static bool wrmsr_on_cpu(uint32_t reg, uint32_t cpu, uint64_t value) -{ - char msr_file_name[64]{}; - - sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu); - int fd = open(msr_file_name, O_WRONLY); - if (fd < 0) { - return false; - } - - const bool success = pwrite(fd, &value, sizeof value, reg) == sizeof value; - - close(fd); - - return success; -} - - -static bool wrmsr_on_all_cpus(uint32_t reg, uint64_t value) -{ - struct dirent **namelist; - int dir_entries = scandir("/dev/cpu", &namelist, dir_filter, 0); - int errors = 0; - - while (dir_entries--) { - if (!wrmsr_on_cpu(reg, strtoul(namelist[dir_entries]->d_name, nullptr, 10), value)) { - ++errors; - } - - free(namelist[dir_entries]); - } - - free(namelist); - - if (errors) { - LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "cannot set MSR 0x%08" PRIx32 " to 0x%08" PRIx64, tag, reg, value); - } - - return errors == 0; -} - - bool rdmsr_on_cpu(uint32_t reg, uint32_t cpu, uint64_t &value) { char msr_file_name[64]{}; @@ -131,6 +89,56 @@ static MsrItem rdmsr(uint32_t reg) } +static bool wrmsr_on_cpu(uint32_t reg, uint32_t cpu, uint64_t value, uint64_t mask) +{ + // If a bit in mask is set to 1, use new value, otherwise use old value + if (mask != uint64_t(-1)) { + uint64_t old_value; + if (rdmsr_on_cpu(reg, cpu, old_value)) { + value = (value & mask) | (old_value & ~mask); + } + } + + char msr_file_name[64]{}; + + sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu); + int fd = open(msr_file_name, O_WRONLY); + if (fd < 0) { + return false; + } + + const bool success = pwrite(fd, &value, sizeof value, reg) == sizeof value; + + close(fd); + + return success; +} + + +static bool wrmsr_on_all_cpus(uint32_t reg, uint64_t value, uint64_t mask) +{ + struct dirent **namelist; + int dir_entries = scandir("/dev/cpu", &namelist, dir_filter, 0); + int errors = 0; + + while (dir_entries--) { + if (!wrmsr_on_cpu(reg, strtoul(namelist[dir_entries]->d_name, nullptr, 10), value, mask)) { + ++errors; + } + + free(namelist[dir_entries]); + } + + free(namelist); + + if (errors) { + LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "cannot set MSR 0x%08" PRIx32 " to 0x%08" PRIx64, tag, reg, value); + } + + return errors == 0; +} + + static bool wrmsr_modprobe() { if (system("/sbin/modprobe msr > /dev/null 2>&1") != 0) { @@ -161,7 +169,7 @@ static bool wrmsr(const MsrItems &preset, bool save) } for (const auto &i : preset) { - if (!wrmsr_on_all_cpus(i.reg(), i.value())) { + if (!wrmsr_on_all_cpus(i.reg(), i.value(), i.mask())) { return false; } } diff --git a/src/crypto/rx/Rx_win.cpp b/src/crypto/rx/Rx_win.cpp index af2919b7..b4e7588d 100644 --- a/src/crypto/rx/Rx_win.cpp +++ b/src/crypto/rx/Rx_win.cpp @@ -196,31 +196,6 @@ static HANDLE wrmsr_install_driver() #define IOCTL_WRITE_MSR CTL_CODE(40000, 0x822, METHOD_BUFFERED, FILE_ANY_ACCESS) -static bool wrmsr(HANDLE driver, uint32_t reg, uint64_t value) -{ - struct { - uint32_t reg = 0; - uint32_t value[2]{}; - } input; - - static_assert(sizeof(input) == 12, "Invalid struct size for WinRing0 driver"); - - input.reg = reg; - *(reinterpret_cast(input.value)) = value; - - DWORD output; - DWORD k; - - if (!DeviceIoControl(driver, IOCTL_WRITE_MSR, &input, sizeof(input), &output, sizeof(output), &k, nullptr)) { - LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "cannot set MSR 0x%08" PRIx32 " to 0x%08" PRIx64, tag, reg, value); - - return false; - } - - return true; -} - - static bool rdmsr(HANDLE driver, uint32_t reg, uint64_t &value) { DWORD size = 0; @@ -242,6 +217,39 @@ static MsrItem rdmsr(HANDLE driver, uint32_t reg) } +static bool wrmsr(HANDLE driver, uint32_t reg, uint64_t value, uint64_t mask) +{ + struct { + uint32_t reg = 0; + uint32_t value[2]{}; + } input; + + static_assert(sizeof(input) == 12, "Invalid struct size for WinRing0 driver"); + + // If a bit in mask is set to 1, use new value, otherwise use old value + if (mask != uint64_t(-1)) { + uint64_t old_value; + if (rdmsr(driver, reg, old_value)) { + value = (value & mask) | (old_value & ~mask); + } + } + + input.reg = reg; + *(reinterpret_cast(input.value)) = value; + + DWORD output; + DWORD k; + + if (!DeviceIoControl(driver, IOCTL_WRITE_MSR, &input, sizeof(input), &output, sizeof(output), &k, nullptr)) { + LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "cannot set MSR 0x%08" PRIx32 " to 0x%08" PRIx64, tag, reg, value); + + return false; + } + + return true; +} + + static bool wrmsr(const MsrItems &preset, bool save) { bool success = true; @@ -275,7 +283,7 @@ static bool wrmsr(const MsrItems &preset, bool save) } for (const auto &i : preset) { - success = wrmsr(driver, i.reg(), i.value()); + success = wrmsr(driver, i.reg(), i.value(), i.mask()); } if (!success) { diff --git a/src/crypto/rx/msr/MsrItem.cpp b/src/crypto/rx/msr/MsrItem.cpp index b97498e9..97eb843f 100644 --- a/src/crypto/rx/msr/MsrItem.cpp +++ b/src/crypto/rx/msr/MsrItem.cpp @@ -45,6 +45,7 @@ xmrig::MsrItem::MsrItem(const rapidjson::Value &value) m_reg = strtoul(kv[0], nullptr, 0); m_value = strtoul(kv[1], nullptr, 0); + m_mask = (kv.size() > 2) ? strtoul(kv[2], nullptr, 0) : uint64_t(-1); } diff --git a/src/crypto/rx/msr/MsrItem.h b/src/crypto/rx/msr/MsrItem.h index ff04bdba..00527489 100644 --- a/src/crypto/rx/msr/MsrItem.h +++ b/src/crypto/rx/msr/MsrItem.h @@ -45,13 +45,14 @@ class MsrItem { public: inline MsrItem() = default; - inline MsrItem(uint32_t reg, uint64_t value) : m_reg(reg), m_value(value) {} + inline MsrItem(uint32_t reg, uint64_t value, uint64_t mask = uint64_t(-1)) : m_reg(reg), m_value(value), m_mask(mask) {} MsrItem(const rapidjson::Value &value); inline bool isValid() const { return m_reg > 0; } inline uint32_t reg() const { return m_reg; } inline uint64_t value() const { return m_value; } + inline uint64_t mask() const { return m_mask; } rapidjson::Value toJSON(rapidjson::Document &doc) const; String toString() const; @@ -59,6 +60,7 @@ public: private: uint32_t m_reg = 0; uint64_t m_value = 0; + uint64_t m_mask = uint64_t(-1); }; From 7459677fd5800c8c6b321abbfad4220c6b4f74eb Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 18 Dec 2019 09:12:25 +0100 Subject: [PATCH 18/31] Add vzeroupper for processors with AVX To avoid false dependencies on upper 128 bits of YMM registers. --- src/crypto/randomx/jit_compiler_x86.cpp | 8 ++++++++ src/crypto/randomx/jit_compiler_x86.hpp | 1 + src/crypto/randomx/jit_compiler_x86_static.asm | 3 +++ 3 files changed, 12 insertions(+) diff --git a/src/crypto/randomx/jit_compiler_x86.cpp b/src/crypto/randomx/jit_compiler_x86.cpp index 84cfe39c..9abd320b 100644 --- a/src/crypto/randomx/jit_compiler_x86.cpp +++ b/src/crypto/randomx/jit_compiler_x86.cpp @@ -289,6 +289,11 @@ namespace randomx { JitCompilerX86::JitCompilerX86() { applyTweaks(); + + int32_t info[4]; + cpuid(1, info); + hasAVX = (info[2] & (1 << 28)) != 0; + allocatedCode = (uint8_t*)allocExecutableMemory(CodeSize * 2); // Shift code base address to improve caching - all threads will use different L2/L3 cache sets code = allocatedCode + (codeOffset.fetch_add(59 * 64) % CodeSize); @@ -374,6 +379,9 @@ namespace randomx { code[codePos + 5] = 0xc0 + pcfg.readReg1; *(uint32_t*)(code + codePos + 10) = RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated; *(uint32_t*)(code + codePos + 20) = RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated; + if (hasAVX) { + *(uint32_t*)(code + codePos + 29) = 0xE977F8C5; + } codePos = prologueSize; memcpy(code + codePos - 48, &pcfg.eMask, sizeof(pcfg.eMask)); diff --git a/src/crypto/randomx/jit_compiler_x86.hpp b/src/crypto/randomx/jit_compiler_x86.hpp index 9354e5db..eabd6e07 100644 --- a/src/crypto/randomx/jit_compiler_x86.hpp +++ b/src/crypto/randomx/jit_compiler_x86.hpp @@ -73,6 +73,7 @@ namespace randomx { uint32_t vm_flags; static bool BranchesWithin32B; + bool hasAVX; static void applyTweaks(); void generateProgramPrologue(Program&, ProgramConfiguration&); diff --git a/src/crypto/randomx/jit_compiler_x86_static.asm b/src/crypto/randomx/jit_compiler_x86_static.asm index 90395c52..9a4d82b9 100644 --- a/src/crypto/randomx/jit_compiler_x86_static.asm +++ b/src/crypto/randomx/jit_compiler_x86_static.asm @@ -82,6 +82,9 @@ randomx_program_prologue_first_load PROC ror rdx, 32 and edx, RANDOMX_SCRATCHPAD_MASK stmxcsr dword ptr [rsp-20] + nop + nop + nop jmp randomx_program_loop_begin randomx_program_prologue_first_load ENDP From f8bf8fddd9bd8bb2aad7c7f962cfdb4d4d5e9786 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 18 Dec 2019 09:13:21 +0100 Subject: [PATCH 19/31] Update jit_compiler_x86_static.S --- src/crypto/randomx/jit_compiler_x86_static.S | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/crypto/randomx/jit_compiler_x86_static.S b/src/crypto/randomx/jit_compiler_x86_static.S index 50019b7e..77411880 100644 --- a/src/crypto/randomx/jit_compiler_x86_static.S +++ b/src/crypto/randomx/jit_compiler_x86_static.S @@ -94,6 +94,9 @@ DECL(randomx_program_prologue_first_load): ror rdx, 32 and edx, RANDOMX_SCRATCHPAD_MASK stmxcsr dword ptr [rsp-20] + nop + nop + nop jmp DECL(randomx_program_loop_begin) .balign 64 From f85aba5d21cc34c626f44389a4009eb68753049d Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 18 Dec 2019 12:20:21 +0100 Subject: [PATCH 20/31] Fixed AVX detection --- src/crypto/randomx/jit_compiler_x86.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/randomx/jit_compiler_x86.cpp b/src/crypto/randomx/jit_compiler_x86.cpp index 9abd320b..c6f79276 100644 --- a/src/crypto/randomx/jit_compiler_x86.cpp +++ b/src/crypto/randomx/jit_compiler_x86.cpp @@ -292,7 +292,7 @@ namespace randomx { int32_t info[4]; cpuid(1, info); - hasAVX = (info[2] & (1 << 28)) != 0; + hasAVX = ((info[2] & (1 << 27)) != 0) && ((info[2] & (1 << 28)) != 0); allocatedCode = (uint8_t*)allocExecutableMemory(CodeSize * 2); // Shift code base address to improve caching - all threads will use different L2/L3 cache sets From c01c03526921708cb42f34fa49cfb479f061a667 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 18 Dec 2019 17:32:57 +0100 Subject: [PATCH 21/31] Fixed crash with GCC compiler --- src/crypto/randomx/jit_compiler_x86.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crypto/randomx/jit_compiler_x86.cpp b/src/crypto/randomx/jit_compiler_x86.cpp index c6f79276..e7a41370 100644 --- a/src/crypto/randomx/jit_compiler_x86.cpp +++ b/src/crypto/randomx/jit_compiler_x86.cpp @@ -380,7 +380,8 @@ namespace randomx { *(uint32_t*)(code + codePos + 10) = RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated; *(uint32_t*)(code + codePos + 20) = RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated; if (hasAVX) { - *(uint32_t*)(code + codePos + 29) = 0xE977F8C5; + uint32_t* p = (uint32_t*)(code + codePos + 29); + *p = (*p & 0xFF000000U) | 0x0077F8C5U; } codePos = prologueSize; From 12fb27e2cf1145c548f8aa3f0f3caa44d49d6951 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 19 Dec 2019 03:20:48 +0700 Subject: [PATCH 22/31] Use MsrItem::kNoMask. --- src/crypto/rx/Rx_linux.cpp | 2 +- src/crypto/rx/Rx_win.cpp | 2 +- src/crypto/rx/msr/MsrItem.cpp | 2 +- src/crypto/rx/msr/MsrItem.h | 7 +++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/crypto/rx/Rx_linux.cpp b/src/crypto/rx/Rx_linux.cpp index 46f13c04..99115125 100644 --- a/src/crypto/rx/Rx_linux.cpp +++ b/src/crypto/rx/Rx_linux.cpp @@ -92,7 +92,7 @@ static MsrItem rdmsr(uint32_t reg) static bool wrmsr_on_cpu(uint32_t reg, uint32_t cpu, uint64_t value, uint64_t mask) { // If a bit in mask is set to 1, use new value, otherwise use old value - if (mask != uint64_t(-1)) { + if (mask != MsrItem::kNoMask) { uint64_t old_value; if (rdmsr_on_cpu(reg, cpu, old_value)) { value = (value & mask) | (old_value & ~mask); diff --git a/src/crypto/rx/Rx_win.cpp b/src/crypto/rx/Rx_win.cpp index b4e7588d..8e9c198f 100644 --- a/src/crypto/rx/Rx_win.cpp +++ b/src/crypto/rx/Rx_win.cpp @@ -227,7 +227,7 @@ static bool wrmsr(HANDLE driver, uint32_t reg, uint64_t value, uint64_t mask) static_assert(sizeof(input) == 12, "Invalid struct size for WinRing0 driver"); // If a bit in mask is set to 1, use new value, otherwise use old value - if (mask != uint64_t(-1)) { + if (mask != MsrItem::kNoMask) { uint64_t old_value; if (rdmsr(driver, reg, old_value)) { value = (value & mask) | (old_value & ~mask); diff --git a/src/crypto/rx/msr/MsrItem.cpp b/src/crypto/rx/msr/MsrItem.cpp index 97eb843f..3f70b8b6 100644 --- a/src/crypto/rx/msr/MsrItem.cpp +++ b/src/crypto/rx/msr/MsrItem.cpp @@ -45,7 +45,7 @@ xmrig::MsrItem::MsrItem(const rapidjson::Value &value) m_reg = strtoul(kv[0], nullptr, 0); m_value = strtoul(kv[1], nullptr, 0); - m_mask = (kv.size() > 2) ? strtoul(kv[2], nullptr, 0) : uint64_t(-1); + m_mask = (kv.size() > 2) ? strtoul(kv[2], nullptr, 0) : kNoMask; } diff --git a/src/crypto/rx/msr/MsrItem.h b/src/crypto/rx/msr/MsrItem.h index 00527489..5b84f432 100644 --- a/src/crypto/rx/msr/MsrItem.h +++ b/src/crypto/rx/msr/MsrItem.h @@ -31,6 +31,7 @@ #include "base/tools/String.h" +#include #include @@ -44,8 +45,10 @@ class RxDataset; class MsrItem { public: + constexpr static uint64_t kNoMask = std::numeric_limits::max(); + inline MsrItem() = default; - inline MsrItem(uint32_t reg, uint64_t value, uint64_t mask = uint64_t(-1)) : m_reg(reg), m_value(value), m_mask(mask) {} + inline MsrItem(uint32_t reg, uint64_t value, uint64_t mask = kNoMask) : m_reg(reg), m_value(value), m_mask(mask) {} MsrItem(const rapidjson::Value &value); @@ -60,7 +63,7 @@ public: private: uint32_t m_reg = 0; uint64_t m_value = 0; - uint64_t m_mask = uint64_t(-1); + uint64_t m_mask = kNoMask; }; From 3e3d34b3ce19ea72053a08d5239c38d01c5e1270 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 19 Dec 2019 03:28:05 +0700 Subject: [PATCH 23/31] Allow number value for "wrmsr" option only for Intel. --- src/crypto/rx/RxConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/rx/RxConfig.cpp b/src/crypto/rx/RxConfig.cpp index 5472bfa5..bef5f8f4 100644 --- a/src/crypto/rx/RxConfig.cpp +++ b/src/crypto/rx/RxConfig.cpp @@ -243,7 +243,7 @@ void xmrig::RxConfig::readMSR(const rapidjson::Value &value) return; } - if (value.IsInt()) { + if (value.IsInt() && Cpu::info()->vendor() == ICpuInfo::VENDOR_INTEL) { const int i = std::min(value.GetInt(), 15); if (i >= 0) { m_msrPreset.emplace_back(0x1a4, i); From f4cedd7b6362c12df84ea4db9d845b797a3cc53b Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 19 Dec 2019 03:49:32 +0700 Subject: [PATCH 24/31] Fixed MsrItem serialization. --- src/crypto/rx/msr/MsrItem.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/crypto/rx/msr/MsrItem.cpp b/src/crypto/rx/msr/MsrItem.cpp index 3f70b8b6..23cf5dc0 100644 --- a/src/crypto/rx/msr/MsrItem.cpp +++ b/src/crypto/rx/msr/MsrItem.cpp @@ -44,8 +44,8 @@ xmrig::MsrItem::MsrItem(const rapidjson::Value &value) } m_reg = strtoul(kv[0], nullptr, 0); - m_value = strtoul(kv[1], nullptr, 0); - m_mask = (kv.size() > 2) ? strtoul(kv[2], nullptr, 0) : kNoMask; + m_value = strtoull(kv[1], nullptr, 0); + m_mask = (kv.size() > 2) ? strtoull(kv[2], nullptr, 0) : kNoMask; } @@ -57,10 +57,16 @@ rapidjson::Value xmrig::MsrItem::toJSON(rapidjson::Document &doc) const xmrig::String xmrig::MsrItem::toString() const { - constexpr size_t size = 32; + constexpr size_t size = 48; auto buf = new char[size](); - snprintf(buf, size, "0x%" PRIx32 ":0x%" PRIx64, m_reg, m_value); + + if (m_mask != kNoMask) { + snprintf(buf, size, "0x%" PRIx32 ":0x%" PRIx64 ":0x%" PRIx64, m_reg, m_value, m_mask); + } + else { + snprintf(buf, size, "0x%" PRIx32 ":0x%" PRIx64, m_reg, m_value); + } return buf; } From 45412a2ace9fc1bcd5ea7a2da93a70ec869cf812 Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Wed, 18 Dec 2019 16:17:22 -0700 Subject: [PATCH 25/31] Add MoneroV (rx/v) algorithm [based on MoneroOcean/master] --- src/backend/opencl/cl/cn/algorithm.cl | 5 +- src/backend/opencl/cl/rx/randomx.cl | 2 + .../opencl/cl/rx/randomx_constants_v.h | 96 +++++++++++++++++++ src/crypto/common/Algorithm.cpp | 4 + src/crypto/common/Algorithm.h | 1 + src/crypto/randomx/randomx.cpp | 6 ++ src/crypto/randomx/randomx.h | 2 + src/crypto/rx/RxAlgo.cpp | 3 + 8 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 src/backend/opencl/cl/rx/randomx_constants_v.h diff --git a/src/backend/opencl/cl/cn/algorithm.cl b/src/backend/opencl/cl/cn/algorithm.cl index a1bed3cc..4f33a680 100644 --- a/src/backend/opencl/cl/cn/algorithm.cl +++ b/src/backend/opencl/cl/cn/algorithm.cl @@ -21,8 +21,9 @@ #define ALGO_RX_LOKI 20 #define ALGO_RX_ARQMA 21 #define ALGO_RX_SFX 22 -#define ALGO_AR2_CHUKWA 23 -#define ALGO_AR2_WRKZ 24 +#define ALGO_RX_V 23 +#define ALGO_AR2_CHUKWA 24 +#define ALGO_AR2_WRKZ 25 #define FAMILY_UNKNOWN 0 #define FAMILY_CN 1 diff --git a/src/backend/opencl/cl/rx/randomx.cl b/src/backend/opencl/cl/rx/randomx.cl index 6fee74ed..b62f78fc 100644 --- a/src/backend/opencl/cl/rx/randomx.cl +++ b/src/backend/opencl/cl/rx/randomx.cl @@ -8,6 +8,8 @@ #include "randomx_constants_loki.h" #elif (ALGO == ALGO_RX_ARQMA) #include "randomx_constants_arqma.h" +#elif (ALGO == ALGO_RX_V) +#include "randomx_constants_v.h" #endif #include "aes.cl" diff --git a/src/backend/opencl/cl/rx/randomx_constants_v.h b/src/backend/opencl/cl/rx/randomx_constants_v.h new file mode 100644 index 00000000..1967a8c2 --- /dev/null +++ b/src/backend/opencl/cl/rx/randomx_constants_v.h @@ -0,0 +1,96 @@ +/* +Copyright (c) 2019 SChernykh + +This file is part of RandomX OpenCL. + +RandomX OpenCL 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. + +RandomX OpenCL 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 RandomX OpenCL. If not, see . +*/ + +//Dataset base size in bytes. Must be a power of 2. +#define RANDOMX_DATASET_BASE_SIZE 2147483648 + +//Dataset extra size. Must be divisible by 64. +#define RANDOMX_DATASET_EXTRA_SIZE 33554368 + +//Scratchpad L3 size in bytes. Must be a power of 2. +#define RANDOMX_SCRATCHPAD_L3 2097152 + +//Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3. +#define RANDOMX_SCRATCHPAD_L2 262144 + +//Scratchpad L1 size in bytes. Must be a power of two (minimum 64) and less than or equal to RANDOMX_SCRATCHPAD_L2. +#define RANDOMX_SCRATCHPAD_L1 16384 + +//Jump condition mask size in bits. +#define RANDOMX_JUMP_BITS 8 + +//Jump condition mask offset in bits. The sum of RANDOMX_JUMP_BITS and RANDOMX_JUMP_OFFSET must not exceed 16. +#define RANDOMX_JUMP_OFFSET 8 + +//Integer instructions +#define RANDOMX_FREQ_IADD_RS 16 +#define RANDOMX_FREQ_IADD_M 7 +#define RANDOMX_FREQ_ISUB_R 16 +#define RANDOMX_FREQ_ISUB_M 7 +#define RANDOMX_FREQ_IMUL_R 16 +#define RANDOMX_FREQ_IMUL_M 4 +#define RANDOMX_FREQ_IMULH_R 4 +#define RANDOMX_FREQ_IMULH_M 1 +#define RANDOMX_FREQ_ISMULH_R 4 +#define RANDOMX_FREQ_ISMULH_M 1 +#define RANDOMX_FREQ_IMUL_RCP 8 +#define RANDOMX_FREQ_INEG_R 2 +#define RANDOMX_FREQ_IXOR_R 15 +#define RANDOMX_FREQ_IXOR_M 5 +#define RANDOMX_FREQ_IROR_R 8 +#define RANDOMX_FREQ_IROL_R 2 +#define RANDOMX_FREQ_ISWAP_R 4 + +//Floating point instructions +#define RANDOMX_FREQ_FSWAP_R 4 +#define RANDOMX_FREQ_FADD_R 16 +#define RANDOMX_FREQ_FADD_M 5 +#define RANDOMX_FREQ_FSUB_R 16 +#define RANDOMX_FREQ_FSUB_M 5 +#define RANDOMX_FREQ_FSCAL_R 6 +#define RANDOMX_FREQ_FMUL_R 32 +#define RANDOMX_FREQ_FDIV_M 4 +#define RANDOMX_FREQ_FSQRT_R 6 + +//Control instructions +#define RANDOMX_FREQ_CBRANCH 25 +#define RANDOMX_FREQ_CFROUND 1 + +//Store instruction +#define RANDOMX_FREQ_ISTORE 16 + +//No-op instruction +#define RANDOMX_FREQ_NOP 0 + +#define RANDOMX_DATASET_ITEM_SIZE 64 + +#define RANDOMX_PROGRAM_SIZE 256 + +#define HASH_SIZE 64 +#define ENTROPY_SIZE (128 + RANDOMX_PROGRAM_SIZE * 8) +#define REGISTERS_SIZE 256 +#define IMM_BUF_SIZE (RANDOMX_PROGRAM_SIZE * 4 - REGISTERS_SIZE) +#define IMM_INDEX_COUNT ((IMM_BUF_SIZE / 4) - 2) +#define VM_STATE_SIZE (REGISTERS_SIZE + IMM_BUF_SIZE + RANDOMX_PROGRAM_SIZE * 4) +#define ROUNDING_MODE (RANDOMX_FREQ_CFROUND ? -1 : 0) + +// Scratchpad L1/L2/L3 bits +#define LOC_L1 (32 - 14) +#define LOC_L2 (32 - 18) +#define LOC_L3 (32 - 21) diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index 99883daa..f7c98816 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -114,6 +114,7 @@ static AlgoName const algorithm_names[] = { { "RandomARQ", nullptr, Algorithm::RX_ARQ }, { "randomx/sfx", "rx/sfx", Algorithm::RX_SFX }, { "RandomSFX", nullptr, Algorithm::RX_SFX }, + { "RandomV", "rx/v", Algorithm::RX_V }, # endif # ifdef XMRIG_ALGO_ARGON2 { "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA }, @@ -141,6 +142,7 @@ size_t xmrig::Algorithm::l2() const case RX_0: case RX_LOKI: case RX_SFX: + case RX_V: return 0x40000; case RX_WOW: @@ -177,6 +179,7 @@ size_t xmrig::Algorithm::l3() const case RX_0: case RX_LOKI: case RX_SFX: + case RX_V: return oneMiB * 2; case RX_WOW: @@ -277,6 +280,7 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) case RX_LOKI: case RX_ARQ: case RX_SFX: + case RX_V: return RANDOM_X; # endif diff --git a/src/crypto/common/Algorithm.h b/src/crypto/common/Algorithm.h index bfdcea5a..c72b4e6a 100644 --- a/src/crypto/common/Algorithm.h +++ b/src/crypto/common/Algorithm.h @@ -68,6 +68,7 @@ public: RX_LOKI, // "rx/loki" RandomXL (Loki). RX_ARQ, // "rx/arq" RandomARQ (Arqma). RX_SFX, // "rx/sfx" RandomSFX (Safex Cash). + RX_V, // "rx/v" RandomV (Monerov). AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa). AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ) MAX diff --git a/src/crypto/randomx/randomx.cpp b/src/crypto/randomx/randomx.cpp index dfbda968..c6d6ff38 100644 --- a/src/crypto/randomx/randomx.cpp +++ b/src/crypto/randomx/randomx.cpp @@ -97,6 +97,11 @@ RandomX_ConfigurationSafex::RandomX_ConfigurationSafex() ArgonSalt = "RandomSFX\x01"; } +RandomX_ConfigurationV::RandomX_ConfigurationV() +{ + ArgonSalt = "RandomV\x03"; +} + RandomX_ConfigurationBase::RandomX_ConfigurationBase() : ArgonMemory(262144) , ArgonIterations(3) @@ -273,6 +278,7 @@ RandomX_ConfigurationWownero RandomX_WowneroConfig; RandomX_ConfigurationLoki RandomX_LokiConfig; RandomX_ConfigurationArqma RandomX_ArqmaConfig; RandomX_ConfigurationSafex RandomX_SafexConfig; +RandomX_ConfigurationV RandomX_VConfig; RandomX_ConfigurationBase RandomX_CurrentConfig; diff --git a/src/crypto/randomx/randomx.h b/src/crypto/randomx/randomx.h index 793e6e1b..90203a44 100644 --- a/src/crypto/randomx/randomx.h +++ b/src/crypto/randomx/randomx.h @@ -183,12 +183,14 @@ struct RandomX_ConfigurationWownero : public RandomX_ConfigurationBase { RandomX struct RandomX_ConfigurationLoki : public RandomX_ConfigurationBase { RandomX_ConfigurationLoki(); }; struct RandomX_ConfigurationArqma : public RandomX_ConfigurationBase { RandomX_ConfigurationArqma(); }; struct RandomX_ConfigurationSafex : public RandomX_ConfigurationBase { RandomX_ConfigurationSafex(); }; +struct RandomX_ConfigurationV : public RandomX_ConfigurationBase { RandomX_ConfigurationV(); }; extern RandomX_ConfigurationMonero RandomX_MoneroConfig; extern RandomX_ConfigurationWownero RandomX_WowneroConfig; extern RandomX_ConfigurationLoki RandomX_LokiConfig; extern RandomX_ConfigurationArqma RandomX_ArqmaConfig; extern RandomX_ConfigurationSafex RandomX_SafexConfig; +extern RandomX_ConfigurationV RandomX_VConfig; extern RandomX_ConfigurationBase RandomX_CurrentConfig; diff --git a/src/crypto/rx/RxAlgo.cpp b/src/crypto/rx/RxAlgo.cpp index 4630303e..7f82227e 100644 --- a/src/crypto/rx/RxAlgo.cpp +++ b/src/crypto/rx/RxAlgo.cpp @@ -52,6 +52,9 @@ const RandomX_ConfigurationBase *xmrig::RxAlgo::base(Algorithm::Id algorithm) case Algorithm::RX_SFX: return &RandomX_SafexConfig; + case Algorithm::RX_V: + return &RandomX_VConfig; + default: break; } From 2911bb3a8128c600bd1defbe4df27ee9f58684b3 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 20 Dec 2019 04:05:09 +0700 Subject: [PATCH 26/31] Fix OpenCL. --- src/backend/opencl/OclLaunchData.cpp | 6 +- src/backend/opencl/cl/rx/randomx.cl | 2 - .../opencl/cl/rx/randomx_constants_v.h | 96 ------------------- .../opencl/runners/OclRxBaseRunner.cpp | 5 +- src/crypto/rx/RxAlgo.cpp | 10 ++ src/crypto/rx/RxAlgo.h | 1 + 6 files changed, 15 insertions(+), 105 deletions(-) delete mode 100644 src/backend/opencl/cl/rx/randomx_constants_v.h diff --git a/src/backend/opencl/OclLaunchData.cpp b/src/backend/opencl/OclLaunchData.cpp index 149ba075..70465a56 100644 --- a/src/backend/opencl/OclLaunchData.cpp +++ b/src/backend/opencl/OclLaunchData.cpp @@ -25,9 +25,9 @@ #include "backend/opencl/OclLaunchData.h" - #include "backend/common/Tags.h" #include "backend/opencl/OclConfig.h" +#include "crypto/rx/RxAlgo.h" xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclPlatform &platform, const OclThread &thread, const OclDevice &device, int64_t affinity) : @@ -44,8 +44,8 @@ xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorit bool xmrig::OclLaunchData::isEqual(const OclLaunchData &other) const { - return (other.algorithm == algorithm && - other.thread == thread); + return (RxAlgo::id(other.algorithm) == RxAlgo::id(algorithm) && + other.thread == thread); } diff --git a/src/backend/opencl/cl/rx/randomx.cl b/src/backend/opencl/cl/rx/randomx.cl index b62f78fc..6fee74ed 100644 --- a/src/backend/opencl/cl/rx/randomx.cl +++ b/src/backend/opencl/cl/rx/randomx.cl @@ -8,8 +8,6 @@ #include "randomx_constants_loki.h" #elif (ALGO == ALGO_RX_ARQMA) #include "randomx_constants_arqma.h" -#elif (ALGO == ALGO_RX_V) -#include "randomx_constants_v.h" #endif #include "aes.cl" diff --git a/src/backend/opencl/cl/rx/randomx_constants_v.h b/src/backend/opencl/cl/rx/randomx_constants_v.h deleted file mode 100644 index 1967a8c2..00000000 --- a/src/backend/opencl/cl/rx/randomx_constants_v.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -Copyright (c) 2019 SChernykh - -This file is part of RandomX OpenCL. - -RandomX OpenCL 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. - -RandomX OpenCL 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 RandomX OpenCL. If not, see . -*/ - -//Dataset base size in bytes. Must be a power of 2. -#define RANDOMX_DATASET_BASE_SIZE 2147483648 - -//Dataset extra size. Must be divisible by 64. -#define RANDOMX_DATASET_EXTRA_SIZE 33554368 - -//Scratchpad L3 size in bytes. Must be a power of 2. -#define RANDOMX_SCRATCHPAD_L3 2097152 - -//Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3. -#define RANDOMX_SCRATCHPAD_L2 262144 - -//Scratchpad L1 size in bytes. Must be a power of two (minimum 64) and less than or equal to RANDOMX_SCRATCHPAD_L2. -#define RANDOMX_SCRATCHPAD_L1 16384 - -//Jump condition mask size in bits. -#define RANDOMX_JUMP_BITS 8 - -//Jump condition mask offset in bits. The sum of RANDOMX_JUMP_BITS and RANDOMX_JUMP_OFFSET must not exceed 16. -#define RANDOMX_JUMP_OFFSET 8 - -//Integer instructions -#define RANDOMX_FREQ_IADD_RS 16 -#define RANDOMX_FREQ_IADD_M 7 -#define RANDOMX_FREQ_ISUB_R 16 -#define RANDOMX_FREQ_ISUB_M 7 -#define RANDOMX_FREQ_IMUL_R 16 -#define RANDOMX_FREQ_IMUL_M 4 -#define RANDOMX_FREQ_IMULH_R 4 -#define RANDOMX_FREQ_IMULH_M 1 -#define RANDOMX_FREQ_ISMULH_R 4 -#define RANDOMX_FREQ_ISMULH_M 1 -#define RANDOMX_FREQ_IMUL_RCP 8 -#define RANDOMX_FREQ_INEG_R 2 -#define RANDOMX_FREQ_IXOR_R 15 -#define RANDOMX_FREQ_IXOR_M 5 -#define RANDOMX_FREQ_IROR_R 8 -#define RANDOMX_FREQ_IROL_R 2 -#define RANDOMX_FREQ_ISWAP_R 4 - -//Floating point instructions -#define RANDOMX_FREQ_FSWAP_R 4 -#define RANDOMX_FREQ_FADD_R 16 -#define RANDOMX_FREQ_FADD_M 5 -#define RANDOMX_FREQ_FSUB_R 16 -#define RANDOMX_FREQ_FSUB_M 5 -#define RANDOMX_FREQ_FSCAL_R 6 -#define RANDOMX_FREQ_FMUL_R 32 -#define RANDOMX_FREQ_FDIV_M 4 -#define RANDOMX_FREQ_FSQRT_R 6 - -//Control instructions -#define RANDOMX_FREQ_CBRANCH 25 -#define RANDOMX_FREQ_CFROUND 1 - -//Store instruction -#define RANDOMX_FREQ_ISTORE 16 - -//No-op instruction -#define RANDOMX_FREQ_NOP 0 - -#define RANDOMX_DATASET_ITEM_SIZE 64 - -#define RANDOMX_PROGRAM_SIZE 256 - -#define HASH_SIZE 64 -#define ENTROPY_SIZE (128 + RANDOMX_PROGRAM_SIZE * 8) -#define REGISTERS_SIZE 256 -#define IMM_BUF_SIZE (RANDOMX_PROGRAM_SIZE * 4 - REGISTERS_SIZE) -#define IMM_INDEX_COUNT ((IMM_BUF_SIZE / 4) - 2) -#define VM_STATE_SIZE (REGISTERS_SIZE + IMM_BUF_SIZE + RANDOMX_PROGRAM_SIZE * 4) -#define ROUNDING_MODE (RANDOMX_FREQ_CFROUND ? -1 : 0) - -// Scratchpad L1/L2/L3 bits -#define LOC_L1 (32 - 14) -#define LOC_L2 (32 - 18) -#define LOC_L3 (32 - 21) diff --git a/src/backend/opencl/runners/OclRxBaseRunner.cpp b/src/backend/opencl/runners/OclRxBaseRunner.cpp index 8eb390e6..36a31e1b 100644 --- a/src/backend/opencl/runners/OclRxBaseRunner.cpp +++ b/src/backend/opencl/runners/OclRxBaseRunner.cpp @@ -56,10 +56,7 @@ xmrig::OclRxBaseRunner::OclRxBaseRunner(size_t index, const OclLaunchData &data) m_gcn_version = 14; } - // rx/sfx is the same as rx/0 except Argon salt for dataset generation - Algorithm::Id id = (m_algorithm.id() == Algorithm::RX_SFX) ? Algorithm::RX_0 : m_algorithm.id(); - - m_options += " -DALGO=" + std::to_string(id); + m_options += " -DALGO=" + std::to_string(RxAlgo::id(m_algorithm)); m_options += " -DWORKERS_PER_HASH=" + std::to_string(m_worksize); m_options += " -DGCN_VERSION=" + std::to_string(m_gcn_version); } diff --git a/src/crypto/rx/RxAlgo.cpp b/src/crypto/rx/RxAlgo.cpp index 7f82227e..b08b3b8e 100644 --- a/src/crypto/rx/RxAlgo.cpp +++ b/src/crypto/rx/RxAlgo.cpp @@ -37,6 +37,16 @@ xmrig::Algorithm::Id xmrig::RxAlgo::apply(Algorithm::Id algorithm) } +xmrig::Algorithm::Id xmrig::RxAlgo::id(Algorithm::Id algorithm) +{ + if (algorithm == Algorithm::RX_SFX || algorithm == Algorithm::RX_V) { + return Algorithm::RX_0; + } + + return algorithm; +} + + const RandomX_ConfigurationBase *xmrig::RxAlgo::base(Algorithm::Id algorithm) { switch (algorithm) { diff --git a/src/crypto/rx/RxAlgo.h b/src/crypto/rx/RxAlgo.h index 00c44ece..ff2750c6 100644 --- a/src/crypto/rx/RxAlgo.h +++ b/src/crypto/rx/RxAlgo.h @@ -46,6 +46,7 @@ class RxAlgo { public: static Algorithm::Id apply(Algorithm::Id algorithm); + static Algorithm::Id id(Algorithm::Id algorithm); static const RandomX_ConfigurationBase *base(Algorithm::Id algorithm); static uint32_t programCount(Algorithm::Id algorithm); static uint32_t programIterations(Algorithm::Id algorithm); From 049caabdaeeb2d402d7737e3387517faed0e117e Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 20 Dec 2019 04:08:47 +0700 Subject: [PATCH 27/31] Add missing algorithm name alias. --- src/crypto/common/Algorithm.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index f7c98816..a725890f 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -114,7 +114,8 @@ static AlgoName const algorithm_names[] = { { "RandomARQ", nullptr, Algorithm::RX_ARQ }, { "randomx/sfx", "rx/sfx", Algorithm::RX_SFX }, { "RandomSFX", nullptr, Algorithm::RX_SFX }, - { "RandomV", "rx/v", Algorithm::RX_V }, + { "randomx/v", "rx/v", Algorithm::RX_V }, + { "RandomV", nullptr, Algorithm::RX_V }, # endif # ifdef XMRIG_ALGO_ARGON2 { "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA }, From a25042db72b38b8c583ffc8228afbfc1195b0fa0 Mon Sep 17 00:00:00 2001 From: xmrig Date: Fri, 20 Dec 2019 04:16:28 +0700 Subject: [PATCH 28/31] Update CHANGELOG.md --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a96a3ae6..47eef9ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v5.4.0 +- [#1434](https://github.com/xmrig/xmrig/pull/1434) Added RandomSFX (`rx/sfx`) algorithm for Safex Cash. +- [#1445](https://github.com/xmrig/xmrig/pull/1445) Added RandomV (`rx/v`) algorithm for *new* MoneroV. +- [#1419](https://github.com/xmrig/xmrig/issues/1419) Added reverting MSR changes on miner exit, use `"rdmsr": false,` in `"randomx"` object to disable this feature. +- [#1423](https://github.com/xmrig/xmrig/issues/1423) Fixed conflicts with exists WinRing0 driver service. +- [#1425](https://github.com/xmrig/xmrig/issues/1425) Fixed crash on first generation Zen CPUs (MSR mod accidentally enable Opcache), additionally now you can disable Opcache and enable MSR mod via config `"wrmsr": ["0xc0011020:0x0", "0xc0011021:0x60", "0xc0011022:0x510000", "0xc001102b:0x1808cc16"],`. +- Added advanced usage for `wrmsr` option, for example: `"wrmsr": ["0x1a4:0x6"],` (Intel) and `"wrmsr": ["0xc0011020:0x0", "0xc0011021:0x40:0xffffffffffffffdf", "0xc0011022:0x510000", "0xc001102b:0x1808cc16"],` (Ryzen). +- Added new config option `"verbose"` and command line option `--verbose`. + # v5.3.0 - [#1414](https://github.com/xmrig/xmrig/pull/1414) Added native MSR support for Windows, by using signed **WinRing0 driver** (© 2007-2009 OpenLibSys.org). - Added new [MSR documentation](https://xmrig.com/docs/miner/randomx-optimization-guide/msr). From 449617d717c9741ae98dea0ccc41420d7b7a5bfe Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 20 Dec 2019 21:10:13 +0700 Subject: [PATCH 29/31] Allow use old CUDA plugin. --- src/backend/cuda/wrappers/CudaLib.cpp | 5 +++-- src/backend/opencl/OclLaunchData.cpp | 5 ++--- src/crypto/rx/RxAlgo.cpp | 10 ---------- src/crypto/rx/RxAlgo.h | 10 +++++++++- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/backend/cuda/wrappers/CudaLib.cpp b/src/backend/cuda/wrappers/CudaLib.cpp index 37924457..189c6b2a 100644 --- a/src/backend/cuda/wrappers/CudaLib.cpp +++ b/src/backend/cuda/wrappers/CudaLib.cpp @@ -28,6 +28,7 @@ #include "backend/cuda/wrappers/CudaLib.h" +#include "crypto/rx/RxAlgo.h" namespace xmrig { @@ -163,7 +164,7 @@ bool xmrig::CudaLib::rxPrepare(nvid_ctx *ctx, const void *dataset, size_t datase bool xmrig::CudaLib::setJob(nvid_ctx *ctx, const void *data, size_t size, const Algorithm &algorithm) noexcept { - return pSetJob(ctx, data, size, algorithm); + return pSetJob(ctx, data, size, RxAlgo::id(algorithm)); } @@ -187,7 +188,7 @@ const char *xmrig::CudaLib::pluginVersion() noexcept int xmrig::CudaLib::deviceInfo(nvid_ctx *ctx, int32_t blocks, int32_t threads, const Algorithm &algorithm, int32_t dataset_host) noexcept { - return pDeviceInfo(ctx, blocks, threads, algorithm, dataset_host); + return pDeviceInfo(ctx, blocks, threads, RxAlgo::id(algorithm), dataset_host); } diff --git a/src/backend/opencl/OclLaunchData.cpp b/src/backend/opencl/OclLaunchData.cpp index 70465a56..2af6d101 100644 --- a/src/backend/opencl/OclLaunchData.cpp +++ b/src/backend/opencl/OclLaunchData.cpp @@ -27,7 +27,6 @@ #include "backend/opencl/OclLaunchData.h" #include "backend/common/Tags.h" #include "backend/opencl/OclConfig.h" -#include "crypto/rx/RxAlgo.h" xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclPlatform &platform, const OclThread &thread, const OclDevice &device, int64_t affinity) : @@ -44,8 +43,8 @@ xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorit bool xmrig::OclLaunchData::isEqual(const OclLaunchData &other) const { - return (RxAlgo::id(other.algorithm) == RxAlgo::id(algorithm) && - other.thread == thread); + return (other.algorithm == algorithm && + other.thread == thread); } diff --git a/src/crypto/rx/RxAlgo.cpp b/src/crypto/rx/RxAlgo.cpp index b08b3b8e..7f82227e 100644 --- a/src/crypto/rx/RxAlgo.cpp +++ b/src/crypto/rx/RxAlgo.cpp @@ -37,16 +37,6 @@ xmrig::Algorithm::Id xmrig::RxAlgo::apply(Algorithm::Id algorithm) } -xmrig::Algorithm::Id xmrig::RxAlgo::id(Algorithm::Id algorithm) -{ - if (algorithm == Algorithm::RX_SFX || algorithm == Algorithm::RX_V) { - return Algorithm::RX_0; - } - - return algorithm; -} - - const RandomX_ConfigurationBase *xmrig::RxAlgo::base(Algorithm::Id algorithm) { switch (algorithm) { diff --git a/src/crypto/rx/RxAlgo.h b/src/crypto/rx/RxAlgo.h index ff2750c6..d2b30988 100644 --- a/src/crypto/rx/RxAlgo.h +++ b/src/crypto/rx/RxAlgo.h @@ -46,12 +46,20 @@ class RxAlgo { public: static Algorithm::Id apply(Algorithm::Id algorithm); - static Algorithm::Id id(Algorithm::Id algorithm); static const RandomX_ConfigurationBase *base(Algorithm::Id algorithm); static uint32_t programCount(Algorithm::Id algorithm); static uint32_t programIterations(Algorithm::Id algorithm); static uint32_t programSize(Algorithm::Id algorithm); static uint32_t version(Algorithm::Id algorithm); + + static inline Algorithm::Id id(Algorithm::Id algorithm) + { + if (algorithm == Algorithm::RX_SFX || algorithm == Algorithm::RX_V) { + return Algorithm::RX_0; + } + + return algorithm; + } }; From 98cfe7ed37ad8f290983f164d91f41ce565b6285 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 20 Dec 2019 23:44:32 +0700 Subject: [PATCH 30/31] Added extra error message. --- src/base/net/stratum/Client.cpp | 26 +++++++++++++++++++------- src/base/net/stratum/Client.h | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index a995bef3..30ef20ea 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -466,11 +466,7 @@ bool xmrig::Client::send(BIO *bio) bool result = false; if (state() == ConnectedState && uv_is_writable(m_stream)) { - result = uv_try_write(m_stream, &buf, 1) > 0; - - if (!result) { - close(); - } + result = write(buf); } else { LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state); @@ -511,6 +507,23 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo } +bool xmrig::Client::write(const uv_buf_t &buf) +{ + const int rc = uv_try_write(m_stream, &buf, 1); + if (static_cast(rc) == buf.len) { + return true; + } + + if (!isQuiet()) { + LOG_ERR("[%s] write error: \"%s\"", url(), uv_strerror(rc)); + } + + close(); + + return false; +} + + int xmrig::Client::resolve(const String &host) { setState(HostLookupState); @@ -553,8 +566,7 @@ int64_t xmrig::Client::send(size_t size) uv_buf_t buf = uv_buf_init(m_sendBuf.data(), (unsigned int) size); - if (uv_try_write(m_stream, &buf, 1) < 0) { - close(); + if (!write(buf)) { return -1; } } diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index 1949e61f..ec90dd85 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -96,6 +96,7 @@ private: bool parseLogin(const rapidjson::Value &result, int *code); bool send(BIO *bio); bool verifyAlgorithm(const Algorithm &algorithm, const char *algo) const; + bool write(const uv_buf_t &buf); int resolve(const String &host); int64_t send(size_t size); void connect(sockaddr *addr); From cd7f73a31cb1f35e278940686b164465151976f8 Mon Sep 17 00:00:00 2001 From: xmrig Date: Sat, 21 Dec 2019 13:40:42 +0700 Subject: [PATCH 31/31] Update ALGORITHMS.md --- doc/ALGORITHMS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/ALGORITHMS.md b/doc/ALGORITHMS.md index 07e5735e..c641f076 100644 --- a/doc/ALGORITHMS.md +++ b/doc/ALGORITHMS.md @@ -12,6 +12,8 @@ Option `coin` useful for pools without algorithm negotiation support or daemon t | Name | Memory | Version | Notes | |------|--------|---------|-------| +| `rx/sfx` | 2 MB | 5.4.0+ | RandomSFX (RandomX variant for Safex). | +| `rx/v` | 2 MB | 5.4.0+ | RandomV (RandomX variant for new MoneroV). | | `rx/arq` | 256 KB | 4.3.0+ | RandomARQ (RandomX variant for ArQmA). | | `rx/0` | 2 MB | 3.2.0+ | RandomX (Monero). | | `argon2/chukwa` | 512 KB | 3.1.0+ | Argon2id (Chukwa). |