Merge branch 'optimize-numa' into evo

This commit is contained in:
XMRig
2019-10-06 11:21:31 +07:00
34 changed files with 1472 additions and 431 deletions

View File

@ -4,9 +4,12 @@ if (WITH_RANDOMX)
list(APPEND HEADERS_CRYPTO
src/crypto/rx/Rx.h
src/crypto/rx/RxAlgo.h
src/crypto/rx/RxBasicStorage.h
src/crypto/rx/RxCache.h
src/crypto/rx/RxConfig.h
src/crypto/rx/RxDataset.h
src/crypto/rx/RxQueue.h
src/crypto/rx/RxSeed.h
src/crypto/rx/RxVm.h
)
@ -32,9 +35,11 @@ if (WITH_RANDOMX)
src/crypto/randomx/vm_interpreted.cpp
src/crypto/rx/Rx.cpp
src/crypto/rx/RxAlgo.cpp
src/crypto/rx/RxBasicStorage.cpp
src/crypto/rx/RxCache.cpp
src/crypto/rx/RxConfig.cpp
src/crypto/rx/RxDataset.cpp
src/crypto/rx/RxQueue.cpp
src/crypto/rx/RxVm.cpp
)
@ -63,6 +68,21 @@ if (WITH_RANDOMX)
if (CMAKE_CXX_COMPILER_ID MATCHES Clang)
set_source_files_properties(src/crypto/randomx/jit_compiler_x86.cpp PROPERTIES COMPILE_FLAGS -Wno-unused-const-variable)
endif()
if (WITH_HWLOC)
list(APPEND SOURCES_CRYPTO
src/crypto/rx/RxNUMAStorage.h
)
list(APPEND SOURCES_CRYPTO
src/crypto/rx/RxConfig_hwloc.cpp
src/crypto/rx/RxNUMAStorage.cpp
)
else()
list(APPEND SOURCES_CRYPTO
src/crypto/rx/RxConfig_basic.cpp
)
endif()
else()
remove_definitions(/DXMRIG_ALGO_RANDOMX)
endif()

View File

@ -38,6 +38,11 @@ const char *ocl_tag();
#endif
#ifdef XMRIG_ALGO_RANDOMX
const char *rx_tag();
#endif
} // namespace xmrig

View File

@ -3,6 +3,7 @@ set(HEADERS_BACKEND_COMMON
src/backend/common/Tags.h
src/backend/common/interfaces/IBackend.h
src/backend/common/interfaces/IRxListener.h
src/backend/common/interfaces/IRxStorage.h
src/backend/common/interfaces/IThread.h
src/backend/common/interfaces/IWorker.h
src/backend/common/misc/PciTopology.h

View File

@ -0,0 +1,53 @@
/* 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-2018 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_IRXSTORAGE_H
#define XMRIG_IRXSTORAGE_H
#include <cstdint>
#include <utility>
namespace xmrig {
class Job;
class RxDataset;
class RxSeed;
class IRxStorage
{
public:
virtual ~IRxStorage() = default;
virtual RxDataset *dataset(const Job &job, uint32_t nodeId) const = 0;
virtual std::pair<uint32_t, uint32_t> hugePages() const = 0;
virtual void init(const RxSeed &seed, uint32_t threads, bool hugePages) = 0;
};
} /* namespace xmrig */
#endif // XMRIG_IRXSTORAGE_H

View File

@ -111,13 +111,13 @@ public:
return;
}
LOG_INFO("%s" GREEN_BOLD(" READY") " threads %s%zu/%zu (%zu)" CLEAR " huge pages %s%zu/%zu %1.0f%%" CLEAR " memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"),
LOG_INFO("%s" GREEN_BOLD(" READY") " threads %s%zu/%zu (%zu)" CLEAR " huge pages %s%1.0f%% %zu/%zu" CLEAR " memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"),
tag,
m_errors == 0 ? CYAN_BOLD_S : YELLOW_BOLD_S,
m_started, m_threads, m_ways,
(m_hugePages == m_pages ? GREEN_BOLD_S : (m_hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
m_hugePages, m_pages,
m_hugePages == 0 ? 0.0 : static_cast<double>(m_hugePages) / m_pages * 100.0,
m_hugePages, m_pages,
memory() / 1024,
Chrono::steadyMSecs() - m_ts
);

View File

@ -69,12 +69,12 @@ xmrig::CpuWorker<N>::CpuWorker(size_t id, const CpuLaunchData &data) :
template<size_t N>
xmrig::CpuWorker<N>::~CpuWorker()
{
CnCtx::release(m_ctx, N);
delete m_memory;
# ifdef XMRIG_ALGO_RANDOMX
delete m_vm;
# endif
CnCtx::release(m_ctx, N);
delete m_memory;
}

View File

@ -46,7 +46,6 @@
namespace xmrig {
std::vector<uint32_t> HwlocCpuInfo::m_nodeIndexes;
uint32_t HwlocCpuInfo::m_features = 0;
@ -185,11 +184,11 @@ xmrig::HwlocCpuInfo::HwlocCpuInfo()
m_features |= SET_THISTHREAD_MEMBIND;
}
m_nodeIndexes.reserve(m_nodes);
m_nodeset.reserve(m_nodes);
hwloc_obj_t node = nullptr;
while ((node = hwloc_get_next_obj_by_type(m_topology, HWLOC_OBJ_NUMANODE, node)) != nullptr) {
m_nodeIndexes.emplace_back(node->os_index);
m_nodeset.emplace_back(node->os_index);
}
}
}
@ -201,6 +200,20 @@ xmrig::HwlocCpuInfo::~HwlocCpuInfo()
}
bool xmrig::HwlocCpuInfo::membind(hwloc_const_bitmap_t nodeset)
{
if (!hwloc_topology_get_support(m_topology)->membind->set_thisthread_membind) {
return false;
}
# if HWLOC_API_VERSION >= 0x20000
return hwloc_set_membind(m_topology, nodeset, HWLOC_MEMBIND_BIND, HWLOC_MEMBIND_THREAD | HWLOC_MEMBIND_BYNODESET) >= 0;
# else
return hwloc_set_membind_nodeset(m_topology, nodeset, HWLOC_MEMBIND_BIND, HWLOC_MEMBIND_THREAD) >= 0;
# endif
}
xmrig::CpuThreads xmrig::HwlocCpuInfo::threads(const Algorithm &algorithm, uint32_t limit) const
{
if (L2() == 0 && L3() == 0) {

View File

@ -30,8 +30,9 @@
#include "base/tools/Object.h"
using hwloc_obj_t = struct hwloc_obj *;
using hwloc_topology_t = struct hwloc_topology *;
using hwloc_const_bitmap_t = const struct hwloc_bitmap_s *;
using hwloc_obj_t = struct hwloc_obj *;
using hwloc_topology_t = struct hwloc_topology *;
namespace xmrig {
@ -52,7 +53,11 @@ public:
~HwlocCpuInfo() override;
static inline bool has(Feature feature) { return m_features & feature; }
static inline const std::vector<uint32_t> &nodeIndexes() { return m_nodeIndexes; }
inline const std::vector<uint32_t> &nodeset() const { return m_nodeset; }
inline hwloc_topology_t topology() const { return m_topology; }
bool membind(hwloc_const_bitmap_t nodeset);
protected:
CpuThreads threads(const Algorithm &algorithm, uint32_t limit) const override;
@ -67,7 +72,7 @@ protected:
private:
void processTopLevelCache(hwloc_obj_t obj, const Algorithm &algorithm, CpuThreads &threads, size_t limit) const;
static std::vector<uint32_t> m_nodeIndexes;
static uint32_t m_features;
char m_backend[20] = { 0 };
@ -76,6 +81,7 @@ private:
size_t m_cores = 0;
size_t m_nodes = 0;
size_t m_packages = 0;
std::vector<uint32_t> m_nodeset;
};

View File

@ -122,7 +122,7 @@ void xmrig::OclRxBaseRunner::set(const Job &job, uint8_t *blob)
m_seed = job.seed();
auto dataset = Rx::dataset(job, 0);
enqueueWriteBuffer(m_dataset, CL_TRUE, 0, dataset->size(), dataset->raw());
enqueueWriteBuffer(m_dataset, CL_TRUE, 0, RxDataset::maxSize(), dataset->raw());
}
if (job.size() < Job::kMaxBlobSize) {

View File

@ -31,10 +31,10 @@
#include <algorithm>
#include <cstring>
#include <ctime>
#include <mutex>
#include <string.h>
#include <string>
#include <time.h>
#include <uv.h>
#include <vector>
@ -42,6 +42,7 @@
#include "base/io/log/Log.h"
#include "base/kernel/interfaces/ILogBackend.h"
#include "base/tools/Chrono.h"
#include "base/tools/Object.h"
namespace xmrig {
@ -67,10 +68,10 @@ static const char *colors_map[] = {
class LogPrivate
{
public:
inline LogPrivate() :
m_buf()
{
}
XMRIG_DISABLE_COPY_MOVE(LogPrivate)
LogPrivate() = default;
inline ~LogPrivate()
@ -134,7 +135,7 @@ private:
const uint64_t ms = Chrono::currentMSecsSinceEpoch();
time_t now = ms / 1000;
tm stime;
tm stime{};
# ifdef _WIN32
localtime_s(&stime, &now);
@ -188,7 +189,7 @@ private:
}
char m_buf[4096];
char m_buf[4096]{};
std::mutex m_mutex;
std::vector<ILogBackend*> m_backends;
};

View File

@ -47,7 +47,6 @@ xmrig::ConsoleLog::ConsoleLog()
}
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
# ifdef WIN32
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
@ -68,25 +67,14 @@ xmrig::ConsoleLog::~ConsoleLog()
}
void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool colors)
void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t, bool colors)
{
if (!m_tty || Log::colors != colors) {
return;
}
# ifdef _WIN32
uv_buf_t buf = uv_buf_init(const_cast<char *>(line), static_cast<unsigned int>(size));
# else
uv_buf_t buf = uv_buf_init(const_cast<char *>(line), size);
# endif
if (!isWritable()) {
fputs(line, stdout);
fflush(stdout);
}
else {
uv_try_write(m_stream, &buf, 1);
}
fputs(line, stdout);
fflush(stdout);
}
@ -95,13 +83,3 @@ bool xmrig::ConsoleLog::isSupported() const
const uv_handle_type type = uv_guess_handle(1);
return type == UV_TTY || type == UV_NAMED_PIPE;
}
bool xmrig::ConsoleLog::isWritable() const
{
if (!m_stream || uv_is_writable(m_stream) != 1) {
return false;
}
return isSupported();
}

