Code cleanup.

This commit is contained in:
XMRig 2020-10-16 19:35:36 +07:00
parent 5155139e9a
commit 36b1523194
No known key found for this signature in database
GPG key ID: 446A53638BE94409
8 changed files with 98 additions and 61 deletions

View file

@ -29,7 +29,6 @@
#include "backend/common/Thread.h"
#include "backend/cpu/CpuLaunchData.h"
#include "base/tools/Object.h"
#ifdef XMRIG_FEATURE_OPENCL

View file

@ -34,26 +34,27 @@
namespace xmrig {
static const char *kEnabled = "enabled";
static const char *kHugePages = "huge-pages";
static const char *kHugePagesJit = "huge-pages-jit";
static const char *kHwAes = "hw-aes";
static const char *kMaxThreadsHint = "max-threads-hint";
static const char *kMemoryPool = "memory-pool";
static const char *kPriority = "priority";
static const char *kYield = "yield";
const char *CpuConfig::kEnabled = "enabled";
const char *CpuConfig::kField = "cpu";
const char *CpuConfig::kHugePages = "huge-pages";
const char *CpuConfig::kHugePagesJit = "huge-pages-jit";
const char *CpuConfig::kHwAes = "hw-aes";
const char *CpuConfig::kMaxThreadsHint = "max-threads-hint";
const char *CpuConfig::kMemoryPool = "memory-pool";
const char *CpuConfig::kPriority = "priority";
const char *CpuConfig::kYield = "yield";
#ifdef XMRIG_FEATURE_ASM
static const char *kAsm = "asm";
const char *CpuConfig::kAsm = "asm";
#endif
#ifdef XMRIG_ALGO_ARGON2
static const char *kArgon2Impl = "argon2-impl";
const char *CpuConfig::kArgon2Impl = "argon2-impl";
#endif
#ifdef XMRIG_ALGO_ASTROBWT
static const char* kAstroBWTMaxSize = "astrobwt-max-size";
static const char* kAstroBWTAVX2 = "astrobwt-avx2";
const char *CpuConfig::kAstroBWTMaxSize = "astrobwt-max-size";
const char *CpuConfig::kAstroBWTAVX2 = "astrobwt-avx2";
#endif

View file

@ -44,6 +44,29 @@ public:
AES_SOFT
};
static const char *kEnabled;
static const char *kField;
static const char *kHugePages;
static const char *kHugePagesJit;
static const char *kHwAes;
static const char *kMaxThreadsHint;
static const char *kMemoryPool;
static const char *kPriority;
static const char *kYield;
# ifdef XMRIG_FEATURE_ASM
static const char *kAsm;
# endif
# ifdef XMRIG_ALGO_ARGON2
static const char *kArgon2Impl;
# endif
# ifdef XMRIG_ALGO_ASTROBWT
static const char *kAstroBWTMaxSize;
static const char *kAstroBWTAVX2;
# endif
CpuConfig() = default;
bool isHwAES() const;

View file

@ -49,7 +49,7 @@ public:
bool isEqual(const CpuLaunchData &other) const;
CnHash::AlgoVariant av() const;
inline constexpr static Nonce::Backend backend() { return Nonce::CPU; }
inline constexpr static Nonce::Backend backend() { return Nonce::CPU; }
inline bool operator!=(const CpuLaunchData &other) const { return !isEqual(other); }
inline bool operator==(const CpuLaunchData &other) const { return isEqual(other); }

View file

