mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-22 19:49:36 +00:00
Code cleanup.
This commit is contained in:
parent
4326ba3c38
commit
c828e6b793
7 changed files with 61 additions and 69 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 <limits>
|
||||
|
||||
|
||||
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<xmrig::Algorithm::ASTROBWT_DERO>(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t)
|
||||
{
|
||||
|
|
|
@ -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<Algorithm::Id ALGO>
|
||||
void single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t);
|
||||
|
|
Loading…
Reference in a new issue