Conversion to NinjaRig.

This commit is contained in:
Haifa Bogdan Adnan 2019-08-26 12:38:34 +03:00
parent 84f56f0a4e
commit 2845347881
280 changed files with 18971 additions and 32469 deletions

View file

@ -27,32 +27,24 @@
#include <uv.h>
#include <inttypes.h>
#include "common/config/ConfigLoader.h"
#include "common/cpu/Cpu.h"
#include "core/Config.h"
#include "core/ConfigCreator.h"
#include "crypto/Asm.h"
#include "crypto/CryptoNight_constants.h"
#include "crypto/Argon2_constants.h"
#include "rapidjson/document.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/prettywriter.h"
#include "workers/CpuThread.h"
#include "HasherConfig.h"
static char affinity_tmp[20] = { 0 };
xmrig::Config::Config() : xmrig::CommonConfig(),
m_aesMode(AES_AUTO),
m_algoVariant(AV_AUTO),
m_assembly(ASM_AUTO),
m_hugePages(true),
m_safe(false),
m_shouldSave(false),
m_maxCpuUsage(100),
m_priority(-1)
m_priority(-1),
m_mask(-1)
{
}
@ -82,47 +74,31 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
api.AddMember("restricted", isApiRestricted(), allocator);
doc.AddMember("api", api, allocator);
# ifndef XMRIG_NO_ASM
doc.AddMember("asm", Asm::toJSON(m_assembly), allocator);
# endif
doc.AddMember("autosave", isAutoSave(), allocator);
doc.AddMember("av", algoVariant(), allocator);
doc.AddMember("background", isBackground(), allocator);
doc.AddMember("colors", isColors(), allocator);
if (affinity() != -1L) {
snprintf(affinity_tmp, sizeof(affinity_tmp) - 1, "0x%" PRIX64, affinity());
doc.AddMember("cpu-threads", cpuThreads(), allocator);
if(cpuOptimization().isNull() || cpuOptimization().isEmpty())
doc.AddMember("cpu-optimization", kNullType, allocator);
else
doc.AddMember("cpu-optimization", StringRef(cpuOptimization().data()), allocator);
if (cpuAffinity() != -1L) {
snprintf(affinity_tmp, sizeof(affinity_tmp) - 1, "0x%" PRIX64, cpuAffinity());
doc.AddMember("cpu-affinity", StringRef(affinity_tmp), allocator);
}
else {
doc.AddMember("cpu-affinity", kNullType, allocator);
}
doc.AddMember("cpu-priority", priority() != -1 ? Value(priority()) : Value(kNullType), allocator);
doc.AddMember("priority", priority() != -1 ? Value(priority()) : Value(kNullType), allocator);
doc.AddMember("donate-level", donateLevel(), allocator);
doc.AddMember("huge-pages", isHugePages(), 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);
doc.AddMember("pools", m_pools.toJSON(doc), allocator);
doc.AddMember("print-time", printTime(), allocator);
doc.AddMember("retries", m_pools.retries(), allocator);
doc.AddMember("retry-pause", m_pools.retryPause(), allocator);
doc.AddMember("safe", m_safe, allocator);
if (threadsMode() != Simple) {
Value threads(kArrayType);
for (const IThread *thread : m_threads.list) {
threads.PushBack(thread->toConfig(doc), allocator);
}
doc.AddMember("threads", threads, allocator);
}
else {
doc.AddMember("threads", threadsCount(), allocator);
}
doc.AddMember("user-agent", userAgent() ? Value(StringRef(userAgent())).Move() : Value(kNullType).Move(), allocator);
@ -131,6 +107,30 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
# endif
doc.AddMember("watch", m_watch, allocator);
Value gpuEngines(kArrayType);
for (const String gpuEngine : m_gpuEngine) {
gpuEngines.PushBack(gpuEngine.toJSON(doc), allocator);
}
doc.AddMember("use-gpu", gpuEngines, allocator);
Value gpuIntensities(kArrayType);
for (const double gpuIntensity : m_gpuIntensity) {
gpuIntensities.PushBack(gpuIntensity, allocator);
}
doc.AddMember("gpu-intensity", gpuIntensities, allocator);
Value gpuFilters(kArrayType);
for (const GPUFilter gpuFilter : m_gpuFilter) {
gpuFilters.PushBack(toGPUFilterConfig(gpuFilter, doc), allocator);
}
doc.AddMember("gpu-filter", gpuFilters, allocator);
}
@ -150,46 +150,20 @@ bool xmrig::Config::finalize()
return false;
}
if (!m_threads.cpu.empty()) {
m_threads.mode = Advanced;
const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::info()->hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT;
if(m_gpuIntensity.size() == 0)
m_gpuIntensity.push_back(50);
for (size_t i = 0; i < m_threads.cpu.size(); ++i) {
m_threads.list.push_back(CpuThread::createFromData(i, m_algorithm.algo(), m_threads.cpu[i], m_priority, softAES));
}
HasherConfig hasherConfig(m_algorithm.algo(), m_algorithm.variant(), m_priority, m_cpuThreads, m_mask, m_cpuOptimization.isNull() ? "" : m_cpuOptimization.data(), m_gpuIntensity, m_gpuFilter);
return true;
}
if(m_cpuThreads > 0)
m_hashers.push_back(hasherConfig.clone(m_hashers.size(), "CPU"));
const AlgoVariant av = getAlgoVariant();
m_threads.mode = m_threads.count ? Simple : Automatic;
if(m_gpuEngine.size() > 0)
for(String gpuEngine : m_gpuEngine)
m_hashers.push_back(hasherConfig.clone(m_hashers.size(), gpuEngine.data()));
size_t size;
if (m_algorithm.algo() == xmrig::ARGON2)
{
size = CpuThread::multiway(av) * argon2_select_memory(m_algorithm.variant());
}
else
{
size = CpuThread::multiway(av) * cn_select_memory(m_algorithm.algo()) / 1024;
}
m_shouldSave = true;
if (!m_threads.count) {
m_threads.count = Cpu::info()->optimalThreadsCount(size, m_maxCpuUsage);
}
else if (m_safe) {
const size_t count = Cpu::info()->optimalThreadsCount(size, m_maxCpuUsage);
if (m_threads.count > count) {
m_threads.count = count;
}
}
for (size_t i = 0; i < m_threads.count; ++i) {
m_threads.list.push_back(CpuThread::createFromAV(i, m_algorithm.algo(), av, m_threads.mask, m_priority, m_assembly));
}
m_shouldSave = m_threads.mode == Automatic;
return true;
}
@ -200,29 +174,6 @@ bool xmrig::Config::parseBoolean(int key, bool enable)
return false;
}
switch (key) {
case SafeKey: /* --safe */
m_safe = enable;
break;
case HugePagesKey: /* --no-huge-pages */
m_hugePages = enable;
break;
case HardwareAESKey: /* hw-aes config only */
m_aesMode = enable ? AES_HW : AES_SOFT;
break;
# ifndef XMRIG_NO_ASM
case AssemblyKey:
m_assembly = Asm::parse(enable);
break;
# endif
default:
break;
}
return true;
}
@ -234,36 +185,92 @@ bool xmrig::Config::parseString(int key, const char *arg)
}
switch (key) {
case AVKey: /* --av */
case MaxCPUUsageKey: /* --max-cpu-usage */
case CPUPriorityKey: /* --cpu-priority */
case PriorityKey: /* --cpu-priority */
return parseUint64(key, strtol(arg, nullptr, 10));
case SafeKey: /* --safe */
return parseBoolean(key, true);
case HugePagesKey: /* --no-huge-pages */
return parseBoolean(key, false);
case ThreadsKey: /* --threads */
case CPUThreadsKey: /* --threads */
if (strncmp(arg, "all", 3) == 0) {
m_threads.count = Cpu::info()->threads();
m_cpuThreads = Cpu::info()->threads();
return true;
}
return parseUint64(key, strtol(arg, nullptr, 10));
case CPUOptimizationKey:
{
String value = arg;
if(value.isEqual("REF", true))
value = "REF";
else if(value.isEqual("SSE2", true))
value = "SSE2";
else if(value.isEqual("SSSE3", true))
value = "SSSE3";
else if(value.isEqual("AVX", true))
value = "AVX";
else if(value.isEqual("AVX2", true))
value = "AVX2";
else if(value.isEqual("AVX512F", true))
value = "AVX512F";
else if(value.isEqual("NEON", true))
value = "NEON";
else {
printf("Invalid CPU optimization %s.\n", arg);
return false;
}
m_cpuOptimization = value;
return true;
}
case CPUAffinityKey: /* --cpu-affinity */
{
const char *p = strstr(arg, "0x");
return parseUint64(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10));
}
# ifndef XMRIG_NO_ASM
case AssemblyKey: /* --asm */
m_assembly = Asm::parse(arg);
break;
# endif
case UseGPUKey:
{
String strArg = arg;
std::vector<String> gpuEngines = strArg.split(',');
m_gpuEngine.clear();
for(String engine : gpuEngines) {
if(engine.isEqual("OPENCL", true))
m_gpuEngine.push_back("OPENCL");
else if(engine.isEqual("CUDA", true))
m_gpuEngine.push_back("CUDA");
else {
printf("Invalid GPU hasher %s, ignoring.\n", engine.data());
}
}
return m_gpuEngine.size() > 0;
}
case GPUIntensityKey:
{
String strArg = arg;
std::vector<String> gpuIntensities = strArg.split(',');
for (const String intensity : gpuIntensities) {
double value = strtod(intensity.data(), NULL);
if(value > 100) value = 100;
if(value < 0) value = 0;
m_gpuIntensity.push_back(value);
}
return true;
}
case GPUFilterKey:
{
String strArg = arg;
std::vector<String> gpuFilters = strArg.split(',');
for (const String filter : gpuFilters) {
std::vector<String> explodedFilter = filter.split(':');
if(explodedFilter.size() == 1)
m_gpuFilter.push_back(GPUFilter("", explodedFilter[0].data()));
else if(explodedFilter.size() >= 2)
m_gpuFilter.push_back(GPUFilter(explodedFilter[0].data(), explodedFilter[1].data()));
}
return true;
}
default:
break;
@ -282,7 +289,7 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg)
switch (key) {
case CPUAffinityKey: /* --cpu-affinity */
if (arg) {
m_threads.mask = arg;
m_mask = arg;
}
break;
@ -298,20 +305,89 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc)
{
CommonConfig::parseJSON(doc);
const rapidjson::Value &threads = doc["threads"];
const rapidjson::Value &threads = doc["cpu-threads"];
if (threads.IsArray()) {
for (const rapidjson::Value &value : threads.GetArray()) {
if (!value.IsObject()) {
if (threads.IsUint())
m_cpuThreads = threads.GetUint();
else if(threads.IsString() && strcasecmp(threads.GetString(), "all") == 0)
m_cpuThreads = Cpu::info()->threads();
const rapidjson::Value &cpuOptimization = doc["cpu-optimization"];
if (cpuOptimization.IsString()) {
String value = cpuOptimization.GetString();
if(value.isEqual("REF", true))
value = "REF";
else if(value.isEqual("SSE2", true))
value = "SSE2";
else if(value.isEqual("SSSE3", true))
value = "SSSE3";
else if(value.isEqual("AVX", true))
value = "AVX";
else if(value.isEqual("AVX2", true))
value = "AVX2";
else if(value.isEqual("AVX512F", true))
value = "AVX512F";
else if(value.isEqual("NEON", true))
value = "NEON";
else {
printf("Invalid CPU optimization %s, ignoring.\n", value.data());
value = "";
}
if(!value.isEqual(""))
m_cpuOptimization = value;
}
const rapidjson::Value &gpuEngines = doc["use-gpu"];
if(gpuEngines.IsArray()) {
m_gpuEngine.clear();
for(const rapidjson::Value &value : gpuEngines.GetArray()) {
if(!value.IsString()) {
continue;
}
if (value.HasMember("low_power_mode")) {
auto data = CpuThread::parse(value);
String engine = value.GetString();
if(engine.isEqual("OPENCL", true))
m_gpuEngine.push_back("OPENCL");
else if(engine.isEqual("CUDA", true))
m_gpuEngine.push_back("CUDA");
else {
printf("Invalid GPU hasher %s, ignoring.\n", engine.data());
}
}
}
if (data.valid) {
m_threads.cpu.push_back(std::move(data));
}
const rapidjson::Value &gpuIntensities = doc["gpu-intensity"];
if(gpuIntensities.IsArray()) {
for(const rapidjson::Value &value : gpuIntensities.GetArray()) {
if(!value.IsDouble()) {
continue;
}
double intensity = value.GetDouble();
if(intensity > 100) intensity = 100;
if(intensity < 0) intensity = 0;
m_gpuIntensity.push_back(intensity);
}
}
const rapidjson::Value &gpuFilters = doc["gpu-filter"];
if(gpuFilters.IsArray()) {
for(const rapidjson::Value &value : gpuFilters.GetArray()) {
if(!value.IsObject()) {
continue;
}
if(value.HasMember("filter")) {
auto data = parseGPUFilterConfig(value);
m_gpuFilter.push_back(data);
}
}
}
@ -321,25 +397,13 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc)
bool xmrig::Config::parseInt(int key, int arg)
{
switch (key) {
case ThreadsKey: /* --threads */
case CPUThreadsKey: /* --threads */
if (arg >= 0 && arg < 1024) {
m_threads.count = arg;
m_cpuThreads = arg;
}
break;
case AVKey: /* --av */
if (arg >= AV_AUTO && arg < AV_MAX) {
m_algoVariant = static_cast<AlgoVariant>(arg);
}
break;
case MaxCPUUsageKey: /* --max-cpu-usage */
if (m_maxCpuUsage > 0 && arg <= 100) {
m_maxCpuUsage = arg;
}
break;
case CPUPriorityKey: /* --cpu-priority */
case PriorityKey: /* --cpu-priority */
if (arg >= 0 && arg <= 5) {
m_priority = arg;
}
@ -351,39 +415,3 @@ bool xmrig::Config::parseInt(int key, int arg)
return true;
}
xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const
{
# ifndef XMRIG_NO_AEON
if (m_algorithm.algo() == xmrig::CRYPTONIGHT_LITE) {
return getAlgoVariantLite();
}
# endif
if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) {
return Cpu::info()->hasAES() ? AV_SINGLE : AV_SINGLE_SOFT;
}
if (m_safe && !Cpu::info()->hasAES() && m_algoVariant <= AV_DOUBLE) {
return static_cast<AlgoVariant>(m_algoVariant + 2);
}
return m_algoVariant;
}
#ifndef XMRIG_NO_AEON
xmrig::AlgoVariant xmrig::Config::getAlgoVariantLite() const
{
if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) {
return Cpu::info()->hasAES() ? AV_DOUBLE : AV_DOUBLE_SOFT;
}
if (m_safe && !Cpu::info()->hasAES() && m_algoVariant <= AV_DOUBLE) {
return static_cast<AlgoVariant>(m_algoVariant + 2);
}
return m_algoVariant;
}
#endif

View file

@ -28,18 +28,16 @@
#include <stdint.h>
#include <vector>
#include "common/config/CommonConfig.h"
#include "common/xmrig.h"
#include "rapidjson/fwd.h"
#include "workers/CpuThread.h"
#include "rapidjson/schema.h"
#include "HasherConfig.h"
namespace xmrig {
class ConfigLoader;
class IThread;
class IConfigListener;
class Process;
@ -58,29 +56,22 @@ class Process;
class Config : public CommonConfig
{
public:
enum ThreadsMode {
Automatic,
Simple,
Advanced
};
Config();
bool reload(const char *json);
void getJSON(rapidjson::Document &doc) const override;
inline AesMode aesMode() const { return m_aesMode; }
inline AlgoVariant algoVariant() const { return m_algoVariant; }
inline Assembly assembly() const { return m_assembly; }
inline bool isHugePages() const { return m_hugePages; }
inline bool isShouldSave() const { return m_shouldSave && isAutoSave(); }
inline const std::vector<IThread *> &threads() const { return m_threads.list; }
inline const std::vector<HasherConfig *> &hasherConfigs() const { return m_hashers; }
inline int priority() const { return m_priority; }
inline int threadsCount() const { return m_threads.list.size(); }
inline int64_t affinity() const { return m_threads.mask; }
inline ThreadsMode threadsMode() const { return m_threads.mode; }
inline int hashersCount() const { return m_hashers.size(); }
inline int cpuThreads() const { return m_cpuThreads; }
inline String cpuOptimization() const { return m_cpuOptimization; }
inline int64_t cpuAffinity() const { return m_mask; }
inline std::vector<String> gpuEngine() const { return m_gpuEngine; }
inline std::vector<double> gpuIntensity() const { return m_gpuIntensity; }
inline std::vector<GPUFilter> gpuFilter() const { return m_gpuFilter; }
static Config *load(Process *process, IConfigListener *listener);
@ -94,36 +85,42 @@ protected:
private:
bool parseInt(int key, int arg);
AlgoVariant getAlgoVariant() const;
# ifndef XMRIG_NO_AEON
AlgoVariant getAlgoVariantLite() const;
# endif
static rapidjson::Value toGPUFilterConfig(const GPUFilter &filter, rapidjson::Document &doc) {
using namespace rapidjson;
Value obj(kObjectType);
auto &allocator = doc.GetAllocator();
if(!filter.engine.empty() && filter.engine != "*")
obj.AddMember("engine", Value(filter.engine.data(), doc.GetAllocator()), allocator);
obj.AddMember("filter", Value(filter.filter.data(), doc.GetAllocator()), allocator);
return obj;
}
struct Threads
{
inline Threads() : mask(-1L), count(0), mode(Automatic) {}
static GPUFilter parseGPUFilterConfig(const rapidjson::Value &object) {
std::string engineInfo;
std::string filterInfo;
const auto &filter = object["filter"];
if (filter.IsString()) {
filterInfo = filter.GetString();
}
const auto &engine = object["engine"];
if (engine.IsString()) {
engineInfo = engine.GetString();
}
int64_t mask;
size_t count;
std::vector<CpuThread::Data> cpu;
std::vector<IThread *> list;
ThreadsMode mode;
};
AesMode m_aesMode;
AlgoVariant m_algoVariant;
Assembly m_assembly;
bool m_hugePages;
bool m_safe;
return GPUFilter(engineInfo, filterInfo);
}
bool m_shouldSave;
int m_maxCpuUsage;
int m_priority;
Threads m_threads;
int64_t m_mask;
int m_cpuThreads;
String m_cpuOptimization;
std::vector<String> m_gpuEngine;
std::vector<double> m_gpuIntensity;
std::vector<GPUFilter> m_gpuFilter;
std::vector<HasherConfig *> m_hashers;
};
} /* namespace xmrig */
#endif /* XMRIG_CONFIG_H */

View file

@ -33,7 +33,7 @@ namespace xmrig {
const static char *default_config =
R"===(
{
"algo": "cryptonight",
"algo": "argon2",
"api": {
"port": 0,
"access-token": null,
@ -42,16 +42,13 @@ R"===(
"ipv6": false,
"restricted": true
},
"asm": true,
"autosave": true,
"av": 0,
"background": false,
"colors": true,
"cpu-affinity": null,
"cpu-priority": null,
"donate-level": 5,
"huge-pages": true,
"hw-aes": null,
"log-file": null,
"max-cpu-usage": 100,
"pools": [

View file

@ -40,7 +40,7 @@
namespace xmrig {
static char const short_options[] = "a:c:kBp:Px:r:R:s:t:T:o:u:O:v:l:S";
static char const short_options[] = "a:c:Bp:Px:r:R:s:t:T:o:u:O:v:l:S";
static struct option const options[] = {
@ -51,28 +51,28 @@ static struct option const options[] = {
{ "api-id", 1, nullptr, xmrig::IConfig::ApiIdKey },
{ "api-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
{ "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
{ "av", 1, nullptr, xmrig::IConfig::AVKey },
{ "background", 0, nullptr, xmrig::IConfig::BackgroundKey },
{ "config", 1, nullptr, xmrig::IConfig::ConfigKey },
{ "cpu-threads", 1, nullptr, xmrig::IConfig::CPUThreadsKey },
{ "cpu-optimization", 1, nullptr, xmrig::IConfig::CPUOptimizationKey},
{ "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey },
{ "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey },
{ "use-gpu", 1, nullptr, xmrig::IConfig::UseGPUKey },
{ "gpu-intensity", 1, nullptr, xmrig::IConfig::GPUIntensityKey },
{ "gpu-filter", 1, nullptr, xmrig::IConfig::GPUFilterKey },
{ "priority", 1, nullptr, xmrig::IConfig::PriorityKey },
{ "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey },
{ "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey },
{ "keepalive", 0, nullptr, xmrig::IConfig::KeepAliveKey },
{ "log-file", 1, nullptr, xmrig::IConfig::LogFileKey },
{ "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey },
{ "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey },
{ "no-color", 0, nullptr, xmrig::IConfig::ColorKey },
{ "no-watch", 0, nullptr, xmrig::IConfig::WatchKey },
{ "no-huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey },
{ "variant", 1, nullptr, xmrig::IConfig::VariantKey },
{ "pass", 1, nullptr, xmrig::IConfig::PasswordKey },
{ "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey },
{ "retries", 1, nullptr, xmrig::IConfig::RetriesKey },
{ "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey },
{ "safe", 0, nullptr, xmrig::IConfig::SafeKey },
{ "syslog", 0, nullptr, xmrig::IConfig::SyslogKey },
{ "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
{ "url", 1, nullptr, xmrig::IConfig::UrlKey },
{ "user", 1, nullptr, xmrig::IConfig::UserKey },
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
@ -80,33 +80,30 @@ static struct option const options[] = {
{ "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey },
{ "tls", 0, nullptr, xmrig::IConfig::TlsKey },
{ "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey },
{ "asm", 1, nullptr, xmrig::IConfig::AssemblyKey },
{ nullptr, 0, nullptr, 0 }
};
static struct option const config_options[] = {
{ "algo", 1, nullptr, xmrig::IConfig::AlgorithmKey },
{ "av", 1, nullptr, xmrig::IConfig::AVKey },
{ "background", 0, nullptr, xmrig::IConfig::BackgroundKey },
{ "colors", 0, nullptr, xmrig::IConfig::ColorKey },
{ "cpu-threads", 1, nullptr, xmrig::IConfig::CPUThreadsKey },
{ "cpu-optimization",1, nullptr, xmrig::IConfig::CPUOptimizationKey },
{ "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey },
{ "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey },
{ "use-gpu", 1, nullptr, xmrig::IConfig::UseGPUKey },
{ "gpu-intensity", 1, nullptr, xmrig::IConfig::GPUIntensityKey},
{ "gpu-filter", 1, nullptr, xmrig::IConfig::GPUFilterKey },
{ "priority", 1, nullptr, xmrig::IConfig::PriorityKey },
{ "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey },
{ "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey },
{ "huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey },
{ "log-file", 1, nullptr, xmrig::IConfig::LogFileKey },
{ "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey },
{ "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey },
{ "retries", 1, nullptr, xmrig::IConfig::RetriesKey },
{ "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey },
{ "safe", 0, nullptr, xmrig::IConfig::SafeKey },
{ "syslog", 0, nullptr, xmrig::IConfig::SyslogKey },
{ "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
{ "watch", 0, nullptr, xmrig::IConfig::WatchKey },
{ "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey },
{ "asm", 1, nullptr, xmrig::IConfig::AssemblyKey },
{ "autosave", 0, nullptr, xmrig::IConfig::AutoSaveKey },
{ nullptr, 0, nullptr, 0 }
};

112
src/core/HasherConfig.cpp Normal file
View file

@ -0,0 +1,112 @@
/* 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/>.
*/
#include <assert.h>
#include <string>
#include <vector>
#include <cstdint>
#include "crypto/argon2_hasher/common/DLLExport.h"
#include "HasherConfig.h"
int xmrig::HasherConfig::m_gpuCardsCount = 0;
xmrig::HasherConfig::HasherConfig(xmrig::Algo algorithm, xmrig::Variant variant, int priority, int cpuThreads,
int64_t cpuAffinity, std::string cpuOptimization,
std::vector<double> &gpuIntensity, std::vector<GPUFilter> &gpuFilter) :
m_index(-1),
m_type(""),
m_algorithm(algorithm),
m_variant(variant),
m_priority(priority),
m_cpuThreads(cpuThreads),
m_cpuAffinity(cpuAffinity),
m_cpuOptimization(cpuOptimization),
m_gpuIntensity(gpuIntensity),
m_gpuFilter(gpuFilter){
}
xmrig::HasherConfig::HasherConfig(int index, std::string type, xmrig::Algo algorithm, xmrig::Variant variant, int priority, int cpuThreads,
int64_t cpuAffinity, std::string cpuOptimization,
std::vector<double> &gpuIntensity, std::vector<GPUFilter> &gpuFilter) :
m_index(index),
m_type(type),
m_algorithm(algorithm),
m_variant(variant),
m_priority(priority),
m_cpuThreads(cpuThreads),
m_cpuAffinity(cpuAffinity),
m_cpuOptimization(cpuOptimization),
m_gpuIntensity(gpuIntensity) {
for(GPUFilter filter : gpuFilter) {
if(filter.engine.empty() || filter.engine == "*" || filter.engine == type) {
m_gpuFilter.push_back(filter);
}
}
}
double xmrig::HasherConfig::getGPUIntensity(int cardIndex) {
if(cardIndex < m_gpuIntensity.size())
return m_gpuIntensity[cardIndex];
else if(m_gpuIntensity.size() > 0)
return m_gpuIntensity[0];
else
return 50;
}
int64_t xmrig::HasherConfig::getCPUAffinity(int cpuIndex) {
int64_t cpuId = -1L;
if (m_cpuAffinity != -1L) {
size_t idx = 0;
for (size_t i = 0; i < 64; i++) {
if (!(m_cpuAffinity & (1ULL << i))) {
continue;
}
if (idx == cpuIndex) {
cpuId = i;
break;
}
idx++;
}
}
return cpuId;
}
xmrig::HasherConfig *xmrig::HasherConfig::clone(int index, std::string hasherType) {
return new HasherConfig(index, hasherType, m_algorithm, m_variant, m_priority, m_cpuThreads, m_cpuAffinity, m_cpuOptimization, m_gpuIntensity, m_gpuFilter);
}
double xmrig::HasherConfig::getAverageGPUIntensity() {
double result = 0;
for(double intensity : m_gpuIntensity) result += intensity;
return result / (m_gpuIntensity.size() > 0 ? m_gpuIntensity.size() : 1);
}

98
src/core/HasherConfig.h Normal file
View file

@ -0,0 +1,98 @@
/* 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_HASHERCONFIG_H
#define XMRIG_HASHERCONFIG_H
#include "common/xmrig.h"
#include "crypto/argon2_hasher/common/common.h"
namespace xmrig {
struct GPUFilter {
GPUFilter(std::string engine, std::string filter) : engine(engine), filter(filter) {}
std::string engine;
std::string filter;
};
class DLLEXPORT HasherConfig
{
public:
HasherConfig(Algo algorithm,
Variant variant,
int priority,
int cpuThreads,
int64_t cpuAffinity,
std::string cpuOptimization,
std::vector<double> &gpuIntensity,
std::vector<GPUFilter> &gpuFilter);
HasherConfig *clone(int index, std::string hasherType);
inline size_t index() const { return m_index; }
inline std::string type() const { return m_type; }
inline Algo algorithm() const { return m_algorithm; }
inline Variant variant() const { return m_variant; }
inline int priority() const { return m_priority; }
inline int cpuThreads() const { return m_cpuThreads; }
inline std::string cpuOptimization() const { return m_cpuOptimization; }
inline std::vector<GPUFilter> &gpuFilter() { return m_gpuFilter; }
double getAverageGPUIntensity();
double getGPUIntensity(int cardIndex);
int64_t getCPUAffinity(int cpuIndex);
inline void addGPUCardsCount(int count) { m_gpuCardsCount += count; }
inline int getGPUCardsCount() { return m_gpuCardsCount; }
private:
HasherConfig(int index,
std::string type,
Algo algorithm,
Variant variant,
int priority,
int cpuThreads,
int64_t cpuAffinity,
std::string cpuOptimization,
std::vector<double> &gpuIntensity,
std::vector<GPUFilter> &gpuFilter);
const size_t m_index;
const std::string m_type;
const Algo m_algorithm;
const Variant m_variant;
const int m_priority;
const int m_cpuThreads;
const int64_t m_cpuAffinity;
const std::string m_cpuOptimization;
std::vector<double> m_gpuIntensity;
std::vector<GPUFilter> m_gpuFilter;
static int m_gpuCardsCount;
};
} /* namespace xmrig */
#endif /*XMRIG_HASHERCONFIG_H*/

View file

@ -31,7 +31,6 @@
xmrig::AdvancedCpuInfo::AdvancedCpuInfo() :
m_assembly(ASM_NONE),
m_aes(false),
m_avx2(false),
m_L2_exclusive(false),
@ -76,20 +75,13 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() :
if (data.flags[CPU_FEATURE_AES]) {
m_aes = true;
if (data.vendor == VENDOR_AMD) {
m_assembly = (data.ext_family >= 23) ? ASM_RYZEN : ASM_BULLDOZER;
}
else if (data.vendor == VENDOR_INTEL) {
m_assembly = ASM_INTEL;
}
}
m_avx2 = data.flags[CPU_FEATURE_AVX2] && data.flags[CPU_FEATURE_OSXSAVE];
}
size_t xmrig::AdvancedCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsage) const
size_t xmrig::AdvancedCpuInfo::optimalThreadsCount(size_t memSize) const
{
if (threads() == 1) {
return 1;
@ -120,9 +112,5 @@ size_t xmrig::AdvancedCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsa
count = threads();
}
if (((float) count / threads() * 100) > maxCpuUsage) {
count = (int) ceil((float) threads() * (maxCpuUsage / 100.0));
}
return count < 1 ? 1 : count;
}

View file

@ -38,9 +38,8 @@ public:
AdvancedCpuInfo();
protected:
size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const override;
size_t optimalThreadsCount(size_t memSize) const override;
inline Assembly assembly() const override { return m_assembly; }
inline bool hasAES() const override { return m_aes; }
inline bool hasAVX2() const override { return m_avx2; }
inline bool isSupported() const override { return true; }
@ -59,7 +58,6 @@ protected:
# endif
private:
Assembly m_assembly;
bool m_aes;
bool m_avx2;
bool m_L2_exclusive;

View file

@ -36,32 +36,26 @@ static char const usage[] = "\
Usage: " APP_ID " [OPTIONS]\n\
Options:\n\
-a, --algo=ALGO specify the algorithm to use\n\
cryptonight\n"
#ifndef XMRIG_NO_AEON
"\
cryptonight-lite\n"
#endif
#ifndef XMRIG_NO_SUMO
"\
cryptonight-heavy\n"
#endif
"\
chukwa\n\
chukwa/wrkz\n\
-o, --url=URL URL of mining server\n\
-O, --userpass=U:P username:password pair for mining server\n\
-u, --user=USERNAME username for mining server\n\
-p, --pass=PASSWORD password for mining server\n\
--rig-id=ID rig identifier for pool-side statistics (needs pool support)\n\
-t, --threads=N number of miner threads\n\
-v, --av=N algorithm variation, 0 auto select\n\
-t, --cpu-threads=N number of cpu miner threads - use 0 to disable\n\
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\
--cpu-optimization=REF|SSE2|SSSE3|AVX|AVX2|AVX512F|NEON force specific optimization for cpu mining\n\
--use-gpu=CUDA,OPENCL gpu engine to use, ignore this param to disable gpu support\n\
--gpu-intensity=v1,v2... percent of gpu memory to use - you can have different values for each card (default 50)\n\
--gpu-filter=<filter1>,CUDA:<filter2>,OPENCL:<filter3> gpu filters to select cards\n\
-k, --keepalive send keepalived packet for prevent timeout (needs pool support)\n\
--nicehash enable nicehash.com support\n\
--tls enable SSL/TLS support (needs pool support)\n\
--tls-fingerprint=F pool TLS certificate fingerprint, if set enable strict certificate pinning\n\
-r, --retries=N number of times to retry before switch to backup server (default: 5)\n\
-R, --retry-pause=N time to pause between retries (default: 5)\n\
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\
--no-huge-pages disable huge pages support\n\
--priority set process priority (0 idle, 2 normal to 5 highest)\n\
--no-color disable colored output\n\
--variant algorithm PoW variant\n\
--donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
@ -74,9 +68,6 @@ Options:\n\
-S, --syslog use system log for output messages\n"
# endif
"\
--max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)\n\
--safe safe adjust threads and av settings for current CPU\n\
--asm=ASM ASM code for cn/2, possible values: auto, none, intel, ryzen, bulldozer.\n\
--print-time=N print hashrate report every N seconds\n\
--api-port=N port for the miner API\n\
--api-access-token=T access token for API\n\