View File

@ -51,10 +51,8 @@ protected:
private:
bool isSupported() const;
bool isWritable() const;
uv_stream_t *m_stream = nullptr;
uv_tty_t *m_tty = nullptr;
uv_tty_t *m_tty = nullptr;
};

View File

@ -72,12 +72,8 @@ class MinerPrivate
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(MinerPrivate)
inline MinerPrivate(Controller *controller) : controller(controller)
{
# ifdef XMRIG_ALGO_RANDOMX
Rx::init();
# endif
}
inline MinerPrivate(Controller *controller) : controller(controller) {}
inline ~MinerPrivate()
@ -232,9 +228,9 @@ public:
# ifdef XMRIG_ALGO_RANDOMX
bool initRX(IRxListener *listener)
inline bool initRX()
{
return Rx::init(job, controller->config()->rx().threads(), controller->config()->cpu().isHugePages(), controller->config()->rx().isNUMA(), listener);
return Rx::init(job, controller->config()->rx(), controller->config()->cpu().isHugePages());
}
# endif
@ -261,6 +257,10 @@ public:
xmrig::Miner::Miner(Controller *controller)
: d_ptr(new MinerPrivate(controller))
{
# ifdef XMRIG_ALGO_RANDOMX
Rx::init(this);
# endif
controller->addListener(this);
# ifdef XMRIG_FEATURE_API
@ -402,7 +402,7 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
}
# ifdef XMRIG_ALGO_RANDOMX
const bool ready = d_ptr->initRX(this);
const bool ready = d_ptr->initRX();
# else
constexpr const bool ready = true;
# endif

