From 36b1523194242a7f4cf427ffb3d29d0dd547c154 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 16 Oct 2020 19:35:36 +0700 Subject: [PATCH] Code cleanup. --- src/backend/common/Workers.h | 1 - src/backend/cpu/CpuConfig.cpp | 25 +++++------ src/backend/cpu/CpuConfig.h | 23 ++++++++++ src/backend/cpu/CpuLaunchData.h | 2 +- src/core/config/Config.cpp | 13 ++---- src/core/config/ConfigTransform.cpp | 65 ++++++++++++++++------------- src/crypto/rx/RxConfig.cpp | 17 ++++---- src/crypto/rx/RxConfig.h | 13 ++++++ 8 files changed, 98 insertions(+), 61 deletions(-) diff --git a/src/backend/common/Workers.h b/src/backend/common/Workers.h index 28d9501b2..f3dd19288 100644 --- a/src/backend/common/Workers.h +++ b/src/backend/common/Workers.h @@ -29,7 +29,6 @@ #include "backend/common/Thread.h" #include "backend/cpu/CpuLaunchData.h" -#include "base/tools/Object.h" #ifdef XMRIG_FEATURE_OPENCL diff --git a/src/backend/cpu/CpuConfig.cpp b/src/backend/cpu/CpuConfig.cpp index cfc5e728b..5c70795de 100644 --- a/src/backend/cpu/CpuConfig.cpp +++ b/src/backend/cpu/CpuConfig.cpp @@ -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 diff --git a/src/backend/cpu/CpuConfig.h b/src/backend/cpu/CpuConfig.h index 00842f5ae..95defa67b 100644 --- a/src/backend/cpu/CpuConfig.h +++ b/src/backend/cpu/CpuConfig.h @@ -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; diff --git a/src/backend/cpu/CpuLaunchData.h b/src/backend/cpu/CpuLaunchData.h index 7728d1d34..86a8f97eb 100644 --- a/src/backend/cpu/CpuLaunchData.h +++ b/src/backend/cpu/CpuLaunchData.h @@ -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); } diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index 4205e5e6f..f6b19b437 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -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); diff --git a/src/core/config/ConfigTransform.cpp b/src/core/config/ConfigTransform.cpp index ca6fadcfb..0b75bf506 100644 --- a/src/core/config/ConfigTransform.cpp +++ b/src/core/config/ConfigTransform.cpp @@ -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(strtol(arg, nullptr, 10))); + return set(doc, CpuConfig::kField, CpuConfig::kMaxThreadsHint, static_cast(strtol(arg, nullptr, 10))); case IConfig::MemoryPoolKey: /* --cpu-memory-pool */ - return set(doc, kCpu, "memory-pool", static_cast(strtol(arg, nullptr, 10))); + return set(doc, CpuConfig::kField, CpuConfig::kMemoryPool, static_cast(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(strtol(arg, nullptr, 10))); + return set(doc, CpuConfig::kField, CpuConfig::kAstroBWTMaxSize, static_cast(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(strtol(arg, nullptr, 10))); + return set(doc, RxConfig::kField, RxConfig::kInit, static_cast(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(strtol(arg, nullptr, 10))); + return set(doc, RxConfig::kField, RxConfig::kWrmsr, static_cast(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; diff --git a/src/crypto/rx/RxConfig.cpp b/src/crypto/rx/RxConfig.cpp index d480d17b9..cb90892fa 100644 --- a/src/crypto/rx/RxConfig.cpp +++ b/src/crypto/rx/RxConfig.cpp @@ -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 modeNames = { "auto", "fast", "light" }; diff --git a/src/crypto/rx/RxConfig.h b/src/crypto/rx/RxConfig.h index c8d715d07..1e79d468c 100644 --- a/src/crypto/rx/RxConfig.h +++ b/src/crypto/rx/RxConfig.h @@ -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;