Merge from xmrig-2.8.0-rc
This commit is contained in:
commit
021cf75b10
86 changed files with 4366 additions and 1946 deletions
|
@ -28,9 +28,10 @@
|
|||
|
||||
|
||||
#include "common/config/ConfigLoader.h"
|
||||
#include "common/cpu/Cpu.h"
|
||||
#include "core/Config.h"
|
||||
#include "core/ConfigCreator.h"
|
||||
#include "Cpu.h"
|
||||
#include "crypto/Asm.h"
|
||||
#include "crypto/CryptoNight_constants.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/filewritestream.h"
|
||||
|
@ -48,8 +49,10 @@ 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(75),
|
||||
m_priority(-1)
|
||||
{
|
||||
|
@ -61,11 +64,6 @@ xmrig::Config::Config() : xmrig::CommonConfig(),
|
|||
}
|
||||
|
||||
|
||||
xmrig::Config::~Config()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Config::reload(const char *json)
|
||||
{
|
||||
return xmrig::ConfigLoader::reload(this, json);
|
||||
|
@ -85,11 +83,17 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
|||
Value api(kObjectType);
|
||||
api.AddMember("port", apiPort(), allocator);
|
||||
api.AddMember("access-token", apiToken() ? Value(StringRef(apiToken())).Move() : Value(kNullType).Move(), allocator);
|
||||
api.AddMember("id", apiId() ? Value(StringRef(apiId())).Move() : Value(kNullType).Move(), allocator);
|
||||
api.AddMember("worker-id", apiWorkerId() ? Value(StringRef(apiWorkerId())).Move() : Value(kNullType).Move(), allocator);
|
||||
api.AddMember("ipv6", isApiIPv6(), allocator);
|
||||
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);
|
||||
|
@ -121,14 +125,14 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
|||
doc.AddMember("retry-pause", retryPause(), allocator);
|
||||
doc.AddMember("safe", m_safe, allocator);
|
||||
|
||||
<<<<<<< HEAD
|
||||
// save extended "threads" based on m_threads
|
||||
Value threads(kObjectType);
|
||||
for (int a = 0; a != xmrig::Algo::ALGO_MAX; ++ a) {
|
||||
const xmrig::Algo algo = static_cast<xmrig::Algo>(a);
|
||||
Value key(xmrig::Algorithm::perfAlgoName(xmrig::Algorithm(algo).perf_algo()), allocator);
|
||||
if (threadsMode(algo) == Advanced) {
|
||||
if (threadsMode(algo) != Simple) {
|
||||
Value threads2(kArrayType);
|
||||
|
||||
for (const IThread *thread : m_threads[algo].list) {
|
||||
threads2.PushBack(thread->toConfig(doc), allocator);
|
||||
}
|
||||
|
@ -136,7 +140,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
|||
threads.AddMember(key, threads2, allocator);
|
||||
}
|
||||
else {
|
||||
threads.AddMember(key, threadsMode(algo) == Automatic ? Value(kNullType) : Value(threadsCount(algo)), allocator);
|
||||
threads.AddMember(key, threadsCount(), allocator);
|
||||
}
|
||||
}
|
||||
doc.AddMember("threads", threads, allocator);
|
||||
|
@ -184,31 +188,32 @@ bool xmrig::Config::finalize()
|
|||
const xmrig::Algo algo = static_cast<xmrig::Algo>(a);
|
||||
if (!m_threads[algo].cpu.empty()) {
|
||||
m_threads[algo].mode = Advanced;
|
||||
const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT;
|
||||
|
||||
const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::info()->hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT;
|
||||
for (size_t i = 0; i < m_threads[algo].cpu.size(); ++i) {
|
||||
m_threads[algo].list.push_back(CpuThread::createFromData(i, algo, m_threads[algo].cpu[i], m_priority, softAES));
|
||||
}
|
||||
} else {
|
||||
const AlgoVariant av = getAlgoVariant();
|
||||
m_threads[algo].mode = m_threads[algo].count ? Simple : Automatic;
|
||||
}
|
||||
|
||||
const size_t size = CpuThread::multiway(av) * cn_select_memory(algo) / 1024;
|
||||
const AlgoVariant av = getAlgoVariant();
|
||||
m_threads[algo].mode = m_threads[algo].count ? Simple : Automatic;
|
||||
|
||||
if (!m_threads[algo].count) {
|
||||
m_threads[algo].count = Cpu::optimalThreadsCount(size, m_maxCpuUsage);
|
||||
}
|
||||
else if (m_safe) {
|
||||
const size_t count = Cpu::optimalThreadsCount(size, m_maxCpuUsage);
|
||||
if (m_threads[algo].count > count) {
|
||||
m_threads[algo].count = count;
|
||||
}
|
||||
}
|
||||
const size_t size = CpuThread::multiway(av) * cn_select_memory(algo) / 1024;
|
||||
|
||||
for (size_t i = 0; i < m_threads[algo].count; ++i) {
|
||||
m_threads[algo].list.push_back(CpuThread::createFromAV(i, algo, av, m_threads[algo].mask, m_priority));
|
||||
if (!m_threads[algo].count) {
|
||||
m_threads[algo].count = Cpu::optimalThreadsCount(size, m_maxCpuUsage);
|
||||
}
|
||||
else if (m_safe) {
|
||||
const size_t count = Cpu::optimalThreadsCount(size, m_maxCpuUsage);
|
||||
if (m_threads[algo].count > count) {
|
||||
m_threads[algo].count = count;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_threads[algo].count; ++i) {
|
||||
m_threads[algo].list.push_back(CpuThread::createFromAV(i, algo, av, m_threads[algo].mask, m_priority));
|
||||
}
|
||||
|
||||
m_shouldSave ||= m_threads[algo].mode == Automatic;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -234,6 +239,12 @@ bool xmrig::Config::parseBoolean(int key, bool enable)
|
|||
m_aesMode = enable ? AES_HW : AES_SOFT;
|
||||
break;
|
||||
|
||||
# ifndef XMRIG_NO_ASM
|
||||
case AssemblyKey:
|
||||
m_assembly = Asm::parse(enable);
|
||||
break;
|
||||
# endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -262,7 +273,7 @@ bool xmrig::Config::parseString(int key, const char *arg)
|
|||
|
||||
case ThreadsKey: /* --threads */
|
||||
if (strncmp(arg, "all", 3) == 0) {
|
||||
m_threads[m_algorithm.algo()].count = Cpu::threads(); // sets default algo threads
|
||||
m_threads[m_algorithm.algo()].count = Cpu::info()->threads(); // sets default algo threads
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -274,6 +285,12 @@ bool xmrig::Config::parseString(int key, const char *arg)
|
|||
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
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -398,10 +415,10 @@ xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const
|
|||
# endif
|
||||
|
||||
if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV_SINGLE : AV_SINGLE_SOFT;
|
||||
return Cpu::info()->hasAES() ? AV_SINGLE : AV_SINGLE_SOFT;
|
||||
}
|
||||
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV_DOUBLE) {
|
||||
if (m_safe && !Cpu::info()->hasAES() && m_algoVariant <= AV_DOUBLE) {
|
||||
return static_cast<AlgoVariant>(m_algoVariant + 2);
|
||||
}
|
||||
|
||||
|
@ -413,10 +430,10 @@ xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const
|
|||
xmrig::AlgoVariant xmrig::Config::getAlgoVariantLite() const
|
||||
{
|
||||
if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV_DOUBLE : AV_DOUBLE_SOFT;
|
||||
return Cpu::info()->hasAES() ? AV_DOUBLE : AV_DOUBLE_SOFT;
|
||||
}
|
||||
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV_DOUBLE) {
|
||||
if (m_safe && !Cpu::info()->hasAES() && m_algoVariant <= AV_DOUBLE) {
|
||||
return static_cast<AlgoVariant>(m_algoVariant + 2);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#define __CONFIG_H__
|
||||
#ifndef XMRIG_CONFIG_H
|
||||
#define XMRIG_CONFIG_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -70,7 +70,6 @@ public:
|
|||
|
||||
|
||||
Config();
|
||||
~Config();
|
||||
|
||||
bool reload(const char *json);
|
||||
|
||||
|
@ -78,7 +77,9 @@ public:
|
|||
|
||||
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 int priority() const { return m_priority; }
|
||||
|
||||
// access to m_threads taking into accoun that it is now separated for each perf algo
|
||||
|
@ -133,8 +134,10 @@ private:
|
|||
|
||||
AesMode m_aesMode;
|
||||
AlgoVariant m_algoVariant;
|
||||
Assembly m_assembly;
|
||||
bool m_hugePages;
|
||||
bool m_safe;
|
||||
bool m_shouldSave;
|
||||
int m_maxCpuUsage;
|
||||
int m_priority;
|
||||
// threads config for each algo
|
||||
|
@ -148,4 +151,4 @@ extern Config* pconfig;
|
|||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIG_H__ */
|
||||
#endif /* XMRIG_CONFIG_H */
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CONFIGLOADER_PLATFORM_H__
|
||||
#define __CONFIGLOADER_PLATFORM_H__
|
||||
#ifndef XMRIG_CONFIGLOADER_PLATFORM_H
|
||||
#define XMRIG_CONFIGLOADER_PLATFORM_H
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -89,6 +89,7 @@ Options:\n\
|
|||
--api-port=N port for the miner API\n\
|
||||
--api-access-token=T access token for API\n\
|
||||
--api-worker-id=ID custom worker-id for API\n\
|
||||
--api-id=ID custom instance ID for API\n\
|
||||
--api-ipv6 enable IPv6 support for API\n\
|
||||
--api-no-restricted enable full remote access (only if API token set)\n\
|
||||
-h, --help display this help and exit\n\
|
||||
|
@ -104,6 +105,7 @@ static struct option const options[] = {
|
|||
{ "api-access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey },
|
||||
{ "api-port", 1, nullptr, xmrig::IConfig::ApiPort },
|
||||
{ "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
|
||||
{ "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 },
|
||||
|
@ -135,8 +137,11 @@ static struct option const options[] = {
|
|||
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
|
||||
{ "userpass", 1, nullptr, xmrig::IConfig::UserpassKey },
|
||||
{ "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey },
|
||||
{ "tls", 0, nullptr, xmrig::IConfig::TlsKey },
|
||||
{ "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey },
|
||||
{ "version", 0, nullptr, xmrig::IConfig::VersionKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
{ "asm", 1, nullptr, xmrig::IConfig::AssemblyKey },
|
||||
{ nullptr, 0, nullptr, 0 }
|
||||
};
|
||||
|
||||
|
||||
|
@ -162,20 +167,24 @@ static struct option const config_options[] = {
|
|||
{ "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
|
||||
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
|
||||
{ "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
{ "asm", 1, nullptr, xmrig::IConfig::AssemblyKey },
|
||||
{ "autosave", 0, nullptr, xmrig::IConfig::AutoSaveKey },
|
||||
{ nullptr, 0, nullptr, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const pool_options[] = {
|
||||
{ "url", 1, nullptr, xmrig::IConfig::UrlKey },
|
||||
{ "pass", 1, nullptr, xmrig::IConfig::PasswordKey },
|
||||
{ "user", 1, nullptr, xmrig::IConfig::UserKey },
|
||||
{ "userpass", 1, nullptr, xmrig::IConfig::UserpassKey },
|
||||
{ "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey },
|
||||
{ "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey },
|
||||
{ "variant", 1, nullptr, xmrig::IConfig::VariantKey },
|
||||
{ "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
{ "url", 1, nullptr, xmrig::IConfig::UrlKey },
|
||||
{ "pass", 1, nullptr, xmrig::IConfig::PasswordKey },
|
||||
{ "user", 1, nullptr, xmrig::IConfig::UserKey },
|
||||
{ "userpass", 1, nullptr, xmrig::IConfig::UserpassKey },
|
||||
{ "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey },
|
||||
{ "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey },
|
||||
{ "variant", 1, nullptr, xmrig::IConfig::VariantKey },
|
||||
{ "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey },
|
||||
{ "tls", 0, nullptr, xmrig::IConfig::TlsKey },
|
||||
{ "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey },
|
||||
{ nullptr, 0, nullptr, 0 }
|
||||
};
|
||||
|
||||
|
||||
|
@ -185,10 +194,11 @@ static struct option const api_options[] = {
|
|||
{ "worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
|
||||
{ "ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
|
||||
{ "restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
{ "id", 1, nullptr, xmrig::IConfig::ApiIdKey },
|
||||
{ nullptr, 0, nullptr, 0 }
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIGLOADER_PLATFORM_H__ */
|
||||
#endif /* XMRIG_CONFIGLOADER_PLATFORM_H */
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
|
||||
#include "common/config/ConfigLoader.h"
|
||||
#include "common/cpu/Cpu.h"
|
||||
#include "common/interfaces/IControllerListener.h"
|
||||
#include "common/log/ConsoleLog.h"
|
||||
#include "common/log/FileLog.h"
|
||||
|
@ -34,7 +35,6 @@
|
|||
#include "common/Platform.h"
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "Cpu.h"
|
||||
#include "net/Network.h"
|
||||
|
||||
|
||||
|
|
124
src/core/cpu/AdvancedCpuInfo.cpp
Normal file
124
src/core/cpu/AdvancedCpuInfo.cpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
/* 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 2016-2018 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 <libcpuid.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "core/cpu/AdvancedCpuInfo.h"
|
||||
|
||||
|
||||
xmrig::AdvancedCpuInfo::AdvancedCpuInfo() :
|
||||
m_assembly(ASM_NONE),
|
||||
m_aes(false),
|
||||
m_L2_exclusive(false),
|
||||
m_brand(),
|
||||
m_cores(0),
|
||||
m_L2(0),
|
||||
m_L3(0),
|
||||
m_sockets(1),
|
||||
m_threads(std::thread::hardware_concurrency())
|
||||
{
|
||||
struct cpu_raw_data_t raw = { 0 };
|
||||
struct cpu_id_t data = { 0 };
|
||||
|
||||
cpuid_get_raw_data(&raw);
|
||||
cpu_identify(&raw, &data);
|
||||
|
||||
strncpy(m_brand, data.brand_str, sizeof(m_brand));
|
||||
|
||||
m_sockets = threads() / data.num_logical_cpus;
|
||||
if (m_sockets == 0) {
|
||||
m_sockets = 1;
|
||||
}
|
||||
|
||||
m_cores = data.num_cores * m_sockets;
|
||||
m_L3 = data.l3_cache > 0 ? data.l3_cache * m_sockets : 0;
|
||||
|
||||
// Workaround for AMD CPUs https://github.com/anrieff/libcpuid/issues/97
|
||||
if (data.vendor == VENDOR_AMD && data.ext_family >= 0x15 && data.ext_family < 0x17) {
|
||||
m_L2 = data.l2_cache * (cores() / 2) * m_sockets;
|
||||
m_L2_exclusive = true;
|
||||
}
|
||||
// Workaround for Intel Pentium Dual-Core, Core Duo, Core 2 Duo, Core 2 Quad and their Xeon homologue
|
||||
// These processors have L2 cache shared by 2 cores.
|
||||
else if (data.vendor == VENDOR_INTEL && data.ext_family == 0x06 && (data.ext_model == 0x0E || data.ext_model == 0x0F || data.ext_model == 0x17)) {
|
||||
int l2_count_per_socket = cores() > 1 ? cores() / 2 : 1;
|
||||
m_L2 = data.l2_cache > 0 ? data.l2_cache * l2_count_per_socket * m_sockets : 0;
|
||||
}
|
||||
else{
|
||||
m_L2 = data.l2_cache > 0 ? data.l2_cache * cores() * m_sockets : 0;
|
||||
}
|
||||
|
||||
if (data.flags[CPU_FEATURE_AES]) {
|
||||
m_aes = true;
|
||||
|
||||
if (data.vendor == VENDOR_AMD && data.ext_family >= 23) {
|
||||
m_assembly = ASM_RYZEN;
|
||||
}
|
||||
else if (data.vendor == VENDOR_INTEL && data.ext_model >= 42) {
|
||||
m_assembly = ASM_INTEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t xmrig::AdvancedCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsage) const
|
||||
{
|
||||
if (threads() == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t cache = 0;
|
||||
if (m_L3) {
|
||||
cache = m_L2_exclusive ? (m_L2 + m_L3) : m_L3;
|
||||
}
|
||||
else {
|
||||
cache = m_L2;
|
||||
}
|
||||
|
||||
size_t count = 0;
|
||||
|
||||
if (cache) {
|
||||
count = cache / memSize;
|
||||
|
||||
if (cache % memSize >= memSize / 2) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
count = threads() / 2;
|
||||
}
|
||||
|
||||
if (count > (size_t) threads()) {
|
||||
count = threads();
|
||||
}
|
||||
|
||||
if (((float) count / threads() * 100) > maxCpuUsage) {
|
||||
count = (int) ceil((float) threads() * (maxCpuUsage / 100.0));
|
||||
}
|
||||
|
||||
return count < 1 ? 1 : count;
|
||||
}
|
75
src/core/cpu/AdvancedCpuInfo.h
Normal file
75
src/core/cpu/AdvancedCpuInfo.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/* 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 2016-2018 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_ADVANCEDCPUINFO_H
|
||||
#define XMRIG_ADVANCEDCPUINFO_H
|
||||
|
||||
|
||||
#include "common/interfaces/ICpuInfo.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class AdvancedCpuInfo : public ICpuInfo
|
||||
{
|
||||
public:
|
||||
AdvancedCpuInfo();
|
||||
|
||||
protected:
|
||||
size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const override;
|
||||
|
||||
inline Assembly assembly() const override { return m_assembly; }
|
||||
inline bool hasAES() const override { return m_aes; }
|
||||
inline bool isSupported() const override { return true; }
|
||||
inline const char *brand() const override { return m_brand; }
|
||||
inline int32_t cores() const override { return m_cores; }
|
||||
inline int32_t L2() const override { return m_L2; }
|
||||
inline int32_t L3() const override { return m_L3; }
|
||||
inline int32_t nodes() const override { return -1; }
|
||||
inline int32_t sockets() const override { return m_sockets; }
|
||||
inline int32_t threads() const override { return m_threads; }
|
||||
|
||||
# if defined(__x86_64__) || defined(_M_AMD64)
|
||||
inline bool isX64() const override { return true; }
|
||||
# else
|
||||
inline bool isX64() const override { return false; }
|
||||
# endif
|
||||
|
||||
private:
|
||||
Assembly m_assembly;
|
||||
bool m_aes;
|
||||
bool m_L2_exclusive;
|
||||
char m_brand[64];
|
||||
int32_t m_cores;
|
||||
int32_t m_L2;
|
||||
int32_t m_L3;
|
||||
int32_t m_sockets;
|
||||
int32_t m_threads;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_ADVANCEDCPUINFO_H */
|
61
src/core/cpu/Cpu.cpp
Normal file
61
src/core/cpu/Cpu.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* 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 2016-2017 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 "common/cpu/Cpu.h"
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_LIBCPUID
|
||||
# include "core/cpu/AdvancedCpuInfo.h"
|
||||
#endif
|
||||
|
||||
|
||||
static xmrig::ICpuInfo *cpuInfo = nullptr;
|
||||
|
||||
|
||||
xmrig::ICpuInfo *xmrig::Cpu::info()
|
||||
{
|
||||
assert(cpuInfo != nullptr);
|
||||
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Cpu::init()
|
||||
{
|
||||
assert(cpuInfo == nullptr);
|
||||
|
||||
cpuInfo = new AdvancedCpuInfo();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Cpu::release()
|
||||
{
|
||||
assert(cpuInfo != nullptr);
|
||||
|
||||
delete cpuInfo;
|
||||
cpuInfo = nullptr;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue