mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-23 03:05:09 +00:00
Added class CpuThreads.
This commit is contained in:
parent
0adab95ce4
commit
96fd7545d1
12 changed files with 160 additions and 58 deletions
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "backend/common/Threads.h"
|
#include "backend/common/Threads.h"
|
||||||
#include "backend/cpu/CpuThread.h"
|
#include "backend/cpu/CpuThreads.h"
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ static const char *kAsterisk = "*";
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
const std::vector<T> &xmrig::Threads<T>::get(const String &profileName) const
|
const T &xmrig::Threads<T>::get(const String &profileName) const
|
||||||
{
|
{
|
||||||
static std::vector<T> empty;
|
static T empty;
|
||||||
if (profileName.isNull() || !has(profileName)) {
|
if (profileName.isNull() || !has(profileName)) {
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
@ -56,16 +56,9 @@ size_t xmrig::Threads<T>::read(const rapidjson::Value &value)
|
||||||
|
|
||||||
for (auto &member : value.GetObject()) {
|
for (auto &member : value.GetObject()) {
|
||||||
if (member.value.IsArray()) {
|
if (member.value.IsArray()) {
|
||||||
std::vector<T> threads;
|
T threads(member.value);
|
||||||
|
|
||||||
for (auto &v : member.value.GetArray()) {
|
if (!threads.isEmpty()) {
|
||||||
T thread(v);
|
|
||||||
if (thread.isValid()) {
|
|
||||||
threads.push_back(std::move(thread));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!threads.empty()) {
|
|
||||||
move(member.name.GetString(), std::move(threads));
|
move(member.name.GetString(), std::move(threads));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,13 +131,7 @@ void xmrig::Threads<T>::toJSON(rapidjson::Value &out, rapidjson::Document &doc)
|
||||||
auto &allocator = doc.GetAllocator();
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
for (const auto &kv : m_profiles) {
|
for (const auto &kv : m_profiles) {
|
||||||
Value arr(kArrayType);
|
out.AddMember(kv.first.toJSON(), kv.second.toJSON(doc), allocator);
|
||||||
|
|
||||||
for (const T &thread : kv.second) {
|
|
||||||
arr.PushBack(thread.toJSON(doc), allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
out.AddMember(kv.first.toJSON(), arr, allocator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const Algorithm &algo : m_disabled) {
|
for (const Algorithm &algo : m_disabled) {
|
||||||
|
@ -159,6 +146,6 @@ void xmrig::Threads<T>::toJSON(rapidjson::Value &out, rapidjson::Document &doc)
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
template class Threads<CpuThread>;
|
template class Threads<CpuThreads>;
|
||||||
|
|
||||||
} // namespace xmrig
|
} // namespace xmrig
|
||||||
|
|
|
@ -45,18 +45,18 @@ public:
|
||||||
inline bool has(const char *profile) const { return m_profiles.count(profile) > 0; }
|
inline bool has(const char *profile) const { return m_profiles.count(profile) > 0; }
|
||||||
inline bool isDisabled(const Algorithm &algo) const { return m_disabled.count(algo) > 0; }
|
inline bool isDisabled(const Algorithm &algo) const { return m_disabled.count(algo) > 0; }
|
||||||
inline bool isExist(const Algorithm &algo) const { return isDisabled(algo) || m_aliases.count(algo) > 0 || has(algo.shortName()); }
|
inline bool isExist(const Algorithm &algo) const { return isDisabled(algo) || m_aliases.count(algo) > 0 || has(algo.shortName()); }
|
||||||
inline const std::vector<T> &get(const Algorithm &algo, bool strict = false) const { return get(profileName(algo, strict)); }
|
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 disable(const Algorithm &algo) { m_disabled.insert(algo); }
|
||||||
inline void move(const char *profile, std::vector<T> &&threads) { m_profiles.insert({ profile, threads }); }
|
inline void move(const char *profile, T &&threads) { m_profiles.insert({ profile, threads }); }
|
||||||
|
|
||||||
const std::vector<T> &get(const String &profileName) const;
|
const T &get(const String &profileName) const;
|
||||||
size_t read(const rapidjson::Value &value);
|
size_t read(const rapidjson::Value &value);
|
||||||
String profileName(const Algorithm &algorithm, bool strict = false) const;
|
String profileName(const Algorithm &algorithm, bool strict = false) const;
|
||||||
void toJSON(rapidjson::Value &out, rapidjson::Document &doc) const;
|
void toJSON(rapidjson::Value &out, rapidjson::Document &doc) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<Algorithm, String> m_aliases;
|
std::map<Algorithm, String> m_aliases;
|
||||||
std::map<String, std::vector<T> > m_profiles;
|
std::map<String, T> m_profiles;
|
||||||
std::set<Algorithm> m_disabled;
|
std::set<Algorithm> m_disabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
extern template class Threads<CpuThread>;
|
extern template class Threads<CpuThreads>;
|
||||||
|
|
||||||
|
|
||||||
static const char *tag = CYAN_BG_BOLD(" cpu ");
|
static const char *tag = CYAN_BG_BOLD(" cpu ");
|
||||||
|
@ -150,7 +150,7 @@ bool xmrig::CpuBackend::isEnabled() const
|
||||||
|
|
||||||
bool xmrig::CpuBackend::isEnabled(const Algorithm &algorithm) const
|
bool xmrig::CpuBackend::isEnabled(const Algorithm &algorithm) const
|
||||||
{
|
{
|
||||||
return !d_ptr->controller->config()->cpu().threads().get(algorithm).empty();
|
return !d_ptr->controller->config()->cpu().threads().get(algorithm).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ static const char *kRx = "rx";
|
||||||
static const char *kRxWOW = "rx/wow";
|
static const char *kRxWOW = "rx/wow";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern template class Threads<CpuThread>;
|
extern template class Threads<CpuThreads>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,15 +103,15 @@ rapidjson::Value xmrig::CpuConfig::toJSON(rapidjson::Document &doc) const
|
||||||
std::vector<xmrig::CpuLaunchData> xmrig::CpuConfig::get(const Miner *miner, const Algorithm &algorithm) const
|
std::vector<xmrig::CpuLaunchData> xmrig::CpuConfig::get(const Miner *miner, const Algorithm &algorithm) const
|
||||||
{
|
{
|
||||||
std::vector<CpuLaunchData> out;
|
std::vector<CpuLaunchData> out;
|
||||||
const std::vector<CpuThread> &threads = m_threads.get(algorithm);
|
const CpuThreads &threads = m_threads.get(algorithm);
|
||||||
|
|
||||||
if (threads.empty()) {
|
if (threads.isEmpty()) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.reserve(threads.size());
|
out.reserve(threads.count());
|
||||||
|
|
||||||
for (const CpuThread &thread : threads) {
|
for (const CpuThread &thread : threads.data()) {
|
||||||
out.push_back(CpuLaunchData(miner, algorithm, *this, thread));
|
out.push_back(CpuLaunchData(miner, algorithm, *this, thread));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "backend/common/Threads.h"
|
#include "backend/common/Threads.h"
|
||||||
#include "backend/cpu/CpuLaunchData.h"
|
#include "backend/cpu/CpuLaunchData.h"
|
||||||
#include "backend/cpu/CpuThread.h"
|
#include "backend/cpu/CpuThreads.h"
|
||||||
#include "crypto/common/Assembly.h"
|
#include "crypto/common/Assembly.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
inline bool isHugePages() const { return m_hugePages; }
|
inline bool isHugePages() const { return m_hugePages; }
|
||||||
inline bool isShouldSave() const { return m_shouldSave; }
|
inline bool isShouldSave() const { return m_shouldSave; }
|
||||||
inline const Assembly &assembly() const { return m_assembly; }
|
inline const Assembly &assembly() const { return m_assembly; }
|
||||||
inline const Threads<CpuThread> &threads() const { return m_threads; }
|
inline const Threads<CpuThreads> &threads() const { return m_threads; }
|
||||||
inline int priority() const { return m_priority; }
|
inline int priority() const { return m_priority; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -70,7 +70,7 @@ private:
|
||||||
bool m_hugePages = true;
|
bool m_hugePages = true;
|
||||||
bool m_shouldSave = false;
|
bool m_shouldSave = false;
|
||||||
int m_priority = -1;
|
int m_priority = -1;
|
||||||
Threads<CpuThread> m_threads;
|
Threads<CpuThreads> m_threads;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef XMRIG_CPUTHREADCONFIG_H
|
#ifndef XMRIG_CPUTHREAD_H
|
||||||
#define XMRIG_CPUTHREADCONFIG_H
|
#define XMRIG_CPUTHREAD_H
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
#include "rapidjson/fwd.h"
|
#include "rapidjson/fwd.h"
|
||||||
|
@ -58,10 +55,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef std::vector<CpuThread> CpuThreads;
|
|
||||||
|
|
||||||
|
|
||||||
} /* namespace xmrig */
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
#endif /* XMRIG_CPUTHREADCONFIG_H */
|
#endif /* XMRIG_CPUTHREAD_H */
|
||||||
|
|
54
src/backend/cpu/CpuThreads.cpp
Normal file
54
src/backend/cpu/CpuThreads.cpp
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/* 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 "backend/cpu/CpuThreads.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::CpuThreads::CpuThreads(const rapidjson::Value &value)
|
||||||
|
{
|
||||||
|
if (value.IsArray()) {
|
||||||
|
for (auto &v : value.GetArray()) {
|
||||||
|
CpuThread thread(v);
|
||||||
|
if (thread.isValid()) {
|
||||||
|
add(std::move(thread));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::CpuThreads::toJSON(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
Value array(kArrayType);
|
||||||
|
for (const CpuThread &thread : m_data) {
|
||||||
|
array.PushBack(thread.toJSON(doc), allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
63
src/backend/cpu/CpuThreads.h
Normal file
63
src/backend/cpu/CpuThreads.h
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/* 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_CPUTHREADS_H
|
||||||
|
#define XMRIG_CPUTHREADS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
#include "backend/cpu/CpuThread.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class CpuThreads
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline CpuThreads() {}
|
||||||
|
inline CpuThreads(size_t count) : m_data(count) {}
|
||||||
|
|
||||||
|
CpuThreads(const rapidjson::Value &value);
|
||||||
|
|
||||||
|
inline bool isEmpty() const { return m_data.empty(); }
|
||||||
|
inline const std::vector<CpuThread> &data() const { return m_data; }
|
||||||
|
inline size_t count() const { return m_data.size(); }
|
||||||
|
inline void add(CpuThread &&thread) { m_data.push_back(thread); }
|
||||||
|
inline void add(int64_t affinity, int intensity = 1) { add(CpuThread(intensity, affinity)); }
|
||||||
|
inline void reserve(size_t capacity) { m_data.reserve(capacity); }
|
||||||
|
|
||||||
|
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<CpuThread> m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_CPUTHREADS_H */
|
|
@ -4,6 +4,7 @@ set(HEADERS_BACKEND_CPU
|
||||||
src/backend/cpu/CpuConfig.h
|
src/backend/cpu/CpuConfig.h
|
||||||
src/backend/cpu/CpuLaunchData.cpp
|
src/backend/cpu/CpuLaunchData.cpp
|
||||||
src/backend/cpu/CpuThread.h
|
src/backend/cpu/CpuThread.h
|
||||||
|
src/backend/cpu/CpuThreads.h
|
||||||
src/backend/cpu/CpuWorker.h
|
src/backend/cpu/CpuWorker.h
|
||||||
src/backend/cpu/interfaces/ICpuInfo.h
|
src/backend/cpu/interfaces/ICpuInfo.h
|
||||||
)
|
)
|
||||||
|
@ -14,6 +15,7 @@ set(SOURCES_BACKEND_CPU
|
||||||
src/backend/cpu/CpuConfig.cpp
|
src/backend/cpu/CpuConfig.cpp
|
||||||
src/backend/cpu/CpuLaunchData.h
|
src/backend/cpu/CpuLaunchData.h
|
||||||
src/backend/cpu/CpuThread.cpp
|
src/backend/cpu/CpuThread.cpp
|
||||||
|
src/backend/cpu/CpuThreads.cpp
|
||||||
src/backend/cpu/CpuWorker.cpp
|
src/backend/cpu/CpuWorker.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#define XMRIG_CPUINFO_H
|
#define XMRIG_CPUINFO_H
|
||||||
|
|
||||||
|
|
||||||
#include "backend/cpu/CpuThread.h"
|
#include "backend/cpu/CpuThreads.h"
|
||||||
#include "crypto/common/Assembly.h"
|
#include "crypto/common/Assembly.h"
|
||||||
#include "crypto/common/Algorithm.h"
|
#include "crypto/common/Algorithm.h"
|
||||||
|
|
||||||
|
|
|
@ -182,23 +182,25 @@ const char *xmrig::BasicCpuInfo::backend() const
|
||||||
|
|
||||||
xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm) const
|
xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm) const
|
||||||
{
|
{
|
||||||
if (threads() == 1) {
|
const size_t count = std::thread::hardware_concurrency();
|
||||||
return CpuThreads(1);
|
|
||||||
|
if (count == 1) {
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef XMRIG_ALGO_CN_GPU
|
# ifdef XMRIG_ALGO_CN_GPU
|
||||||
if (algorithm == Algorithm::CN_GPU) {
|
if (algorithm == Algorithm::CN_GPU) {
|
||||||
return CpuThreads(threads());
|
return count;
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
if (algorithm.family() == Algorithm::CN_LITE || algorithm.family() == Algorithm::CN_PICO) {
|
if (algorithm.family() == Algorithm::CN_LITE || algorithm.family() == Algorithm::CN_PICO) {
|
||||||
return CpuThreads(threads());
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (algorithm.family() == Algorithm::CN_HEAVY) {
|
if (algorithm.family() == Algorithm::CN_HEAVY) {
|
||||||
return CpuThreads(std::max<size_t>(threads() / 4, 1));
|
return std::max<size_t>(count / 4, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CpuThreads(std::max<size_t>(threads() / 2, 1));
|
return std::max<size_t>(count / 2, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ xmrig::CpuThreads xmrig::HwlocCpuInfo::threads(const Algorithm &algorithm) const
|
||||||
processTopLevelCache(cache, algorithm, threads);
|
processTopLevelCache(cache, algorithm, threads);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (threads.empty()) {
|
if (threads.isEmpty()) {
|
||||||
LOG_WARN("hwloc auto configuration for algorithm \"%s\" failed.", algorithm.shortName());
|
LOG_WARN("hwloc auto configuration for algorithm \"%s\" failed.", algorithm.shortName());
|
||||||
|
|
||||||
return BasicCpuInfo::threads(algorithm);
|
return BasicCpuInfo::threads(algorithm);
|
||||||
|
@ -286,7 +286,7 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith
|
||||||
for (hwloc_obj_t core : cores) {
|
for (hwloc_obj_t core : cores) {
|
||||||
const std::vector<hwloc_obj_t> units = findByType(core, HWLOC_OBJ_PU);
|
const std::vector<hwloc_obj_t> units = findByType(core, HWLOC_OBJ_PU);
|
||||||
for (hwloc_obj_t pu : units) {
|
for (hwloc_obj_t pu : units) {
|
||||||
threads.push_back(CpuThread(1, pu->os_index));
|
threads.add(pu->os_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith
|
||||||
PUs--;
|
PUs--;
|
||||||
|
|
||||||
allocated_pu = true;
|
allocated_pu = true;
|
||||||
threads.push_back(CpuThread(1, units[pu_id]->os_index));
|
threads.add(units[pu_id]->os_index);
|
||||||
|
|
||||||
if (cacheHashes == 0) {
|
if (cacheHashes == 0) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue