From d10527036e4181eb1718d7b0295e507824fc48ca Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 28 Jul 2019 07:46:59 +0700 Subject: [PATCH] Added "randomx" object to config. --- CMakeLists.txt | 2 ++ src/backend/cpu/CpuConfig.cpp | 3 -- src/backend/cpu/CpuConfig.h | 2 -- src/core/Miner.cpp | 7 ++-- src/core/config/Config.cpp | 26 +++++++++++++-- src/core/config/Config.h | 13 ++++++++ src/crypto/rx/RxConfig.cpp | 63 +++++++++++++++++++++++++++++++++++ src/crypto/rx/RxConfig.h | 53 +++++++++++++++++++++++++++++ 8 files changed, 159 insertions(+), 10 deletions(-) create mode 100644 src/crypto/rx/RxConfig.cpp create mode 100644 src/crypto/rx/RxConfig.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 42dcdb8d9..f9dd6fd54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,8 @@ if (WITH_RANDOMX) src/crypto/rx/RxAlgo.h src/crypto/rx/RxCache.cpp src/crypto/rx/RxCache.h + src/crypto/rx/RxConfig.cpp + src/crypto/rx/RxConfig.h src/crypto/rx/RxDataset.cpp src/crypto/rx/RxDataset.h src/crypto/rx/RxVm.cpp diff --git a/src/backend/cpu/CpuConfig.cpp b/src/backend/cpu/CpuConfig.cpp index ba66a45f6..582649efc 100644 --- a/src/backend/cpu/CpuConfig.cpp +++ b/src/backend/cpu/CpuConfig.cpp @@ -35,7 +35,6 @@ static const char *kCn = "cn"; static const char *kEnabled = "enabled"; static const char *kHugePages = "huge-pages"; static const char *kHwAes = "hw-aes"; -static const char *kInitThreads = "init-threads"; static const char *kPriority = "priority"; #ifdef XMRIG_FEATURE_ASM @@ -90,7 +89,6 @@ rapidjson::Value xmrig::CpuConfig::toJSON(rapidjson::Document &doc) const obj.AddMember(StringRef(kHugePages), m_hugePages, allocator); obj.AddMember(StringRef(kHwAes), m_aes == AES_AUTO ? Value(kNullType) : Value(m_aes == AES_HW), allocator); obj.AddMember(StringRef(kPriority), priority() != -1 ? Value(priority()) : Value(kNullType), allocator); - obj.AddMember(StringRef(kInitThreads), m_initThreads, allocator); # ifdef XMRIG_FEATURE_ASM obj.AddMember(StringRef(kAsm), m_assembly.toJSON(), allocator); @@ -126,7 +124,6 @@ void xmrig::CpuConfig::read(const rapidjson::Value &value) if (value.IsObject()) { m_enabled = Json::getBool(value, kEnabled, m_enabled); m_hugePages = Json::getBool(value, kHugePages, m_hugePages); - m_initThreads = Json::getInt(value, kInitThreads, m_initThreads); setAesMode(Json::getValue(value, kHwAes)); setPriority(Json::getInt(value, kPriority, -1)); diff --git a/src/backend/cpu/CpuConfig.h b/src/backend/cpu/CpuConfig.h index fc06bab91..5b2f3f862 100644 --- a/src/backend/cpu/CpuConfig.h +++ b/src/backend/cpu/CpuConfig.h @@ -56,7 +56,6 @@ public: inline bool isShouldSave() const { return m_shouldSave; } inline const Assembly &assembly() const { return m_assembly; } inline const Threads &threads() const { return m_threads; } - inline int initThreads() const { return m_initThreads; } inline int priority() const { return m_priority; } private: @@ -70,7 +69,6 @@ private: bool m_enabled = true; bool m_hugePages = true; bool m_shouldSave = false; - int m_initThreads = -1; int m_priority = -1; Threads m_threads; }; diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 8d0596c2e..9d977d120 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -365,8 +365,11 @@ void xmrig::Miner::setJob(const Job &job, bool donate) } # ifdef XMRIG_ALGO_RANDOMX - const CpuConfig &cpu = d_ptr->controller->config()->cpu(); - Rx::init(job, cpu.initThreads(), cpu.isHugePages(), true); + Rx::init(job, + d_ptr->controller->config()->rx().threads(), + d_ptr->controller->config()->cpu().isHugePages(), + d_ptr->controller->config()->rx().isNUMA() + ); # endif uv_rwlock_wrunlock(&d_ptr->rwlock); diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index d6336b67b..28c15234e 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -38,6 +38,14 @@ #include "rapidjson/prettywriter.h" +namespace xmrig { + +static const char *kCPU = "cpu"; +static const char *kRandomX = "randomx"; + +} + + xmrig::Config::Config() : BaseConfig() { } @@ -49,7 +57,14 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName) return false; } - m_cpu.read(reader.getValue("cpu")); + m_cpu.read(reader.getValue(kCPU)); + +# ifdef XMRIG_ALGO_RANDOMX + if (!m_rx.read(reader.getValue(kRandomX))) { + printf("upgrade\n"); + m_upgrade = true; + } +# endif return true; } @@ -68,13 +83,18 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const api.AddMember("worker-id", m_apiWorkerId.toJSON(), allocator); doc.AddMember("api", api, allocator); + doc.AddMember("http", m_http.toJSON(doc), allocator); doc.AddMember("autosave", isAutoSave(), allocator); doc.AddMember("background", isBackground(), allocator); doc.AddMember("colors", Log::colors, allocator); - doc.AddMember("cpu", m_cpu.toJSON(doc), allocator); + +# ifdef XMRIG_ALGO_RANDOMX + doc.AddMember(StringRef(kRandomX), m_rx.toJSON(doc), allocator); +# endif + + doc.AddMember(StringRef(kCPU), m_cpu.toJSON(doc), allocator); doc.AddMember("donate-level", m_pools.donateLevel(), allocator); doc.AddMember("donate-over-proxy", m_pools.proxyDonate(), allocator); - doc.AddMember("http", m_http.toJSON(doc), allocator); doc.AddMember("log-file", m_logFile.toJSON(), allocator); doc.AddMember("pools", m_pools.toJSON(doc), allocator); doc.AddMember("print-time", printTime(), allocator); diff --git a/src/core/config/Config.h b/src/core/config/Config.h index e6b5c7357..0014cb05a 100644 --- a/src/core/config/Config.h +++ b/src/core/config/Config.h @@ -34,6 +34,11 @@ #include "rapidjson/fwd.h" +#ifdef XMRIG_ALGO_RANDOMX +# include "crypto/rx/RxConfig.h" +#endif + + namespace xmrig { @@ -51,9 +56,17 @@ public: inline bool isShouldSave() const { return (m_shouldSave || m_upgrade || m_cpu.isShouldSave()) && isAutoSave(); } inline const CpuConfig &cpu() const { return m_cpu; } +# ifdef XMRIG_ALGO_RANDOMX + inline const RxConfig &rx() const { return m_rx; } +# endif + private: bool m_shouldSave = false; CpuConfig m_cpu; + +# ifdef XMRIG_ALGO_RANDOMX + RxConfig m_rx; +# endif }; diff --git a/src/crypto/rx/RxConfig.cpp b/src/crypto/rx/RxConfig.cpp new file mode 100644 index 000000000..dc543fb43 --- /dev/null +++ b/src/crypto/rx/RxConfig.cpp @@ -0,0 +1,63 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "base/io/json/Json.h" +#include "crypto/rx/RxConfig.h" +#include "rapidjson/document.h" + + +namespace xmrig { + +static const char *kInit = "init"; +static const char *kNUMA = "numa"; + +} + + +rapidjson::Value xmrig::RxConfig::toJSON(rapidjson::Document &doc) const +{ + using namespace rapidjson; + auto &allocator = doc.GetAllocator(); + + Value obj(kObjectType); + + obj.AddMember(StringRef(kInit), m_threads, allocator); + obj.AddMember(StringRef(kNUMA), m_numa, allocator); + + return obj; +} + + +bool xmrig::RxConfig::read(const rapidjson::Value &value) +{ + if (value.IsObject()) { + m_numa = Json::getBool(value, kNUMA, m_numa); + m_threads = Json::getInt(value, kInit, m_threads); + + return true; + } + + return false; +} diff --git a/src/crypto/rx/RxConfig.h b/src/crypto/rx/RxConfig.h new file mode 100644 index 000000000..e06c764cf --- /dev/null +++ b/src/crypto/rx/RxConfig.h @@ -0,0 +1,53 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_RXCONFIG_H +#define XMRIG_RXCONFIG_H + + +#include "rapidjson/fwd.h" + + +namespace xmrig { + + +class RxConfig +{ +public: + bool read(const rapidjson::Value &value); + rapidjson::Value toJSON(rapidjson::Document &doc) const; + + inline bool isNUMA() const { return m_numa; } + inline int threads() const { return m_threads; } + +private: + bool m_numa = true; + int m_threads = -1; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_RXCONFIG_H */