Fixed automatic threads mode for --av above 4

This commit is contained in:
XMRig 2018-04-17 09:42:53 +07:00
parent 9e3f2ae9f9
commit b32ec5342e
6 changed files with 63 additions and 69 deletions

View file

@ -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")

View file

@ -26,6 +26,7 @@
#include <math.h>
#include <string.h>
#include "Cpu.h"
@ -36,16 +37,16 @@ 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;
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;

View file

@ -28,9 +28,6 @@
#include <stdint.h>
#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;
};

View file

@ -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;
}

View file

@ -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
{

View file

@ -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; }