Improved CPU profile generation.

This commit is contained in:
XMRig 2019-10-09 12:58:11 +07:00
parent 7db7b3727d
commit 61ab47cc95
10 changed files with 190 additions and 80 deletions

View file

@ -48,6 +48,7 @@ public:
inline bool isExist(const Algorithm &algo) const { return isDisabled(algo) || m_aliases.count(algo) > 0 || has(algo.shortName()); }
inline const T &get(const Algorithm &algo, bool strict = false) const { return get(profileName(algo, strict)); }
inline void disable(const Algorithm &algo) { m_disabled.insert(algo); }
inline void setAlias(const Algorithm &algo, const char *profile) { m_aliases[algo] = profile; }
inline size_t move(const char *profile, T &&threads)
{

View file

@ -23,15 +23,15 @@
*/
#include "backend/cpu/Cpu.h"
#include "backend/cpu/CpuConfig.h"
#include "backend/cpu/CpuConfig_gen.h"
#include "backend/cpu/Cpu.h"
#include "base/io/json/Json.h"
#include "rapidjson/document.h"
namespace xmrig {
static const char *kCn = "cn";
static const char *kEnabled = "enabled";
static const char *kHugePages = "huge-pages";
static const char *kHwAes = "hw-aes";
@ -43,29 +43,7 @@ static const char *kPriority = "priority";
static const char *kAsm = "asm";
#endif
#ifdef XMRIG_ALGO_CN_GPU
static const char *kCnGPU = "cn/gpu";
#endif
#ifdef XMRIG_ALGO_CN_LITE
static const char *kCnLite = "cn-lite";
#endif
#ifdef XMRIG_ALGO_CN_HEAVY
static const char *kCnHeavy = "cn-heavy";
#endif
#ifdef XMRIG_ALGO_CN_PICO
static const char *kCnPico = "cn-pico";
#endif
#ifdef XMRIG_ALGO_RANDOMX
static const char *kRx = "rx";
static const char *kRxWOW = "rx/wow";
#endif
#ifdef XMRIG_ALGO_ARGON2
static const char *kArgon2 = "argon2";
static const char *kArgon2Impl = "argon2-impl";
#endif
@ -136,7 +114,7 @@ std::vector<xmrig::CpuLaunchData> xmrig::CpuConfig::get(const Miner *miner, cons
}
void xmrig::CpuConfig::read(const rapidjson::Value &value, uint32_t version)
void xmrig::CpuConfig::read(const rapidjson::Value &value)
{
if (value.IsObject()) {
m_enabled = Json::getBool(value, kEnabled, m_enabled);
@ -155,16 +133,14 @@ void xmrig::CpuConfig::read(const rapidjson::Value &value, uint32_t version)
m_argon2Impl = Json::getString(value, kArgon2Impl);
# endif
if (!m_threads.read(value)) {
generate();
}
m_threads.read(value);
if (version == 0) {
generateArgon2();
}
generate();
}
else if (value.IsBool() && value.IsFalse()) {
m_enabled = false;
else if (value.IsBool()) {
m_enabled = value.GetBool();
generate();
}
else {
generate();
@ -174,43 +150,20 @@ void xmrig::CpuConfig::read(const rapidjson::Value &value, uint32_t version)
void xmrig::CpuConfig::generate()
{
m_shouldSave = true;
ICpuInfo *cpu = Cpu::info();
if (!isEnabled() || m_threads.has("*")) {
return;
}
m_threads.disable(Algorithm::CN_0);
m_threads.move(kCn, cpu->threads(Algorithm::CN_0, m_limit));
size_t count = 0;
# ifdef XMRIG_ALGO_CN_GPU
m_threads.move(kCnGPU, cpu->threads(Algorithm::CN_GPU, m_limit));
# endif
count += xmrig::generate<Algorithm::CN>(m_threads, m_limit);
count += xmrig::generate<Algorithm::CN_LITE>(m_threads, m_limit);
count += xmrig::generate<Algorithm::CN_HEAVY>(m_threads, m_limit);
count += xmrig::generate<Algorithm::CN_PICO>(m_threads, m_limit);
count += xmrig::generate<Algorithm::RANDOM_X>(m_threads, m_limit);
count += xmrig::generate<Algorithm::ARGON2>(m_threads, m_limit);
# ifdef XMRIG_ALGO_CN_LITE
m_threads.disable(Algorithm::CN_LITE_0);
m_threads.move(kCnLite, cpu->threads(Algorithm::CN_LITE_1, m_limit));
# endif
# ifdef XMRIG_ALGO_CN_HEAVY
m_threads.move(kCnHeavy, cpu->threads(Algorithm::CN_HEAVY_0, m_limit));
# endif
# ifdef XMRIG_ALGO_CN_PICO
m_threads.move(kCnPico, cpu->threads(Algorithm::CN_PICO_0, m_limit));
# endif
# ifdef XMRIG_ALGO_RANDOMX
m_threads.move(kRx, cpu->threads(Algorithm::RX_0, m_limit));
m_threads.move(kRxWOW, cpu->threads(Algorithm::RX_WOW, m_limit));
# endif
generateArgon2();
}
void xmrig::CpuConfig::generateArgon2()
{
# ifdef XMRIG_ALGO_ARGON2
m_threads.move(kArgon2, Cpu::info()->threads(Algorithm::AR2_CHUKWA, m_limit));
# endif
m_shouldSave = count > 0;
}

View file

@ -50,7 +50,7 @@ public:
rapidjson::Value toJSON(rapidjson::Document &doc) const;
size_t memPoolSize() const;
std::vector<CpuLaunchData> get(const Miner *miner, const Algorithm &algorithm) const;
void read(const rapidjson::Value &value, uint32_t version);
void read(const rapidjson::Value &value);
inline bool isEnabled() const { return m_enabled; }
inline bool isHugePages() const { return m_hugePages; }
@ -62,7 +62,6 @@ public:
private:
void generate();
void generateArgon2();
void setAesMode(const rapidjson::Value &value);
void setMemoryPool(const rapidjson::Value &value);

View file

@ -0,0 +1,149 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_CPUCONFIG_GEN_H
#define XMRIG_CPUCONFIG_GEN_H
#include "backend/common/Threads.h"
#include "backend/cpu/Cpu.h"
#include "backend/cpu/CpuThreads.h"
namespace xmrig {
static inline size_t generate(const char *key, Threads<CpuThreads> &threads, const Algorithm &algorithm, uint32_t limit)
{
if (threads.isExist(algorithm) || threads.has(key)) {
return 0;
}
return threads.move(key, Cpu::info()->threads(algorithm, limit));
}
template<Algorithm::Family FAMILY>
static inline size_t generate(Threads<CpuThreads> &, uint32_t) { return 0; }
template<>
size_t inline generate<Algorithm::CN>(Threads<CpuThreads> &threads, uint32_t limit)
{
size_t count = 0;
count += generate("cn", threads, Algorithm::CN_0, limit);
if (!threads.isExist(Algorithm::CN_0)) {
threads.disable(Algorithm::CN_0);
++count;
}
# ifdef XMRIG_ALGO_CN_GPU
count += generate("cn/gpu", threads, Algorithm::CN_GPU, limit);
# endif
return count;
}
#ifdef XMRIG_ALGO_CN_LITE
template<>
size_t inline generate<Algorithm::CN_LITE>(Threads<CpuThreads> &threads, uint32_t limit)
{
size_t count = 0;
count += generate("cn-lite", threads, Algorithm::CN_LITE_1, limit);
if (!threads.isExist(Algorithm::CN_LITE_0)) {
threads.disable(Algorithm::CN_LITE_0);
++count;
}
return count;
}
#endif
#ifdef XMRIG_ALGO_CN_HEAVY
template<>
size_t inline generate<Algorithm::CN_HEAVY>(Threads<CpuThreads> &threads, uint32_t limit)
{
return generate("cn-heavy", threads, Algorithm::CN_HEAVY_0, limit);
}
#endif
#ifdef XMRIG_ALGO_CN_PICO
template<>
size_t inline generate<Algorithm::CN_PICO>(Threads<CpuThreads> &threads, uint32_t limit)
{
return generate("cn-pico", threads, Algorithm::CN_PICO_0, limit);
}
#endif
#ifdef XMRIG_ALGO_RANDOMX
template<>
size_t inline generate<Algorithm::RANDOM_X>(Threads<CpuThreads> &threads, uint32_t limit)
{
size_t count = 0;
auto wow = Cpu::info()->threads(Algorithm::RX_WOW, limit);
if (!threads.isExist(Algorithm::RX_ARQ)) {
auto arq = Cpu::info()->threads(Algorithm::RX_ARQ, limit);
if (arq == wow) {
threads.setAlias(Algorithm::RX_ARQ, "rx/wow");
++count;
}
else {
count += threads.move("rx/arq", std::move(arq));
}
}
if (!threads.isExist(Algorithm::RX_WOW)) {
count += threads.move("rx/wow", std::move(wow));
}
count += generate("rx", threads, Algorithm::RX_0, limit);
return count;
}
#endif
#ifdef XMRIG_ALGO_ARGON2
template<>
size_t inline generate<Algorithm::ARGON2>(Threads<CpuThreads> &threads, uint32_t limit)
{
return generate("argon2", threads, Algorithm::AR2_CHUKWA, limit);
}
#endif
} /* namespace xmrig */
#endif /* XMRIG_CPUCONFIG_GEN_H */

View file

@ -120,6 +120,16 @@ xmrig::CpuThreads::CpuThreads(size_t count, uint32_t intensity)
}
bool xmrig::CpuThreads::isEqual(const CpuThreads &other) const
{
if (isEmpty() && other.isEmpty()) {
return true;
}
return count() == other.count() && std::equal(m_data.begin(), m_data.end(), other.m_data.begin());
}
rapidjson::Value xmrig::CpuThreads::toJSON(rapidjson::Document &doc) const
{
using namespace rapidjson;

View file

@ -38,7 +38,7 @@ namespace xmrig {
class CpuThreads
{
public:
inline CpuThreads() {}
inline CpuThreads() = default;
inline CpuThreads(size_t count) : m_data(count) {}
CpuThreads(const rapidjson::Value &value);
@ -51,6 +51,10 @@ public:
inline void add(int64_t affinity, uint32_t intensity) { add(CpuThread(affinity, intensity)); }
inline void reserve(size_t capacity) { m_data.reserve(capacity); }
inline bool operator!=(const CpuThreads &other) const { return !isEqual(other); }
inline bool operator==(const CpuThreads &other) const { return isEqual(other); }
bool isEqual(const CpuThreads &other) const;
rapidjson::Value toJSON(rapidjson::Document &doc) const;
private:

View file

@ -2,6 +2,7 @@ set(HEADERS_BACKEND_CPU
src/backend/cpu/Cpu.h
src/backend/cpu/CpuBackend.h
src/backend/cpu/CpuConfig.h
src/backend/cpu/CpuConfig_gen.h
src/backend/cpu/CpuLaunchData.cpp
src/backend/cpu/CpuThread.h
src/backend/cpu/CpuThreads.h

View file

@ -38,7 +38,7 @@ namespace xmrig {
static inline size_t generate(const char *key, Threads<OclThreads> &threads, const Algorithm &algorithm, const std::vector<OclDevice> &devices)
{
if (threads.isExist(algorithm)) {
if (threads.isExist(algorithm) || threads.has(key)) {
return 0;
}

View file

@ -56,7 +56,6 @@ public:
inline const String &apiId() const { return m_apiId; }
inline const String &apiWorkerId() const { return m_apiWorkerId; }
inline uint32_t printTime() const { return m_printTime; }
inline uint32_t version() const { return m_version; }
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
inline const String &fileName() const override { return m_fileName; }

View file

@ -50,8 +50,7 @@
namespace xmrig {
static const char *kCPU = "cpu";
static constexpr const uint32_t kVersion = 1;
static const char *kCPU = "cpu";
#ifdef XMRIG_ALGO_RANDOMX
static const char *kRandomX = "randomx";
@ -119,10 +118,6 @@ bool xmrig::Config::isShouldSave() const
return false;
}
if (version() < kVersion) {
return true;
}
# ifdef XMRIG_FEATURE_OPENCL
if (cl().isShouldSave()) {
return true;
@ -139,7 +134,7 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
return false;
}
d_ptr->cpu.read(reader.getValue(kCPU), version());
d_ptr->cpu.read(reader.getValue(kCPU));
# ifdef XMRIG_ALGO_RANDOMX
if (!d_ptr->rx.read(reader.getValue(kRandomX))) {
@ -170,7 +165,6 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember("api", api, allocator);
doc.AddMember("http", m_http.toJSON(doc), allocator);
doc.AddMember("autosave", isAutoSave(), allocator);
doc.AddMember("version", kVersion, allocator);
doc.AddMember("background", isBackground(), allocator);
doc.AddMember("colors", Log::colors, allocator);