View File

@ -33,6 +33,7 @@
#include "base/api/interfaces/IApiListener.h"
#include "base/kernel/interfaces/IBaseListener.h"
#include "base/kernel/interfaces/ITimerListener.h"
#include "base/tools/Object.h"
#include "crypto/common/Algorithm.h"
@ -48,6 +49,8 @@ class IBackend;
class Miner : public ITimerListener, public IBaseListener, public IApiListener, public IRxListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Miner)
Miner(Controller *controller);
~Miner() override;

View File

@ -23,9 +23,9 @@
*/
#include <algorithm>
#include <string.h>
#include <cstring>
#include <uv.h>
#include <inttypes.h>
#include <cinttypes>
#include "backend/cpu/Cpu.h"
@ -79,7 +79,7 @@ public:
}
xmrig::Config::Config() : BaseConfig(),
xmrig::Config::Config() :
d_ptr(new ConfigPrivate())
{
}

View File

@ -28,57 +28,34 @@
#ifdef XMRIG_FEATURE_HWLOC
# include <hwloc.h>
# include "backend/cpu/platform/HwlocCpuInfo.h"
#
# if HWLOC_API_VERSION < 0x00010b00
# define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE
# endif
#endif
#include "base/io/log/Log.h"
#include "crypto/common/VirtualMemory.h"
#include "backend/cpu/Cpu.h"
#include "base/io/log/Log.h"
#include <cinttypes>
uint32_t xmrig::VirtualMemory::bindToNUMANode(int64_t affinity)
{
# ifdef XMRIG_FEATURE_HWLOC
if (affinity < 0 || !HwlocCpuInfo::has(HwlocCpuInfo::SET_THISTHREAD_MEMBIND)) {
if (affinity < 0 || Cpu::info()->nodes() < 2) {
return 0;
}
hwloc_topology_t topology;
hwloc_topology_init(&topology);
hwloc_topology_load(topology);
auto cpu = static_cast<HwlocCpuInfo *>(Cpu::info());
hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(cpu->topology(), static_cast<unsigned>(affinity));
const unsigned puId = static_cast<unsigned>(affinity);
if (pu == nullptr || !cpu->membind(pu->nodeset)) {
LOG_WARN("CPU #%02" PRId64 " warning: \"can't bind memory\"", affinity);
hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(topology, puId);
# if HWLOC_API_VERSION >= 0x20000
if (pu == nullptr || hwloc_set_membind(topology, pu->nodeset, HWLOC_MEMBIND_BIND, HWLOC_MEMBIND_THREAD | HWLOC_MEMBIND_BYNODESET) < 0) {
# else
if (pu == nullptr || hwloc_set_membind_nodeset(topology, pu->nodeset, HWLOC_MEMBIND_BIND, HWLOC_MEMBIND_THREAD) < 0) {
# endif
LOG_WARN("CPU #%02u warning: \"can't bind memory\"", puId);
return 0;
}
uint32_t nodeId = 0;
if (pu) {
hwloc_obj_t node = nullptr;
while ((node = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, node)) != nullptr) {
if (hwloc_bitmap_intersects(node->cpuset, pu->cpuset)) {
nodeId = node->os_index;
break;
}
}
}
hwloc_topology_destroy(topology);
return nodeId;
return hwloc_bitmap_first(pu->nodeset);
# else
return 0;
# endif

File diff suppressed because it is too large Load Diff

View File

@ -39,18 +39,19 @@ namespace xmrig
class Algorithm;
class IRxListener;
class Job;
class RxConfig;
class RxDataset;
class Rx
{
public:
static bool init(const Job &job, int initThreads, bool hugePages, bool numa, IRxListener *listener);
static bool init(const Job &job, const RxConfig &config, bool hugePages);
static bool isReady(const Job &job);
static RxDataset *dataset(const Job &job, uint32_t nodeId);
static std::pair<unsigned, unsigned> hugePages();
static std::pair<uint32_t, uint32_t> hugePages();
static void destroy();
static void init();
static void init(IRxListener *listener);
};

View File

@ -0,0 +1,169 @@
/* 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-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 tevador <tevador@gmail.com>
* 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 "crypto/rx/RxBasicStorage.h"
#include "backend/common/Tags.h"
#include "base/io/log/Log.h"
#include "base/tools/Chrono.h"
#include "base/tools/Object.h"
#include "crypto/rx/RxAlgo.h"
#include "crypto/rx/RxCache.h"
#include "crypto/rx/RxDataset.h"
#include "crypto/rx/RxSeed.h"
namespace xmrig {
constexpr size_t oneMiB = 1024 * 1024;
class RxBasicStoragePrivate
{
public:
XMRIG_DISABLE_COPY_MOVE(RxBasicStoragePrivate)
inline RxBasicStoragePrivate() = default;
inline ~RxBasicStoragePrivate()
{
delete m_dataset;
}
inline bool isReady(const Job &job) const { return m_ready && m_seed == job; }
inline RxDataset *dataset() const { return m_dataset; }
inline void setSeed(const RxSeed &seed)
{
m_ready = false;
if (m_seed.algorithm() != seed.algorithm()) {
RxAlgo::apply(seed.algorithm());
}
m_seed = seed;
}
inline void createDataset(bool hugePages)
{
const uint64_t ts = Chrono::steadyMSecs();
m_dataset = new RxDataset(hugePages, true);
printAllocStatus(ts);
}
inline void initDataset(uint32_t threads)
{
const uint64_t ts = Chrono::steadyMSecs();
m_dataset->init(m_seed.data(), threads);
LOG_INFO("%s" GREEN_BOLD("dataset ready") BLACK_BOLD(" (%" PRIu64 " ms)"), rx_tag(), Chrono::steadyMSecs() - ts);
m_ready = true;
}
private:
void printAllocStatus(uint64_t ts)
{
if (m_dataset->get() != nullptr) {
const auto pages = m_dataset->hugePages();
const double percent = pages.first == 0 ? 0.0 : static_cast<double>(pages.first) / pages.second * 100.0;
LOG_INFO("%s" GREEN_BOLD("allocated") CYAN_BOLD(" %zu MB") BLACK_BOLD(" (%zu+%zu)") " huge pages %s%1.0f%% %u/%u" CLEAR " %sJIT" BLACK_BOLD(" (%" PRIu64 " ms)"),
rx_tag(),
m_dataset->size() / oneMiB,
RxDataset::maxSize() / oneMiB,
RxCache::maxSize() / oneMiB,
(pages.first == pages.second ? GREEN_BOLD_S : (pages.first == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
percent,
pages.first,
pages.second,
m_dataset->cache()->isJIT() ? GREEN_BOLD_S "+" : RED_BOLD_S "-",
Chrono::steadyMSecs() - ts
);
}
else {
LOG_WARN(CLEAR "%s" YELLOW_BOLD_S "failed to allocate RandomX dataset, switching to slow mode" BLACK_BOLD(" (%" PRIu64 " ms)"), rx_tag(), Chrono::steadyMSecs() - ts);
}
}
bool m_ready = false;
RxDataset *m_dataset = nullptr;
RxSeed m_seed;
};
} // namespace xmrig
xmrig::RxBasicStorage::RxBasicStorage() :
d_ptr(new RxBasicStoragePrivate())
{
}
xmrig::RxBasicStorage::~RxBasicStorage()
{
delete d_ptr;
}
xmrig::RxDataset *xmrig::RxBasicStorage::dataset(const Job &job, uint32_t) const
{
if (!d_ptr->isReady(job)) {
return nullptr;
}
return d_ptr->dataset();
}
std::pair<uint32_t, uint32_t> xmrig::RxBasicStorage::hugePages() const
{
if (!d_ptr->dataset()) {
return { 0u, 0u };
}
return d_ptr->dataset()->hugePages();
}
void xmrig::RxBasicStorage::init(const RxSeed &seed, uint32_t threads, bool hugePages)
{
d_ptr->setSeed(seed);
if (!d_ptr->dataset()) {
d_ptr->createDataset(hugePages);
}
d_ptr->initDataset(threads);
}

View 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-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 tevador <tevador@gmail.com>
* 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_RX_BASICSTORAGE_H
#define XMRIG_RX_BASICSTORAGE_H
#include "backend/common/interfaces/IRxStorage.h"
#include "base/tools/Object.h"
namespace xmrig
{
class RxBasicStoragePrivate;
class RxBasicStorage : public IRxStorage
{
public:
XMRIG_DISABLE_COPY_MOVE(RxBasicStorage);
RxBasicStorage();
~RxBasicStorage() override;
protected:
RxDataset *dataset(const Job &job, uint32_t nodeId) const override;
std::pair<uint32_t, uint32_t> hugePages() const override;
void init(const RxSeed &seed, uint32_t threads, bool hugePages) override;
private:
RxBasicStoragePrivate *d_ptr;
};
} /* namespace xmrig */
#endif /* XMRIG_RX_BASICSTORAGE_H */

View File

@ -25,8 +25,9 @@
*/
#include "crypto/randomx/randomx.h"
#include "crypto/rx/RxCache.h"
#include "crypto/common/VirtualMemory.h"
#include "crypto/randomx/randomx.h"
static_assert(RANDOMX_FLAG_JIT == 8, "RANDOMX_FLAG_JIT flag mismatch");
@ -72,3 +73,17 @@ bool xmrig::RxCache::init(const Buffer &seed)
return true;
}
std::pair<uint32_t, uint32_t> xmrig::RxCache::hugePages() const
{
constexpr size_t twoMiB = 2u * 1024u * 1024u;
constexpr size_t total = VirtualMemory::align(maxSize(), twoMiB) / twoMiB;
uint32_t count = 0;
if (isHugePages()) {
count += total;
}
return { count, total };
}

View File

@ -55,8 +55,10 @@ public:
inline bool isJIT() const { return m_flags & 8; }
inline const Buffer &seed() const { return m_seed; }
inline randomx_cache *get() const { return m_cache; }
inline size_t size() const { return maxSize(); }
bool init(const Buffer &seed);
std::pair<uint32_t, uint32_t> hugePages() const;
static inline constexpr size_t maxSize() { return RANDOMX_CACHE_MAX_SIZE; }

View File

@ -23,41 +23,11 @@
*/
#include "base/io/json/Json.h"
#include "crypto/rx/RxConfig.h"
#include "rapidjson/document.h"
#include "backend/cpu/Cpu.h"
namespace xmrig {
static const char *kInit = "init";
static const char *kNUMA = "numa";
}
rapidjson::Value xmrig::RxConfig::toJSON(rapidjson::Document &doc) const
uint32_t xmrig::RxConfig::threads() 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;
return m_threads < 1 ? static_cast<uint32_t>(Cpu::info()->threads()) : static_cast<uint32_t>(m_threads);
}

View File

@ -29,6 +29,9 @@
#include "rapidjson/fwd.h"
#include <vector>
namespace xmrig {
@ -38,12 +41,22 @@ 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; }
# ifdef XMRIG_FEATURE_HWLOC
std::vector<uint32_t> nodeset() const;
# else
inline std::vector<uint32_t> nodeset() const { return std::vector<uint32_t>(); }
# endif
uint32_t threads() const;
private:
bool m_numa = true;
int m_threads = -1;
# ifdef XMRIG_FEATURE_HWLOC
std::vector<uint32_t> m_nodeset;
# endif
};

