Display backend for shares.

This commit is contained in:
XMRig 2019-10-29 15:43:13 +07:00
parent b1eac17d60
commit 23ebcfb2db
14 changed files with 121 additions and 32 deletions

View file

@ -27,10 +27,15 @@
#define XMRIG_TAGS_H #define XMRIG_TAGS_H
#include <cstdint>
namespace xmrig { namespace xmrig {
const char *backend_tag(uint32_t backend);
const char *cpu_tag(); const char *cpu_tag();
const char *net_tag();
#ifdef XMRIG_FEATURE_OPENCL #ifdef XMRIG_FEATURE_OPENCL

View file

@ -26,7 +26,7 @@
#define XMRIG_WORKERJOB_H #define XMRIG_WORKERJOB_H
#include <string.h> #include <cstring>
#include "base/net/stratum/Job.h" #include "base/net/stratum/Job.h"
@ -47,9 +47,9 @@ public:
inline uint8_t index() const { return m_index; } inline uint8_t index() const { return m_index; }
inline void add(const Job &job, uint64_t sequence, uint32_t reserveCount) inline void add(const Job &job, uint32_t reserveCount, Nonce::Backend backend)
{ {
m_sequence = sequence; m_sequence = Nonce::sequence(backend);
if (currentJob() == job) { if (currentJob() == job) {
return; return;
@ -60,7 +60,7 @@ public:
return; return;
} }
save(job, reserveCount); save(job, reserveCount, backend);
} }
@ -82,13 +82,15 @@ public:
private: private:
inline void save(const Job &job, uint32_t reserveCount) inline void save(const Job &job, uint32_t reserveCount, Nonce::Backend backend)
{ {
m_index = job.index(); m_index = job.index();
const size_t size = job.size(); const size_t size = job.size();
m_jobs[index()] = job; m_jobs[index()] = job;
m_rounds[index()] = 0; m_rounds[index()] = 0;
m_jobs[index()].setBackend(backend);
for (size_t i = 0; i < N; ++i) { for (size_t i = 0; i < N; ++i) {
memcpy(m_blobs[index()] + (i * size), job.blob(), size); memcpy(m_blobs[index()] + (i * size), job.blob(), size);
*nonce(i) = Nonce::next(index(), *nonce(i), reserveCount, job.isNicehash()); *nonce(i) = Nonce::next(index(), *nonce(i), reserveCount, job.isNicehash());
@ -96,7 +98,7 @@ private:
} }
alignas(16) uint8_t m_blobs[2][Job::kMaxBlobSize * N]; alignas(16) uint8_t m_blobs[2][Job::kMaxBlobSize * N]{};
Job m_jobs[2]; Job m_jobs[2];
uint32_t m_rounds[2] = { 0, 0 }; uint32_t m_rounds[2] = { 0, 0 };
uint64_t m_sequence = 0; uint64_t m_sequence = 0;
@ -126,12 +128,14 @@ inline void xmrig::WorkerJob<1>::nextRound(uint32_t rounds, uint32_t roundSize)
template<> template<>
inline void xmrig::WorkerJob<1>::save(const Job &job, uint32_t reserveCount) inline void xmrig::WorkerJob<1>::save(const Job &job, uint32_t reserveCount, Nonce::Backend backend)
{ {
m_index = job.index(); m_index = job.index();
m_jobs[index()] = job; m_jobs[index()] = job;
m_rounds[index()] = 0; m_rounds[index()] = 0;
m_jobs[index()].setBackend(backend);
memcpy(blob(), job.blob(), job.size()); memcpy(blob(), job.blob(), job.size());
*nonce() = Nonce::next(index(), *nonce(), reserveCount, currentJob().isNicehash()); *nonce() = Nonce::next(index(), *nonce(), reserveCount, currentJob().isNicehash());
} }

View file

@ -210,6 +210,24 @@ public:
} // namespace xmrig } // namespace xmrig
const char *xmrig::backend_tag(uint32_t backend)
{
# ifdef XMRIG_FEATURE_OPENCL
if (backend == Nonce::OPENCL) {
return ocl_tag();
}
# endif
# ifdef XMRIG_FEATURE_CUDA
if (backend == Nonce::CUDA) {
return cuda_tag();
}
# endif
return tag;
}
const char *xmrig::cpu_tag() const char *xmrig::cpu_tag()
{ {
return tag; return tag;

View file

@ -303,7 +303,7 @@ void xmrig::CpuWorker<N>::consumeJob()
return; return;
} }
m_job.add(m_miner->job(), Nonce::sequence(Nonce::CPU), kReserveCount); m_job.add(m_miner->job(), kReserveCount, Nonce::CPU);
# ifdef XMRIG_ALGO_RANDOMX # ifdef XMRIG_ALGO_RANDOMX
if (m_job.currentJob().algorithm().family() == Algorithm::RANDOM_X) { if (m_job.currentJob().algorithm().family() == Algorithm::RANDOM_X) {

View file

@ -153,7 +153,7 @@ bool xmrig::CudaWorker::consumeJob()
} }
const size_t batch_size = intensity(); const size_t batch_size = intensity();
m_job.add(m_miner->job(), Nonce::sequence(Nonce::CUDA), roundSize(batch_size) * batch_size); m_job.add(m_miner->job(), roundSize(batch_size) * batch_size, Nonce::CUDA);
return m_runner->set(m_job.currentJob(), m_job.blob());; return m_runner->set(m_job.currentJob(), m_job.blob());;
} }

View file

@ -206,7 +206,7 @@ bool xmrig::OclWorker::consumeJob()
return false; return false;
} }
m_job.add(m_miner->job(), Nonce::sequence(Nonce::OPENCL), roundSize(m_intensity) * m_intensity); m_job.add(m_miner->job(), roundSize(m_intensity) * m_intensity, Nonce::OPENCL);
try { try {
m_runner->set(m_job.currentJob(), m_job.blob()); m_runner->set(m_job.currentJob(), m_job.blob());

View file

@ -214,7 +214,7 @@ int64_t xmrig::Client::submit(const JobResult &result)
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id); m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
# else # else
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff()); m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), 0, result.backend);
# endif # endif
return send(doc); return send(doc);

View file

@ -119,7 +119,7 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id); m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
# else # else
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff()); m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), 0, result.backend);
# endif # endif
send(HTTP_POST, kJsonRPC, doc); send(HTTP_POST, kJsonRPC, doc);

View file

@ -157,6 +157,7 @@ void xmrig::Job::copy(const Job &other)
m_size = other.m_size; m_size = other.m_size;
m_clientId = other.m_clientId; m_clientId = other.m_clientId;
m_id = other.m_id; m_id = other.m_id;
m_backend = other.m_backend;
m_diff = other.m_diff; m_diff = other.m_diff;
m_height = other.m_height; m_height = other.m_height;
m_target = other.m_target; m_target = other.m_target;
@ -174,3 +175,34 @@ void xmrig::Job::copy(const Job &other)
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget)); memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
# endif # endif
} }
void xmrig::Job::move(Job &&other)
{
m_algorithm = other.m_algorithm;
m_nicehash = other.m_nicehash;
m_size = other.m_size;
m_clientId = std::move(other.m_clientId);
m_id = std::move(other.m_id);
m_backend = other.m_backend;
m_diff = other.m_diff;
m_height = other.m_height;
m_target = other.m_target;
m_index = other.m_index;
m_seed = std::move(other.m_seed);
m_extraNonce = std::move(other.m_extraNonce);
m_poolWallet = std::move(other.m_poolWallet);
memcpy(m_blob, other.m_blob, sizeof(m_blob));
other.m_size = 0;
other.m_diff = 0;
other.m_algorithm = Algorithm::INVALID;
# ifdef XMRIG_PROXY_PROJECT
m_rawSeedHash = std::move(other.m_rawSeedHash);
memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob));
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
# endif
}

View file

@ -50,6 +50,10 @@ public:
Job() = default; Job() = default;
Job(bool nicehash, const Algorithm &algorithm, const String &clientId); Job(bool nicehash, const Algorithm &algorithm, const String &clientId);
inline Job(const Job &other) { copy(other); }
inline Job(Job &&other) noexcept { move(std::move(other)); }
~Job() = default; ~Job() = default;
bool isEqual(const Job &other) const; bool isEqual(const Job &other) const;
@ -71,6 +75,7 @@ public:
inline const uint8_t *blob() const { return m_blob; } inline const uint8_t *blob() const { return m_blob; }
inline size_t size() const { return m_size; } inline size_t size() const { return m_size; }
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); } inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
inline uint32_t backend() const { return m_backend; }
inline uint64_t diff() const { return m_diff; } inline uint64_t diff() const { return m_diff; }
inline uint64_t height() const { return m_height; } inline uint64_t height() const { return m_height; }
inline uint64_t target() const { return m_target; } inline uint64_t target() const { return m_target; }
@ -79,6 +84,7 @@ public:
inline void reset() { m_size = 0; m_diff = 0; } inline void reset() { m_size = 0; m_diff = 0; }
inline void setAlgorithm(const Algorithm::Id id) { m_algorithm = id; } inline void setAlgorithm(const Algorithm::Id id) { m_algorithm = id; }
inline void setAlgorithm(const char *algo) { m_algorithm = algo; } inline void setAlgorithm(const char *algo) { m_algorithm = algo; }
inline void setBackend(uint32_t backend) { m_backend = backend; }
inline void setClientId(const String &id) { m_clientId = id; } inline void setClientId(const String &id) { m_clientId = id; }
inline void setExtraNonce(const String &extraNonce) { m_extraNonce = extraNonce; } inline void setExtraNonce(const String &extraNonce) { m_extraNonce = extraNonce; }
inline void setHeight(uint64_t height) { m_height = height; } inline void setHeight(uint64_t height) { m_height = height; }
@ -95,12 +101,14 @@ public:
static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); } static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); }
static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; } static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; }
inline bool operator==(const Job &other) const { return isEqual(other); }
inline bool operator!=(const Job &other) const { return !isEqual(other); } inline bool operator!=(const Job &other) const { return !isEqual(other); }
inline bool operator==(const Job &other) const { return isEqual(other); }
inline Job &operator=(const Job &other) { copy(other); return *this; } inline Job &operator=(const Job &other) { copy(other); return *this; }
inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; }
private: private:
void copy(const Job &other); void copy(const Job &other);
void move(Job &&other);
Algorithm m_algorithm; Algorithm m_algorithm;
bool m_nicehash = false; bool m_nicehash = false;
@ -110,6 +118,7 @@ private:
String m_extraNonce; String m_extraNonce;
String m_id; String m_id;
String m_poolWallet; String m_poolWallet;
uint32_t m_backend = 0;
uint64_t m_diff = 0; uint64_t m_diff = 0;
uint64_t m_height = 0; uint64_t m_height = 0;
uint64_t m_target = 0; uint64_t m_target = 0;

View file

@ -37,9 +37,10 @@ class SubmitResult
public: public:
SubmitResult() = default; SubmitResult() = default;
inline SubmitResult(int64_t seq, uint64_t diff, uint64_t actualDiff, int64_t reqId = 0) : inline SubmitResult(int64_t seq, uint64_t diff, uint64_t actualDiff, int64_t reqId, uint32_t backend) :
reqId(reqId), reqId(reqId),
seq(seq), seq(seq),
backend(backend),
actualDiff(actualDiff), actualDiff(actualDiff),
diff(diff), diff(diff),
m_start(Chrono::steadyMSecs()) m_start(Chrono::steadyMSecs())
@ -49,6 +50,7 @@ public:
int64_t reqId = 0; int64_t reqId = 0;
int64_t seq = 0; int64_t seq = 0;
uint32_t backend = 0;
uint64_t actualDiff = 0; uint64_t actualDiff = 0;
uint64_t diff = 0; uint64_t diff = 0;
uint64_t elapsed = 0; uint64_t elapsed = 0;

View file

@ -35,7 +35,7 @@ namespace xmrig {
class Nonce class Nonce
{ {
public: public:
enum Backend { enum Backend : uint32_t {
CPU, CPU,
OPENCL, OPENCL,
CUDA, CUDA,

View file

@ -47,6 +47,7 @@ public:
algorithm(job.algorithm()), algorithm(job.algorithm()),
clientId(job.clientId()), clientId(job.clientId()),
jobId(job.id()), jobId(job.id()),
backend(job.backend()),
nonce(nonce), nonce(nonce),
diff(job.diff()), diff(job.diff()),
index(job.index()) index(job.index())
@ -61,9 +62,10 @@ public:
const Algorithm algorithm; const Algorithm algorithm;
const String clientId; const String clientId;
const String jobId; const String jobId;
const uint32_t nonce = 0; const uint32_t backend;
const uint64_t diff = 0; const uint32_t nonce;
const uint8_t index = 0; const uint64_t diff;
const uint8_t index;
private: private:
uint8_t m_result[32] = { 0 }; uint8_t m_result[32] = { 0 };

View file

@ -34,6 +34,7 @@
#include <memory> #include <memory>
#include "backend/common/Tags.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/net/stratum/Client.h" #include "base/net/stratum/Client.h"
#include "base/net/stratum/SubmitResult.h" #include "base/net/stratum/SubmitResult.h"
@ -55,6 +56,22 @@
#endif #endif
namespace xmrig {
static const char *tag = BLUE_BG_BOLD(WHITE_BOLD_S " net ");
} // namespace xmrig
const char *xmrig::net_tag()
{
return tag;
}
xmrig::Network::Network(Controller *controller) : xmrig::Network::Network(Controller *controller) :
m_controller(controller), m_controller(controller),
m_donate(nullptr), m_donate(nullptr),
@ -97,19 +114,19 @@ void xmrig::Network::connect()
void xmrig::Network::onActive(IStrategy *strategy, IClient *client) void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
{ {
if (m_donate && m_donate == strategy) { if (m_donate && m_donate == strategy) {
LOG_NOTICE("dev donate started"); LOG_NOTICE("%s " WHITE_BOLD("dev donate started"), tag);
return; return;
} }
m_state.onActive(client); m_state.onActive(client);
const char *tlsVersion = client->tlsVersion(); const char *tlsVersion = client->tlsVersion();
LOG_INFO(WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"), LOG_INFO("%s " WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
client->mode(), client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data()); tag, client->mode(), client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data());
const char *fingerprint = client->tlsFingerprint(); const char *fingerprint = client->tlsFingerprint();
if (fingerprint != nullptr) { if (fingerprint != nullptr) {
LOG_INFO(BLACK_BOLD("fingerprint (SHA-256): \"%s\""), fingerprint); LOG_INFO("%s " BLACK_BOLD("fingerprint (SHA-256): \"%s\""), tag, fingerprint);
} }
} }
@ -178,12 +195,12 @@ void xmrig::Network::onLogin(IStrategy *, IClient *client, rapidjson::Document &
void xmrig::Network::onPause(IStrategy *strategy) void xmrig::Network::onPause(IStrategy *strategy)
{ {
if (m_donate && m_donate == strategy) { if (m_donate && m_donate == strategy) {
LOG_NOTICE("dev donate finished"); LOG_NOTICE("%s " WHITE_BOLD("dev donate finished"), tag);
m_strategy->resume(); m_strategy->resume();
} }
if (!m_strategy->isActive()) { if (!m_strategy->isActive()) {
LOG_ERR("no active pools, stop mining"); LOG_ERR("%s " RED("no active pools, stop mining"), tag);
m_state.stop(); m_state.stop();
return m_controller->miner()->pause(); return m_controller->miner()->pause();
@ -196,12 +213,12 @@ void xmrig::Network::onResultAccepted(IStrategy *, IClient *, const SubmitResult
m_state.add(result, error); m_state.add(result, error);
if (error) { if (error) {
LOG_INFO(RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"), LOG_INFO("%s " RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"),
m_state.accepted, m_state.rejected, result.diff, error, result.elapsed); backend_tag(result.backend), m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
} }
else { else {
LOG_INFO(GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " BLACK_BOLD("(%" PRIu64 " ms)"), LOG_INFO("%s " GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " BLACK_BOLD("(%" PRIu64 " ms)"),
m_state.accepted, m_state.rejected, result.diff, result.elapsed); backend_tag(result.backend), m_state.accepted, m_state.rejected, result.diff, result.elapsed);
} }
} }
@ -232,12 +249,12 @@ void xmrig::Network::onRequest(IApiRequest &request)
void xmrig::Network::setJob(IClient *client, const Job &job, bool donate) void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
{ {
if (job.height()) { if (job.height()) {
LOG_INFO(MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s") " height " WHITE_BOLD("%" PRIu64), LOG_INFO("%s " MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s") " height " WHITE_BOLD("%" PRIu64),
client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName(), job.height()); tag, client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName(), job.height());
} }
else { else {
LOG_INFO(MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s"), LOG_INFO("%s " MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s"),
client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName()); tag, client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName());
} }
if (!donate && m_donate) { if (!donate && m_donate) {