mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 03:59:41 +00:00
Added RxNUMAStorage stub.
This commit is contained in:
parent
7508411faf
commit
207dae418d
7 changed files with 275 additions and 8 deletions
|
@ -68,8 +68,13 @@ if (WITH_RANDOMX)
|
|||
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
|
||||
|
|
|
@ -200,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) {
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
using hwloc_const_bitmap_t = const struct hwloc_bitmap_s *;
|
||||
using hwloc_obj_t = struct hwloc_obj *;
|
||||
using hwloc_topology_t = struct hwloc_topology *;
|
||||
|
||||
|
@ -56,6 +57,8 @@ public:
|
|||
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;
|
||||
|
||||
|
|
|
@ -46,6 +46,11 @@
|
|||
#include "crypto/rx/RxSeed.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HWLOC
|
||||
# include "crypto/rx/RxNUMAStorage.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
@ -94,11 +99,19 @@ public:
|
|||
inline void asyncSend() { --m_pending; if (pending() == 0) { uv_async_send(m_async); } }
|
||||
|
||||
|
||||
inline IRxStorage *storage()
|
||||
inline IRxStorage *storage(const std::vector<uint32_t> &nodeset)
|
||||
{
|
||||
if (!m_storage) {
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
if (!nodeset.empty()) {
|
||||
m_storage = new RxNUMAStorage(nodeset);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
m_storage = new RxBasicStorage();
|
||||
}
|
||||
}
|
||||
|
||||
return m_storage;
|
||||
}
|
||||
|
@ -116,7 +129,7 @@ public:
|
|||
Buffer::toHex(seed.data().data(), 8).data()
|
||||
);
|
||||
|
||||
d_ptr->storage()->init(seed, threads, hugePages);
|
||||
d_ptr->storage(nodeset)->init(seed, threads, hugePages);
|
||||
d_ptr->asyncSend();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_RX_VM_H
|
||||
#define XMRIG_RX_VM_H
|
||||
#ifndef XMRIG_RX_BASICSTORAGE_H
|
||||
#define XMRIG_RX_BASICSTORAGE_H
|
||||
|
||||
|
||||
#include "backend/common/interfaces/IRxStorage.h"
|
||||
|
@ -60,4 +60,4 @@ private:
|
|||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_RX_VM_H */
|
||||
#endif /* XMRIG_RX_BASICSTORAGE_H */
|
||||
|
|
166
src/crypto/rx/RxNUMAStorage.cpp
Normal file
166
src/crypto/rx/RxNUMAStorage.cpp
Normal file
|
@ -0,0 +1,166 @@
|
|||
/* 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/RxNUMAStorage.h"
|
||||
#include "backend/common/Tags.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "crypto/rx/RxAlgo.h"
|
||||
#include "crypto/rx/RxCache.h"
|
||||
#include "crypto/rx/RxDataset.h"
|
||||
#include "crypto/rx/RxSeed.h"
|
||||
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
constexpr size_t oneMiB = 1024 * 1024;
|
||||
|
||||
|
||||
class RxNUMAStoragePrivate
|
||||
{
|
||||
public:
|
||||
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, uint64_t ts)
|
||||
{
|
||||
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%u/%u %1.0f%%" CLEAR " %sJIT" BLACK_BOLD(" (%" PRIu64 " ms)"),
|
||||
rx_tag(),
|
||||
(RxDataset::maxSize() + RxCache::maxSize()) / oneMiB,
|
||||
RxDataset::maxSize() / oneMiB,
|
||||
RxCache::maxSize() / oneMiB,
|
||||
(pages.first == pages.second ? GREEN_BOLD_S : (pages.first == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
|
||||
pages.first,
|
||||
pages.second,
|
||||
percent,
|
||||
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;
|
||||
std::map<uint32_t, RxDataset *> m_datasets;
|
||||
std::vector<uint32_t> m_nodeset;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::RxNUMAStorage::RxNUMAStorage(const std::vector<uint32_t> &nodeset) :
|
||||
d_ptr(new RxNUMAStoragePrivate())
|
||||
{
|
||||
LOG_WARN(">>>>>> %zu", nodeset.size()); // FIXME
|
||||
}
|
||||
|
||||
|
||||
xmrig::RxNUMAStorage::~RxNUMAStorage()
|
||||
{
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
|
||||
xmrig::RxDataset *xmrig::RxNUMAStorage::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::RxNUMAStorage::hugePages() const
|
||||
{
|
||||
if (!d_ptr->dataset()) {
|
||||
return { 0u, 0u };
|
||||
}
|
||||
|
||||
return d_ptr->dataset()->hugePages();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::RxNUMAStorage::init(const RxSeed &seed, uint32_t threads, bool hugePages)
|
||||
{
|
||||
const uint64_t ts = Chrono::steadyMSecs();
|
||||
|
||||
d_ptr->setSeed(seed);
|
||||
|
||||
if (!d_ptr->dataset()) {
|
||||
d_ptr->createDataset(hugePages);
|
||||
}
|
||||
|
||||
d_ptr->initDataset(threads, ts);
|
||||
}
|
66
src/crypto/rx/RxNUMAStorage.h
Normal file
66
src/crypto/rx/RxNUMAStorage.h
Normal 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 */
|
Loading…
Reference in a new issue