diff --git a/CMakeLists.txt b/CMakeLists.txt index c7017b01..ae2a4ed7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,7 +167,7 @@ endif() add_definitions(/D__STDC_FORMAT_MACROS) add_definitions(/DUNICODE) -#add_definitions(/DAPP_DEBUG) +add_definitions(/DAPP_DEBUG) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") diff --git a/src/Cpu.cpp b/src/Cpu.cpp index f8fb092c..eebe585d 100644 --- a/src/Cpu.cpp +++ b/src/Cpu.cpp @@ -26,26 +26,27 @@ #include #include + #include "Cpu.h" -bool Cpu::m_l2_exclusive = false; -char Cpu::m_brand[64] = { 0 }; -int Cpu::m_flags = 0; -int Cpu::m_l2_cache = 0; -int Cpu::m_l3_cache = 0; -int Cpu::m_sockets = 1; -int Cpu::m_totalCores = 0; -int Cpu::m_totalThreads = 0; +bool Cpu::m_l2_exclusive = false; +char Cpu::m_brand[64] = { 0 }; +int Cpu::m_flags = 0; +int Cpu::m_l2_cache = 0; +int Cpu::m_l3_cache = 0; +int Cpu::m_sockets = 1; +int Cpu::m_totalCores = 0; +size_t Cpu::m_totalThreads = 0; -int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage) +size_t Cpu::optimalThreadsCount(size_t size, int maxCpuUsage) { if (m_totalThreads == 1) { return 1; } - int cache = 0; + size_t cache = 0; if (m_l3_cache) { cache = m_l2_exclusive ? (m_l2_cache + m_l3_cache) : m_l3_cache; } @@ -53,22 +54,14 @@ int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage) cache = m_l2_cache; } - int count = 0; - int size = 2048; - - if (algo == xmrig::CRYPTONIGHT_LITE) { - size = 1024; - } - else if (algo == xmrig::CRYPTONIGHT_HEAVY) { - size = 4096; - } - - if (doubleHash) { - size *= 2; - } + size_t count = 0; if (cache) { count = cache / size; + + if (cache % size >= size / 2) { + count++; + } } else { count = m_totalThreads / 2; diff --git a/src/Cpu.h b/src/Cpu.h index 97e593ed..a125bae8 100644 --- a/src/Cpu.h +++ b/src/Cpu.h @@ -28,9 +28,6 @@ #include -#include "common/xmrig.h" - - class Cpu { public: @@ -40,7 +37,7 @@ public: BMI2 = 4 }; - static int optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage); + static size_t optimalThreadsCount(size_t size, int maxCpuUsage); static void init(); static inline bool hasAES() { return (m_flags & AES) != 0; } @@ -62,7 +59,7 @@ private: static int m_l3_cache; static int m_sockets; static int m_totalCores; - static int m_totalThreads; + static size_t m_totalThreads; }; diff --git a/src/core/Config.cpp b/src/core/Config.cpp index b3564f92..4d48af29 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -30,6 +30,7 @@ #include "core/Config.h" #include "core/ConfigCreator.h" #include "Cpu.h" +#include "crypto/CryptoNight_constants.h" #include "net/Pool.h" #include "rapidjson/document.h" #include "rapidjson/filewritestream.h" @@ -177,13 +178,13 @@ bool xmrig::Config::adjust() m_algoVariant = getAlgoVariant(); m_threads.mode = m_threads.count ? Simple : Automatic; - const bool doubleHash = m_algoVariant == AV_DOUBLE || m_algoVariant == AV_DOUBLE_SOFT; + const size_t size = CpuThread::multiway(m_algoVariant) * cn_select_memory(m_algorithm) / 1024; if (!m_threads.count) { - m_threads.count = Cpu::optimalThreadsCount(m_algorithm, doubleHash, m_maxCpuUsage); + m_threads.count = Cpu::optimalThreadsCount(size, m_maxCpuUsage); } else if (m_safe) { - const size_t count = Cpu::optimalThreadsCount(m_algorithm, doubleHash, m_maxCpuUsage); + const size_t count = Cpu::optimalThreadsCount(size, m_maxCpuUsage); if (m_threads.count > count) { m_threads.count = count; } diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index ac733ef6..3632e193 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -54,6 +54,12 @@ xmrig::CpuThread::~CpuThread() } +bool xmrig::CpuThread::isSoftAES(AlgoVariant av) +{ + return av == AV_SINGLE_SOFT || av == AV_DOUBLE_SOFT || av > AV_PENTA; +} + + xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) { assert(variant == VARIANT_NONE || variant == VARIANT_V1); @@ -138,42 +144,6 @@ xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, A { assert(av > AV_AUTO && av < AV_MAX); - Multiway multiway = SingleWay; - bool softAES = false; - - switch (av) { - case AV_SINGLE_SOFT: - softAES = true; - break; - - case AV_DOUBLE_SOFT: - softAES = true; - case AV_DOUBLE: - multiway = DoubleWay; - break; - - case AV_TRIPLE_SOFT: - softAES = true; - case AV_TRIPLE: - multiway = TripleWay; - break; - - case AV_QUAD_SOFT: - softAES = true; - case AV_QUAD: - multiway = QuadWay; - break; - - case AV_PENTA_SOFT: - softAES = true; - case AV_PENTA: - multiway = PentaWay; - break; - - default: - break; - } - int64_t cpuId = -1L; if (affinity != -1L) { @@ -193,7 +163,7 @@ xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, A } } - return new CpuThread(index, algorithm, av, multiway, cpuId, priority, softAES, false); + return new CpuThread(index, algorithm, av, multiway(av), cpuId, priority, isSoftAES(av), false); } @@ -242,6 +212,37 @@ xmrig::CpuThread::Data xmrig::CpuThread::parse(const rapidjson::Value &object) } +xmrig::IThread::Multiway xmrig::CpuThread::multiway(AlgoVariant av) +{ + switch (av) { + case AV_SINGLE: + case AV_SINGLE_SOFT: + return SingleWay; + + case AV_DOUBLE_SOFT: + case AV_DOUBLE: + return DoubleWay; + + case AV_TRIPLE_SOFT: + case AV_TRIPLE: + return TripleWay; + + case AV_QUAD_SOFT: + case AV_QUAD: + return QuadWay; + + case AV_PENTA_SOFT: + case AV_PENTA: + return PentaWay; + + default: + break; + } + + return SingleWay; +} + + #ifndef XMRIG_NO_API rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const { diff --git a/src/workers/CpuThread.h b/src/workers/CpuThread.h index ba36cc87..0e364764 100644 --- a/src/workers/CpuThread.h +++ b/src/workers/CpuThread.h @@ -61,10 +61,12 @@ public: typedef void (*cn_hash_fun)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx **ctx); + static bool isSoftAES(AlgoVariant av); static cn_hash_fun fn(Algo algorithm, AlgoVariant av, Variant variant); static CpuThread *createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority); static CpuThread *createFromData(size_t index, Algo algorithm, const CpuThread::Data &data, int priority, bool softAES); static Data parse(const rapidjson::Value &object); + static Multiway multiway(AlgoVariant av); inline bool isPrefetch() const { return m_prefetch; } inline bool isSoftAES() const { return m_softAES; }