From c828e6b79330783094df785846fa07bab04e3d53 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 May 2020 01:55:00 +0700 Subject: [PATCH] Code cleanup. --- cmake/randomx.cmake | 1 + src/base/kernel/config/BaseConfig.cpp | 2 +- src/base/kernel/config/BaseConfig.h | 2 - src/core/Miner.cpp | 78 +++++++++++++-------------- src/core/Miner.h | 1 - src/crypto/astrobwt/AstroBWT.cpp | 43 +++++++-------- src/crypto/astrobwt/AstroBWT.h | 3 +- 7 files changed, 61 insertions(+), 69 deletions(-) diff --git a/cmake/randomx.cmake b/cmake/randomx.cmake index 85e18fe3..0d3f7bab 100644 --- a/cmake/randomx.cmake +++ b/cmake/randomx.cmake @@ -1,5 +1,6 @@ if (WITH_RANDOMX) add_definitions(/DXMRIG_ALGO_RANDOMX) + set(WITH_ARGON2 ON) list(APPEND HEADERS_CRYPTO src/crypto/rx/Rx.h diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index 1fe2d1ed..e2023d76 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -89,13 +89,13 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) m_watch = reader.getBool(kWatch, m_watch); m_logFile = reader.getString(kLogFile); m_userAgent = reader.getString(kUserAgent); + m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U); # ifdef XMRIG_FEATURE_TLS m_tls = reader.getValue(kTls); # endif Log::setColors(reader.getBool(kColors, Log::isColors())); - setPrintTime(reader.getUint(kPrintTime, 60)); setVerbose(reader.getValue(kVerbose)); const auto &api = reader.getObject(kApi); diff --git a/src/base/kernel/config/BaseConfig.h b/src/base/kernel/config/BaseConfig.h index c7e69308..5335dd6c 100644 --- a/src/base/kernel/config/BaseConfig.h +++ b/src/base/kernel/config/BaseConfig.h @@ -112,8 +112,6 @@ protected: # endif private: - inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } } - void setVerbose(const rapidjson::Value &value); }; diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 78beeb8e..a56eafce 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -40,7 +40,6 @@ #include "base/tools/Timer.h" #include "core/config/Config.h" #include "core/Controller.h" -#include "crypto/astrobwt/AstroBWT.h" #include "crypto/common/Nonce.h" #include "crypto/rx/Rx.h" #include "version.h" @@ -67,6 +66,11 @@ #endif +#ifdef XMRIG_ALGO_ASTROBWT +# include "crypto/astrobwt/AstroBWT.h" +#endif + + namespace xmrig { @@ -238,15 +242,36 @@ public: # endif + void printHashrate(bool details) + { + char num[8 * 4] = { 0 }; + double speed[3] = { 0.0 }; + + for (auto backend : backends) { + const auto hashrate = backend->hashrate(); + if (hashrate) { + speed[0] += hashrate->calc(Hashrate::ShortInterval); + speed[1] += hashrate->calc(Hashrate::MediumInterval); + speed[2] += hashrate->calc(Hashrate::LargeInterval); + } + + backend->printHashrate(details); + } + + LOG_INFO(WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s"), + Hashrate::format(speed[0], num, sizeof(num) / 4), + Hashrate::format(speed[1], num + 8, sizeof(num) / 4), + Hashrate::format(speed[2], num + 8 * 2, sizeof(num) / 4 ), + Hashrate::format(maxHashrate[algorithm], num + 8 * 3, sizeof(num) / 4) + ); + } + + # ifdef XMRIG_ALGO_RANDOMX inline bool initRX() { return Rx::init(job, controller->config()->rx(), controller->config()->cpu()); } # endif -# ifdef XMRIG_ALGO_ASTROBWT - inline bool initAstroBWT() { return astrobwt::init(job); } -# endif - Algorithm algorithm; Algorithms algorithms; bool active = false; @@ -279,6 +304,10 @@ xmrig::Miner::Miner(Controller *controller) Rx::init(this); # endif +# ifdef XMRIG_ALGO_ASTROBWT + astrobwt::init(); +# endif + controller->addListener(this); # ifdef XMRIG_FEATURE_API @@ -345,7 +374,7 @@ void xmrig::Miner::execCommand(char command) switch (command) { case 'h': case 'H': - printHashrate(true); + d_ptr->printHashrate(true); break; case 'p': @@ -384,31 +413,6 @@ void xmrig::Miner::pause() } -void xmrig::Miner::printHashrate(bool details) -{ - char num[8 * 4] = { 0 }; - double speed[3] = { 0.0 }; - - for (IBackend *backend : d_ptr->backends) { - const Hashrate *hashrate = backend->hashrate(); - if (hashrate) { - speed[0] += hashrate->calc(Hashrate::ShortInterval); - speed[1] += hashrate->calc(Hashrate::MediumInterval); - speed[2] += hashrate->calc(Hashrate::LargeInterval); - } - - backend->printHashrate(details); - } - - LOG_INFO(WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s"), - Hashrate::format(speed[0], num, sizeof(num) / 4), - Hashrate::format(speed[1], num + 8, sizeof(num) / 4), - Hashrate::format(speed[2], num + 8 * 2, sizeof(num) / 4 ), - Hashrate::format(d_ptr->maxHashrate[d_ptr->algorithm], num + 8 * 3, sizeof(num) / 4) - ); -} - - void xmrig::Miner::setEnabled(bool enabled) { if (d_ptr->enabled == enabled) { @@ -459,14 +463,10 @@ void xmrig::Miner::setJob(const Job &job, bool donate) d_ptr->userJobId = job.id(); } - bool ready = true; - # ifdef XMRIG_ALGO_RANDOMX - ready &= d_ptr->initRX(); -# endif - -# ifdef XMRIG_ALGO_ASTROBWT - ready &= d_ptr->initAstroBWT(); + const bool ready = d_ptr->initRX(); +# else + constexpr const bool ready = true; # endif mutex.unlock(); @@ -524,7 +524,7 @@ void xmrig::Miner::onTimer(const Timer *) const auto printTime = d_ptr->controller->config()->printTime(); if (printTime && d_ptr->ticks && (d_ptr->ticks % (printTime * 2)) == 0) { - printHashrate(false); + d_ptr->printHashrate(false); } d_ptr->ticks++; diff --git a/src/core/Miner.h b/src/core/Miner.h index b529d969..1de19c4a 100644 --- a/src/core/Miner.h +++ b/src/core/Miner.h @@ -61,7 +61,6 @@ public: Job job() const; void execCommand(char command); void pause(); - void printHashrate(bool details); void setEnabled(bool enabled); void setJob(const Job &job, bool donate); void stop(); diff --git a/src/crypto/astrobwt/AstroBWT.cpp b/src/crypto/astrobwt/AstroBWT.cpp index 47949e4c..c692bddd 100644 --- a/src/crypto/astrobwt/AstroBWT.cpp +++ b/src/crypto/astrobwt/AstroBWT.cpp @@ -27,15 +27,15 @@ */ -#include "AstroBWT.h" -#include "sha3.h" -#include "crypto/cn/CryptoNight.h" -#include "base/net/stratum/Job.h" -#include "base/crypto/Algorithm.h" -#include "base/io/log/Log.h" +#include "crypto/astrobwt/AstroBWT.h" #include "backend/cpu/Cpu.h" +#include "crypto/astrobwt/sha3.h" +#include "crypto/cn/CryptoNight.h" + + #include + constexpr int STAGE1_SIZE = 147253; constexpr int ALLOCATION_SIZE = (STAGE1_SIZE + 1048576) + (128 - (STAGE1_SIZE & 63)); @@ -171,24 +171,6 @@ void sort_indices(int N, const uint8_t* v, uint64_t* indices, uint64_t* tmp_indi } } -bool xmrig::astrobwt::init(const xmrig::Job& job) -{ - if (job.algorithm().family() != xmrig::Algorithm::ASTROBWT) - return true; - - if (astrobwtInitialized) - return true; - -#ifdef ASTROBWT_AVX2 - if (xmrig::Cpu::info()->hasAVX2()) { - hasAVX2 = true; - } -#endif - - astrobwtInitialized = true; - return true; -} - bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size, bool avx2) { uint8_t key[32]; @@ -257,6 +239,19 @@ bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size, return true; } + +void xmrig::astrobwt::init() +{ + if (!astrobwtInitialized) { +# ifdef ASTROBWT_AVX2 + hasAVX2 = Cpu::info()->hasAVX2(); +# endif + + astrobwtInitialized = true; + } +} + + template<> void xmrig::astrobwt::single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t) { diff --git a/src/crypto/astrobwt/AstroBWT.h b/src/crypto/astrobwt/AstroBWT.h index e10dc8a5..4e526060 100644 --- a/src/crypto/astrobwt/AstroBWT.h +++ b/src/crypto/astrobwt/AstroBWT.h @@ -35,12 +35,11 @@ struct cryptonight_ctx; namespace xmrig { -class Job; namespace astrobwt { -bool init(const Job&); bool astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size, bool avx2); +void init(); template void single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t);