diff --git a/src/backend/common/interfaces/IWorker.h b/src/backend/common/interfaces/IWorker.h index dcc925dcd..979d998ff 100644 --- a/src/backend/common/interfaces/IWorker.h +++ b/src/backend/common/interfaces/IWorker.h @@ -35,6 +35,7 @@ namespace xmrig { class VirtualMemory; class Job; +class Config; class IWorker @@ -48,7 +49,7 @@ public: virtual size_t intensity() const = 0; virtual uint64_t rawHashes() const = 0; virtual void getHashrateData(uint64_t&, uint64_t&) const = 0; - virtual void start() = 0; + virtual void start(Config*) = 0; virtual void jobEarlyNotification(const Job&) = 0; # ifdef XMRIG_FEATURE_BENCHMARK diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index ecce64fe1..a847567ae 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -390,7 +390,7 @@ void xmrig::CpuBackend::start(IWorker *worker, bool ready) mutex.unlock(); if (ready) { - worker->start(); + worker->start(d_ptr->controller->config()); } } diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index fd1a5932b..4c7781c3c 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -30,6 +30,7 @@ #include "backend/cpu/CpuWorker.h" #include "base/tools/Chrono.h" +#include "core/config/Config.h" #include "core/Miner.h" #include "crypto/cn/CnCtx.h" #include "crypto/cn/CryptoNight_test.h" @@ -198,7 +199,7 @@ bool xmrig::CpuWorker::selfTest() template -void xmrig::CpuWorker::start() +void xmrig::CpuWorker::start(xmrig::Config* config) { while (Nonce::sequence(Nonce::CPU) > 0) { if (Nonce::isPaused()) { @@ -219,6 +220,10 @@ void xmrig::CpuWorker::start() alignas(16) uint64_t tempHash[8] = {}; # endif +# ifdef XMRIG_FEATURE_BENCHMARK + const size_t benchThreads = config->cpu().threads().get(m_job.currentJob().algorithm()).count(); +# endif + while (!Nonce::isOutdated(Nonce::CPU, m_job.sequence())) { const Job &job = m_job.currentJob(); @@ -231,6 +236,29 @@ void xmrig::CpuWorker::start() current_job_nonces[i] = *m_job.nonce(i); } +# ifdef XMRIG_FEATURE_BENCHMARK + if (m_benchSize) { + bool done = true; + for (size_t i = 0; i < N; ++i) { + if (current_job_nonces[i] < m_benchSize) { + done = false; + break; + } + } + + // Stop benchmark when all hashes have been counted + if (done) { + m_benchDoneTime = Chrono::steadyMSecs(); + return; + } + + // Make each hash dependent on the previous one in single thread benchmark to prevent cheating with multiple threads + if (benchThreads == 1) { + *(uint64_t*)(m_job.blob()) ^= m_benchData; + } + } +# endif + bool valid = true; # ifdef XMRIG_ALGO_RANDOMX @@ -274,10 +302,6 @@ void xmrig::CpuWorker::start() if (current_job_nonces[i] < m_benchSize) { m_benchData ^= value; } - else { - m_benchDoneTime = Chrono::steadyMSecs(); - return; - } } else # endif diff --git a/src/backend/cpu/CpuWorker.h b/src/backend/cpu/CpuWorker.h index 087156c24..a43837812 100644 --- a/src/backend/cpu/CpuWorker.h +++ b/src/backend/cpu/CpuWorker.h @@ -43,6 +43,7 @@ namespace xmrig { class RxVm; +class Config; template @@ -56,7 +57,7 @@ public: protected: bool selfTest() override; - void start() override; + void start(Config*) override; inline const VirtualMemory *memory() const override { return m_memory; } inline size_t intensity() const override { return N; } diff --git a/src/backend/cuda/CudaBackend.cpp b/src/backend/cuda/CudaBackend.cpp index ab5b22e53..f347aacfd 100644 --- a/src/backend/cuda/CudaBackend.cpp +++ b/src/backend/cuda/CudaBackend.cpp @@ -481,7 +481,7 @@ void xmrig::CudaBackend::start(IWorker *worker, bool ready) mutex.unlock(); if (ready) { - worker->start(); + worker->start(d_ptr->controller->config()); } } diff --git a/src/backend/cuda/CudaWorker.cpp b/src/backend/cuda/CudaWorker.cpp index 7bb8844c1..9e34e8500 100644 --- a/src/backend/cuda/CudaWorker.cpp +++ b/src/backend/cuda/CudaWorker.cpp @@ -145,7 +145,7 @@ size_t xmrig::CudaWorker::intensity() const } -void xmrig::CudaWorker::start() +void xmrig::CudaWorker::start(xmrig::Config*) { while (Nonce::sequence(Nonce::CUDA) > 0) { if (!isReady()) { diff --git a/src/backend/cuda/CudaWorker.h b/src/backend/cuda/CudaWorker.h index e82e34254..9ccdc519b 100644 --- a/src/backend/cuda/CudaWorker.h +++ b/src/backend/cuda/CudaWorker.h @@ -39,6 +39,7 @@ namespace xmrig { class ICudaRunner; +class Config; class CudaWorker : public Worker @@ -58,7 +59,7 @@ public: protected: bool selfTest() override; size_t intensity() const override; - void start() override; + void start(Config*) override; private: bool consumeJob(); diff --git a/src/backend/opencl/OclBackend.cpp b/src/backend/opencl/OclBackend.cpp index 7b99700b5..04bc2cdb5 100644 --- a/src/backend/opencl/OclBackend.cpp +++ b/src/backend/opencl/OclBackend.cpp @@ -463,7 +463,7 @@ void xmrig::OclBackend::start(IWorker *worker, bool ready) mutex.unlock(); if (ready) { - worker->start(); + worker->start(d_ptr->controller->config()); } } diff --git a/src/backend/opencl/OclWorker.cpp b/src/backend/opencl/OclWorker.cpp index ac493ab55..ca6cfaccf 100644 --- a/src/backend/opencl/OclWorker.cpp +++ b/src/backend/opencl/OclWorker.cpp @@ -163,7 +163,7 @@ size_t xmrig::OclWorker::intensity() const } -void xmrig::OclWorker::start() +void xmrig::OclWorker::start(xmrig::Config*) { cl_uint results[0x100]; diff --git a/src/backend/opencl/OclWorker.h b/src/backend/opencl/OclWorker.h index 403a0765d..d43ccf561 100644 --- a/src/backend/opencl/OclWorker.h +++ b/src/backend/opencl/OclWorker.h @@ -40,6 +40,7 @@ namespace xmrig { class IOclRunner; class Job; +class Config; class OclWorker : public Worker @@ -59,7 +60,7 @@ public: protected: bool selfTest() override; size_t intensity() const override; - void start() override; + void start(Config*) override; private: bool consumeJob(); diff --git a/src/crypto/randomx/jit_compiler_x86.cpp b/src/crypto/randomx/jit_compiler_x86.cpp index 88c1ce4ef..182de1fa6 100644 --- a/src/crypto/randomx/jit_compiler_x86.cpp +++ b/src/crypto/randomx/jit_compiler_x86.cpp @@ -297,7 +297,7 @@ namespace randomx { } void JitCompilerX86::generateProgramPrologue(Program& prog, ProgramConfiguration& pcfg) { - codePos = ((uint8_t*)randomx_program_prologue_first_load) - ((uint8_t*)randomx_program_prologue); + codePos = ADDR(randomx_program_prologue_first_load) - ADDR(randomx_program_prologue); code[codePos + 2] = 0xc0 + pcfg.readReg0; code[codePos + 5] = 0xc0 + pcfg.readReg1; *(uint32_t*)(code + codePos + 10) = RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated;