Merged v4.0.0-beta
This commit is contained in:
commit
993733cb1f
231 changed files with 32642 additions and 3380 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "backend/common/Hashrate.h"
|
||||
#include "backend/common/interfaces/IWorker.h"
|
||||
#include "backend/common/Tags.h"
|
||||
#include "backend/common/Workers.h"
|
||||
#include "backend/cpu/Cpu.h"
|
||||
#include "backend/cpu/CpuBackend.h"
|
||||
|
@ -43,6 +44,11 @@
|
|||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
# include "base/api/interfaces/IApiRequest.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_ALGO_ARGON2
|
||||
# include "crypto/argon2/Impl.h"
|
||||
#endif
|
||||
|
@ -56,29 +62,63 @@ extern template class Threads<CpuThreads>;
|
|||
|
||||
static const char *tag = CYAN_BG_BOLD(" cpu ");
|
||||
static const String kType = "cpu";
|
||||
static std::mutex mutex;
|
||||
|
||||
|
||||
struct LaunchStatus
|
||||
struct CpuLaunchStatus
|
||||
{
|
||||
public:
|
||||
inline void reset()
|
||||
inline size_t hugePages() const { return m_hugePages; }
|
||||
inline size_t memory() const { return m_ways * m_memory; }
|
||||
inline size_t pages() const { return m_pages; }
|
||||
inline size_t threads() const { return m_threads; }
|
||||
inline size_t ways() const { return m_ways; }
|
||||
|
||||
inline void start(const std::vector<CpuLaunchData> &threads, size_t memory)
|
||||
{
|
||||
hugePages = 0;
|
||||
memory = 0;
|
||||
pages = 0;
|
||||
started = 0;
|
||||
threads = 0;
|
||||
ways = 0;
|
||||
ts = Chrono::steadyMSecs();
|
||||
m_hugePages = 0;
|
||||
m_memory = memory;
|
||||
m_pages = 0;
|
||||
m_started = 0;
|
||||
m_threads = threads.size();
|
||||
m_ways = 0;
|
||||
m_ts = Chrono::steadyMSecs();
|
||||
|
||||
for (const CpuLaunchData &data : threads) {
|
||||
m_ways += data.intensity;
|
||||
}
|
||||
}
|
||||
|
||||
size_t hugePages = 0;
|
||||
size_t memory = 0;
|
||||
size_t pages = 0;
|
||||
size_t started = 0;
|
||||
size_t threads = 0;
|
||||
size_t ways = 0;
|
||||
uint64_t ts = 0;
|
||||
inline bool started(const std::pair<size_t, size_t> &hugePages)
|
||||
{
|
||||
m_started++;
|
||||
m_hugePages += hugePages.first;
|
||||
m_pages += hugePages.second;
|
||||
|
||||
return m_started == m_threads;
|
||||
}
|
||||
|
||||
inline void print() const
|
||||
{
|
||||
LOG_INFO("%s" GREEN_BOLD(" READY") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"),
|
||||
tag,
|
||||
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_ways * m_memory / 1024,
|
||||
Chrono::steadyMSecs() - m_ts
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_hugePages = 0;
|
||||
size_t m_memory = 0;
|
||||
size_t m_pages = 0;
|
||||
size_t m_started = 0;
|
||||
size_t m_threads = 0;
|
||||
size_t m_ways = 0;
|
||||
uint64_t m_ts = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -100,16 +140,7 @@ public:
|
|||
algo.l3() / 1024
|
||||
);
|
||||
|
||||
workers.stop();
|
||||
|
||||
status.reset();
|
||||
status.memory = algo.l3();
|
||||
status.threads = threads.size();
|
||||
|
||||
for (const CpuLaunchData &data : threads) {
|
||||
status.ways += static_cast<size_t>(data.intensity);
|
||||
}
|
||||
|
||||
status.start(threads, algo.l3());
|
||||
workers.start(threads);
|
||||
}
|
||||
|
||||
|
@ -118,14 +149,45 @@ public:
|
|||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
return status.ways;
|
||||
return status.ways();
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value hugePages(int version, rapidjson::Document &doc)
|
||||
{
|
||||
std::pair<unsigned, unsigned> pages(0, 0);
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (algo.family() == Algorithm::RANDOM_X) {
|
||||
pages = Rx::hugePages();
|
||||
}
|
||||
# endif
|
||||
|
||||
mutex.lock();
|
||||
|
||||
pages.first += status.hugePages();
|
||||
pages.second += status.pages();
|
||||
|
||||
mutex.unlock();
|
||||
|
||||
rapidjson::Value hugepages;
|
||||
|
||||
if (version > 1) {
|
||||
hugepages.SetArray();
|
||||
hugepages.PushBack(pages.first, doc.GetAllocator());
|
||||
hugepages.PushBack(pages.second, doc.GetAllocator());
|
||||
}
|
||||
else {
|
||||
hugepages = pages.first == pages.second;
|
||||
}
|
||||
|
||||
return hugepages;
|
||||
}
|
||||
|
||||
|
||||
Algorithm algo;
|
||||
Controller *controller;
|
||||
LaunchStatus status;
|
||||
std::mutex mutex;
|
||||
CpuLaunchStatus status;
|
||||
std::vector<CpuLaunchData> threads;
|
||||
String profileName;
|
||||
Workers<CpuLaunchData> workers;
|
||||
|
@ -135,6 +197,12 @@ public:
|
|||
} // namespace xmrig
|
||||
|
||||
|
||||
const char *xmrig::cpu_tag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
xmrig::CpuBackend::CpuBackend(Controller *controller) :
|
||||
d_ptr(new CpuBackendPrivate(controller))
|
||||
{
|
||||
|
@ -148,25 +216,6 @@ xmrig::CpuBackend::~CpuBackend()
|
|||
}
|
||||
|
||||
|
||||
std::pair<unsigned, unsigned> xmrig::CpuBackend::hugePages() const
|
||||
{
|
||||
std::pair<unsigned, unsigned> pages(0, 0);
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (d_ptr->algo.family() == Algorithm::RANDOM_X) {
|
||||
pages = Rx::hugePages();
|
||||
}
|
||||
# endif
|
||||
|
||||
std::lock_guard<std::mutex> lock(d_ptr->mutex);
|
||||
|
||||
pages.first += d_ptr->status.hugePages;
|
||||
pages.second += d_ptr->status.pages;
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CpuBackend::isEnabled() const
|
||||
{
|
||||
return d_ptr->controller->config()->cpu().isEnabled();
|
||||
|
@ -219,11 +268,11 @@ void xmrig::CpuBackend::printHashrate(bool details)
|
|||
|
||||
char num[8 * 3] = { 0 };
|
||||
|
||||
Log::print(WHITE_BOLD_S "| CPU THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |");
|
||||
Log::print(WHITE_BOLD_S "| CPU # | AFFINITY | 10s H/s | 60s H/s | 15m H/s |");
|
||||
|
||||
size_t i = 0;
|
||||
for (const CpuLaunchData &data : d_ptr->threads) {
|
||||
Log::print("| %13zu | %8" PRId64 " | %7s | %7s | %7s |",
|
||||
Log::print("| %8zu | %8" PRId64 " | %7s | %7s | %7s |",
|
||||
i,
|
||||
data.affinity,
|
||||
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval), num, sizeof num / 3),
|
||||
|
@ -233,6 +282,14 @@ void xmrig::CpuBackend::printHashrate(bool details)
|
|||
|
||||
i++;
|
||||
}
|
||||
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
Log::print(WHITE_BOLD_S "| - | - | %7s | %7s | %7s |",
|
||||
Hashrate::format(hashrate()->calc(Hashrate::ShortInterval), num, sizeof num / 3),
|
||||
Hashrate::format(hashrate()->calc(Hashrate::MediumInterval), num + 8, sizeof num / 3),
|
||||
Hashrate::format(hashrate()->calc(Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3)
|
||||
);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -245,7 +302,7 @@ void xmrig::CpuBackend::setJob(const Job &job)
|
|||
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
|
||||
|
||||
std::vector<CpuLaunchData> threads = cpu.get(d_ptr->controller->miner(), job.algorithm());
|
||||
if (d_ptr->threads.size() == threads.size() && std::equal(d_ptr->threads.begin(), d_ptr->threads.end(), threads.begin())) {
|
||||
if (!d_ptr->threads.empty() && d_ptr->threads.size() == threads.size() && std::equal(d_ptr->threads.begin(), d_ptr->threads.end(), threads.begin())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -253,13 +310,13 @@ void xmrig::CpuBackend::setJob(const Job &job)
|
|||
d_ptr->profileName = cpu.threads().profileName(job.algorithm());
|
||||
|
||||
if (d_ptr->profileName.isNull() || threads.empty()) {
|
||||
d_ptr->workers.stop();
|
||||
LOG_WARN("%s " RED_BOLD("disabled") YELLOW(" (no suitable configuration found)"), tag);
|
||||
|
||||
LOG_WARN(YELLOW_BOLD_S "CPU disabled, no suitable configuration for algo %s", job.algorithm().shortName());
|
||||
|
||||
return;
|
||||
return stop();
|
||||
}
|
||||
|
||||
stop();
|
||||
|
||||
d_ptr->threads = std::move(threads);
|
||||
d_ptr->start();
|
||||
}
|
||||
|
@ -267,28 +324,13 @@ void xmrig::CpuBackend::setJob(const Job &job)
|
|||
|
||||
void xmrig::CpuBackend::start(IWorker *worker)
|
||||
{
|
||||
d_ptr->mutex.lock();
|
||||
mutex.lock();
|
||||
|
||||
const auto pages = worker->memory()->hugePages();
|
||||
|
||||
d_ptr->status.started++;
|
||||
d_ptr->status.hugePages += pages.first;
|
||||
d_ptr->status.pages += pages.second;
|
||||
|
||||
if (d_ptr->status.started == d_ptr->status.threads) {
|
||||
const double percent = d_ptr->status.hugePages == 0 ? 0.0 : static_cast<double>(d_ptr->status.hugePages) / d_ptr->status.pages * 100.0;
|
||||
const size_t memory = d_ptr->status.ways * d_ptr->status.memory / 1024;
|
||||
|
||||
LOG_INFO("%s" GREEN_BOLD(" READY") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"),
|
||||
tag,
|
||||
d_ptr->status.threads, d_ptr->status.ways,
|
||||
(d_ptr->status.hugePages == d_ptr->status.pages ? GREEN_BOLD_S : (d_ptr->status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
|
||||
d_ptr->status.hugePages, d_ptr->status.pages, percent, memory,
|
||||
Chrono::steadyMSecs() - d_ptr->status.ts
|
||||
);
|
||||
if (d_ptr->status.started(worker->memory()->hugePages())) {
|
||||
d_ptr->status.print();
|
||||
}
|
||||
|
||||
d_ptr->mutex.unlock();
|
||||
mutex.unlock();
|
||||
|
||||
worker->start();
|
||||
}
|
||||
|
@ -296,6 +338,10 @@ void xmrig::CpuBackend::start(IWorker *worker)
|
|||
|
||||
void xmrig::CpuBackend::stop()
|
||||
{
|
||||
if (d_ptr->threads.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uint64_t ts = Chrono::steadyMSecs();
|
||||
|
||||
d_ptr->workers.stop();
|
||||
|
@ -337,13 +383,7 @@ rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const
|
|||
out.AddMember("argon2-impl", argon2::Impl::name().toJSON(), allocator);
|
||||
# endif
|
||||
|
||||
const auto pages = hugePages();
|
||||
|
||||
rapidjson::Value hugepages(rapidjson::kArrayType);
|
||||
hugepages.PushBack(pages.first, allocator);
|
||||
hugepages.PushBack(pages.second, allocator);
|
||||
|
||||
out.AddMember("hugepages", hugepages, allocator);
|
||||
out.AddMember("hugepages", d_ptr->hugePages(2, doc), allocator);
|
||||
out.AddMember("memory", static_cast<uint64_t>(d_ptr->algo.isValid() ? (d_ptr->ways() * d_ptr->algo.l3()) : 0), allocator);
|
||||
|
||||
if (d_ptr->threads.empty() || !hashrate()) {
|
||||
|
@ -375,4 +415,12 @@ rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const
|
|||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CpuBackend::handleRequest(IApiRequest &request)
|
||||
{
|
||||
if (request.type() == IApiRequest::REQ_SUMMARY) {
|
||||
request.reply().AddMember("hugepages", d_ptr->hugePages(request.version(), request.doc()), request.doc().GetAllocator());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -46,8 +46,6 @@ public:
|
|||
CpuBackend(Controller *controller);
|
||||
~CpuBackend() override;
|
||||
|
||||
std::pair<unsigned, unsigned> hugePages() const;
|
||||
|
||||
protected:
|
||||
bool isEnabled() const override;
|
||||
bool isEnabled(const Algorithm &algorithm) const override;
|
||||
|
@ -63,6 +61,7 @@ protected:
|
|||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const override;
|
||||
void handleRequest(IApiRequest &request) override;
|
||||
# endif
|
||||
|
||||
private:
|
||||
|
|
|
@ -122,7 +122,7 @@ std::vector<xmrig::CpuLaunchData> xmrig::CpuConfig::get(const Miner *miner, cons
|
|||
out.reserve(threads.count());
|
||||
|
||||
for (const CpuThread &thread : threads.data()) {
|
||||
out.push_back(CpuLaunchData(miner, algorithm, *this, thread));
|
||||
out.emplace_back(miner, algorithm, *this, thread);
|
||||
}
|
||||
|
||||
return out;
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace xmrig {
|
|||
class CpuThread
|
||||
{
|
||||
public:
|
||||
inline constexpr CpuThread() {}
|
||||
inline constexpr CpuThread() = default;
|
||||
inline constexpr CpuThread(int64_t affinity, uint32_t intensity) : m_affinity(affinity), m_intensity(intensity) {}
|
||||
|
||||
CpuThread(const rapidjson::Value &value);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <cassert>
|
||||
#include <thread>
|
||||
|
||||
|
||||
|
@ -47,15 +47,15 @@
|
|||
|
||||
namespace xmrig {
|
||||
|
||||
static constexpr uint32_t kReserveCount = 4096;
|
||||
static constexpr uint32_t kReserveCount = 32768;
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
||||
template<size_t N>
|
||||
xmrig::CpuWorker<N>::CpuWorker(size_t index, const CpuLaunchData &data) :
|
||||
Worker(index, data.affinity, data.priority),
|
||||
xmrig::CpuWorker<N>::CpuWorker(size_t id, const CpuLaunchData &data) :
|
||||
Worker(id, data.affinity, data.priority),
|
||||
m_algorithm(data.algorithm),
|
||||
m_assembly(data.assembly),
|
||||
m_hwAES(data.hwAES),
|
||||
|
@ -121,7 +121,6 @@ bool xmrig::CpuWorker<N>::selfTest()
|
|||
verify(Algorithm::CN_XAO, test_output_xao) &&
|
||||
verify(Algorithm::CN_RTO, test_output_rto) &&
|
||||
verify(Algorithm::CN_HALF, test_output_half) &&
|
||||
verify2(Algorithm::CN_WOW, test_output_wow) &&
|
||||
verify2(Algorithm::CN_R, test_output_r) &&
|
||||
verify(Algorithm::CN_RWZ, test_output_rwz) &&
|
||||
verify(Algorithm::CN_ZLS, test_output_zls) &&
|
||||
|
@ -214,11 +213,11 @@ void xmrig::CpuWorker<N>::start()
|
|||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < job.target()) {
|
||||
JobResults::submit(JobResult(job, *m_job.nonce(i), m_hash + (i * 32)));
|
||||
JobResults::submit(job, *m_job.nonce(i), m_hash + (i * 32));
|
||||
}
|
||||
}
|
||||
|
||||
m_job.nextRound(kReserveCount);
|
||||
m_job.nextRound(kReserveCount, 1);
|
||||
m_count += N;
|
||||
|
||||
std::this_thread::yield();
|
||||
|
@ -305,6 +304,10 @@ void xmrig::CpuWorker<N>::allocateCnCtx()
|
|||
template<size_t N>
|
||||
void xmrig::CpuWorker<N>::consumeJob()
|
||||
{
|
||||
if (Nonce::sequence(Nonce::CPU) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_job.add(m_miner->job(), Nonce::sequence(Nonce::CPU), kReserveCount);
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "backend/common/Worker.h"
|
||||
#include "backend/common/WorkerJob.h"
|
||||
#include "backend/cpu/CpuLaunchData.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "net/JobResult.h"
|
||||
|
||||
|
||||
|
@ -44,7 +44,9 @@ template<size_t N>
|
|||
class CpuWorker : public Worker
|
||||
{
|
||||
public:
|
||||
CpuWorker(size_t index, const CpuLaunchData &data);
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(CpuWorker)
|
||||
|
||||
CpuWorker(size_t id, const CpuLaunchData &data);
|
||||
~CpuWorker() override;
|
||||
|
||||
protected:
|
||||
|
@ -71,7 +73,7 @@ private:
|
|||
const CnHash::AlgoVariant m_av;
|
||||
const Miner *m_miner;
|
||||
cryptonight_ctx *m_ctx[N];
|
||||
uint8_t m_hash[N * 32];
|
||||
uint8_t m_hash[N * 32]{ 0 };
|
||||
VirtualMemory *m_memory = nullptr;
|
||||
WorkerJob<N> m_job;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue