mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 12:09:22 +00:00
Finalize config changes.
This commit is contained in:
parent
f8bf48a522
commit
dba1acd302
5 changed files with 59 additions and 22 deletions
|
@ -43,12 +43,10 @@ static char affinity_tmp[20] = { 0 };
|
||||||
xmrig::Config::Config() : xmrig::CommonConfig(),
|
xmrig::Config::Config() : xmrig::CommonConfig(),
|
||||||
m_aesMode(AES_AUTO),
|
m_aesMode(AES_AUTO),
|
||||||
m_algoVariant(AV_AUTO),
|
m_algoVariant(AV_AUTO),
|
||||||
m_doubleHash(false),
|
|
||||||
m_dryRun(false),
|
m_dryRun(false),
|
||||||
m_hugePages(true),
|
m_hugePages(true),
|
||||||
m_safe(false),
|
m_safe(false),
|
||||||
m_maxCpuUsage(75),
|
m_maxCpuUsage(75),
|
||||||
m_printTime(60),
|
|
||||||
m_priority(-1)
|
m_priority(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -129,7 +127,20 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
||||||
doc.AddMember("retries", retries(), allocator);
|
doc.AddMember("retries", retries(), allocator);
|
||||||
doc.AddMember("retry-pause", retryPause(), allocator);
|
doc.AddMember("retry-pause", retryPause(), allocator);
|
||||||
doc.AddMember("safe", m_safe, allocator);
|
doc.AddMember("safe", m_safe, allocator);
|
||||||
doc.AddMember("threads", threadsCount(), allocator);
|
|
||||||
|
if (threadsMode() == Advanced) {
|
||||||
|
Value threads(kArrayType);
|
||||||
|
|
||||||
|
for (const IThread *thread : m_threads.list) {
|
||||||
|
threads.PushBack(thread->toConfig(doc), doc.GetAllocator());
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.AddMember("threads", threads, allocator);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
doc.AddMember("threads", threadsMode() == Automatic ? Value(kNullType) : Value(threadsCount()), allocator);
|
||||||
|
}
|
||||||
|
|
||||||
doc.AddMember("user-agent", userAgent() ? Value(StringRef(userAgent())).Move() : Value(kNullType).Move(), allocator);
|
doc.AddMember("user-agent", userAgent() ? Value(StringRef(userAgent())).Move() : Value(kNullType).Move(), allocator);
|
||||||
|
|
||||||
# ifdef HAVE_SYSLOG_H
|
# ifdef HAVE_SYSLOG_H
|
||||||
|
@ -153,6 +164,7 @@ bool xmrig::Config::adjust()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_threads.cpu.empty()) {
|
if (!m_threads.cpu.empty()) {
|
||||||
|
m_threads.mode = Advanced;
|
||||||
const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT;
|
const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT;
|
||||||
|
|
||||||
for (size_t i = 0; i < m_threads.cpu.size(); ++i) {
|
for (size_t i = 0; i < m_threads.cpu.size(); ++i) {
|
||||||
|
@ -163,15 +175,15 @@ bool xmrig::Config::adjust()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_algoVariant = getAlgoVariant();
|
m_algoVariant = getAlgoVariant();
|
||||||
if (m_algoVariant == AV_DOUBLE || m_algoVariant == AV_DOUBLE_SOFT) {
|
m_threads.mode = m_threads.count ? Simple : Automatic;
|
||||||
m_doubleHash = true;
|
|
||||||
}
|
const bool doubleHash = m_algoVariant == AV_DOUBLE || m_algoVariant == AV_DOUBLE_SOFT;
|
||||||
|
|
||||||
if (!m_threads.count) {
|
if (!m_threads.count) {
|
||||||
m_threads.count = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
|
m_threads.count = Cpu::optimalThreadsCount(m_algorithm, 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, doubleHash, m_maxCpuUsage);
|
||||||
if (m_threads.count > count) {
|
if (m_threads.count > count) {
|
||||||
m_threads.count = count;
|
m_threads.count = count;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,13 @@ class IWatcherListener;
|
||||||
class Config : public CommonConfig
|
class Config : public CommonConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum ThreadsMode {
|
||||||
|
Automatic,
|
||||||
|
Simple,
|
||||||
|
Advanced
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Config();
|
Config();
|
||||||
~Config();
|
~Config();
|
||||||
|
|
||||||
|
@ -70,14 +77,13 @@ public:
|
||||||
|
|
||||||
inline AesMode aesMode() const { return m_aesMode; }
|
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 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.list; }
|
inline const std::vector<IThread *> &threads() const { return m_threads.list; }
|
||||||
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_threads.list.size(); }
|
inline int threadsCount() const { return m_threads.list.size(); }
|
||||||
inline int64_t affinity() const { return m_threads.mask; }
|
inline int64_t affinity() const { return m_threads.mask; }
|
||||||
|
inline ThreadsMode threadsMode() const { return m_threads.mode; }
|
||||||
|
|
||||||
static Config *load(int argc, char **argv, IWatcherListener *listener);
|
static Config *load(int argc, char **argv, IWatcherListener *listener);
|
||||||
|
|
||||||
|
@ -99,23 +105,22 @@ private:
|
||||||
|
|
||||||
struct Threads
|
struct Threads
|
||||||
{
|
{
|
||||||
inline Threads() : mask(-1L), count(0) {}
|
inline Threads() : mask(-1L), count(0), mode(Automatic) {}
|
||||||
|
|
||||||
int64_t mask;
|
int64_t mask;
|
||||||
size_t count;
|
size_t count;
|
||||||
std::vector<CpuThread::Data> cpu;
|
std::vector<CpuThread::Data> cpu;
|
||||||
std::vector<IThread *> list;
|
std::vector<IThread *> list;
|
||||||
|
ThreadsMode mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
AesMode m_aesMode;
|
AesMode m_aesMode;
|
||||||
AlgoVariant m_algoVariant;
|
AlgoVariant m_algoVariant;
|
||||||
bool m_doubleHash;
|
|
||||||
bool m_dryRun;
|
bool m_dryRun;
|
||||||
bool m_hugePages;
|
bool m_hugePages;
|
||||||
bool m_safe;
|
bool m_safe;
|
||||||
int m_maxCpuUsage;
|
int m_maxCpuUsage;
|
||||||
int m_printTime;
|
|
||||||
int m_priority;
|
int m_priority;
|
||||||
Threads m_threads;
|
Threads m_threads;
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
virtual int priority() const = 0;
|
virtual int priority() const = 0;
|
||||||
virtual int64_t affinity() const = 0;
|
virtual int64_t affinity() const = 0;
|
||||||
virtual Multiway multiway() const = 0;
|
virtual Multiway multiway() const = 0;
|
||||||
|
virtual rapidjson::Value toConfig(rapidjson::Document &doc) const = 0;
|
||||||
virtual size_t index() const = 0;
|
virtual size_t index() const = 0;
|
||||||
virtual Type type() const = 0;
|
virtual Type type() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,9 @@ xmrig::CpuThread::Data xmrig::CpuThread::parse(const rapidjson::Value &object)
|
||||||
#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
|
||||||
{
|
{
|
||||||
rapidjson::Value obj(rapidjson::kObjectType);
|
using namespace rapidjson;
|
||||||
|
|
||||||
|
Value obj(kObjectType);
|
||||||
auto &allocator = doc.GetAllocator();
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
obj.AddMember("type", "cpu", allocator);
|
obj.AddMember("type", "cpu", allocator);
|
||||||
|
@ -259,3 +261,17 @@ rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::CpuThread::toConfig(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
|
||||||
|
Value obj(kObjectType);
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
obj.AddMember("low_power_mode", multiway(), allocator);
|
||||||
|
obj.AddMember("affine_to_cpu", affinity() == -1L ? Value(kFalseType) : Value(affinity()), allocator);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
|
@ -77,10 +77,13 @@ public:
|
||||||
inline size_t index() const override { return m_index; }
|
inline size_t index() const override { return m_index; }
|
||||||
inline Type type() const override { return CPU; }
|
inline Type type() const override { return CPU; }
|
||||||
|
|
||||||
|
protected:
|
||||||
# ifndef XMRIG_NO_API
|
# ifndef XMRIG_NO_API
|
||||||
rapidjson::Value toAPI(rapidjson::Document &doc) const override;
|
rapidjson::Value toAPI(rapidjson::Document &doc) const override;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
rapidjson::Value toConfig(rapidjson::Document &doc) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Algo m_algorithm;
|
const Algo m_algorithm;
|
||||||
const AlgoVariant m_av;
|
const AlgoVariant m_av;
|
||||||
|
|
Loading…
Reference in a new issue