@ -53,11 +53,6 @@
namespace xmrig {
static const char *kCPU = "cpu";
#ifdef XMRIG_ALGO_RANDOMX
static const char *kRandomX = "randomx";
#endif
#ifdef XMRIG_FEATURE_OPENCL
static const char *kOcl = "opencl";
@ -176,10 +171,10 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
return false;
}
d_ptr->cpu.read(reader.getValue(kCPU));
d_ptr->cpu.read(reader.getValue(CpuConfig::kField));
# ifdef XMRIG_ALGO_RANDOMX
if (!d_ptr->rx.read(reader.getValue(kRandomX))) {
if (!d_ptr->rx.read(reader.getValue(RxConfig::kField))) {
m_upgrade = true;
}
# endif
@ -220,10 +215,10 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember(StringRef(kTitle), title().toJSON(), allocator);
# ifdef XMRIG_ALGO_RANDOMX
doc.AddMember(StringRef(kRandomX), rx().toJSON(doc), allocator);
doc.AddMember(StringRef(RxConfig::kField), rx().toJSON(doc), allocator);
# endif
doc.AddMember(StringRef(kCPU), cpu().toJSON(doc), allocator);
doc.AddMember(StringRef(CpuConfig::kField), cpu().toJSON(doc), allocator);
# ifdef XMRIG_FEATURE_OPENCL
doc.AddMember(StringRef(kOcl), cl().toJSON(doc), allocator);

View file

@ -24,27 +24,28 @@
#include "base/kernel/interfaces/IConfig.h"
#include "backend/cpu/CpuConfig.h"
#include "base/net/stratum/Pool.h"
#include "base/net/stratum/Pools.h"
#include "core/config/ConfigTransform.h"
#include "crypto/cn/CnHash.h"
#ifdef XMRIG_ALGO_RANDOMX
# include "crypto/rx/RxConfig.h"
#endif
namespace xmrig
{
static const char *kAffinity = "affinity";
static const char *kAsterisk = "*";
static const char *kCpu = "cpu";
static const char *kEnabled = "enabled";
static const char *kIntensity = "intensity";
static const char *kThreads = "threads";
#ifdef XMRIG_ALGO_RANDOMX
static const char *kRandomX = "randomx";
#endif
#ifdef XMRIG_FEATURE_OPENCL
static const char *kOcl = "opencl";
#endif
@ -104,8 +105,8 @@ void xmrig::ConfigTransform::finalize(rapidjson::Document &doc)
if (m_threads) {
doc.AddMember("version", 1, allocator);
if (!doc.HasMember(kCpu)) {
doc.AddMember(StringRef(kCpu), Value(kObjectType), allocator);
if (!doc.HasMember(CpuConfig::kField)) {
doc.AddMember(StringRef(CpuConfig::kField), Value(kObjectType), allocator);
}
Value profile(kObjectType);
@ -113,7 +114,7 @@ void xmrig::ConfigTransform::finalize(rapidjson::Document &doc)
profile.AddMember(StringRef(kThreads), m_threads, allocator);
profile.AddMember(StringRef(kAffinity), m_affinity, allocator);
doc[kCpu].AddMember(StringRef(kAsterisk), profile, doc.GetAllocator());
doc[CpuConfig::kField].AddMember(StringRef(kAsterisk), profile, doc.GetAllocator());
}
# ifdef XMRIG_FEATURE_OPENCL
@ -145,55 +146,57 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
}
case IConfig::CPUMaxThreadsKey: /* --cpu-max-threads-hint */
return set(doc, kCpu, "max-threads-hint", static_cast<uint64_t>(strtol(arg, nullptr, 10)));
return set(doc, CpuConfig::kField, CpuConfig::kMaxThreadsHint, static_cast<uint64_t>(strtol(arg, nullptr, 10)));
case IConfig::MemoryPoolKey: /* --cpu-memory-pool */
return set(doc, kCpu, "memory-pool", static_cast<int64_t>(strtol(arg, nullptr, 10)));
return set(doc, CpuConfig::kField, CpuConfig::kMemoryPool, static_cast<int64_t>(strtol(arg, nullptr, 10)));
case IConfig::YieldKey: /* --cpu-no-yield */
return set(doc, kCpu, "yield", false);
return set(doc, CpuConfig::kField, CpuConfig::kYield, false);
case IConfig::Argon2ImplKey: /* --argon2-impl */
return set(doc, kCpu, "argon2-impl", arg);
return set(doc, CpuConfig::kField, CpuConfig::kArgon2Impl, arg);
# ifdef XMRIG_FEATURE_ASM
case IConfig::AssemblyKey: /* --asm */
return set(doc, kCpu, "asm", arg);
return set(doc, CpuConfig::kField, CpuConfig::kAsm, arg);
# endif
# ifdef XMRIG_ALGO_ASTROBWT
case IConfig::AstroBWTMaxSizeKey: /* --astrobwt-max-size */
return set(doc, kCpu, "astrobwt-max-size", static_cast<uint64_t>(strtol(arg, nullptr, 10)));
return set(doc, CpuConfig::kField, CpuConfig::kAstroBWTMaxSize, static_cast<uint64_t>(strtol(arg, nullptr, 10)));
case IConfig::AstroBWTAVX2Key: /* --astrobwt-avx2 */
return set(doc, kCpu, "astrobwt-avx2", true);
return set(doc, CpuConfig::kField, CpuConfig::kAstroBWTAVX2, true);
# endif
# ifdef XMRIG_ALGO_RANDOMX
case IConfig::RandomXInitKey: /* --randomx-init */
return set(doc, kRandomX, "init", static_cast<int64_t>(strtol(arg, nullptr, 10)));
return set(doc, RxConfig::kField, RxConfig::kInit, static_cast<int64_t>(strtol(arg, nullptr, 10)));
# ifdef XMRIG_FEATURE_HWLOC
case IConfig::RandomXNumaKey: /* --randomx-no-numa */
return set(doc, kRandomX, "numa", false);
return set(doc, RxConfig::kField, RxConfig::kNUMA, false);
# endif
case IConfig::RandomXModeKey: /* --randomx-mode */
return set(doc, kRandomX, "mode", arg);
return set(doc, RxConfig::kField, RxConfig::kMode, arg);
case IConfig::RandomX1GbPagesKey: /* --randomx-1gb-pages */
return set(doc, kRandomX, "1gb-pages", true);
return set(doc, RxConfig::kField, RxConfig::kOneGbPages, true);
case IConfig::RandomXWrmsrKey: /* --randomx-wrmsr */
if (arg == nullptr) {
return set(doc, kRandomX, "wrmsr", true);
return set(doc, RxConfig::kField, RxConfig::kWrmsr, true);
}
return set(doc, kRandomX, "wrmsr", static_cast<int64_t>(strtol(arg, nullptr, 10)));
return set(doc, RxConfig::kField, RxConfig::kWrmsr, static_cast<int64_t>(strtol(arg, nullptr, 10)));
case IConfig::RandomXRdmsrKey: /* --randomx-no-rdmsr */
return set(doc, kRandomX, "rdmsr", false);
return set(doc, RxConfig::kField, RxConfig::kRdmsr, false);
case IConfig::RandomXCacheQoSKey: /* --cache-qos */
return set(doc, kRandomX, "cache_qos", true);
return set(doc, RxConfig::kField, RxConfig::kCacheQoS, true);
# endif
# ifdef XMRIG_FEATURE_OPENCL
@ -248,9 +251,11 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
# ifdef XMRIG_FEATURE_BENCHMARK
case IConfig::StressKey: /* --stress */
case IConfig::BenchKey: /* --bench */
set(doc, kCpu, "huge-pages-jit", true);
set(doc, kCpu, "priority", 2);
set(doc, kCpu, "yield", false);
set(doc, CpuConfig::kField, CpuConfig::kHugePagesJit, true);
set(doc, CpuConfig::kField, CpuConfig::kPriority, 2);
set(doc, CpuConfig::kField, CpuConfig::kYield, false);
add(doc, Pools::kPools, Pool::kUser, Pool::kBenchmark);
if (key == IConfig::BenchKey) {
add(doc, Pools::kPools, Pool::kBenchmark, arg);
@ -268,10 +273,10 @@ void xmrig::ConfigTransform::transformBoolean(rapidjson::Document &doc, int key,
{
switch (key) {
case IConfig::HugePagesKey: /* --no-huge-pages */
return set(doc, kCpu, "huge-pages", enable);
return set(doc, CpuConfig::kField, CpuConfig::kHugePages, enable);
case IConfig::CPUKey: /* --no-cpu */
return set(doc, kCpu, kEnabled, enable);
return set(doc, CpuConfig::kField, kEnabled, enable);
default:
break;
@ -294,11 +299,11 @@ void xmrig::ConfigTransform::transformUint64(rapidjson::Document &doc, int key,
case IConfig::AVKey: /* --av */
m_intensity = intensity(arg);
set(doc, kCpu, "hw-aes", isHwAes(arg));
set(doc, CpuConfig::kField, CpuConfig::kHwAes, isHwAes(arg));
break;
case IConfig::CPUPriorityKey: /* --cpu-priority */
return set(doc, kCpu, "priority", arg);
return set(doc, CpuConfig::kField, CpuConfig::kPriority, arg);
default:
break;

View file

@ -46,18 +46,19 @@
namespace xmrig {
static const char *kInit = "init";
static const char *kMode = "mode";
static const char *kOneGbPages = "1gb-pages";
static const char *kRdmsr = "rdmsr";
static const char *kWrmsr = "wrmsr";
static const char *kCacheQoS = "cache_qos";
const char *RxConfig::kInit = "init";
const char *RxConfig::kField = "randomx";
const char *RxConfig::kMode = "mode";
const char *RxConfig::kOneGbPages = "1gb-pages";
const char *RxConfig::kRdmsr = "rdmsr";
const char *RxConfig::kWrmsr = "wrmsr";
const char *RxConfig::kScratchpadPrefetchMode = "scratchpad_prefetch_mode";
const char *RxConfig::kCacheQoS = "cache_qos";
#ifdef XMRIG_FEATURE_HWLOC
static const char *kNUMA = "numa";
const char *RxConfig::kNUMA = "numa";
#endif
static const char *kScratchpadPrefetchMode = "scratchpad_prefetch_mode";
static const std::array<const char *, RxConfig::ModeMax> modeNames = { "auto", "fast", "light" };

View file

@ -58,6 +58,19 @@ public:
ScratchpadPrefetchMax,
};
static const char *kCacheQoS;
static const char *kField;
static const char *kInit;
static const char *kMode;
static const char *kOneGbPages;
static const char *kRdmsr;
static const char *kScratchpadPrefetchMode;
static const char *kWrmsr;
# ifdef XMRIG_FEATURE_HWLOC
static const char *kNUMA;
# endif
bool read(const rapidjson::Value &value);
rapidjson::Value toJSON(rapidjson::Document &doc) const;