Added reader for advanced threads.

This commit is contained in:
XMRig 2018-04-13 17:59:27 +07:00
parent 9ce9147dad
commit c44b299750
5 changed files with 101 additions and 18 deletions

View file

@ -64,6 +64,13 @@ enum Variant {
}; };
enum AesMode {
AES_AUTO,
AES_HW,
AES_SOFT
};
} /* namespace xmrig */ } /* namespace xmrig */

View file

@ -41,6 +41,7 @@ static char affinity_tmp[20] = { 0 };
xmrig::Config::Config() : xmrig::CommonConfig(), xmrig::Config::Config() : xmrig::CommonConfig(),
m_aesMode(AES_AUTO),
m_algoVariant(AV_AUTO), m_algoVariant(AV_AUTO),
m_doubleHash(false), m_doubleHash(false),
m_dryRun(false), m_dryRun(false),
@ -48,9 +49,7 @@ xmrig::Config::Config() : xmrig::CommonConfig(),
m_safe(false), m_safe(false),
m_maxCpuUsage(75), m_maxCpuUsage(75),
m_printTime(60), m_printTime(60),
m_priority(-1), m_priority(-1)
m_affinity(-1L),
m_threadsCount(0)
{ {
} }
@ -162,18 +161,18 @@ bool xmrig::Config::adjust()
m_doubleHash = true; m_doubleHash = true;
} }
if (!m_threadsCount) { if (!m_threads.count) {
m_threadsCount = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage); m_threads.count = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
} }
else if (m_safe) { else if (m_safe) {
const size_t count = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage); const size_t count = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
if (m_threadsCount > count) { if (m_threads.count > count) {
m_threadsCount = count; m_threads.count = count;
} }
} }
for (size_t i = 0; i < m_threadsCount; ++i) { for (size_t i = 0; i < m_threads.count; ++i) {
m_threads.push_back(CpuThread::createFromAV(i, m_algorithm, m_algoVariant, m_affinity, m_priority)); m_threads.list.push_back(CpuThread::createFromAV(i, m_algorithm, m_algoVariant, m_threads.mask, m_priority));
} }
return true; return true;
@ -228,7 +227,7 @@ bool xmrig::Config::parseString(int key, const char *arg)
case xmrig::IConfig::ThreadsKey: /* --threads */ case xmrig::IConfig::ThreadsKey: /* --threads */
if (strncmp(arg, "all", 3) == 0) { if (strncmp(arg, "all", 3) == 0) {
m_threadsCount = Cpu::threads(); m_threads.count = Cpu::threads();
return true; return true;
} }
@ -257,7 +256,7 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg)
switch (key) { switch (key) {
case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */ case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */
if (arg) { if (arg) {
m_affinity = arg; m_threads.mask = arg;
} }
break; break;
@ -271,6 +270,23 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg)
void xmrig::Config::parseJSON(const rapidjson::Document &doc) void xmrig::Config::parseJSON(const rapidjson::Document &doc)
{ {
const rapidjson::Value &threads = doc["threads"];
if (threads.IsArray()) {
for (const rapidjson::Value &value : threads.GetArray()) {
if (!value.IsObject()) {
continue;
}
if (value.HasMember("low_power_mode")) {
auto data = CpuThread::parse(value);
if (data.valid) {
m_threads.cpu.push_back(std::move(data));
}
}
}
}
} }
@ -279,7 +295,7 @@ bool xmrig::Config::parseInt(int key, int arg)
switch (key) { switch (key) {
case xmrig::IConfig::ThreadsKey: /* --threads */ case xmrig::IConfig::ThreadsKey: /* --threads */
if (arg >= 0 && arg < 1024) { if (arg >= 0 && arg < 1024) {
m_threadsCount = arg; m_threads.count = arg;
} }
break; break;

View file

@ -32,6 +32,7 @@
#include "common/config/CommonConfig.h" #include "common/config/CommonConfig.h"
#include "common/xmrig.h" #include "common/xmrig.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
#include "workers/CpuThread.h"
class Addr; class Addr;
@ -67,15 +68,16 @@ public:
void getJSON(rapidjson::Document &doc) const override; void getJSON(rapidjson::Document &doc) const override;
inline AesMode aesMode() const { return m_aesMode; }
inline AlgoVariant algoVariant() const { return m_algoVariant; } inline AlgoVariant algoVariant() const { return m_algoVariant; }
inline bool isDoubleHash() const { return m_doubleHash; } inline bool isDoubleHash() const { return m_doubleHash; }
inline bool isDryRun() const { return m_dryRun; } inline bool isDryRun() const { return m_dryRun; }
inline bool isHugePages() const { return m_hugePages; } inline bool isHugePages() const { return m_hugePages; }
inline const std::vector<IThread *> &threads() const { return m_threads; } inline const std::vector<IThread *> &threads() const { return m_threads.list; }
inline int printTime() const { return m_printTime; } inline int printTime() const { return m_printTime; }
inline int priority() const { return m_priority; } inline int priority() const { return m_priority; }
inline int threadsCount() const { return m_threadsCount; } inline int threadsCount() const { return m_threads.count; }
inline int64_t affinity() const { return m_affinity; } inline int64_t affinity() const { return m_threads.mask; }
static Config *load(int argc, char **argv, IWatcherListener *listener); static Config *load(int argc, char **argv, IWatcherListener *listener);
@ -94,6 +96,19 @@ private:
AlgoVariant getAlgoVariantLite() const; AlgoVariant getAlgoVariantLite() const;
# endif # endif
struct Threads
{
inline Threads() : mask(-1L), count(0) {}
int64_t mask;
size_t count;
std::vector<CpuThread::Data> cpu;
std::vector<IThread *> list;
};
AesMode m_aesMode;
AlgoVariant m_algoVariant; AlgoVariant m_algoVariant;
bool m_doubleHash; bool m_doubleHash;
bool m_dryRun; bool m_dryRun;
@ -102,9 +117,7 @@ private:
int m_maxCpuUsage; int m_maxCpuUsage;
int m_printTime; int m_printTime;
int m_priority; int m_priority;
int64_t m_affinity; Threads m_threads;
size_t m_threadsCount;
std::vector<IThread *> m_threads;
}; };

View file

@ -197,6 +197,33 @@ xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, A
} }
xmrig::CpuThread::Data xmrig::CpuThread::parse(const rapidjson::Value &object)
{
Data data;
const auto &multiway = object["low_power_mode"];
if (multiway.IsBool()) {
data.multiway = multiway.IsTrue() ? DoubleWay : SingleWay;
data.valid = true;
}
else if (multiway.IsUint()) {
data.setMultiway(multiway.GetInt());
}
if (!data.valid) {
return data;
}
const auto &affinity = object["affine_to_cpu"];
if (affinity.IsUint64()) {
data.affinity = affinity.GetInt64();
}
return data;
}
#ifndef XMRIG_NO_API #ifndef XMRIG_NO_API
rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const
{ {

View file

@ -46,6 +46,25 @@ public:
PentaWay PentaWay
}; };
struct Data
{
inline Data() : valid(false), affinity(-1L), multiway(SingleWay) {}
inline void setMultiway(int value)
{
if (value >= SingleWay && value <= PentaWay) {
multiway = static_cast<Multiway>(value);
valid = true;
}
}
bool valid;
int64_t affinity;
Multiway multiway;
};
CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch); CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch);
~CpuThread(); ~CpuThread();
@ -53,6 +72,7 @@ public:
static cn_hash_fun fn(Algo algorithm, AlgoVariant av, Variant variant); 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 *createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority);
static Data parse(const rapidjson::Value &object);
inline bool isPrefetch() const { return m_prefetch; } inline bool isPrefetch() const { return m_prefetch; }
inline bool isSoftAES() const { return m_softAES; } inline bool isSoftAES() const { return m_softAES; }