View File

@ -0,0 +1,59 @@
/* 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 "crypto/rx/RxConfig.h"
#include "base/io/json/Json.h"
#include "rapidjson/document.h"
namespace xmrig {
static const char *kInit = "init";
}
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);
return obj;
}
bool xmrig::RxConfig::read(const rapidjson::Value &value)
{
if (value.IsObject()) {
m_threads = Json::getInt(value, kInit, m_threads);
return true;
}
return false;
}

View File

@ -0,0 +1,100 @@
/* 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/Cpu.h"
#include "backend/cpu/platform/HwlocCpuInfo.h"
#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);
if (!m_nodeset.empty()) {
Value numa(kArrayType);
for (uint32_t i : m_nodeset) {
numa.PushBack(i, allocator);
}
obj.AddMember(StringRef(kNUMA), numa, allocator);
}
else {
obj.AddMember(StringRef(kNUMA), m_numa, allocator);
}
return obj;
}
bool xmrig::RxConfig::read(const rapidjson::Value &value)
{
if (value.IsObject()) {
m_threads = Json::getInt(value, kInit, m_threads);
const auto &numa = Json::getValue(value, kNUMA);
if (numa.IsArray()) {
m_nodeset.reserve(numa.Size());
for (const auto &node : numa.GetArray()) {
if (node.IsUint()) {
m_nodeset.emplace_back(node.GetUint());
}
}
}
else if (numa.IsBool()) {
m_numa = numa.GetBool();
}
return true;
}
return false;
}
std::vector<uint32_t> xmrig::RxConfig::nodeset() const
{
if (!m_nodeset.empty()) {
return m_nodeset;
}
return (m_numa && Cpu::info()->nodes() > 1) ? static_cast<HwlocCpuInfo *>(Cpu::info())->nodeset() : std::vector<uint32_t>();
}

View File

@ -25,32 +25,32 @@
*/
#include <thread>
#include "crypto/rx/RxDataset.h"
#include "crypto/common/VirtualMemory.h"
#include "crypto/randomx/randomx.h"
#include "crypto/rx/RxAlgo.h"
#include "crypto/rx/RxCache.h"
#include "crypto/rx/RxDataset.h"
#include <thread>
static_assert(RANDOMX_FLAG_LARGE_PAGES == 1, "RANDOMX_FLAG_LARGE_PAGES flag mismatch");
xmrig::RxDataset::RxDataset(bool hugePages)
xmrig::RxDataset::RxDataset(bool hugePages, bool cache)
{
if (hugePages) {
m_flags = RANDOMX_FLAG_LARGE_PAGES;
m_dataset = randomx_alloc_dataset(static_cast<randomx_flags>(m_flags));
}
allocate(hugePages);
if (!m_dataset) {
m_flags = RANDOMX_FLAG_DEFAULT;
m_dataset = randomx_alloc_dataset(static_cast<randomx_flags>(m_flags));
if (cache) {
m_cache = new RxCache(hugePages);
}
}
m_cache = new RxCache(hugePages);
xmrig::RxDataset::RxDataset(RxCache *cache) :
m_cache(cache)
{
}
@ -66,7 +66,11 @@ xmrig::RxDataset::~RxDataset()
bool xmrig::RxDataset::init(const Buffer &seed, uint32_t numThreads)
{
cache()->init(seed);
if (!m_cache) {
return false;
}
m_cache->init(seed);
if (!get()) {
return true;
@ -96,18 +100,39 @@ bool xmrig::RxDataset::init(const Buffer &seed, uint32_t numThreads)
}
std::pair<size_t, size_t> xmrig::RxDataset::hugePages() const
size_t xmrig::RxDataset::size(bool cache) const
{
constexpr size_t twoMiB = 2u * 1024u * 1024u;
constexpr const size_t total = (VirtualMemory::align(maxSize(), twoMiB) + VirtualMemory::align(RxCache::maxSize(), twoMiB)) / twoMiB;
size_t size = 0;
size_t count = 0;
if (isHugePages()) {
count += VirtualMemory::align(maxSize(), twoMiB) / twoMiB;
if (m_dataset) {
size += maxSize();
}
if (m_cache->isHugePages()) {
count += VirtualMemory::align(RxCache::maxSize(), twoMiB) / twoMiB;
if (cache && m_cache) {
size += RxCache::maxSize();
}
return size;
}
std::pair<uint32_t, uint32_t> xmrig::RxDataset::hugePages(bool cache) const
{
constexpr size_t twoMiB = 2u * 1024u * 1024u;
constexpr size_t cacheSize = VirtualMemory::align(RxCache::maxSize(), twoMiB) / twoMiB;
size_t total = VirtualMemory::align(maxSize(), twoMiB) / twoMiB;
uint32_t count = 0;
if (isHugePages()) {
count += total;
}
if (cache && m_cache) {
total += cacheSize;
if (m_cache->isHugePages()) {
count += cacheSize;
}
}
return { count, total };
@ -118,3 +143,27 @@ void *xmrig::RxDataset::raw() const
{
return m_dataset ? randomx_get_dataset_memory(m_dataset) : nullptr;
}
void xmrig::RxDataset::setRaw(const void *raw)
{
if (!m_dataset) {
return;
}
memcpy(randomx_get_dataset_memory(m_dataset), raw, maxSize());
}
void xmrig::RxDataset::allocate(bool hugePages)
{
if (hugePages) {
m_flags = RANDOMX_FLAG_LARGE_PAGES;
m_dataset = randomx_alloc_dataset(static_cast<randomx_flags>(m_flags));
}
if (!m_dataset) {
m_flags = RANDOMX_FLAG_DEFAULT;
m_dataset = randomx_alloc_dataset(static_cast<randomx_flags>(m_flags));
}
}

View File

@ -49,22 +49,26 @@ class RxDataset
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(RxDataset)
RxDataset(bool hugePages = true);
RxDataset(bool hugePages, bool cache);
RxDataset(RxCache *cache);
~RxDataset();
inline bool isHugePages() const { return m_flags & 1; }
inline randomx_dataset *get() const { return m_dataset; }
inline RxCache *cache() const { return m_cache; }
inline size_t size() const { return maxSize(); }
inline bool isHugePages() const { return m_flags & 1; }
inline randomx_dataset *get() const { return m_dataset; }
inline RxCache *cache() const { return m_cache; }
inline void setCache(RxCache *cache) { m_cache = cache; }
bool init(const Buffer &seed, uint32_t numThreads);
std::pair<size_t, size_t> hugePages() const;
size_t size(bool cache = true) const;
std::pair<uint32_t, uint32_t> hugePages(bool cache = true) const;
void *raw() const;
void setRaw(const void *raw);
static inline constexpr size_t maxSize() { return RANDOMX_DATASET_MAX_SIZE; }
private:
Algorithm m_algorithm;
void allocate(bool hugePages);
int m_flags = 0;
randomx_dataset *m_dataset = nullptr;
RxCache *m_cache = nullptr;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,66 @@
/* 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-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 tevador <tevador@gmail.com>
* 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_RX_NUMASTORAGE_H
#define XMRIG_RX_NUMASTORAGE_H
#include "backend/common/interfaces/IRxStorage.h"
#include "base/tools/Object.h"
#include <vector>
namespace xmrig
{
class RxNUMAStoragePrivate;
class RxNUMAStorage : public IRxStorage
{
public:
XMRIG_DISABLE_COPY_MOVE(RxNUMAStorage);
RxNUMAStorage(const std::vector<uint32_t> &nodeset);
~RxNUMAStorage() override;
protected:
RxDataset *dataset(const Job &job, uint32_t nodeId) const override;
std::pair<uint32_t, uint32_t> hugePages() const override;
void init(const RxSeed &seed, uint32_t threads, bool hugePages) override;
private:
RxNUMAStoragePrivate *d_ptr;
};
} /* namespace xmrig */
#endif /* XMRIG_RX_NUMASTORAGE_H */

Some files were not shown because too many files have changed in this diff Show More