diff --git a/CHANGELOG.md b/CHANGELOG.md index 26355c66..af2706d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# v6.2.2 +- [#1742](https://github.com/xmrig/xmrig/issues/1742) Fixed crash when use HTTP API. + +# v6.2.1 +- [#1726](https://github.com/xmrig/xmrig/issues/1726) Fixed detection of AVX2/AVX512. +- [#1728](https://github.com/xmrig/xmrig/issues/1728) Fixed, 32 bit Windows builds was crash on start. +- [#1729](https://github.com/xmrig/xmrig/pull/1729) Fixed KawPow crash on old CPUs. +- [#1730](https://github.com/xmrig/xmrig/pull/1730) Improved displaying information for compute errors on GPUs. +- [#1732](https://github.com/xmrig/xmrig/pull/1732) Fixed NiceHash disconnects for KawPow. +- Fixed AMD GPU health (temperatures/power/clocks/fans) readings on Linux. + # v6.2.0-beta - [#1717](https://github.com/xmrig/xmrig/pull/1717) Added new algorithm `cn/ccx` for Conceal. - [#1718](https://github.com/xmrig/xmrig/pull/1718) Fixed, linker on Linux was marking entire executable as having an executable stack. diff --git a/src/backend/cpu/interfaces/ICpuInfo.h b/src/backend/cpu/interfaces/ICpuInfo.h index badb44c0..bc73e75a 100644 --- a/src/backend/cpu/interfaces/ICpuInfo.h +++ b/src/backend/cpu/interfaces/ICpuInfo.h @@ -61,6 +61,7 @@ public: FLAG_SSE2, FLAG_SSSE3, FLAG_XOP, + FLAG_POPCNT, FLAG_MAX }; diff --git a/src/backend/cpu/platform/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp index eb042980..1f3d5410 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -57,7 +57,7 @@ namespace xmrig { -static const std::array flagNames = { "aes", "avx2", "avx512f", "bmi2", "osxsave", "pdpe1gb", "sse2", "ssse3", "xop" }; +static const std::array flagNames = { "aes", "avx2", "avx512f", "bmi2", "osxsave", "pdpe1gb", "sse2", "ssse3", "xop", "popcnt" }; static const std::array msrNames = { "none", "ryzen", "intel", "custom" }; @@ -119,15 +119,30 @@ static inline int32_t get_masked(int32_t val, int32_t h, int32_t l) } +static inline uint64_t xgetbv() +{ +#ifdef _MSC_VER + return _xgetbv(_XCR_XFEATURE_ENABLED_MASK); +#else + uint32_t eax_reg = 0; + uint32_t edx_reg = 0; + __asm__ __volatile__("xgetbv": "=a"(eax_reg), "=d"(edx_reg) : "c"(0) : "cc"); + return (static_cast(edx_reg) << 32) | eax_reg; +#endif +} + +static inline bool has_xcr_avx2() { return (xgetbv() & 0x06) == 0x06; } +static inline bool has_xcr_avx512() { return (xgetbv() & 0xE6) == 0xE6; } static inline bool has_osxsave() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 27); } static inline bool has_aes_ni() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 25); } -static inline bool has_avx2() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 5) && has_osxsave(); } -static inline bool has_avx512f() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 16) && has_osxsave(); } +static inline bool has_avx2() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 5) && has_osxsave() && has_xcr_avx2(); } +static inline bool has_avx512f() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 16) && has_osxsave() && has_xcr_avx512(); } static inline bool has_bmi2() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 8); } static inline bool has_pdpe1gb() { return has_feature(PROCESSOR_EXT_INFO, EDX_Reg, 1 << 26); } static inline bool has_sse2() { return has_feature(PROCESSOR_INFO, EDX_Reg, 1 << 26); } static inline bool has_ssse3() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 9); } static inline bool has_xop() { return has_feature(0x80000001, ECX_Reg, 1 << 11); } +static inline bool has_popcnt() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 23); } } // namespace xmrig @@ -162,6 +177,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : m_flags.set(FLAG_SSE2, has_sse2()); m_flags.set(FLAG_SSSE3, has_ssse3()); m_flags.set(FLAG_XOP, has_xop()); + m_flags.set(FLAG_POPCNT, has_popcnt()); # ifdef XMRIG_FEATURE_ASM if (hasAES()) { diff --git a/src/backend/cuda/CudaWorker.cpp b/src/backend/cuda/CudaWorker.cpp index 5ec4a3de..c8cb6f73 100644 --- a/src/backend/cuda/CudaWorker.cpp +++ b/src/backend/cuda/CudaWorker.cpp @@ -27,6 +27,7 @@ #include "backend/cuda/CudaWorker.h" #include "backend/common/Tags.h" #include "backend/cuda/runners/CudaCnRunner.h" +#include "backend/cuda/wrappers/CudaDevice.h" #include "base/io/log/Log.h" #include "base/tools/Chrono.h" #include "core/Miner.h" @@ -71,7 +72,8 @@ static inline uint32_t roundSize(uint32_t intensity) { return kReserveCount / in xmrig::CudaWorker::CudaWorker(size_t id, const CudaLaunchData &data) : Worker(id, data.thread.affinity(), -1), m_algorithm(data.algorithm), - m_miner(data.miner) + m_miner(data.miner), + m_deviceIndex(data.device.index()) { switch (m_algorithm.family()) { case Algorithm::RANDOM_X: @@ -165,7 +167,7 @@ void xmrig::CudaWorker::start() } if (foundCount) { - JobResults::submit(m_job.currentJob(), foundNonce, foundCount); + JobResults::submit(m_job.currentJob(), foundNonce, foundCount, m_deviceIndex); } const size_t batch_size = intensity(); diff --git a/src/backend/cuda/CudaWorker.h b/src/backend/cuda/CudaWorker.h index d18b6681..3f4e713a 100644 --- a/src/backend/cuda/CudaWorker.h +++ b/src/backend/cuda/CudaWorker.h @@ -66,6 +66,7 @@ private: const Miner *m_miner; ICudaRunner *m_runner = nullptr; WorkerJob<1> m_job; + uint32_t m_deviceIndex; }; diff --git a/src/backend/opencl/OclWorker.cpp b/src/backend/opencl/OclWorker.cpp index c93d7e64..c6d6daed 100644 --- a/src/backend/opencl/OclWorker.cpp +++ b/src/backend/opencl/OclWorker.cpp @@ -83,7 +83,8 @@ xmrig::OclWorker::OclWorker(size_t id, const OclLaunchData &data) : m_algorithm(data.algorithm), m_miner(data.miner), m_intensity(data.thread.intensity()), - m_sharedData(OclSharedState::get(data.device.index())) + m_sharedData(OclSharedState::get(data.device.index())), + m_deviceIndex(data.device.index()) { switch (m_algorithm.family()) { case Algorithm::RANDOM_X: @@ -210,7 +211,7 @@ void xmrig::OclWorker::start() } if (results[0xFF] > 0) { - JobResults::submit(m_job.currentJob(), results, results[0xFF]); + JobResults::submit(m_job.currentJob(), results, results[0xFF], m_deviceIndex); } if (!Nonce::isOutdated(Nonce::OPENCL, m_job.sequence()) && !m_job.nextRound(roundSize(runnerRoundSize), runnerRoundSize)) { diff --git a/src/backend/opencl/OclWorker.h b/src/backend/opencl/OclWorker.h index 64708e9d..fc666f80 100644 --- a/src/backend/opencl/OclWorker.h +++ b/src/backend/opencl/OclWorker.h @@ -69,6 +69,7 @@ private: IOclRunner *m_runner = nullptr; OclSharedData &m_sharedData; WorkerJob<1> m_job; + uint32_t m_deviceIndex; }; diff --git a/src/backend/opencl/wrappers/AdlLib_linux.cpp b/src/backend/opencl/wrappers/AdlLib_linux.cpp index 5ef0e5e5..7dbb1ea2 100644 --- a/src/backend/opencl/wrappers/AdlLib_linux.cpp +++ b/src/backend/opencl/wrappers/AdlLib_linux.cpp @@ -36,27 +36,29 @@ bool AdlLib::m_ready = false; static const std::string kPrefix = "/sys/bus/pci/drivers/amdgpu/"; -static inline bool sysfs_is_file(const char *path) +static inline bool sysfs_is_file(const std::string &path) { struct stat sb; - return stat(path, &sb) == 0 && ((sb.st_mode & S_IFMT) == S_IFREG); + return stat(path.c_str(), &sb) == 0 && ((sb.st_mode & S_IFMT) == S_IFREG); } -static inline std::string sysfs_prefix(const PciTopology &topology) +static inline bool sysfs_is_amdgpu(const std::string &path) { - std::string path = kPrefix + "0000:" + topology.toString().data() + "/hwmon/hwmon"; - - if (sysfs_is_file((path + "2/name").c_str())) { - return path + "2/"; + if (!sysfs_is_file(path)) { + return false; } - if (sysfs_is_file((path + "3/name").c_str())) { - return path + "3/"; + std::ifstream file(path); + if (!file.is_open()) { + return false; } - return {}; + std::string name; + std::getline(file, name); + + return name == "amdgpu"; } @@ -74,6 +76,21 @@ uint32_t sysfs_read(const std::string &path) } +static inline std::string sysfs_prefix(const PciTopology &topology) +{ + const std::string path = kPrefix + "0000:" + topology.toString().data() + "/hwmon/hwmon"; + + for (uint32_t i = 1; i < 10; ++i) { + const std::string prefix = path + std::to_string(i) + "/"; + if (sysfs_is_amdgpu(prefix + "name") && sysfs_read(prefix + "freq1_input")) { + return prefix; + } + } + + return {}; +} + + } // namespace xmrig diff --git a/src/base/kernel/Platform_win.cpp b/src/base/kernel/Platform_win.cpp index 018dba31..00497453 100644 --- a/src/base/kernel/Platform_win.cpp +++ b/src/base/kernel/Platform_win.cpp @@ -34,7 +34,7 @@ static inline OSVERSIONINFOEX winOsVersion() { - using RtlGetVersionFunction = NTSTATUS (*)(LPOSVERSIONINFO); + typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO); OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0}; HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); diff --git a/src/base/net/stratum/EthStratumClient.cpp b/src/base/net/stratum/EthStratumClient.cpp index d445186a..5e7edfd4 100644 --- a/src/base/net/stratum/EthStratumClient.cpp +++ b/src/base/net/stratum/EthStratumClient.cpp @@ -145,6 +145,22 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj return; } + if (strcmp(method, "mining.set_extranonce") == 0) { + if (!params.IsArray()) { + LOG_ERR("%s " RED("invalid mining.set_extranonce notification: params is not an array"), tag()); + return; + } + + auto arr = params.GetArray(); + + if (arr.Empty()) { + LOG_ERR("%s " RED("invalid mining.set_extranonce notification: params array is empty"), tag()); + return; + } + + setExtraNonce(arr[0]); + } + if (strcmp(method, "mining.notify") == 0) { if (!params.IsArray()) { LOG_ERR("%s " RED("invalid mining.notify notification: params is not an array"), tag()); @@ -345,6 +361,14 @@ void xmrig::EthStratumClient::onSubscribeResponse(const rapidjson::Value &result } setExtraNonce(result.GetArray()[1]); + + if (m_pool.isNicehash()) { + using namespace rapidjson; + Document doc(kObjectType); + Value params(kArrayType); + JsonRequest::create(doc, m_sequence, "mining.extranonce.subscribe", params); + send(doc); + } } catch (const std::exception &ex) { LOG_ERR("%s " RED("%s"), tag(), ex.what()); diff --git a/src/base/net/stratum/Pool.cpp b/src/base/net/stratum/Pool.cpp index 06d29635..dc0ac792 100644 --- a/src/base/net/stratum/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -74,6 +74,9 @@ const char *Pool::kUrl = "url"; const char *Pool::kUser = "user"; +const char *Pool::kNicehashHost = "nicehash.com"; + + } @@ -94,7 +97,7 @@ xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char m_pollInterval(kDefaultPollInterval), m_url(host, port, tls) { - m_flags.set(FLAG_NICEHASH, nicehash); + m_flags.set(FLAG_NICEHASH, nicehash || strstr(host, kNicehashHost)); m_flags.set(FLAG_TLS, tls); } @@ -119,7 +122,7 @@ xmrig::Pool::Pool(const rapidjson::Value &object) : m_proxy = Json::getValue(object, kSOCKS5); m_flags.set(FLAG_ENABLED, Json::getBool(object, kEnabled, true)); - m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash)); + m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash) || m_url.host().contains(kNicehashHost)); m_flags.set(FLAG_TLS, Json::getBool(object, kTls) || m_url.isTLS()); if (m_daemon.isValid()) { diff --git a/src/base/net/stratum/Pool.h b/src/base/net/stratum/Pool.h index 68276ca0..7569eae7 100644 --- a/src/base/net/stratum/Pool.h +++ b/src/base/net/stratum/Pool.h @@ -71,6 +71,7 @@ public: static const char *kTls; static const char *kUrl; static const char *kUser; + static const char *kNicehashHost; constexpr static int kKeepAliveTimeout = 60; constexpr static uint16_t kDefaultPort = 3333; diff --git a/src/crypto/kawpow/KPHash.cpp b/src/crypto/kawpow/KPHash.cpp index 243d20af..fe5873a6 100644 --- a/src/crypto/kawpow/KPHash.cpp +++ b/src/crypto/kawpow/KPHash.cpp @@ -25,6 +25,7 @@ */ +#include "backend/cpu/Cpu.h" #include "crypto/kawpow/KPHash.h" #include "crypto/kawpow/KPCache.h" #include "3rdparty/libethash/ethash.h" @@ -156,7 +157,22 @@ static inline uint32_t popcount(uint32_t a) } -static inline uint32_t random_math(uint32_t a, uint32_t b, uint32_t selector) +// Taken from https://en.wikipedia.org/wiki/Hamming_weight +static inline uint32_t popcount_soft(uint64_t x) +{ + constexpr uint64_t m1 = 0x5555555555555555ull; + constexpr uint64_t m2 = 0x3333333333333333ull; + constexpr uint64_t m4 = 0x0f0f0f0f0f0f0f0full; + constexpr uint64_t h01 = 0x0101010101010101ull; + + x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits + x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits + x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits + return (x * h01) >> 56; //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ... +} + + +static inline uint32_t random_math(uint32_t a, uint32_t b, uint32_t selector, bool has_popcnt) { switch (selector % 11) { @@ -181,7 +197,10 @@ static inline uint32_t random_math(uint32_t a, uint32_t b, uint32_t selector) case 9: return clz(a) + clz(b); case 10: - return popcount(a) + popcount(b); + if (has_popcnt) + return popcount(a) + popcount(b); + else + return popcount_soft(a) + popcount_soft(b); default: #ifdef _MSC_VER __assume(false); @@ -260,6 +279,8 @@ void KPHash::calculate(const KPCache& light_cache, uint32_t block_height, const uint32_t jsr0 = jsr; uint32_t jcong0 = jcong; + const bool has_popcnt = Cpu::info()->has(ICpuInfo::FLAG_POPCNT); + for (uint32_t r = 0; r < ETHASH_ACCESSES; ++r) { uint32_t item_index = (mix[r % LANES][0] % num_items) * 4; @@ -302,7 +323,7 @@ void KPHash::calculate(const KPCache& light_cache, uint32_t block_height, const for (size_t l = 0; l < LANES; ++l) { - const uint32_t data = random_math(mix[l][src1], mix[l][src2], sel1); + const uint32_t data = random_math(mix[l][src1], mix[l][src2], sel1, has_popcnt); random_merge(mix[l][dst], data, sel2); } } diff --git a/src/net/JobResults.cpp b/src/net/JobResults.cpp index 2fe89e84..66502bad 100644 --- a/src/net/JobResults.cpp +++ b/src/net/JobResults.cpp @@ -29,6 +29,7 @@ #include "base/tools/Object.h" #include "net/interfaces/IJobResultListener.h" #include "net/JobResult.h" +#include "backend/common/Tags.h" #ifdef XMRIG_ALGO_RANDOMX @@ -66,15 +67,17 @@ namespace xmrig { class JobBundle { public: - inline JobBundle(const Job &job, uint32_t *results, size_t count) : + inline JobBundle(const Job &job, uint32_t *results, size_t count, uint32_t device_index) : job(job), - nonces(count) + nonces(count), + device_index(device_index) { memcpy(nonces.data(), results, sizeof(uint32_t) * count); } Job job; std::vector nonces; + uint32_t device_index; }; @@ -101,7 +104,7 @@ static inline void checkHash(const JobBundle &bundle, std::vector &re results.emplace_back(bundle.job, nonce, hash); } else { - LOG_ERR("COMPUTE ERROR"); // TODO Extend information. + LOG_ERR("%s " RED_S "GPU #%u COMPUTE ERROR", backend_tag(bundle.job.backend()), bundle.device_index); errors++; } } @@ -165,7 +168,7 @@ static void getResults(JobBundle &bundle, std::vector &results, uint3 results.emplace_back(bundle.job, full_nonce, (uint8_t*)output, bundle.job.blob(), (uint8_t*)mix_hash); } else { - LOG_ERR("COMPUTE ERROR"); // TODO Extend information. + LOG_ERR("%s " RED_S "GPU #%u COMPUTE ERROR", backend_tag(bundle.job.backend()), bundle.device_index); ++errors; } } @@ -221,10 +224,10 @@ public: # if defined(XMRIG_FEATURE_OPENCL) || defined(XMRIG_FEATURE_CUDA) - inline void submit(const Job &job, uint32_t *results, size_t count) + inline void submit(const Job &job, uint32_t *results, size_t count, uint32_t device_index) { std::lock_guard lock(m_mutex); - m_bundles.emplace_back(job, results, count); + m_bundles.emplace_back(job, results, count, device_index); uv_async_send(m_async); } @@ -351,10 +354,10 @@ void xmrig::JobResults::submit(const JobResult &result) #if defined(XMRIG_FEATURE_OPENCL) || defined(XMRIG_FEATURE_CUDA) -void xmrig::JobResults::submit(const Job &job, uint32_t *results, size_t count) +void xmrig::JobResults::submit(const Job &job, uint32_t *results, size_t count, uint32_t device_index) { if (handler) { - handler->submit(job, results, count); + handler->submit(job, results, count, device_index); } } #endif diff --git a/src/net/JobResults.h b/src/net/JobResults.h index 1b32e5bd..5ca243d7 100644 --- a/src/net/JobResults.h +++ b/src/net/JobResults.h @@ -49,7 +49,7 @@ public: static void submit(const JobResult &result); # if defined(XMRIG_FEATURE_OPENCL) || defined(XMRIG_FEATURE_CUDA) - static void submit(const Job &job, uint32_t *results, size_t count); + static void submit(const Job &job, uint32_t *results, size_t count, uint32_t device_index); # endif }; diff --git a/src/version.h b/src/version.h index a2e0ff1d..a14c7f6f 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 "6.2.0-beta-mo2" +#define APP_VERSION "6.2.2-mo1" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2020 xmrig.com" @@ -36,7 +36,7 @@ #define APP_VER_MAJOR 6 #define APP_VER_MINOR 2 -#define APP_VER_PATCH 0 +#define APP_VER_PATCH 2 #ifdef _MSC_VER # if (_MSC_VER >= 1920)