From f8bf48a522c3bcf6f6a3b2e3f83363cbeb3c89eb Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 15 Apr 2018 19:25:09 +0700 Subject: [PATCH] Added config only boolean option "hw-aes". --- src/core/Config.cpp | 58 +++++++++++++++----------------- src/core/ConfigLoader_platform.h | 1 + src/interfaces/IConfig.h | 1 + 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 1eb8e6e5a..f75e058ae 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -67,53 +67,49 @@ bool xmrig::Config::reload(const char *json) void xmrig::Config::getJSON(rapidjson::Document &doc) const { + using namespace rapidjson; + doc.SetObject(); auto &allocator = doc.GetAllocator(); - doc.AddMember("algo", rapidjson::StringRef(algoName()), allocator); + doc.AddMember("algo", StringRef(algoName()), allocator); - rapidjson::Value api(rapidjson::kObjectType); + Value api(kObjectType); api.AddMember("port", apiPort(), allocator); - api.AddMember("access-token", apiToken() ? rapidjson::Value(rapidjson::StringRef(apiToken())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator); - api.AddMember("worker-id", apiWorkerId() ? rapidjson::Value(rapidjson::StringRef(apiWorkerId())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator); + api.AddMember("access-token", apiToken() ? Value(StringRef(apiToken())).Move() : Value(kNullType).Move(), allocator); + api.AddMember("worker-id", apiWorkerId() ? Value(StringRef(apiWorkerId())).Move() : Value(kNullType).Move(), allocator); api.AddMember("ipv6", isApiIPv6(), allocator); api.AddMember("restricted", isApiRestricted(), allocator); doc.AddMember("api", api, allocator); doc.AddMember("av", algoVariant(), allocator); doc.AddMember("background", isBackground(), allocator); - - doc.AddMember("colors", isColors(), allocator); + doc.AddMember("colors", isColors(), allocator); if (affinity() != -1L) { snprintf(affinity_tmp, sizeof(affinity_tmp) - 1, "0x%" PRIX64, affinity()); - doc.AddMember("cpu-affinity", rapidjson::StringRef(affinity_tmp), allocator); + doc.AddMember("cpu-affinity", StringRef(affinity_tmp), allocator); } else { - doc.AddMember("cpu-affinity", rapidjson::kNullType, allocator); - } - - if (priority() != -1) { - doc.AddMember("cpu-priority", priority(), allocator); - } - else { - doc.AddMember("cpu-priority", rapidjson::kNullType, allocator); + doc.AddMember("cpu-affinity", kNullType, allocator); } + doc.AddMember("cpu-priority", priority() != -1 ? Value(priority()) : Value(kNullType), allocator); doc.AddMember("donate-level", donateLevel(), allocator); doc.AddMember("huge-pages", isHugePages(), allocator); - doc.AddMember("log-file", logFile() ? rapidjson::Value(rapidjson::StringRef(logFile())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator); + doc.AddMember("hw-aes", m_aesMode == AES_AUTO ? Value(kNullType) : Value(m_aesMode == AES_HW), allocator); + doc.AddMember("log-file", logFile() ? Value(StringRef(logFile())).Move() : Value(kNullType).Move(), allocator); doc.AddMember("max-cpu-usage", m_maxCpuUsage, allocator); - rapidjson::Value pools(rapidjson::kArrayType); + Value pools(kArrayType); for (const Pool &pool : m_pools) { - rapidjson::Value obj(rapidjson::kObjectType); + Value obj(kObjectType); - obj.AddMember("url", rapidjson::StringRef(pool.url()), allocator); - obj.AddMember("user", rapidjson::StringRef(pool.user()), allocator); - obj.AddMember("pass", rapidjson::StringRef(pool.password()), allocator); + obj.AddMember("url", StringRef(pool.url()), allocator); + obj.AddMember("user", StringRef(pool.user()), allocator); + obj.AddMember("pass", StringRef(pool.password()), allocator); if (pool.keepAlive() == 0 || pool.keepAlive() == Pool::kKeepAliveTimeout) { obj.AddMember("keepalive", pool.keepAlive() > 0, allocator); @@ -134,7 +130,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("retry-pause", retryPause(), allocator); doc.AddMember("safe", m_safe, allocator); doc.AddMember("threads", threadsCount(), allocator); - doc.AddMember("user-agent", userAgent() ? rapidjson::Value(rapidjson::StringRef(userAgent())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator); + doc.AddMember("user-agent", userAgent() ? Value(StringRef(userAgent())).Move() : Value(kNullType).Move(), allocator); # ifdef HAVE_SYSLOG_H doc.AddMember("syslog", isSyslog(), allocator); @@ -156,13 +152,11 @@ bool xmrig::Config::adjust() return false; } - if (m_aesMode == AES_AUTO) { - m_aesMode = Cpu::hasAES() ? AES_HW : AES_SOFT; - } - if (!m_threads.cpu.empty()) { + 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) { - m_threads.list.push_back(CpuThread::createFromData(i, m_algorithm, m_threads.cpu[i], m_priority, m_aesMode == AES_SOFT)); + m_threads.list.push_back(CpuThread::createFromData(i, m_algorithm, m_threads.cpu[i], m_priority, softAES)); } return true; @@ -198,18 +192,22 @@ bool xmrig::Config::parseBoolean(int key, bool enable) } switch (key) { - case xmrig::IConfig::SafeKey: /* --safe */ + case IConfig::SafeKey: /* --safe */ m_safe = enable; break; - case xmrig::IConfig::HugePagesKey: /* --no-huge-pages */ + case IConfig::HugePagesKey: /* --no-huge-pages */ m_hugePages = enable; break; - case xmrig::IConfig::DryRunKey: /* --dry-run */ + case IConfig::DryRunKey: /* --dry-run */ m_dryRun = enable; break; + case IConfig::HardwareAESKey: /* hw-aes config only */ + m_aesMode = enable ? AES_HW : AES_SOFT; + break; + default: break; } diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index a090fb99d..7e1a4baa8 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -150,6 +150,7 @@ static struct option const config_options[] = { { "syslog", 0, nullptr, xmrig::IConfig::SyslogKey }, { "threads", 1, nullptr, xmrig::IConfig::ThreadsKey }, { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, + { "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey }, { 0, 0, 0, 0 } }; diff --git a/src/interfaces/IConfig.h b/src/interfaces/IConfig.h index 89aa62177..f7433d7f4 100644 --- a/src/interfaces/IConfig.h +++ b/src/interfaces/IConfig.h @@ -74,6 +74,7 @@ public: MaxCPUUsageKey = 1004, SafeKey = 1005, ThreadsKey = 't', + HardwareAESKey = 1011, // xmrig-proxy AccessLogFileKey = 'A',